rasterized occlusion culling #38
No files matched your search
+1
-1
@@ -89,7 +89,7 @@ public class MultiDrawBench {
|
|||||||
this.syntheticWorld = new SyntheticWorld(this.world, this.renderDistance, SyntheticWorld.DEFAULT_SEED,
|
this.syntheticWorld = new SyntheticWorld(this.world, this.renderDistance, SyntheticWorld.DEFAULT_SEED,
|
||||||
this.caveWidth, true, 0.0D, false, false);
|
this.caveWidth, true, 0.0D, false, false);
|
||||||
|
|
||||||
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, false);
|
||||||
|
|
||||||
for (RenderSection section : this.syntheticWorld.getConstructionOrder()) {
|
for (RenderSection section : this.syntheticWorld.getConstructionOrder()) {
|
||||||
this.lattice.attach(section);
|
this.lattice.attach(section);
|
||||||
|
|||||||
+1
-1
@@ -89,7 +89,7 @@ public class ShadowOcclusionCullerBench {
|
|||||||
this.numRegions = BenchPlatform.regionManager().getRegionIdsLength();
|
this.numRegions = BenchPlatform.regionManager().getRegionIdsLength();
|
||||||
|
|
||||||
// hasShadowPass: allocates the second visit-state array the shadow search stamps.
|
// hasShadowPass: allocates the second visit-state array the shadow search stamps.
|
||||||
this.lattice = new SectionLattice(SyntheticWorld.MIN_SECTION_Y, SyntheticWorld.MAX_SECTION_Y, true);
|
this.lattice = new SectionLattice(SyntheticWorld.MIN_SECTION_Y, SyntheticWorld.MAX_SECTION_Y, true, false);
|
||||||
|
|
||||||
for (RenderSection section : syntheticWorld.getConstructionOrder()) {
|
for (RenderSection section : syntheticWorld.getConstructionOrder()) {
|
||||||
this.lattice.attach(section);
|
this.lattice.attach(section);
|
||||||
|
|||||||
+40
-32
@@ -115,6 +115,8 @@ public final class SectionLattice {
|
|||||||
// Non-null only when the lattice serves a shadow pass as well.
|
// Non-null only when the lattice serves a shadow pass as well.
|
||||||
@Nullable
|
@Nullable
|
||||||
private final ShadowOcclusionCuller shadowCuller;
|
private final ShadowOcclusionCuller shadowCuller;
|
||||||
|
// Whether the raster occluder is in use; gates maintenance of occluderData/occluderBounds, which only it reads.
|
||||||
|
private final boolean rasterOcclusion;
|
||||||
|
|
||||||
private final int minSectionY, maxSectionY;
|
private final int minSectionY, maxSectionY;
|
||||||
|
|
||||||
@@ -138,17 +140,9 @@ public final class SectionLattice {
|
|||||||
long[] sectionMeta;
|
long[] sectionMeta;
|
||||||
int[] regionOfCell;
|
int[] regionOfCell;
|
||||||
|
|
||||||
/**
|
int[] @Nullable [] occluderData;
|
||||||
* Per-cell occluder data ({@code BuiltRenderSectionData.occluderBoxes}) mirrored here so the raster test
|
|
||||||
* does not chase section and build-data pointers for every cell it visits. Null when absent.
|
|
||||||
*/
|
|
||||||
int[][] occluderData;
|
|
||||||
|
|
||||||
/**
|
int @Nullable [] occluderBounds;
|
||||||
* The packed bounds word of each cell's occluder data, mirrored densely so the raster test reads one
|
|
||||||
* array instead of chasing the pointer above into a second cache line; only a draw needs the boxes.
|
|
||||||
*/
|
|
||||||
int[] occluderBounds;
|
|
||||||
|
|
||||||
RenderSection[] latticeSection;
|
RenderSection[] latticeSection;
|
||||||
|
|
||||||
@@ -204,10 +198,6 @@ public final class SectionLattice {
|
|||||||
* @param hasShadowPass whether the lattice must also support {@link #findShadowVisible}, which costs a second
|
* @param hasShadowPass whether the lattice must also support {@link #findShadowVisible}, which costs a second
|
||||||
* visit-state array
|
* visit-state array
|
||||||
*/
|
*/
|
||||||
public SectionLattice(int minSectionY, int maxSectionY, boolean hasShadowPass) {
|
|
||||||
this(minSectionY, maxSectionY, hasShadowPass, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SectionLattice(int minSectionY, int maxSectionY, boolean hasShadowPass, boolean rasterOcclusion) {
|
public SectionLattice(int minSectionY, int maxSectionY, boolean hasShadowPass, boolean rasterOcclusion) {
|
||||||
this.minSectionY = minSectionY;
|
this.minSectionY = minSectionY;
|
||||||
this.maxSectionY = maxSectionY;
|
this.maxSectionY = maxSectionY;
|
||||||
@@ -215,6 +205,7 @@ public final class SectionLattice {
|
|||||||
this.dimY = (maxSectionY - minSectionY) + 2;
|
this.dimY = (maxSectionY - minSectionY) + 2;
|
||||||
this.culler = new OcclusionCuller(this, minSectionY, maxSectionY, rasterOcclusion);
|
this.culler = new OcclusionCuller(this, minSectionY, maxSectionY, rasterOcclusion);
|
||||||
this.shadowCuller = hasShadowPass ? new ShadowOcclusionCuller(this) : null;
|
this.shadowCuller = hasShadowPass ? new ShadowOcclusionCuller(this) : null;
|
||||||
|
this.rasterOcclusion = rasterOcclusion;
|
||||||
|
|
||||||
if (this.dimY > MAX_DIM) {
|
if (this.dimY > MAX_DIM) {
|
||||||
throw new IllegalStateException("World height " + this.dimY + " exceeds occlusion lattice limit " + MAX_DIM);
|
throw new IllegalStateException("World height " + this.dimY + " exceeds occlusion lattice limit " + MAX_DIM);
|
||||||
@@ -285,9 +276,12 @@ public final class SectionLattice {
|
|||||||
|
|
||||||
long previous = this.sectionMeta[idx];
|
long previous = this.sectionMeta[idx];
|
||||||
this.sectionMeta[idx] = packedMetadata;
|
this.sectionMeta[idx] = packedMetadata;
|
||||||
int[] data = PackedSectionMetadata.hasOccluderData(packedMetadata) ? occluderDataOf(this.latticeSection[idx]) : null;
|
|
||||||
this.occluderData[idx] = data;
|
if (this.rasterOcclusion) {
|
||||||
this.occluderBounds[idx] = boundsOf(data);
|
int[] data = PackedSectionMetadata.hasOccluderData(packedMetadata) ? occluderDataOf(this.latticeSection[idx]) : null;
|
||||||
|
this.occluderData[idx] = data;
|
||||||
|
this.occluderBounds[idx] = boundsOf(data);
|
||||||
|
}
|
||||||
|
|
||||||
return ((previous ^ packedMetadata) & PackedSectionMetadata.GRAPH_INPUT_MASK) != 0;
|
return ((previous ^ packedMetadata) & PackedSectionMetadata.GRAPH_INPUT_MASK) != 0;
|
||||||
}
|
}
|
||||||
@@ -555,8 +549,8 @@ public final class SectionLattice {
|
|||||||
this.sectionMeta = new long[slots];
|
this.sectionMeta = new long[slots];
|
||||||
this.regionOfCell = new int[slots];
|
this.regionOfCell = new int[slots];
|
||||||
this.latticeSection = new RenderSection[slots];
|
this.latticeSection = new RenderSection[slots];
|
||||||
this.occluderData = new int[slots][];
|
this.occluderData = this.rasterOcclusion ? new int[slots][] : null;
|
||||||
this.occluderBounds = new int[slots];
|
this.occluderBounds = this.rasterOcclusion ? new int[slots] : null;
|
||||||
|
|
||||||
// Existing coordinates are no longer valid after resizing; the next
|
// Existing coordinates are no longer valid after resizing; the next
|
||||||
// ensureWindowCovers must rebase and reinstall every attached section.
|
// ensureWindowCovers must rebase and reinstall every attached section.
|
||||||
@@ -575,8 +569,10 @@ public final class SectionLattice {
|
|||||||
Arrays.fill(this.sectionMeta, VisibilityEncoding.NULL);
|
Arrays.fill(this.sectionMeta, VisibilityEncoding.NULL);
|
||||||
Arrays.fill(this.regionOfCell, -1);
|
Arrays.fill(this.regionOfCell, -1);
|
||||||
Arrays.fill(this.latticeSection, null);
|
Arrays.fill(this.latticeSection, null);
|
||||||
Arrays.fill(this.occluderData, null);
|
if (this.rasterOcclusion) {
|
||||||
Arrays.fill(this.occluderBounds, 0);
|
Arrays.fill(this.occluderData, null);
|
||||||
|
Arrays.fill(this.occluderBounds, 0);
|
||||||
|
}
|
||||||
|
|
||||||
this.baseX = newBaseX;
|
this.baseX = newBaseX;
|
||||||
this.baseZ = newBaseZ;
|
this.baseZ = newBaseZ;
|
||||||
@@ -656,8 +652,10 @@ public final class SectionLattice {
|
|||||||
System.arraycopy(this.sectionMeta, srcOff, this.sectionMeta, destOff, len);
|
System.arraycopy(this.sectionMeta, srcOff, this.sectionMeta, destOff, len);
|
||||||
System.arraycopy(this.regionOfCell, srcOff, this.regionOfCell, destOff, len);
|
System.arraycopy(this.regionOfCell, srcOff, this.regionOfCell, destOff, len);
|
||||||
System.arraycopy(this.latticeSection, srcOff, this.latticeSection, destOff, len);
|
System.arraycopy(this.latticeSection, srcOff, this.latticeSection, destOff, len);
|
||||||
System.arraycopy(this.occluderData, srcOff, this.occluderData, destOff, len);
|
if (this.rasterOcclusion) {
|
||||||
System.arraycopy(this.occluderBounds, srcOff, this.occluderBounds, destOff, len);
|
System.arraycopy(this.occluderData, srcOff, this.occluderData, destOff, len);
|
||||||
|
System.arraycopy(this.occluderBounds, srcOff, this.occluderBounds, destOff, len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -691,8 +689,10 @@ public final class SectionLattice {
|
|||||||
System.arraycopy(this.sectionMeta, srcOff, this.sectionMeta, destOff, runLen);
|
System.arraycopy(this.sectionMeta, srcOff, this.sectionMeta, destOff, runLen);
|
||||||
System.arraycopy(this.regionOfCell, srcOff, this.regionOfCell, destOff, runLen);
|
System.arraycopy(this.regionOfCell, srcOff, this.regionOfCell, destOff, runLen);
|
||||||
System.arraycopy(this.latticeSection, srcOff, this.latticeSection, destOff, runLen);
|
System.arraycopy(this.latticeSection, srcOff, this.latticeSection, destOff, runLen);
|
||||||
System.arraycopy(this.occluderData, srcOff, this.occluderData, destOff, runLen);
|
if (this.rasterOcclusion) {
|
||||||
System.arraycopy(this.occluderBounds, srcOff, this.occluderBounds, destOff, runLen);
|
System.arraycopy(this.occluderData, srcOff, this.occluderData, destOff, runLen);
|
||||||
|
System.arraycopy(this.occluderBounds, srcOff, this.occluderBounds, destOff, runLen);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -778,8 +778,10 @@ public final class SectionLattice {
|
|||||||
this.sectionMeta[idx] = VisibilityEncoding.NULL;
|
this.sectionMeta[idx] = VisibilityEncoding.NULL;
|
||||||
this.regionOfCell[idx] = -1;
|
this.regionOfCell[idx] = -1;
|
||||||
this.latticeSection[idx] = null;
|
this.latticeSection[idx] = null;
|
||||||
this.occluderData[idx] = null;
|
if (this.rasterOcclusion) {
|
||||||
this.occluderBounds[idx] = 0;
|
this.occluderData[idx] = null;
|
||||||
|
this.occluderBounds[idx] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
RenderSection section = this.sections.get(
|
RenderSection section = this.sections.get(
|
||||||
PositionUtil.packSection(worldX, this.baseY + ly, worldZ));
|
PositionUtil.packSection(worldX, this.baseY + ly, worldZ));
|
||||||
@@ -855,9 +857,13 @@ public final class SectionLattice {
|
|||||||
this.regionOfCell[idx] = section.getRegion().getId();
|
this.regionOfCell[idx] = section.getRegion().getId();
|
||||||
long packedMetadata = section.getPackedMetadata();
|
long packedMetadata = section.getPackedMetadata();
|
||||||
this.sectionMeta[idx] = packedMetadata;
|
this.sectionMeta[idx] = packedMetadata;
|
||||||
int[] data = PackedSectionMetadata.hasOccluderData(packedMetadata) ? occluderDataOf(section) : null;
|
|
||||||
this.occluderData[idx] = data;
|
if (this.rasterOcclusion) {
|
||||||
this.occluderBounds[idx] = boundsOf(data);
|
int[] data = PackedSectionMetadata.hasOccluderData(packedMetadata) ? occluderDataOf(section) : null;
|
||||||
|
this.occluderData[idx] = data;
|
||||||
|
this.occluderBounds[idx] = boundsOf(data);
|
||||||
|
}
|
||||||
|
|
||||||
this.installedCount++;
|
this.installedCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -877,8 +883,10 @@ public final class SectionLattice {
|
|||||||
this.sectionMeta[idx] = VisibilityEncoding.NULL;
|
this.sectionMeta[idx] = VisibilityEncoding.NULL;
|
||||||
this.regionOfCell[idx] = -1;
|
this.regionOfCell[idx] = -1;
|
||||||
this.latticeSection[idx] = null;
|
this.latticeSection[idx] = null;
|
||||||
this.occluderData[idx] = null;
|
if (this.rasterOcclusion) {
|
||||||
this.occluderBounds[idx] = 0;
|
this.occluderData[idx] = null;
|
||||||
|
this.occluderBounds[idx] = 0;
|
||||||
|
}
|
||||||
this.installedCount--;
|
this.installedCount--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user