Skip to content

Commit

Permalink
Add back depth mask plus front to back sorting to improve overlap cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Sep 15, 2018
1 parent 5d35912 commit 904c2c7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions Source/Scene/DerivedCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ define([
if (!defined(pickState)) {
var rs = RenderState.getState(renderState);
rs.blending.enabled = false;
rs.depthMask = true;

pickState = RenderState.fromCache(rs);
cache[renderState.id] = pickState;
Expand Down
30 changes: 26 additions & 4 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -1841,14 +1841,34 @@ define([
}
}

function translucentCompare(a, b, position) {
function backToFront(a, b, position) {
return b.boundingVolume.distanceSquaredTo(position) - a.boundingVolume.distanceSquaredTo(position);
}

function executeTranslucentCommandsSorted(scene, executeFunction, passState, commands, invertClassification) {
function frontToBack(a, b, position) {
// When distances are equal equal favor sorting b before a. This gives render priority to commands later in the list.
return a.boundingVolume.distanceSquaredTo(position) - b.boundingVolume.distanceSquaredTo(position) + CesiumMath.EPSILON12;
}

function executeTranslucentCommandsBackToFront(scene, executeFunction, passState, commands, invertClassification) {
var context = scene.context;

mergeSort(commands, backToFront, scene.camera.positionWC);

if (defined(invertClassification)) {
executeFunction(invertClassification.unclassifiedCommand, scene, context, passState);
}

var length = commands.length;
for (var i = 0; i < length; ++i) {
executeFunction(commands[i], scene, context, passState);
}
}

function executeTranslucentCommandsFrontToBack(scene, executeFunction, passState, commands, invertClassification) {
var context = scene.context;

mergeSort(commands, translucentCompare, scene.camera.positionWC);
mergeSort(commands, frontToBack, scene.camera.positionWC);

if (defined(invertClassification)) {
executeFunction(invertClassification.unclassifiedCommand, scene, context, passState);
Expand Down Expand Up @@ -1961,8 +1981,10 @@ define([
};
}
executeTranslucentCommands = scene._executeOITFunction;
} else if (passes.render) {
executeTranslucentCommands = executeTranslucentCommandsBackToFront;
} else {
executeTranslucentCommands = executeTranslucentCommandsSorted;
executeTranslucentCommands = executeTranslucentCommandsFrontToBack
}

var clearGlobeDepth = environmentState.clearGlobeDepth;
Expand Down

0 comments on commit 904c2c7

Please sign in to comment.