Search in sources :

Example 11 with RenderableChunk

use of org.terasology.world.chunks.RenderableChunk in project Terasology by MovingBlocks.

the class OpaqueBlocksNode method process.

/**
 * Renders the world's opaque blocks, effectively, the world's landscape.
 * Does not render semi-transparent blocks, i.e. semi-transparent vegetation.
 *
 * If RenderingDebugConfig.isRenderChunkBoundingBoxes() returns true
 * this method also draws wireframe boxes around chunks, displaying
 * their boundaries.
 *
 * Finally, takes advantage of the two methods
 *
 * - WorldRenderer.increaseTrianglesCount(int)
 * - WorldRenderer.increaseNotReadyChunkCount(int)
 *
 * to publish some statistics over its own activity.
 */
@Override
public void process() {
    PerformanceMonitor.startActivity("rendering/" + getUri());
    // Common Shader Parameters
    chunkMaterial.setFloat("time", worldProvider.getTime().getDays(), true);
    // Specific Shader Parameters
    chunkMaterial.setFloat("clip", 0.0f, true);
    if (normalMappingIsEnabled) {
        if (parallaxMappingIsEnabled) {
            chunkMaterial.setFloat4("parallaxProperties", parallaxBias, parallaxScale, 0.0f, 0.0f, true);
        }
    }
    // Actual Node Processing
    final Vector3f cameraPosition = activeCamera.getPosition();
    int numberOfRenderedTriangles = 0;
    int numberOfChunksThatAreNotReadyYet = 0;
    while (renderQueues.chunksOpaque.size() > 0) {
        RenderableChunk chunk = renderQueues.chunksOpaque.poll();
        if (chunk.hasMesh()) {
            final ChunkMesh chunkMesh = chunk.getMesh();
            final Vector3f chunkPosition = chunk.getPosition().toVector3f();
            chunkMesh.updateMaterial(chunkMaterial, chunkPosition, chunk.isAnimated());
            numberOfRenderedTriangles += chunkMesh.render(OPAQUE, chunkPosition, cameraPosition);
            if (renderingDebugConfig.isRenderChunkBoundingBoxes()) {
                renderChunkBoundingBox(chunk, chunkPosition, cameraPosition);
            }
        } else {
            numberOfChunksThatAreNotReadyYet++;
        }
    }
    worldRenderer.increaseTrianglesCount(numberOfRenderedTriangles);
    worldRenderer.increaseNotReadyChunkCount(numberOfChunksThatAreNotReadyYet);
    PerformanceMonitor.endActivity();
}
Also used : ChunkMesh(org.terasology.rendering.primitives.ChunkMesh) Vector3f(org.terasology.math.geom.Vector3f) RenderableChunk(org.terasology.world.chunks.RenderableChunk)

Example 12 with RenderableChunk

use of org.terasology.world.chunks.RenderableChunk in project Terasology by MovingBlocks.

the class RefractiveReflectiveBlocksNode method process.

/**
 * This method is where the actual rendering of refractive/reflective blocks takes place.
 *
 * Also takes advantage of the two methods
 *
 * - WorldRenderer.increaseTrianglesCount(int)
 * - WorldRenderer.increaseNotReadyChunkCount(int)
 *
 * to publish some statistics over its own activity.
 */
@Override
public void process() {
    PerformanceMonitor.startActivity("rendering/" + getUri());
    chunkMaterial.activateFeature(ShaderProgramFeature.FEATURE_REFRACTIVE_PASS);
    // Common Shader Parameters
    sunDirection = backdropProvider.getSunDirection(false);
    chunkMaterial.setFloat("daylight", backdropProvider.getDaylight(), true);
    chunkMaterial.setFloat("swimming", activeCamera.isUnderWater() ? 1.0f : 0.0f, true);
    chunkMaterial.setFloat("time", worldProvider.getTime().getDays(), true);
    chunkMaterial.setFloat3("sunVec", sunDirection, true);
    // Specific Shader Parameters
    // TODO: This is necessary right now because activateFeature removes all material parameters.
    // TODO: Remove this explicit binding once we get rid of activateFeature, or find a way to retain parameters through it.
    chunkMaterial.setInt("textureAtlas", 0, true);
    chunkMaterial.setInt("textureEffects", 1, true);
    chunkMaterial.setInt("textureWater", 2, true);
    chunkMaterial.setInt("textureWaterNormal", 3, true);
    chunkMaterial.setInt("textureWaterNormalAlt", 4, true);
    chunkMaterial.setInt("textureWaterReflection", 5, true);
    chunkMaterial.setInt("texSceneOpaque", 6, true);
    if (normalMappingIsEnabled) {
        chunkMaterial.setInt("textureAtlasNormal", 7, true);
        if (parallaxMappingIsEnabled) {
            chunkMaterial.setInt("textureAtlasHeight", 8, true);
            chunkMaterial.setFloat4("parallaxProperties", parallaxBias, parallaxScale, 0.0f, 0.0f, true);
        }
    }
    chunkMaterial.setFloat4("lightingSettingsFrag", 0, 0, waterSpecExp, 0, true);
    chunkMaterial.setFloat4("waterSettingsFrag", waterNormalBias, waterRefraction, waterFresnelBias, waterFresnelPow, true);
    chunkMaterial.setFloat4("alternativeWaterSettingsFrag", waterTint, 0, 0, 0, true);
    if (animatedWaterIsEnabled) {
        chunkMaterial.setFloat("waveIntensityFalloff", waveIntensityFalloff, true);
        chunkMaterial.setFloat("waveSizeFalloff", waveSizeFalloff, true);
        chunkMaterial.setFloat("waveSize", waveSize, true);
        chunkMaterial.setFloat("waveSpeedFalloff", waveSpeedFalloff, true);
        chunkMaterial.setFloat("waveSpeed", waveSpeed, true);
        chunkMaterial.setFloat("waveIntensity", waveIntensity, true);
        chunkMaterial.setFloat("waterOffsetY", waterOffsetY, true);
        chunkMaterial.setFloat("waveOverallScale", waveOverallScale, true);
    }
    // Actual Node Processing
    int numberOfRenderedTriangles = 0;
    int numberOfChunksThatAreNotReadyYet = 0;
    final Vector3f cameraPosition = activeCamera.getPosition();
    while (renderQueues.chunksAlphaBlend.size() > 0) {
        RenderableChunk chunk = renderQueues.chunksAlphaBlend.poll();
        if (chunk.hasMesh()) {
            final ChunkMesh chunkMesh = chunk.getMesh();
            final Vector3f chunkPosition = chunk.getPosition().toVector3f();
            chunkMesh.updateMaterial(chunkMaterial, chunkPosition, chunk.isAnimated());
            numberOfRenderedTriangles += chunkMesh.render(REFRACTIVE, chunkPosition, cameraPosition);
        } else {
            numberOfChunksThatAreNotReadyYet++;
        }
    }
    worldRenderer.increaseTrianglesCount(numberOfRenderedTriangles);
    worldRenderer.increaseNotReadyChunkCount(numberOfChunksThatAreNotReadyYet);
    chunkMaterial.deactivateFeature(ShaderProgramFeature.FEATURE_REFRACTIVE_PASS);
    PerformanceMonitor.endActivity();
}
Also used : ChunkMesh(org.terasology.rendering.primitives.ChunkMesh) Vector3f(org.terasology.math.geom.Vector3f) RenderableChunk(org.terasology.world.chunks.RenderableChunk)

Example 13 with RenderableChunk

use of org.terasology.world.chunks.RenderableChunk in project Terasology by MovingBlocks.

the class WorldProviderCoreImpl method setBiome.

@Override
public Biome setBiome(Vector3i worldPos, Biome biome) {
    Vector3i chunkPos = ChunkMath.calcChunkPos(worldPos);
    CoreChunk chunk = chunkProvider.getChunk(chunkPos);
    if (chunk != null) {
        Vector3i blockPos = ChunkMath.calcBlockPos(worldPos);
        Biome oldBiomeType = chunk.setBiome(blockPos.x, blockPos.y, blockPos.z, biome);
        if (oldBiomeType != biome) {
            BiomeChange oldChange = biomeChanges.get(worldPos);
            if (oldChange == null) {
                biomeChanges.put(worldPos, new BiomeChange(worldPos, oldBiomeType, biome));
            } else {
                oldChange.setTo(biome);
            }
            for (Vector3i pos : ChunkMath.getChunkRegionAroundWorldPos(worldPos, 1)) {
                RenderableChunk dirtiedChunk = chunkProvider.getChunk(pos);
                if (dirtiedChunk != null) {
                    dirtiedChunk.setDirty(true);
                }
            }
            notifyBiomeChanged(worldPos, biome, oldBiomeType);
        }
        return oldBiomeType;
    }
    return null;
}
Also used : CoreChunk(org.terasology.world.chunks.CoreChunk) Biome(org.terasology.world.biomes.Biome) BiomeChange(org.terasology.world.propagation.BiomeChange) Vector3i(org.terasology.math.geom.Vector3i) RenderableChunk(org.terasology.world.chunks.RenderableChunk)

Example 14 with RenderableChunk

use of org.terasology.world.chunks.RenderableChunk in project Terasology by MovingBlocks.

the class WorldProviderCoreImpl method setBlocks.

@Override
public Map<Vector3i, Block> setBlocks(Map<Vector3i, Block> blocks) {
    /*
         * Hint: This method has a benchmark available in the BenchmarkScreen, The screen can be opened ingame via the
         * command "showSCreen BenchmarkScreen".
         */
    Set<RenderableChunk> dirtiedChunks = new HashSet<>();
    Set<BlockChange> changedBlocks = new HashSet<>();
    Map<Vector3i, Block> result = new HashMap<>(blocks.size());
    for (Map.Entry<Vector3i, Block> entry : blocks.entrySet()) {
        Vector3i worldPos = entry.getKey();
        Vector3i chunkPos = ChunkMath.calcChunkPos(worldPos);
        CoreChunk chunk = chunkProvider.getChunk(chunkPos);
        if (chunk != null) {
            Block type = entry.getValue();
            Vector3i blockPos = ChunkMath.calcBlockPos(worldPos);
            Block oldBlockType = chunk.setBlock(blockPos, type);
            if (oldBlockType != type) {
                BlockChange oldChange = blockChanges.get(worldPos);
                if (oldChange == null) {
                    blockChanges.put(worldPos, new BlockChange(worldPos, oldBlockType, type));
                } else {
                    oldChange.setTo(type);
                }
                for (Vector3i pos : ChunkMath.getChunkRegionAroundWorldPos(worldPos, 1)) {
                    RenderableChunk dirtiedChunk = chunkProvider.getChunk(pos);
                    if (dirtiedChunk != null) {
                        dirtiedChunks.add(dirtiedChunk);
                    }
                }
                changedBlocks.add(new BlockChange(worldPos, oldBlockType, type));
            }
            result.put(worldPos, oldBlockType);
        } else {
            result.put(worldPos, null);
        }
    }
    for (RenderableChunk chunk : dirtiedChunks) {
        chunk.setDirty(true);
    }
    for (BlockChange change : changedBlocks) {
        notifyBlockChanged(change.getPosition(), change.getTo(), change.getFrom());
    }
    return result;
}
Also used : CoreChunk(org.terasology.world.chunks.CoreChunk) BlockChange(org.terasology.world.propagation.BlockChange) HashMap(java.util.HashMap) RenderableChunk(org.terasology.world.chunks.RenderableChunk) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

RenderableChunk (org.terasology.world.chunks.RenderableChunk)14 ChunkMesh (org.terasology.rendering.primitives.ChunkMesh)8 Vector3i (org.terasology.math.geom.Vector3i)6 Vector3f (org.terasology.math.geom.Vector3f)5 CoreChunk (org.terasology.world.chunks.CoreChunk)3 Block (org.terasology.world.block.Block)2 BlockChange (org.terasology.world.propagation.BlockChange)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Region3i (org.terasology.math.Region3i)1 ChunkView (org.terasology.world.ChunkView)1 Biome (org.terasology.world.biomes.Biome)1 BiomeChange (org.terasology.world.propagation.BiomeChange)1