@@ -1841,14 +1841,34 @@ define([
1841
1841
}
1842
1842
}
1843
1843
1844
- function translucentCompare ( a , b , position ) {
1844
+ function backToFront ( a , b , position ) {
1845
1845
return b . boundingVolume . distanceSquaredTo ( position ) - a . boundingVolume . distanceSquaredTo ( position ) ;
1846
1846
}
1847
1847
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 ) {
1849
1869
var context = scene . context ;
1850
1870
1851
- mergeSort ( commands , translucentCompare , scene . camera . positionWC ) ;
1871
+ mergeSort ( commands , frontToBack , scene . camera . positionWC ) ;
1852
1872
1853
1873
if ( defined ( invertClassification ) ) {
1854
1874
executeFunction ( invertClassification . unclassifiedCommand , scene , context , passState ) ;
@@ -1961,8 +1981,10 @@ define([
1961
1981
} ;
1962
1982
}
1963
1983
executeTranslucentCommands = scene . _executeOITFunction ;
1984
+ } else if ( passes . render ) {
1985
+ executeTranslucentCommands = executeTranslucentCommandsBackToFront ;
1964
1986
} else {
1965
- executeTranslucentCommands = executeTranslucentCommandsSorted ;
1987
+ executeTranslucentCommands = executeTranslucentCommandsFrontToBack
1966
1988
}
1967
1989
1968
1990
var clearGlobeDepth = environmentState . clearGlobeDepth ;
0 commit comments