Skip to content

Commit

Permalink
Merge pull request CesiumGS#7039 from AnalyticalGraphicsInc/transluce…
Browse files Browse the repository at this point in the history
…nt-pick-fix

Fix translucent picking
  • Loading branch information
bagnell authored Sep 17, 2018
2 parents 229fdf6 + d726c4f commit 0734aee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 external tilesets would not always traverse to their root tile. [#7035](https://github.com/AnalyticalGraphicsInc/cesium/pull/7035)
* 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 an issue where scaling near zero with an model animation could cause rendering to stop. [#6954](https://github.com/AnalyticalGraphicsInc/cesium/pull/6954)
Expand Down
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
19 changes: 13 additions & 6 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -1841,14 +1841,19 @@ 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, translucentCompare, scene.camera.positionWC);
mergeSort(commands, backToFront, scene.camera.positionWC);

if (defined(invertClassification)) {
executeFunction(invertClassification.unclassifiedCommand, scene, context, passState);
Expand All @@ -1860,9 +1865,11 @@ define([
}
}

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

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

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

var clearGlobeDepth = environmentState.clearGlobeDepth;
Expand Down

0 comments on commit 0734aee

Please sign in to comment.