Search in sources :

Example 1 with RenderableChunk

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

the class RenderableWorldImpl method onChunkUnloaded.

@Override
public void onChunkUnloaded(Vector3i chunkCoordinates) {
    if (renderableRegion.encompasses(chunkCoordinates)) {
        RenderableChunk chunk;
        Iterator<RenderableChunk> iterator = chunksInProximityOfCamera.iterator();
        while (iterator.hasNext()) {
            chunk = iterator.next();
            if (chunk.getPosition().equals(chunkCoordinates)) {
                chunk.disposeMesh();
                iterator.remove();
                break;
            }
        }
    }
}
Also used : RenderableChunk(org.terasology.world.chunks.RenderableChunk)

Example 2 with RenderableChunk

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

the class RenderableWorldImpl method updateChunksInProximity.

/**
 * Updates the list of chunks around the player.
 *
 * @return True if the list was changed
 */
@Override
public boolean updateChunksInProximity(Region3i newRenderableRegion) {
    if (!newRenderableRegion.equals(renderableRegion)) {
        Vector3i chunkPosition;
        RenderableChunk chunk;
        Iterator<Vector3i> chunksToRemove = renderableRegion.subtract(newRenderableRegion);
        while (chunksToRemove.hasNext()) {
            chunkPosition = chunksToRemove.next();
            Iterator<RenderableChunk> nearbyChunks = chunksInProximityOfCamera.iterator();
            while (nearbyChunks.hasNext()) {
                chunk = nearbyChunks.next();
                if (chunk.getPosition().equals(chunkPosition)) {
                    chunk.disposeMesh();
                    nearbyChunks.remove();
                    break;
                }
            }
        }
        boolean chunksHaveBeenAdded = false;
        Iterator<Vector3i> chunksToAdd = newRenderableRegion.subtract(renderableRegion);
        while (chunksToAdd.hasNext()) {
            chunkPosition = chunksToAdd.next();
            chunk = chunkProvider.getChunk(chunkPosition);
            if (chunk != null) {
                chunksInProximityOfCamera.add(chunk);
                chunksHaveBeenAdded = true;
            }
        }
        if (chunksHaveBeenAdded) {
            Collections.sort(chunksInProximityOfCamera, new ChunkFrontToBackComparator());
        }
        renderableRegion = newRenderableRegion;
        return true;
    }
    return false;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) RenderableChunk(org.terasology.world.chunks.RenderableChunk)

Example 3 with RenderableChunk

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

the class RenderableWorldImpl method pregenerateChunks.

/**
 * @return true if pregeneration is complete
 */
@Override
public boolean pregenerateChunks() {
    boolean pregenerationIsComplete = true;
    chunkProvider.completeUpdate();
    chunkProvider.beginUpdate();
    RenderableChunk chunk;
    ChunkMesh newMesh;
    ChunkView localView;
    for (Vector3i chunkCoordinates : calculateRenderableRegion(renderingConfig.getViewDistance())) {
        chunk = chunkProvider.getChunk(chunkCoordinates);
        if (chunk == null) {
            pregenerationIsComplete = false;
        } else if (chunk.isDirty()) {
            localView = worldProvider.getLocalView(chunkCoordinates);
            if (localView == null) {
                continue;
            }
            chunk.setDirty(false);
            newMesh = chunkTessellator.generateMesh(localView, ChunkConstants.SIZE_Y, 0);
            newMesh.generateVBOs();
            if (chunk.hasMesh()) {
                chunk.getMesh().dispose();
            }
            chunk.setMesh(newMesh);
            pregenerationIsComplete = false;
            break;
        }
    }
    return pregenerationIsComplete;
}
Also used : ChunkMesh(org.terasology.rendering.primitives.ChunkMesh) RenderableChunk(org.terasology.world.chunks.RenderableChunk) Vector3i(org.terasology.math.geom.Vector3i) ChunkView(org.terasology.world.ChunkView)

Example 4 with RenderableChunk

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

the class RenderableWorldImpl method queueVisibleChunks.

/**
 * Updates the currently visible chunks (in sight of the player).
 */
@Override
public int queueVisibleChunks(boolean isFirstRenderingStageForCurrentFrame) {
    PerformanceMonitor.startActivity("Queueing Visible Chunks");
    statDirtyChunks = 0;
    statVisibleChunks = 0;
    statIgnoredPhases = 0;
    int processedChunks = 0;
    int chunkCounter = 0;
    ChunkMesh mesh;
    boolean isDynamicShadows = renderingConfig.isDynamicShadows();
    for (RenderableChunk chunk : chunksInProximityOfCamera) {
        if (isChunkValidForRender(chunk)) {
            mesh = chunk.getMesh();
            if (isDynamicShadows && isFirstRenderingStageForCurrentFrame && chunkCounter < maxChunksForShadows && isChunkVisibleFromMainLight(chunk)) {
                if (triangleCount(mesh, ChunkMesh.RenderPhase.OPAQUE) > 0) {
                    renderQueues.chunksOpaqueShadow.add(chunk);
                } else {
                    statIgnoredPhases++;
                }
            }
            if (isChunkVisible(chunk)) {
                if (triangleCount(mesh, ChunkMesh.RenderPhase.OPAQUE) > 0) {
                    renderQueues.chunksOpaque.add(chunk);
                } else {
                    statIgnoredPhases++;
                }
                if (triangleCount(mesh, ChunkMesh.RenderPhase.REFRACTIVE) > 0) {
                    renderQueues.chunksAlphaBlend.add(chunk);
                } else {
                    statIgnoredPhases++;
                }
                if (triangleCount(mesh, ChunkMesh.RenderPhase.ALPHA_REJECT) > 0 && chunkCounter < MAX_BILLBOARD_CHUNKS) {
                    renderQueues.chunksAlphaReject.add(chunk);
                } else {
                    statIgnoredPhases++;
                }
                statVisibleChunks++;
                if (statVisibleChunks < MAX_ANIMATED_CHUNKS) {
                    chunk.setAnimated(true);
                } else {
                    chunk.setAnimated(false);
                }
            }
            if (isChunkVisibleReflection(chunk)) {
                renderQueues.chunksOpaqueReflection.add(chunk);
            }
            // Process all chunks in the area, not only the visible ones
            if (isFirstRenderingStageForCurrentFrame && (chunk.isDirty() || !chunk.hasMesh())) {
                statDirtyChunks++;
                chunkMeshUpdateManager.queueChunkUpdate(chunk);
                processedChunks++;
            }
        }
        chunkCounter++;
    }
    PerformanceMonitor.endActivity();
    return processedChunks;
}
Also used : ChunkMesh(org.terasology.rendering.primitives.ChunkMesh) RenderableChunk(org.terasology.world.chunks.RenderableChunk)

Example 5 with RenderableChunk

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

the class AlphaRejectBlocksNode method process.

/**
 * Renders the world's semi-transparent blocks, i.e. tree foliage and terrain plants.
 * Does not render fully opaque blocks, i.e. the typical landscape blocks.
 *
 * 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_ALPHA_REJECT);
    // Common Shader Parameters
    chunkMaterial.setFloat("time", worldProvider.getTime().getDays(), 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("textureLava", 2, true);
    if (normalMappingIsEnabled) {
        chunkMaterial.setInt("textureAtlasNormal", 3, true);
        if (parallaxMappingIsEnabled) {
            chunkMaterial.setInt("textureAtlasHeight", 4, true);
            chunkMaterial.setFloat4("parallaxProperties", parallaxBias, parallaxScale, 0.0f, 0.0f, true);
        }
    }
    chunkMaterial.setFloat("clip", 0.0f, true);
    // Actual Node Processing
    final Vector3f cameraPosition = activeCamera.getPosition();
    int numberOfRenderedTriangles = 0;
    int numberOfChunksThatAreNotReadyYet = 0;
    while (renderQueues.chunksAlphaReject.size() > 0) {
        RenderableChunk chunk = renderQueues.chunksAlphaReject.poll();
        if (chunk.hasMesh()) {
            final ChunkMesh chunkMesh = chunk.getMesh();
            final Vector3f chunkPosition = chunk.getPosition().toVector3f();
            chunkMesh.updateMaterial(chunkMaterial, chunkPosition, chunk.isAnimated());
            numberOfRenderedTriangles += chunkMesh.render(ALPHA_REJECT, chunkPosition, cameraPosition);
        } else {
            // TODO: verify - should we count them only in ChunksOpaqueNode?
            numberOfChunksThatAreNotReadyYet++;
        }
    }
    worldRenderer.increaseTrianglesCount(numberOfRenderedTriangles);
    worldRenderer.increaseNotReadyChunkCount(numberOfChunksThatAreNotReadyYet);
    chunkMaterial.deactivateFeature(ShaderProgramFeature.FEATURE_ALPHA_REJECT);
    PerformanceMonitor.endActivity();
}
Also used : ChunkMesh(org.terasology.rendering.primitives.ChunkMesh) Vector3f(org.terasology.math.geom.Vector3f) RenderableChunk(org.terasology.world.chunks.RenderableChunk)

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