Search in sources :

Example 1 with RenderableChunk

use of org.terasology.engine.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;
    renderQueues.clear();
    ChunkMesh mesh;
    boolean isDynamicShadows = renderingConfig.isDynamicShadows();
    int billboardLimit = (int) renderingConfig.getBillboardLimit();
    List<RenderableChunk> allChunks = new ArrayList<>(chunksInProximityOfCamera);
    allChunks.addAll(chunkMeshRenderer.getRenderableChunks());
    if (lodChunkProvider != null) {
        lodChunkProvider.addAllChunks(allChunks);
    }
    for (RenderableChunk chunk : allChunks) {
        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 && (billboardLimit == 0 || chunkCounter < billboardLimit)) {
                    renderQueues.chunksAlphaReject.add(chunk);
                } else {
                    statIgnoredPhases++;
                }
                statVisibleChunks++;
                chunk.setAnimated(statVisibleChunks < MAX_ANIMATED_CHUNKS);
            }
            if (isChunkVisibleReflection(chunk)) {
                renderQueues.chunksOpaqueReflection.add(chunk);
            }
        }
        chunkCounter++;
    }
    if (isFirstRenderingStageForCurrentFrame) {
        for (Chunk chunk : chunksInProximityOfCamera) {
            if (isChunkValidForRender(chunk) && (chunk.isDirty() || !chunk.hasMesh())) {
                statDirtyChunks++;
                chunkMeshUpdateManager.queueChunkUpdate(chunk);
                processedChunks++;
            }
        }
    }
    PerformanceMonitor.endActivity();
    return processedChunks;
}
Also used : ChunkMesh(org.terasology.engine.rendering.primitives.ChunkMesh) RenderableChunk(org.terasology.engine.world.chunks.RenderableChunk) ArrayList(java.util.ArrayList) RenderableChunk(org.terasology.engine.world.chunks.RenderableChunk) Chunk(org.terasology.engine.world.chunks.Chunk)

Aggregations

ArrayList (java.util.ArrayList)1 ChunkMesh (org.terasology.engine.rendering.primitives.ChunkMesh)1 Chunk (org.terasology.engine.world.chunks.Chunk)1 RenderableChunk (org.terasology.engine.world.chunks.RenderableChunk)1