From 904c2c72e1f001dfe23b387c6874f18d4baac8e2 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Sat, 15 Sep 2018 15:32:49 -0400 Subject: [PATCH] Add back depth mask plus front to back sorting to improve overlap cases --- Source/Scene/DerivedCommand.js | 1 + Source/Scene/Scene.js | 30 ++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Source/Scene/DerivedCommand.js b/Source/Scene/DerivedCommand.js index a4f969c41ba7..4394ef9b509c 100644 --- a/Source/Scene/DerivedCommand.js +++ b/Source/Scene/DerivedCommand.js @@ -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; diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index b5ea43f7bc16..8590eacfb976 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -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); @@ -1961,8 +1981,10 @@ define([ }; } executeTranslucentCommands = scene._executeOITFunction; + } else if (passes.render) { + executeTranslucentCommands = executeTranslucentCommandsBackToFront; } else { - executeTranslucentCommands = executeTranslucentCommandsSorted; + executeTranslucentCommands = executeTranslucentCommandsFrontToBack } var clearGlobeDepth = environmentState.clearGlobeDepth;