Skip to content

Commit 904c2c7

Browse files
committedSep 15, 2018
Add back depth mask plus front to back sorting to improve overlap cases
1 parent 5d35912 commit 904c2c7

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed
 

‎Source/Scene/DerivedCommand.js

+1
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ define([
289289
if (!defined(pickState)) {
290290
var rs = RenderState.getState(renderState);
291291
rs.blending.enabled = false;
292+
rs.depthMask = true;
292293

293294
pickState = RenderState.fromCache(rs);
294295
cache[renderState.id] = pickState;

‎Source/Scene/Scene.js

+26-4
Original file line numberDiff line numberDiff line change
@@ -1841,14 +1841,34 @@ define([
18411841
}
18421842
}
18431843

1844-
function translucentCompare(a, b, position) {
1844+
function backToFront(a, b, position) {
18451845
return b.boundingVolume.distanceSquaredTo(position) - a.boundingVolume.distanceSquaredTo(position);
18461846
}
18471847

1848-
function executeTranslucentCommandsSorted(scene, executeFunction, passState, commands, invertClassification) {
1848+
function frontToBack(a, b, position) {
1849+
// When distances are equal equal favor sorting b before a. This gives render priority to commands later in the list.
1850+
return a.boundingVolume.distanceSquaredTo(position) - b.boundingVolume.distanceSquaredTo(position) + CesiumMath.EPSILON12;
1851+
}
1852+
1853+
function executeTranslucentCommandsBackToFront(scene, executeFunction, passState, commands, invertClassification) {
1854+
var context = scene.context;
1855+
1856+
mergeSort(commands, backToFront, scene.camera.positionWC);
1857+
1858+
if (defined(invertClassification)) {
1859+
executeFunction(invertClassification.unclassifiedCommand, scene, context, passState);
1860+
}
1861+
1862+
var length = commands.length;
1863+
for (var i = 0; i < length; ++i) {
1864+
executeFunction(commands[i], scene, context, passState);
1865+
}
1866+
}
1867+
1868+
function executeTranslucentCommandsFrontToBack(scene, executeFunction, passState, commands, invertClassification) {
18491869
var context = scene.context;
18501870

1851-
mergeSort(commands, translucentCompare, scene.camera.positionWC);
1871+
mergeSort(commands, frontToBack, scene.camera.positionWC);
18521872

18531873
if (defined(invertClassification)) {
18541874
executeFunction(invertClassification.unclassifiedCommand, scene, context, passState);
@@ -1961,8 +1981,10 @@ define([
19611981
};
19621982
}
19631983
executeTranslucentCommands = scene._executeOITFunction;
1984+
} else if (passes.render) {
1985+
executeTranslucentCommands = executeTranslucentCommandsBackToFront;
19641986
} else {
1965-
executeTranslucentCommands = executeTranslucentCommandsSorted;
1987+
executeTranslucentCommands = executeTranslucentCommandsFrontToBack
19661988
}
19671989

19681990
var clearGlobeDepth = environmentState.clearGlobeDepth;

0 commit comments

Comments
 (0)
Please sign in to comment.