rasterized occlusion culling #38
No files matched your search
+2
@@ -347,6 +347,8 @@ public abstract class RenderSectionManager {
|
|||||||
|
|
||||||
protected abstract boolean useFogOcclusion();
|
protected abstract boolean useFogOcclusion();
|
||||||
|
|
||||||
|
protected abstract boolean useRasterOcclusionCulling();
|
||||||
|
|
||||||
private float getSearchDistance(@Nullable Matrix4fc projectionMatrix) {
|
private float getSearchDistance(@Nullable Matrix4fc projectionMatrix) {
|
||||||
float distance;
|
float distance;
|
||||||
|
|
||||||
|
|||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
package org.embeddedt.embeddium.impl.render.chunk.occlusion;
|
||||||
|
|
||||||
|
import org.embeddedt.embeddium.impl.render.chunk.occlusion.geometry.BoxFinder;
|
||||||
|
import org.embeddedt.embeddium.impl.render.chunk.occlusion.geometry.OccluderBoxes;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.BitSet;
|
||||||
|
|
||||||
|
// Separate from SectionVisibilityBuilder so a platform whose game already computes the visibility encoding
|
||||||
|
// can keep using that and supply opacity here instead of paying for a second flood fill it doesn't need
|
||||||
|
public final class OccluderBoxBuilder {
|
||||||
|
private final BitSet blocks = new BitSet(SectionVisibilityBuilder.TOTAL_BLOCKS);
|
||||||
|
|
||||||
|
public void markOpaque(int x, int y, int z) {
|
||||||
|
this.blocks.set(SectionVisibilityBuilder.getIndex(x & 15, y & 15, z & 15));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int @Nullable [] build() {
|
||||||
|
return boxesFrom(this.blocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int @Nullable [] boxesFrom(BitSet blocks) {
|
||||||
|
if (blocks.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OccluderBoxes.from(Arrays.copyOf(blocks.toLongArray(), BoxFinder.INTERIOR_CACHE_WORDS));
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-10
@@ -2,11 +2,8 @@ package org.embeddedt.embeddium.impl.render.chunk.occlusion;
|
|||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayFIFOQueue;
|
import it.unimi.dsi.fastutil.ints.IntArrayFIFOQueue;
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.occlusion.geometry.BoxFinder;
|
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.occlusion.geometry.OccluderBoxes;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,7 +13,7 @@ import java.util.BitSet;
|
|||||||
public class SectionVisibilityBuilder {
|
public class SectionVisibilityBuilder {
|
||||||
private static final int SECTION_AXIS_SIZE = 16;
|
private static final int SECTION_AXIS_SIZE = 16;
|
||||||
private static final int SECTION_AXIS_MASK = SECTION_AXIS_SIZE - 1;
|
private static final int SECTION_AXIS_MASK = SECTION_AXIS_SIZE - 1;
|
||||||
private static final int TOTAL_BLOCKS = SECTION_AXIS_SIZE * SECTION_AXIS_SIZE * SECTION_AXIS_SIZE;
|
static final int TOTAL_BLOCKS = SECTION_AXIS_SIZE * SECTION_AXIS_SIZE * SECTION_AXIS_SIZE;
|
||||||
private static final int BLOCKS_ON_ONE_FACE = SECTION_AXIS_SIZE * SECTION_AXIS_SIZE;
|
private static final int BLOCKS_ON_ONE_FACE = SECTION_AXIS_SIZE * SECTION_AXIS_SIZE;
|
||||||
private static final int BITS_PER_AXIS = 4;
|
private static final int BITS_PER_AXIS = 4;
|
||||||
private static final int X_SHIFT = 0;
|
private static final int X_SHIFT = 0;
|
||||||
@@ -73,11 +70,7 @@ public class SectionVisibilityBuilder {
|
|||||||
throw new IllegalStateException("opacity was consumed by computeVisibilityEncoding()");
|
throw new IllegalStateException("opacity was consumed by computeVisibilityEncoding()");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.blocks.isEmpty()) {
|
return OccluderBoxBuilder.boxesFrom(this.blocks);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return OccluderBoxes.from(Arrays.copyOf(this.blocks.toLongArray(), BoxFinder.INTERIOR_CACHE_WORDS));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private long computeWithFloodFill() {
|
private long computeWithFloodFill() {
|
||||||
@@ -173,7 +166,7 @@ public class SectionVisibilityBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getIndex(int x, int y, int z) {
|
static int getIndex(int x, int y, int z) {
|
||||||
return (y << Y_SHIFT) | (z << Z_SHIFT) | (x << X_SHIFT);
|
return (y << Y_SHIFT) | (z << Z_SHIFT) | (x << X_SHIFT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+5
@@ -57,6 +57,11 @@ public class VintageRenderSectionManager extends RenderSectionManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean useRasterOcclusionCulling() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean useFogOcclusion() {
|
protected boolean useFogOcclusion() {
|
||||||
return CeleritasVintage.options().performance.useFogOcclusion;
|
return CeleritasVintage.options().performance.useFogOcclusion;
|
||||||
|
|||||||
+7
-1
@@ -44,6 +44,11 @@ public class ArchaicRenderSectionManager extends RenderSectionManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean useRasterOcclusionCulling() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean useFogOcclusion() {
|
protected boolean useFogOcclusion() {
|
||||||
return true;
|
return true;
|
||||||
@@ -80,7 +85,8 @@ public class ArchaicRenderSectionManager extends RenderSectionManager {
|
|||||||
|
|
||||||
ChunkRenderContext context = new ChunkRenderContext(new SectionPos(render.getChunkX(), render.getChunkY(), render.getChunkZ()));
|
ChunkRenderContext context = new ChunkRenderContext(new SectionPos(render.getChunkX(), render.getChunkY(), render.getChunkZ()));
|
||||||
|
|
||||||
return new ChunkBuilderMeshingTask(render, context, frame, this.cameraPosition);
|
return new ChunkBuilderMeshingTask(render, context, frame, this.cameraPosition,
|
||||||
|
this.useRasterOcclusionCulling());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+8
-1
@@ -43,6 +43,7 @@ public class ChunkBuilderMeshingTask extends ChunkBuilderTask<ChunkBuildOutput>
|
|||||||
private final int buildTime;
|
private final int buildTime;
|
||||||
private final Vector3d camera;
|
private final Vector3d camera;
|
||||||
private final ChunkRenderContext renderContext;
|
private final ChunkRenderContext renderContext;
|
||||||
|
private final boolean rasterOcclusion;
|
||||||
|
|
||||||
private static final MethodHandle RENDER_PASS_HANDLE;
|
private static final MethodHandle RENDER_PASS_HANDLE;
|
||||||
|
|
||||||
@@ -64,11 +65,13 @@ public class ChunkBuilderMeshingTask extends ChunkBuilderTask<ChunkBuildOutput>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChunkBuilderMeshingTask(RenderSection render, ChunkRenderContext context, int time, Vector3d camera) {
|
public ChunkBuilderMeshingTask(RenderSection render, ChunkRenderContext context, int time, Vector3d camera,
|
||||||
|
boolean rasterOcclusion) {
|
||||||
this.render = render;
|
this.render = render;
|
||||||
this.buildTime = time;
|
this.buildTime = time;
|
||||||
this.camera = camera;
|
this.camera = camera;
|
||||||
this.renderContext = context;
|
this.renderContext = context;
|
||||||
|
this.rasterOcclusion = rasterOcclusion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -163,6 +166,10 @@ public class ChunkBuilderMeshingTask extends ChunkBuilderTask<ChunkBuildOutput>
|
|||||||
renderData.hasBlockGeometry = true;
|
renderData.hasBlockGeometry = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.rasterOcclusion) {
|
||||||
|
renderData.occluderBoxes = occluder.computeOccluderBoxes();
|
||||||
|
}
|
||||||
|
|
||||||
renderData.visibilityData = occluder.computeVisibilityEncoding();
|
renderData.visibilityData = occluder.computeVisibilityEncoding();
|
||||||
|
|
||||||
return new ChunkBuildOutput(this.render, renderData, meshes, this.buildTime);
|
return new ChunkBuildOutput(this.render, renderData, meshes, this.buildTime);
|
||||||
|
|||||||
+7
-1
@@ -112,7 +112,8 @@ public class ModernRenderSectionManager extends RenderSectionManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ChunkBuilderMeshingTask(render, context, frame, this.cameraPosition);
|
return new ChunkBuilderMeshingTask(render, context, frame, this.cameraPosition,
|
||||||
|
this.useRasterOcclusionCulling());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -126,6 +127,11 @@ public class ModernRenderSectionManager extends RenderSectionManager {
|
|||||||
return new GenericSectionSpriteTicker<>(SpriteUtil::markSpriteActive);
|
return new GenericSectionSpriteTicker<>(SpriteUtil::markSpriteActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean useRasterOcclusionCulling() {
|
||||||
|
return Celeritas.options().performance.useRasterOcclusionCulling;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean useFogOcclusion() {
|
protected boolean useFogOcclusion() {
|
||||||
// TODO: does *every* shaderpack really disable fog?
|
// TODO: does *every* shaderpack really disable fog?
|
||||||
|
|||||||
+14
-1
@@ -21,6 +21,7 @@ import org.embeddedt.embeddium.impl.render.chunk.compile.tasks.ChunkBuilderTask;
|
|||||||
import org.embeddedt.embeddium.impl.render.chunk.data.BuiltRenderSectionData;
|
import org.embeddedt.embeddium.impl.render.chunk.data.BuiltRenderSectionData;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.data.BuiltSectionMeshParts;
|
import org.embeddedt.embeddium.impl.render.chunk.data.BuiltSectionMeshParts;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.data.MinecraftBuiltRenderSectionData;
|
import org.embeddedt.embeddium.impl.render.chunk.data.MinecraftBuiltRenderSectionData;
|
||||||
|
import org.embeddedt.embeddium.impl.render.chunk.occlusion.OccluderBoxBuilder;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.occlusion.VisibilityEncoding;
|
import org.embeddedt.embeddium.impl.render.chunk.occlusion.VisibilityEncoding;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
||||||
import org.embeddedt.embeddium.impl.util.WorldUtil;
|
import org.embeddedt.embeddium.impl.util.WorldUtil;
|
||||||
@@ -66,13 +67,16 @@ public class ChunkBuilderMeshingTask extends ChunkBuilderTask<ChunkBuildOutput>
|
|||||||
|
|
||||||
private final int buildTime;
|
private final int buildTime;
|
||||||
private final Vector3d camera;
|
private final Vector3d camera;
|
||||||
|
private final boolean rasterOcclusion;
|
||||||
|
|
||||||
|
|
||||||
public ChunkBuilderMeshingTask(RenderSection render, ChunkRenderContext renderContext, int time, Vector3d camera) {
|
public ChunkBuilderMeshingTask(RenderSection render, ChunkRenderContext renderContext, int time, Vector3d camera,
|
||||||
|
boolean rasterOcclusion) {
|
||||||
this.render = render;
|
this.render = render;
|
||||||
this.renderContext = renderContext;
|
this.renderContext = renderContext;
|
||||||
this.buildTime = time;
|
this.buildTime = time;
|
||||||
this.camera = camera;
|
this.camera = camera;
|
||||||
|
this.rasterOcclusion = rasterOcclusion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -80,6 +84,7 @@ public class ChunkBuilderMeshingTask extends ChunkBuilderTask<ChunkBuildOutput>
|
|||||||
ModernChunkBuildContext buildContext = (ModernChunkBuildContext)jobContext;
|
ModernChunkBuildContext buildContext = (ModernChunkBuildContext)jobContext;
|
||||||
MinecraftBuiltRenderSectionData<TextureAtlasSprite, BlockEntity> renderData = new MinecraftBuiltRenderSectionData<>();
|
MinecraftBuiltRenderSectionData<TextureAtlasSprite, BlockEntity> renderData = new MinecraftBuiltRenderSectionData<>();
|
||||||
VisGraph occluder = new VisGraph();
|
VisGraph occluder = new VisGraph();
|
||||||
|
OccluderBoxBuilder occluderBoxes = this.rasterOcclusion ? new OccluderBoxBuilder() : null;
|
||||||
|
|
||||||
ChunkBuildBuffers buffers = buildContext.buffers;
|
ChunkBuildBuffers buffers = buildContext.buffers;
|
||||||
buffers.init(renderData, this.render.getSectionIndex());
|
buffers.init(renderData, this.render.getSectionIndex());
|
||||||
@@ -224,6 +229,10 @@ public class ChunkBuilderMeshingTask extends ChunkBuilderTask<ChunkBuildOutput>
|
|||||||
|
|
||||||
if (blockState.isSolidRender(/*? if <1.21.11 {*/ slice, blockPos /*?}*/)) {
|
if (blockState.isSolidRender(/*? if <1.21.11 {*/ slice, blockPos /*?}*/)) {
|
||||||
occluder.setOpaque(blockPos);
|
occluder.setOpaque(blockPos);
|
||||||
|
|
||||||
|
if (occluderBoxes != null) {
|
||||||
|
occluderBoxes.markOpaque(x, y, z);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,6 +255,10 @@ public class ChunkBuilderMeshingTask extends ChunkBuilderTask<ChunkBuildOutput>
|
|||||||
|
|
||||||
encodeVisibilityData(occluder, renderData);
|
encodeVisibilityData(occluder, renderData);
|
||||||
|
|
||||||
|
if (occluderBoxes != null) {
|
||||||
|
renderData.occluderBoxes = occluderBoxes.build();
|
||||||
|
}
|
||||||
|
|
||||||
postSectionDataBuiltEvent(renderData);
|
postSectionDataBuiltEvent(renderData);
|
||||||
|
|
||||||
return new ChunkBuildOutput(this.render, renderData, meshes, this.buildTime);
|
return new ChunkBuildOutput(this.render, renderData, meshes, this.buildTime);
|
||||||
|
|||||||
Reference in new issue
Block a user