6
6
'../Core/Cartesian2' ,
7
7
'../Core/Cartesian3' ,
8
8
'../Core/Cartesian4' ,
9
+ '../Core/Cartographic' ,
9
10
'../Core/Color' ,
10
11
'../Core/ColorGeometryInstanceAttribute' ,
11
12
'../Core/createGuid' ,
@@ -28,6 +29,7 @@ define([
28
29
'../Core/mergeSort' ,
29
30
'../Core/Occluder' ,
30
31
'../Core/ShowGeometryInstanceAttribute' ,
32
+ '../Core/Transforms' ,
31
33
'../Renderer/ClearCommand' ,
32
34
'../Renderer/ComputeEngine' ,
33
35
'../Renderer/Context' ,
@@ -68,6 +70,7 @@ define([
68
70
Cartesian2 ,
69
71
Cartesian3 ,
70
72
Cartesian4 ,
73
+ Cartographic ,
71
74
Color ,
72
75
ColorGeometryInstanceAttribute ,
73
76
createGuid ,
@@ -90,6 +93,7 @@ define([
90
93
mergeSort ,
91
94
Occluder ,
92
95
ShowGeometryInstanceAttribute ,
96
+ Transforms ,
93
97
ClearCommand ,
94
98
ComputeEngine ,
95
99
Context ,
@@ -1319,9 +1323,9 @@ define([
1319
1323
}
1320
1324
1321
1325
var transformFrom2D = new Matrix4 ( 0.0 , 0.0 , 1.0 , 0.0 ,
1322
- 1.0 , 0.0 , 0.0 , 0.0 ,
1323
- 0.0 , 1.0 , 0.0 , 0.0 ,
1324
- 0.0 , 0.0 , 0.0 , 1.0 ) ;
1326
+ 1.0 , 0.0 , 0.0 , 0.0 ,
1327
+ 0.0 , 1.0 , 0.0 , 0.0 ,
1328
+ 0.0 , 0.0 , 0.0 , 1.0 ) ;
1325
1329
transformFrom2D = Matrix4 . inverseTransformation ( transformFrom2D , transformFrom2D ) ;
1326
1330
1327
1331
function executeCommand ( command , scene , context , passState , renderState , shaderProgram , debugFramebuffer ) {
@@ -1490,9 +1494,11 @@ define([
1490
1494
executeCommand ( environmentState . skyAtmosphereCommand , scene , context , passState ) ;
1491
1495
}
1492
1496
1497
+ var useWebVR = scene . _useWebVR && scene . mode !== SceneMode . SCENE2D ;
1498
+
1493
1499
if ( environmentState . isSunVisible ) {
1494
1500
environmentState . sunDrawCommand . execute ( context , passState ) ;
1495
- if ( scene . sunBloom && ! scene . _useWebVR ) {
1501
+ if ( scene . sunBloom && ! useWebVR ) {
1496
1502
var framebuffer ;
1497
1503
if ( environmentState . useGlobeDepthFramebuffer ) {
1498
1504
framebuffer = scene . _globeDepth . framebuffer ;
@@ -1644,76 +1650,170 @@ define([
1644
1650
}
1645
1651
}
1646
1652
1647
- function executeViewportCommands ( scene , passState ) {
1653
+ function updateAndExecuteCommands ( scene , passState , backgroundColor , picking ) {
1648
1654
var context = scene . _context ;
1649
1655
1650
1656
var viewport = passState . viewport ;
1651
1657
1652
1658
var frameState = scene . _frameState ;
1653
1659
var camera = frameState . camera ;
1660
+ var mode = frameState . mode ;
1661
+
1662
+ if ( scene . _useWebVR && mode !== SceneMode . SCENE2D ) {
1663
+ updatePrimitives ( scene ) ;
1664
+ createPotentiallyVisibleSet ( scene ) ;
1665
+ updateAndClearFramebuffers ( scene , passState , backgroundColor , picking ) ;
1666
+ executeComputeCommands ( scene ) ;
1667
+
1668
+ // Based on Calculating Stereo pairs by Paul Bourke
1669
+ // http://paulbourke.net/stereographics/stereorender/
1654
1670
1655
- if ( scene . _useWebVR ) {
1656
- if ( frameState . mode !== SceneMode . SCENE2D ) {
1657
- // Based on Calculating Stereo pairs by Paul Bourke
1658
- // http://paulbourke.net/stereographics/stereorender/
1671
+ viewport . x = 0 ;
1672
+ viewport . y = 0 ;
1673
+ viewport . width = context . drawingBufferWidth * 0.5 ;
1674
+ viewport . height = context . drawingBufferHeight ;
1659
1675
1660
- viewport . x = 0 ;
1661
- viewport . y = 0 ;
1662
- viewport . width = context . drawingBufferWidth * 0.5 ;
1663
- viewport . height = context . drawingBufferHeight ;
1676
+ var savedCamera = Camera . clone ( camera , scene . _cameraVR ) ;
1664
1677
1665
- var savedCamera = Camera . clone ( camera , scene . _cameraVR ) ;
1678
+ var near = camera . frustum . near ;
1679
+ var fo = near * 5.0 ;
1680
+ var eyeSeparation = fo / 30.0 ;
1681
+ var eyeTranslation = Cartesian3 . multiplyByScalar ( savedCamera . right , eyeSeparation * 0.5 , scratchEyeTranslation ) ;
1666
1682
1667
- var near = camera . frustum . near ;
1668
- var fo = near * 5.0 ;
1669
- var eyeSeparation = fo / 30.0 ;
1670
- var eyeTranslation = Cartesian3 . multiplyByScalar ( savedCamera . right , eyeSeparation * 0.5 , scratchEyeTranslation ) ;
1683
+ camera . frustum . aspectRatio = viewport . width / viewport . height ;
1671
1684
1672
- camera . frustum . aspectRatio = viewport . width / viewport . height ;
1685
+ var offset = 0.5 * eyeSeparation * near / fo ;
1673
1686
1674
- var offset = 0.5 * eyeSeparation * near / fo ;
1687
+ Cartesian3 . add ( savedCamera . position , eyeTranslation , camera . position ) ;
1688
+ camera . frustum . xOffset = offset ;
1675
1689
1676
- Cartesian3 . add ( savedCamera . position , eyeTranslation , camera . position ) ;
1677
- camera . frustum . xOffset = offset ;
1690
+ executeCommands ( scene , passState ) ;
1678
1691
1679
- executeCommands ( scene , passState ) ;
1692
+ viewport . x = passState . viewport . width ;
1680
1693
1681
- viewport . x = passState . viewport . width ;
1694
+ Cartesian3 . subtract ( savedCamera . position , eyeTranslation , camera . position ) ;
1695
+ camera . frustum . xOffset = - offset ;
1682
1696
1683
- Cartesian3 . subtract ( savedCamera . position , eyeTranslation , camera . position ) ;
1684
- camera . frustum . xOffset = - offset ;
1697
+ executeCommands ( scene , passState ) ;
1685
1698
1686
- executeCommands ( scene , passState ) ;
1699
+ Camera . clone ( savedCamera , camera ) ;
1700
+ } else {
1701
+ viewport . x = 0 ;
1702
+ viewport . y = 0 ;
1703
+ viewport . width = context . drawingBufferWidth ;
1704
+ viewport . height = context . drawingBufferHeight ;
1687
1705
1688
- Camera . clone ( savedCamera , camera ) ;
1706
+ if ( mode !== SceneMode . SCENE2D ) {
1707
+ executeCommandsInViewport ( true , scene , passState , backgroundColor , picking ) ;
1689
1708
} else {
1690
- viewport . x = 0 ;
1691
- viewport . y = 0 ;
1692
- viewport . width = context . drawingBufferWidth * 0.5 ;
1693
- viewport . height = context . drawingBufferHeight ;
1709
+ execute2DViewportCommands ( scene , passState , backgroundColor , picking ) ;
1710
+ }
1711
+ }
1712
+ }
1694
1713
1695
- var savedTop = camera . frustum . top ;
1714
+ var scratch2DViewportCartographic = new Cartographic ( Math . PI , CesiumMath . PI_OVER_TWO ) ;
1715
+ var scratch2DViewportMaxCoord = new Cartesian3 ( ) ;
1716
+ var scratch2DViewportSavedPosition = new Cartesian3 ( ) ;
1717
+ var scratch2DViewportTransform = new Matrix4 ( ) ;
1718
+ var scratch2DViewportCameraTransform = new Matrix4 ( ) ;
1719
+ var scratch2DViewportEyePoint = new Cartesian3 ( ) ;
1720
+ var scratch2DViewportWindowCoords = new Cartesian3 ( ) ;
1696
1721
1697
- camera . frustum . top = camera . frustum . right * ( viewport . height / viewport . width ) ;
1698
- camera . frustum . bottom = - camera . frustum . top ;
1722
+ function execute2DViewportCommands ( scene , passState , backgroundColor , picking ) {
1723
+ var context = scene . context ;
1724
+ var frameState = scene . frameState ;
1725
+ var camera = scene . camera ;
1726
+ var viewport = passState . viewport ;
1699
1727
1700
- executeCommands ( scene , passState ) ;
1728
+ var maxCartographic = scratch2DViewportCartographic ;
1729
+ var maxCoord = scratch2DViewportMaxCoord ;
1701
1730
1702
- viewport . x = passState . viewport . width ;
1731
+ var projection = scene . mapProjection ;
1732
+ projection . project ( maxCartographic , maxCoord ) ;
1703
1733
1704
- executeCommands ( scene , passState ) ;
1734
+ var position = Cartesian3 . clone ( camera . position , scratch2DViewportSavedPosition ) ;
1735
+ var transform = Matrix4 . clone ( camera . transform , scratch2DViewportCameraTransform ) ;
1736
+ var frustum = camera . frustum . clone ( ) ;
1705
1737
1706
- camera . frustum . top = savedTop ;
1707
- camera . frustum . bottom = - savedTop ;
1708
- }
1738
+ camera . _setTransform ( Matrix4 . IDENTITY ) ;
1739
+
1740
+ var viewportTransformation = Matrix4 . computeViewportTransformation ( viewport , 0.0 , 1.0 , scratch2DViewportTransform ) ;
1741
+ var projectionMatrix = camera . frustum . projectionMatrix ;
1742
+
1743
+ var x = camera . positionWC . y ;
1744
+ var eyePoint = Cartesian3 . fromElements ( Math . sign ( x ) * maxCoord . x - x , 0.0 , - camera . positionWC . x , scratch2DViewportEyePoint ) ;
1745
+ var windowCoordinates = Transforms . pointToGLWindowCoordinates ( projectionMatrix , viewportTransformation , eyePoint , scratch2DViewportWindowCoords ) ;
1746
+
1747
+ windowCoordinates . x = Math . floor ( windowCoordinates . x ) ;
1748
+
1749
+ var viewportX = viewport . x ;
1750
+ var viewportWidth = viewport . width ;
1751
+
1752
+ if ( x === 0.0 || windowCoordinates . x <= 0.0 || windowCoordinates . x >= context . drawingBufferWidth ) {
1753
+ executeCommandsInViewport ( true , scene , passState , backgroundColor , picking ) ;
1754
+ } else if ( windowCoordinates . x > context . drawingBufferWidth * 0.5 ) {
1755
+ viewport . width = windowCoordinates . x ;
1756
+
1757
+ camera . frustum . right = maxCoord . x - x ;
1758
+
1759
+ executeCommandsInViewport ( true , scene , passState , backgroundColor , picking ) ;
1760
+
1761
+ viewport . x += windowCoordinates . x ;
1762
+
1763
+ camera . position . x = - camera . position . x ;
1764
+
1765
+ var right = camera . frustum . right ;
1766
+ camera . frustum . right = - camera . frustum . left ;
1767
+ camera . frustum . left = - right ;
1768
+
1769
+ frameState . cullingVolume = camera . frustum . computeCullingVolume ( camera . positionWC , camera . directionWC , camera . upWC ) ;
1770
+ context . uniformState . update ( frameState ) ;
1771
+
1772
+ executeCommandsInViewport ( false , scene , passState , backgroundColor , picking ) ;
1709
1773
} else {
1710
- viewport . x = 0 ;
1711
- viewport . y = 0 ;
1712
- viewport . width = context . drawingBufferWidth ;
1713
- viewport . height = context . drawingBufferHeight ;
1774
+ viewport . x += windowCoordinates . x ;
1775
+ viewport . width -= windowCoordinates . x ;
1714
1776
1715
- executeCommands ( scene , passState ) ;
1777
+ camera . frustum . left = - maxCoord . x - x ;
1778
+
1779
+ executeCommandsInViewport ( true , scene , passState , backgroundColor , picking ) ;
1780
+
1781
+ viewport . x = viewport . x - viewport . width ;
1782
+
1783
+ camera . position . x = - camera . position . x ;
1784
+
1785
+ var left = camera . frustum . left ;
1786
+ camera . frustum . left = - camera . frustum . right ;
1787
+ camera . frustum . right = - left ;
1788
+
1789
+ frameState . cullingVolume = camera . frustum . computeCullingVolume ( camera . positionWC , camera . directionWC , camera . upWC ) ;
1790
+ context . uniformState . update ( frameState ) ;
1791
+
1792
+ executeCommandsInViewport ( false , scene , passState , backgroundColor , picking ) ;
1716
1793
}
1794
+
1795
+ camera . _setTransform ( transform ) ;
1796
+ Cartesian3 . clone ( position , camera . position ) ;
1797
+ camera . frustum = frustum . clone ( ) ;
1798
+
1799
+ viewport . x = viewportX ;
1800
+ viewport . width = viewportWidth ;
1801
+ }
1802
+
1803
+ function executeCommandsInViewport ( firstViewport , scene , passState , backgroundColor , picking ) {
1804
+ if ( ! firstViewport ) {
1805
+ scene . frameState . commandList . length = 0 ;
1806
+ }
1807
+
1808
+ updatePrimitives ( scene ) ;
1809
+ createPotentiallyVisibleSet ( scene ) ;
1810
+
1811
+ if ( firstViewport ) {
1812
+ updateAndClearFramebuffers ( scene , passState , backgroundColor , picking ) ;
1813
+ executeComputeCommands ( scene ) ;
1814
+ }
1815
+
1816
+ executeCommands ( scene , passState ) ;
1717
1817
}
1718
1818
1719
1819
function updateEnvironment ( scene ) {
@@ -1738,6 +1838,7 @@ define([
1738
1838
scene . _depthPlane . update ( frameState ) ;
1739
1839
}
1740
1840
}
1841
+
1741
1842
function updatePrimitives ( scene ) {
1742
1843
var frameState = scene . _frameState ;
1743
1844
@@ -1753,12 +1854,14 @@ define([
1753
1854
var context = scene . _context ;
1754
1855
var environmentState = scene . _environmentState ;
1755
1856
1857
+ var useWebVR = scene . _useWebVR && scene . mode !== SceneMode . SCENE2D ;
1858
+
1756
1859
// Preserve the reference to the original framebuffer.
1757
1860
environmentState . originalFramebuffer = passState . framebuffer ;
1758
1861
1759
1862
// Manage sun bloom post-processing effect.
1760
1863
if ( defined ( scene . sun ) && scene . sunBloom !== scene . _sunBloom ) {
1761
- if ( scene . sunBloom && ! scene . _useWebVR ) {
1864
+ if ( scene . sunBloom && ! useWebVR ) {
1762
1865
scene . _sunPostProcess = new SunPostProcess ( ) ;
1763
1866
} else if ( defined ( scene . _sunPostProcess ) ) {
1764
1867
scene . _sunPostProcess = scene . _sunPostProcess . destroy ( ) ;
@@ -1808,7 +1911,7 @@ define([
1808
1911
scene . _fxaa . clear ( context , passState , clearColor ) ;
1809
1912
}
1810
1913
1811
- if ( environmentState . isSunVisible && scene . sunBloom && ! scene . _useWebVR ) {
1914
+ if ( environmentState . isSunVisible && scene . sunBloom && ! useWebVR ) {
1812
1915
passState . framebuffer = scene . _sunPostProcess . update ( passState ) ;
1813
1916
} else if ( useGlobeDepthFramebuffer ) {
1814
1917
passState . framebuffer = scene . _globeDepth . framebuffer ;
@@ -1932,22 +2035,12 @@ define([
1932
2035
passState . blendingEnabled = undefined ;
1933
2036
passState . scissorTest = undefined ;
1934
2037
1935
- var viewport = passState . viewport ;
1936
- viewport . x = 0 ;
1937
- viewport . y = 0 ;
1938
- viewport . width = context . drawingBufferWidth ;
1939
- viewport . height = context . drawingBufferHeight ;
1940
-
1941
2038
if ( defined ( scene . globe ) ) {
1942
2039
scene . globe . beginFrame ( frameState ) ;
1943
2040
}
1944
2041
1945
2042
updateEnvironment ( scene ) ;
1946
- updatePrimitives ( scene ) ;
1947
- createPotentiallyVisibleSet ( scene ) ;
1948
- updateAndClearFramebuffers ( scene , passState , defaultValue ( scene . backgroundColor , Color . BLACK ) ) ;
1949
- executeComputeCommands ( scene ) ;
1950
- executeViewportCommands ( scene , passState ) ;
2043
+ updateAndExecuteCommands ( scene , passState , defaultValue ( scene . backgroundColor , Color . BLACK ) ) ;
1951
2044
resolveFramebuffers ( scene , passState ) ;
1952
2045
executeOverlayCommands ( scene , passState ) ;
1953
2046
@@ -2130,10 +2223,7 @@ define([
2130
2223
2131
2224
var passState = this . _pickFramebuffer . begin ( scratchRectangle ) ;
2132
2225
2133
- updatePrimitives ( this ) ;
2134
- createPotentiallyVisibleSet ( this ) ;
2135
- updateAndClearFramebuffers ( this , passState , scratchColorZero , true ) ;
2136
- executeCommands ( this , passState ) ;
2226
+ updateAndExecuteCommands ( this , passState , scratchColorZero , true ) ;
2137
2227
resolveFramebuffers ( this , passState ) ;
2138
2228
2139
2229
var object = this . _pickFramebuffer . end ( scratchRectangle ) ;
@@ -2420,4 +2510,4 @@ define([
2420
2510
} ;
2421
2511
2422
2512
return Scene ;
2423
- } ) ;
2513
+ } ) ;
0 commit comments