From 5d359121fd4f4300a0f7dd025282b6612a923a50 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Sat, 15 Sep 2018 14:46:44 -0400 Subject: [PATCH 1/4] Revert 259c314 --- Source/Scene/Scene.js | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index aa4142a27420..b5ea43f7bc16 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -1860,19 +1860,6 @@ define([ } } - function executeTranslucentCommandsUnsorted(scene, executeFunction, passState, commands, invertClassification) { - var context = scene.context; - - 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 getDebugGlobeDepth(scene, index) { var globeDepths = scene._view.debugGlobeDepths; var globeDepth = globeDepths[index]; @@ -1974,10 +1961,8 @@ define([ }; } executeTranslucentCommands = scene._executeOITFunction; - } else if (passes.render) { - executeTranslucentCommands = executeTranslucentCommandsSorted; } else { - executeTranslucentCommands = executeTranslucentCommandsUnsorted; + executeTranslucentCommands = executeTranslucentCommandsSorted; } var clearGlobeDepth = environmentState.clearGlobeDepth; From 904c2c72e1f001dfe23b387c6874f18d4baac8e2 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Sat, 15 Sep 2018 15:32:49 -0400 Subject: [PATCH 2/4] 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; From b166304d1853effbf011fcfd8b71a5c684c97598 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Sat, 15 Sep 2018 15:44:34 -0400 Subject: [PATCH 3/4] eslint fix --- Source/Scene/Scene.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 8590eacfb976..436293542ab2 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -1984,7 +1984,7 @@ define([ } else if (passes.render) { executeTranslucentCommands = executeTranslucentCommandsBackToFront; } else { - executeTranslucentCommands = executeTranslucentCommandsFrontToBack + executeTranslucentCommands = executeTranslucentCommandsFrontToBack; } var clearGlobeDepth = environmentState.clearGlobeDepth; From 869c7742b7cf7339ac27fbe70ecfb0f1fbff923e Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Mon, 17 Sep 2018 15:52:47 -0400 Subject: [PATCH 4/4] Update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 6509bb852f15..b2eb3377c85a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ Change Log * Added `OpenCageGeocoderService`, which provides geocoding via [OpenCage](https://opencagedata.com/). [#7015](https://github.com/AnalyticalGraphicsInc/cesium/pull/7015) ##### Fixes :wrench: +* Fixed picking for overlapping translucent primitives. [#7039](https://github.com/AnalyticalGraphicsInc/cesium/pull/7039) * Fixed an issue in the 3D Tiles traversal where empty tiles would be selected instead of their nearest loaded ancestors. [#7011](https://github.com/AnalyticalGraphicsInc/cesium/pull/7011) * Fixed bug where credits weren't displaying correctly if more than one viewer was initialized [#6965](expect(https://github.com/AnalyticalGraphicsInc/cesium/issues/6965)