Smarter translucency sorting #42
+37
-13
@@ -364,17 +364,19 @@ public abstract class RenderSectionManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var rebuildLists = this.getCurrentRenderListManager().getRebuildLists().byUpdateType();
|
|
||||||
var allowImportant = allowImportantRebuilds();
|
|
||||||
|
|
||||||
this.cutPlaneIndex.query(
|
this.cutPlaneIndex.query(
|
||||||
this.previousCameraPosition.x, this.previousCameraPosition.y, this.previousCameraPosition.z,
|
this.previousCameraPosition.x, this.previousCameraPosition.y, this.previousCameraPosition.z,
|
||||||
this.cameraPosition.x, this.cameraPosition.y, this.cameraPosition.z,
|
this.cameraPosition.x, this.cameraPosition.y, this.cameraPosition.z,
|
||||||
section -> {
|
section -> {
|
||||||
this.treeTriggersThisSecond++;
|
this.treeTriggersThisSecond++;
|
||||||
|
this.scheduleTreeSort(section);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scheduleTreeSort(RenderSection section) {
|
||||||
ChunkUpdateType update = ChunkUpdateType.getPromotionUpdateType(section.getPendingUpdate(),
|
ChunkUpdateType update = ChunkUpdateType.getPromotionUpdateType(section.getPendingUpdate(),
|
||||||
(allowImportant && this.shouldPrioritizeRebuild(section)) ? ChunkUpdateType.IMPORTANT_SORT : ChunkUpdateType.SORT);
|
(allowImportantRebuilds() && this.shouldPrioritizeRebuild(section)) ? ChunkUpdateType.IMPORTANT_SORT : ChunkUpdateType.SORT);
|
||||||
|
|
||||||
if (update == null) {
|
if (update == null) {
|
||||||
// We wouldn't be able to resort this section anyway
|
// We wouldn't be able to resort this section anyway
|
||||||
@@ -382,9 +384,7 @@ public abstract class RenderSectionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
section.setPendingUpdate(update);
|
section.setPendingUpdate(update);
|
||||||
rebuildLists.get(update).add(section);
|
this.getCurrentRenderListManager().getRebuildLists().byUpdateType().get(update).add(section);
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -632,6 +632,10 @@ public abstract class RenderSectionManager {
|
|||||||
|
|
||||||
for (var holder : filtered) {
|
for (var holder : filtered) {
|
||||||
var result = holder.output();
|
var result = holder.output();
|
||||||
|
|
||||||
|
// whether this result belongs to the most recently submitted build
|
||||||
|
boolean latest = result.buildTime >= result.render.getLastSubmittedFrame();
|
||||||
|
|
||||||
if (result instanceof ChunkBuildOutput buildResult) {
|
if (result instanceof ChunkBuildOutput buildResult) {
|
||||||
boolean changed = this.updateSectionInfo(result.render, buildResult.info);
|
boolean changed = this.updateSectionInfo(result.render, buildResult.info);
|
||||||
|
|
||||||
@@ -643,15 +647,12 @@ public abstract class RenderSectionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We only change the translucency info on full rebuilds, as sorts can keep using the same data
|
// We only change the translucency info on full rebuilds, as sorts can keep using the same data
|
||||||
this.updateTranslucencyInfo(result.render, buildResult.meshes);
|
this.updateTranslucencyInfo(result.render, buildResult.meshes, latest);
|
||||||
}
|
}
|
||||||
|
|
||||||
var job = result.render.getBuildCancellationToken();
|
var job = result.render.getBuildCancellationToken();
|
||||||
|
|
||||||
// Only clear the token if this result belongs to the most recently submitted build.
|
if (job != null && latest) {
|
||||||
// A stale result from an earlier submission must not clear the token for a newer
|
|
||||||
// in-flight job, which is identified by a higher lastSubmittedFrame.
|
|
||||||
if (job != null && result.buildTime >= result.render.getLastSubmittedFrame()) {
|
|
||||||
result.render.setBuildCancellationToken(null);
|
result.render.setBuildCancellationToken(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,7 +661,11 @@ public abstract class RenderSectionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTranslucencyInfo(RenderSection render, Map<TerrainRenderPass, BuiltSectionMeshParts> meshes) {
|
/**
|
||||||
|
* @param latestBuild whether the meshes come from the most recent submission; a stale build keeps its planes
|
||||||
|
* indexed but leaves the camera bookkeeping to the build still in flight
|
||||||
|
*/
|
||||||
|
private void updateTranslucencyInfo(RenderSection render, Map<TerrainRenderPass, BuiltSectionMeshParts> meshes, boolean latestBuild) {
|
||||||
Map<TerrainRenderPass, SortState.Resortable> sortStates = new Reference2ObjectArrayMap<>();
|
Map<TerrainRenderPass, SortState.Resortable> sortStates = new Reference2ObjectArrayMap<>();
|
||||||
int highestIndex = RenderSection.NO_TRANSLUCENT_GEOMETRY;
|
int highestIndex = RenderSection.NO_TRANSLUCENT_GEOMETRY;
|
||||||
|
|
||||||
@@ -688,15 +693,29 @@ public abstract class RenderSectionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.cutPlaneIndex.put(render, PartitionTree.mergeCutPlanes(trees), render.getOriginX(), render.getOriginY(), render.getOriginZ());
|
this.cutPlaneIndex.put(render, PartitionTree.mergeCutPlanes(trees), render.getOriginX(), render.getOriginY(), render.getOriginZ());
|
||||||
|
|
||||||
|
// The build sorted for the camera at submission (see submitRebuildTasks). A crossing since then happened
|
||||||
|
// before the planes were indexed, so it has to be caught here or the order stays stale until the next one.
|
||||||
|
int ox = render.getOriginX(), oy = render.getOriginY(), oz = render.getOriginZ();
|
||||||
|
for (PartitionTree tree : trees) {
|
||||||
|
if (latestBuild && tree.crossesCutPlane(render.lastCameraX - ox, render.lastCameraY - oy, render.lastCameraZ - oz,
|
||||||
|
this.cameraPosition.x - ox, this.cameraPosition.y - oy, this.cameraPosition.z - oz)) {
|
||||||
|
this.treeTriggersThisSecond++;
|
||||||
|
this.scheduleTreeSort(render);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// a rebuild that is no longer tree-sorted must drop its stale planes
|
// a rebuild that is no longer tree-sorted must drop its stale planes
|
||||||
this.cutPlaneIndex.remove(render);
|
this.cutPlaneIndex.remove(render);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (latestBuild) {
|
||||||
render.lastCameraX = this.cameraPosition.x;
|
render.lastCameraX = this.cameraPosition.x;
|
||||||
render.lastCameraY = this.cameraPosition.y;
|
render.lastCameraY = this.cameraPosition.y;
|
||||||
render.lastCameraZ = this.cameraPosition.z;
|
render.lastCameraZ = this.cameraPosition.z;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Section MetadataSink: mirrors a section's packed metadata into the graph-search lattice on every
|
// Section MetadataSink: mirrors a section's packed metadata into the graph-search lattice on every
|
||||||
// packedMetadata mutation (visibility/visuals via setInfo, pending update, build-in-flight).
|
// packedMetadata mutation (visibility/visuals via setInfo, pending update, build-in-flight).
|
||||||
@@ -809,6 +828,11 @@ public abstract class RenderSectionManager {
|
|||||||
if (!type.isSort()) {
|
if (!type.isSort()) {
|
||||||
// Prevent further sorts from being performed on this section
|
// Prevent further sorts from being performed on this section
|
||||||
section.clearTranslucencySortStates();
|
section.clearTranslucencySortStates();
|
||||||
|
|
||||||
|
// the meshing task sorts its translucent geometry for this camera
|
||||||
|
section.lastCameraX = this.cameraPosition.x;
|
||||||
|
section.lastCameraY = this.cameraPosition.y;
|
||||||
|
section.lastCameraZ = this.cameraPosition.z;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var result = new ChunkJobResult.Success<>(new ChunkBuildOutput(section, RenderSection.EMPTY_DATA, Reference2ReferenceMaps.emptyMap(), frame), -1);
|
var result = new ChunkJobResult.Success<>(new ChunkBuildOutput(section, RenderSection.EMPTY_DATA, Reference2ReferenceMaps.emptyMap(), frame), -1);
|
||||||
|
|||||||
Reference in new issue
Block a user