rasterized occlusion culling #38
No files matched your search
+7
-2
@@ -45,6 +45,9 @@ public class OcclusionCullerBench {
|
||||
@Param({ "true" })
|
||||
public boolean scatteredAlloc;
|
||||
|
||||
@Param({ "false" })
|
||||
public boolean rasterOcclusion;
|
||||
|
||||
public SyntheticWorld syntheticWorld;
|
||||
public SectionLattice lattice;
|
||||
|
||||
@@ -62,12 +65,14 @@ public class OcclusionCullerBench {
|
||||
public void setup() {
|
||||
BenchPlatform.ensureInitialized();
|
||||
|
||||
this.syntheticWorld = new SyntheticWorld(this.world, this.renderDistance, this.scatteredAlloc);
|
||||
this.syntheticWorld = new SyntheticWorld(this.world, this.renderDistance, this.scatteredAlloc,
|
||||
this.rasterOcclusion);
|
||||
this.searchDistance = this.syntheticWorld.getSearchDistance();
|
||||
|
||||
this.numRegions = BenchPlatform.regionManager().getRegionIdsLength();
|
||||
|
||||
this.lattice = new SectionLattice(SyntheticWorld.MIN_SECTION_Y, SyntheticWorld.MAX_SECTION_Y, false);
|
||||
this.lattice = new SectionLattice(SyntheticWorld.MIN_SECTION_Y, SyntheticWorld.MAX_SECTION_Y, false,
|
||||
this.rasterOcclusion);
|
||||
|
||||
for (RenderSection section : this.syntheticWorld.getConstructionOrder()) {
|
||||
this.lattice.attach(section);
|
||||
|
||||
+1
-2
@@ -4,7 +4,6 @@ import it.unimi.dsi.fastutil.longs.Long2ReferenceMap;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ReferenceOpenHashMap;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.ChunkUpdateType;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.occlusion.geometry.OccluderBoxes;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.bench.voxel.VoxelWorld;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.region.RenderRegion;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.region.RenderRegionManager;
|
||||
@@ -284,7 +283,7 @@ public final class SyntheticWorld {
|
||||
int index = gridIndex(x, y, z, radius, width);
|
||||
|
||||
if (occluderBoxes != null) {
|
||||
occluderBoxes[index] = OccluderBoxes.from(slice.opacityBits());
|
||||
occluderBoxes[index] = slice.occlusionData();
|
||||
}
|
||||
|
||||
visibility[index] = slice.computeVisibility();
|
||||
|
||||
+20
-14
@@ -1,5 +1,6 @@
|
||||
package org.embeddedt.embeddium.impl.render.chunk.occlusion;
|
||||
|
||||
import grondag.bitraster.PackedBox;
|
||||
import org.embeddedt.embeddium.impl.common.util.MathUtil;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.LocalSectionIndex;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.PackedSectionMetadata;
|
||||
@@ -297,18 +298,22 @@ public class OcclusionCuller {
|
||||
visible = aperture != FastFrustumClamping.EMPTY;
|
||||
}
|
||||
|
||||
boolean traverse = visible;
|
||||
|
||||
if (this.rasterActive && visible) {
|
||||
visible = this.rasterTest(idx, chunkX, chunkY, chunkZ, camX, camY, camZ, compactMeta);
|
||||
RasterOccluder.SectionVisibility result = this.rasterTest(idx, chunkX, chunkY, chunkZ, camX, camY, camZ, compactMeta);
|
||||
visible = result == RasterOccluder.SectionVisibility.VISIBLE;
|
||||
traverse = result != RasterOccluder.SectionVisibility.HIDDEN;
|
||||
}
|
||||
|
||||
int sectionIndex = LocalSectionIndex.pack(chunkX, chunkY, chunkZ);
|
||||
visitor.visit(idx, regionId, sectionIndex, compactMeta, visible);
|
||||
|
||||
if (!visible) {
|
||||
if (!traverse) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (visibleCells != null) {
|
||||
if (visible && visibleCells != null) {
|
||||
visibleCells[visibleCount++] = entry;
|
||||
}
|
||||
|
||||
@@ -351,28 +356,29 @@ public class OcclusionCuller {
|
||||
this.visibleCount = visibleCount;
|
||||
}
|
||||
|
||||
private boolean rasterTest(int idx, int chunkX, int chunkY, int chunkZ, int camX, int camY, int camZ, int meta) {
|
||||
private RasterOccluder.SectionVisibility rasterTest(int idx, int chunkX, int chunkY, int chunkZ, int camX, int camY, int camZ, int meta) {
|
||||
int dx = chunkX - camX;
|
||||
int dy = chunkY - camY;
|
||||
int dz = chunkZ - camZ;
|
||||
int squaredChunkDist = (dx * dx) + (dy * dy) + (dz * dz);
|
||||
|
||||
var occluder = this.rasterOccluder;
|
||||
boolean hasGeometry =
|
||||
(PackedSectionMetadata.getCompactVisualsFlags(meta) & (1 << RenderVisualsService.HAS_BLOCK_GEOMETRY)) != 0;
|
||||
|
||||
if (!occluder.isSectionVisible(chunkX << 4, chunkY << 4, chunkZ << 4, squaredChunkDist)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((PackedSectionMetadata.getCompactVisualsFlags(meta) & (1 << RenderVisualsService.HAS_BLOCK_GEOMETRY)) != 0) {
|
||||
var section = this.lattice.latticeSection[idx];
|
||||
var built = section != null ? section.getBuiltContext() : null;
|
||||
int[] data = built != null ? built.occluderBoxes : null;
|
||||
|
||||
if (built != null && built.occluderBoxes != null) {
|
||||
occluder.drawOccluders(built.occluderBoxes, squaredChunkDist);
|
||||
}
|
||||
int bounds = data != null ? OccluderBoxBuilder.bounds(data) : PackedBox.FULL_BOX;
|
||||
|
||||
var occluder = this.rasterOccluder;
|
||||
RasterOccluder.SectionVisibility result = occluder.testSection(chunkX << 4, chunkY << 4, chunkZ << 4, squaredChunkDist, bounds);
|
||||
|
||||
if (result == RasterOccluder.SectionVisibility.VISIBLE && hasGeometry && data != null) {
|
||||
occluder.occlude(data);
|
||||
}
|
||||
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
|
||||
public int rasterBacktrackCount() {
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package org.embeddedt.embeddium.impl.render.chunk.occlusion;
|
||||
|
||||
import grondag.bitraster.PackedBox;
|
||||
|
||||
final class RenderableBounds {
|
||||
private int minX = 16, minY = 16, minZ = 16;
|
||||
private int maxX = -1, maxY = -1, maxZ = -1;
|
||||
|
||||
void mark(int x, int y, int z) {
|
||||
if (x < this.minX) this.minX = x;
|
||||
if (y < this.minY) this.minY = y;
|
||||
if (z < this.minZ) this.minZ = z;
|
||||
if (x > this.maxX) this.maxX = x;
|
||||
if (y > this.maxY) this.maxY = y;
|
||||
if (z > this.maxZ) this.maxZ = z;
|
||||
}
|
||||
|
||||
boolean isEmpty() {
|
||||
return this.maxX < 0;
|
||||
}
|
||||
|
||||
int packed() {
|
||||
if (isEmpty()) {
|
||||
return PackedBox.FULL_BOX;
|
||||
}
|
||||
|
||||
return PackedBox.pack(this.minX, this.minY, this.minZ,
|
||||
this.maxX + 1, this.maxY + 1, this.maxZ + 1, PackedBox.RANGE_EXTREME);
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -26,6 +26,7 @@ public class SectionVisibilityBuilder {
|
||||
private static final int[] INDICES_TO_INITIATE_FLOODFILL = buildFloodfillIndices();
|
||||
|
||||
private final BitSet blocks;
|
||||
private final RenderableBounds renderableBounds = new RenderableBounds();
|
||||
|
||||
private boolean floodFilled;
|
||||
|
||||
@@ -65,12 +66,16 @@ public class SectionVisibilityBuilder {
|
||||
this.blocks.set(getIndex(x & 15, y & 15, z & 15));
|
||||
}
|
||||
|
||||
public void markRenderable(int x, int y, int z) {
|
||||
this.renderableBounds.mark(x & 15, y & 15, z & 15);
|
||||
}
|
||||
|
||||
public int @Nullable [] computeOccluderBoxes() {
|
||||
if (this.floodFilled) {
|
||||
throw new IllegalStateException("opacity was consumed by computeVisibilityEncoding()");
|
||||
}
|
||||
|
||||
return OccluderBoxBuilder.boxesFrom(this.blocks);
|
||||
return OccluderBoxBuilder.dataFrom(this.blocks, this.renderableBounds);
|
||||
}
|
||||
|
||||
private long computeWithFloodFill() {
|
||||
|
||||
+4
@@ -137,6 +137,10 @@ public class ChunkBuilderMeshingTask extends ChunkBuilderTask<ChunkBuildOutput>
|
||||
blockPos.set(x, y, z);
|
||||
modelOffset.set(x & 15, y & 15, z & 15);
|
||||
|
||||
if (occluderBoxes != null) {
|
||||
occluderBoxes.markRenderable(x, y, z);
|
||||
}
|
||||
|
||||
//? if shaders && >=1.17 {
|
||||
if (voxelizingLight && blockState.getBlock() instanceof net.minecraft.world.level.block.LightBlock) {
|
||||
cache.getSpecialBlockRenderer().voxelizeLightBlock(blockPos, blockState, buffers);
|
||||
|
||||
Reference in new issue
Block a user