@cesium/engine 6.2.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/Build/ThirdParty/Workers/z-worker-pako.js +568 -407
  2. package/Build/Workers/{chunk-QRBRVGZC.js → chunk-2HJWSU7B.js} +4 -4
  3. package/Build/Workers/{chunk-ZQRZBHYI.js → chunk-46UD5ABS.js} +4 -4
  4. package/Build/Workers/{chunk-GVL5I7TC.js → chunk-4EBHOMFX.js} +17 -17
  5. package/Build/Workers/{chunk-CDGHUKQ4.js → chunk-5HDYHG3F.js} +13 -13
  6. package/Build/Workers/{chunk-CWJQGBWT.js → chunk-5M3U6ZMA.js} +1 -1
  7. package/Build/Workers/{chunk-Y4OJ4B23.js → chunk-5WQ523AW.js} +5 -5
  8. package/Build/Workers/{chunk-NE4JNU6H.js → chunk-5YLJ77FF.js} +10 -10
  9. package/Build/Workers/{chunk-SV7DDPAC.js → chunk-6HZQPRUS.js} +1 -1
  10. package/Build/Workers/{chunk-434ZTTFX.js → chunk-6VJVYK2V.js} +2 -2
  11. package/Build/Workers/{chunk-LGJUI2CE.js → chunk-72SANQJV.js} +5 -5
  12. package/Build/Workers/{chunk-QTZQZY2C.js → chunk-7XEAYGZK.js} +34 -10
  13. package/Build/Workers/{chunk-Z4JUBRHP.js → chunk-AIPU2VSX.js} +6 -6
  14. package/Build/Workers/{chunk-PZ2WJWUG.js → chunk-AR5DNBJ4.js} +6 -6
  15. package/Build/Workers/{chunk-BUZDZBUH.js → chunk-BZP4T2JJ.js} +10 -10
  16. package/Build/Workers/{chunk-Z2SIPUKB.js → chunk-DTAIXKTO.js} +6 -6
  17. package/Build/Workers/{chunk-HOT2SNXP.js → chunk-F6SE42BK.js} +127 -90
  18. package/Build/Workers/{chunk-TIXXVKUY.js → chunk-FP6GYBFX.js} +10 -10
  19. package/Build/Workers/{chunk-ARPTYYKS.js → chunk-GEJTYLCO.js} +5 -5
  20. package/Build/Workers/{chunk-XUTVA4K5.js → chunk-GV56Q4LU.js} +11 -11
  21. package/Build/Workers/{chunk-HPP4JLNH.js → chunk-IQBYFRVW.js} +7 -7
  22. package/Build/Workers/{chunk-O43GWBSF.js → chunk-IX2JCCNM.js} +1 -1
  23. package/Build/Workers/{chunk-H5DUXHCV.js → chunk-JCNXK6EL.js} +11 -11
  24. package/Build/Workers/{chunk-SQVTYRZY.js → chunk-JJ4VBOQ3.js} +4 -4
  25. package/Build/Workers/{chunk-RIDPF7PO.js → chunk-JXDC723O.js} +2 -2
  26. package/Build/Workers/{chunk-R3HUGXBH.js → chunk-JY5YEZFA.js} +8 -8
  27. package/Build/Workers/{chunk-GF5TNNKP.js → chunk-L2ZN645J.js} +6 -6
  28. package/Build/Workers/{chunk-5GDBZTHX.js → chunk-LZ7JIV3K.js} +17 -17
  29. package/Build/Workers/{chunk-52VSIKEA.js → chunk-LZGHD6NY.js} +15 -15
  30. package/Build/Workers/{chunk-RH4N2ONY.js → chunk-MY3VNFGQ.js} +7 -7
  31. package/Build/Workers/{chunk-MN34FIF5.js → chunk-NKPBIX7F.js} +1 -1
  32. package/Build/Workers/{chunk-AXFRNOVC.js → chunk-NY3K4IM3.js} +12 -12
  33. package/Build/Workers/{chunk-MW3CJYLX.js → chunk-ODW7WYM4.js} +2 -2
  34. package/Build/Workers/{chunk-R4OZKBXH.js → chunk-OVLG3FRS.js} +6 -6
  35. package/Build/Workers/{chunk-TMPVBFJQ.js → chunk-PNBGBETF.js} +10 -10
  36. package/Build/Workers/{chunk-DR5XZ6K5.js → chunk-PTQQUQC3.js} +13 -13
  37. package/Build/Workers/{chunk-3PW6ZBN4.js → chunk-QZAD5O7I.js} +7 -7
  38. package/Build/Workers/{chunk-5SK36PU4.js → chunk-R5X4OQT4.js} +7 -7
  39. package/Build/Workers/{chunk-DMCSY5BU.js → chunk-RAEV7K66.js} +5 -5
  40. package/Build/Workers/{chunk-BP467WX3.js → chunk-RV7ZYPFT.js} +4 -4
  41. package/Build/Workers/{chunk-5HLGKKG3.js → chunk-S4MAZ3SS.js} +2 -2
  42. package/Build/Workers/{chunk-LX6XV4DK.js → chunk-S6SKF6DT.js} +5 -5
  43. package/Build/Workers/{chunk-HUPNRBWW.js → chunk-U2VCRRQW.js} +6 -6
  44. package/Build/Workers/{chunk-SNN7WOC2.js → chunk-UAEW6HKG.js} +13 -13
  45. package/Build/Workers/{chunk-HFKSAB5K.js → chunk-UDO6BFSF.js} +13 -13
  46. package/Build/Workers/{chunk-YBKFS53K.js → chunk-UGK3FCDY.js} +1 -1
  47. package/Build/Workers/{chunk-PIXK6KHB.js → chunk-VK3EJHWI.js} +2 -2
  48. package/Build/Workers/{chunk-5IRLXUTA.js → chunk-VRGFV2UO.js} +7 -7
  49. package/Build/Workers/{chunk-JGG36SQV.js → chunk-WBQCVXR3.js} +4 -4
  50. package/Build/Workers/{chunk-4KP73B43.js → chunk-WZU2YLWG.js} +3 -3
  51. package/Build/Workers/{chunk-LGL4P5KL.js → chunk-XWXM2O2R.js} +6 -6
  52. package/Build/Workers/{chunk-FWGNCYP6.js → chunk-YUCVWAY6.js} +7 -7
  53. package/Build/Workers/{chunk-CSIZ3BGT.js → chunk-ZK5JOS3D.js} +14 -14
  54. package/Build/Workers/{chunk-HPH5HSFE.js → chunk-ZUA2UUNV.js} +2 -2
  55. package/Build/Workers/combineGeometry.js +23 -23
  56. package/Build/Workers/createBoxGeometry.js +17 -17
  57. package/Build/Workers/createBoxOutlineGeometry.js +15 -15
  58. package/Build/Workers/createCircleGeometry.js +25 -25
  59. package/Build/Workers/createCircleOutlineGeometry.js +18 -18
  60. package/Build/Workers/createCoplanarPolygonGeometry.js +32 -32
  61. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +30 -30
  62. package/Build/Workers/createCorridorGeometry.js +28 -29
  63. package/Build/Workers/createCorridorOutlineGeometry.js +27 -28
  64. package/Build/Workers/createCylinderGeometry.js +19 -19
  65. package/Build/Workers/createCylinderOutlineGeometry.js +17 -17
  66. package/Build/Workers/createEllipseGeometry.js +25 -25
  67. package/Build/Workers/createEllipseOutlineGeometry.js +18 -18
  68. package/Build/Workers/createEllipsoidGeometry.js +18 -18
  69. package/Build/Workers/createEllipsoidOutlineGeometry.js +17 -17
  70. package/Build/Workers/createFrustumGeometry.js +17 -17
  71. package/Build/Workers/createFrustumOutlineGeometry.js +17 -17
  72. package/Build/Workers/createGeometry.js +23 -23
  73. package/Build/Workers/createGroundPolylineGeometry.js +21 -21
  74. package/Build/Workers/createPlaneGeometry.js +15 -15
  75. package/Build/Workers/createPlaneOutlineGeometry.js +14 -14
  76. package/Build/Workers/createPolygonGeometry.js +31 -166
  77. package/Build/Workers/createPolygonOutlineGeometry.js +29 -29
  78. package/Build/Workers/createPolylineGeometry.js +24 -24
  79. package/Build/Workers/createPolylineVolumeGeometry.js +31 -33
  80. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +26 -27
  81. package/Build/Workers/createRectangleGeometry.js +26 -26
  82. package/Build/Workers/createRectangleOutlineGeometry.js +19 -19
  83. package/Build/Workers/createSimplePolylineGeometry.js +22 -22
  84. package/Build/Workers/createSphereGeometry.js +18 -18
  85. package/Build/Workers/createSphereOutlineGeometry.js +17 -17
  86. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  87. package/Build/Workers/createVectorTileClampedPolylines.js +14 -14
  88. package/Build/Workers/createVectorTileGeometries.js +23 -23
  89. package/Build/Workers/createVectorTilePoints.js +12 -12
  90. package/Build/Workers/createVectorTilePolygons.js +21 -21
  91. package/Build/Workers/createVectorTilePolylines.js +14 -14
  92. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +21 -21
  93. package/Build/Workers/createVerticesFromHeightmap.js +21 -21
  94. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +18 -18
  95. package/Build/Workers/createWallGeometry.js +23 -23
  96. package/Build/Workers/createWallOutlineGeometry.js +22 -22
  97. package/Build/Workers/decodeDraco.js +11 -11
  98. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
  99. package/Build/Workers/decodeI3S.js +9 -9
  100. package/Build/Workers/transcodeKTX2.js +7 -7
  101. package/Build/Workers/transferTypedArrayTest.js +1 -1
  102. package/Build/Workers/upsampleQuantizedTerrainMesh.js +21 -21
  103. package/LICENSE.md +1 -1
  104. package/Source/Assets/approximateTerrainHeights.json +1 -1
  105. package/Source/Core/GregorianDate.js +85 -0
  106. package/Source/Core/HeadingPitchRange.js +2 -2
  107. package/Source/Core/Ion.js +1 -1
  108. package/Source/Core/PolygonGeometry.js +0 -169
  109. package/Source/Core/Resource.js +30 -69
  110. package/Source/Core/Transforms.js +27 -18
  111. package/Source/Core/createWorldBathymetryAsync.js +45 -0
  112. package/Source/DataSources/EllipsoidGeometryUpdater.js +3 -4
  113. package/Source/DataSources/Entity.js +8 -5
  114. package/Source/DataSources/EntityCollection.js +1 -2
  115. package/Source/DataSources/GeometryUpdater.js +1 -2
  116. package/Source/DataSources/GroundGeometryUpdater.js +6 -3
  117. package/Source/DataSources/ModelVisualizer.js +19 -98
  118. package/Source/DataSources/PolygonGeometryUpdater.js +14 -2
  119. package/Source/DataSources/PolylineGeometryUpdater.js +9 -8
  120. package/Source/DataSources/TerrainOffsetProperty.js +15 -23
  121. package/Source/Renderer/AutomaticUniforms.js +121 -1
  122. package/Source/Renderer/UniformState.js +127 -0
  123. package/Source/Scene/ArcGisMapService.js +1 -1
  124. package/Source/Scene/Atmosphere.js +127 -0
  125. package/Source/Scene/Billboard.js +29 -26
  126. package/Source/Scene/BillboardCollection.js +3 -3
  127. package/Source/Scene/Camera.js +1 -1
  128. package/Source/Scene/Cesium3DTile.js +1 -0
  129. package/Source/Scene/Cesium3DTileContent.js +14 -0
  130. package/Source/Scene/Cesium3DTileset.js +326 -45
  131. package/Source/Scene/Cesium3DTilesetTraversal.js +4 -0
  132. package/Source/Scene/Composite3DTileContent.js +42 -0
  133. package/Source/Scene/DynamicAtmosphereLightingType.js +56 -0
  134. package/Source/Scene/Empty3DTileContent.js +4 -0
  135. package/Source/Scene/Fog.js +1 -0
  136. package/Source/Scene/FrameState.js +9 -1
  137. package/Source/Scene/Geometry3DTileContent.js +4 -0
  138. package/Source/Scene/Globe.js +3 -2
  139. package/Source/Scene/GlobeSurfaceTileProvider.js +3 -1
  140. package/Source/Scene/GltfLoader.js +15 -5
  141. package/Source/Scene/HeightReference.js +59 -2
  142. package/Source/Scene/Implicit3DTileContent.js +4 -0
  143. package/Source/Scene/LabelCollection.js +2 -2
  144. package/Source/Scene/Model/AtmospherePipelineStage.js +59 -0
  145. package/Source/Scene/Model/B3dmLoader.js +4 -0
  146. package/Source/Scene/Model/FeatureIdPipelineStage.js +25 -2
  147. package/Source/Scene/Model/I3dmLoader.js +4 -0
  148. package/Source/Scene/Model/InstancingPipelineStage.js +24 -6
  149. package/Source/Scene/Model/MetadataPipelineStage.js +31 -3
  150. package/Source/Scene/Model/Model.js +82 -32
  151. package/Source/Scene/Model/Model3DTileContent.js +31 -0
  152. package/Source/Scene/Model/ModelAnimationChannel.js +16 -15
  153. package/Source/Scene/Model/ModelSceneGraph.js +6 -0
  154. package/Source/Scene/Model/pickModel.js +408 -0
  155. package/Source/Scene/Multiple3DTileContent.js +42 -0
  156. package/Source/Scene/QuadtreePrimitive.js +1 -1
  157. package/Source/Scene/Scene.js +198 -16
  158. package/Source/Scene/ScreenSpaceCameraController.js +2 -6
  159. package/Source/Scene/SkyAtmosphere.js +5 -6
  160. package/Source/Scene/Terrain.js +49 -0
  161. package/Source/Scene/TileBoundingS2Cell.js +2 -2
  162. package/Source/Scene/Tileset3DTileContent.js +4 -0
  163. package/Source/Scene/Vector3DTileContent.js +4 -0
  164. package/Source/Shaders/AtmosphereCommon.glsl +3 -11
  165. package/Source/Shaders/AtmosphereCommon.js +3 -11
  166. package/Source/Shaders/Builtin/CzmBuiltins.js +12 -0
  167. package/Source/Shaders/Builtin/Functions/applyHSBShift.glsl +32 -0
  168. package/Source/Shaders/Builtin/Functions/applyHSBShift.js +34 -0
  169. package/Source/Shaders/Builtin/Functions/approximateTanh.glsl +10 -0
  170. package/Source/Shaders/Builtin/Functions/approximateTanh.js +12 -0
  171. package/Source/Shaders/Builtin/Functions/computeAtmosphereColor.glsl +44 -0
  172. package/Source/Shaders/Builtin/Functions/computeAtmosphereColor.js +46 -0
  173. package/Source/Shaders/Builtin/Functions/computeGroundAtmosphereScattering.glsl +30 -0
  174. package/Source/Shaders/Builtin/Functions/computeGroundAtmosphereScattering.js +32 -0
  175. package/Source/Shaders/Builtin/Functions/computeScattering.glsl +150 -0
  176. package/Source/Shaders/Builtin/Functions/computeScattering.js +152 -0
  177. package/Source/Shaders/Builtin/Functions/getDynamicAtmosphereLightDirection.glsl +22 -0
  178. package/Source/Shaders/Builtin/Functions/getDynamicAtmosphereLightDirection.js +24 -0
  179. package/Source/Shaders/Builtin/Functions/translateRelativeToEye.glsl +5 -0
  180. package/Source/Shaders/Builtin/Functions/translateRelativeToEye.js +5 -0
  181. package/Source/Shaders/GlobeFS.glsl +16 -25
  182. package/Source/Shaders/GlobeFS.js +16 -25
  183. package/Source/Shaders/GlobeVS.glsl +1 -1
  184. package/Source/Shaders/GlobeVS.js +1 -1
  185. package/Source/Shaders/Model/AtmosphereStageFS.glsl +111 -0
  186. package/Source/Shaders/Model/AtmosphereStageFS.js +113 -0
  187. package/Source/Shaders/Model/AtmosphereStageVS.glsl +12 -0
  188. package/Source/Shaders/Model/AtmosphereStageVS.js +14 -0
  189. package/Source/Shaders/Model/GeometryStageFS.glsl +1 -1
  190. package/Source/Shaders/Model/GeometryStageFS.js +1 -1
  191. package/Source/Shaders/Model/GeometryStageVS.glsl +4 -4
  192. package/Source/Shaders/Model/GeometryStageVS.js +4 -4
  193. package/Source/Shaders/Model/ModelColorStageFS.glsl +1 -1
  194. package/Source/Shaders/Model/ModelColorStageFS.js +2 -1
  195. package/Source/Shaders/Model/ModelFS.glsl +4 -0
  196. package/Source/Shaders/Model/ModelFS.js +4 -0
  197. package/Source/Shaders/Model/ModelVS.glsl +9 -4
  198. package/Source/Shaders/Model/ModelVS.js +9 -4
  199. package/Source/Shaders/SkyAtmosphereCommon.glsl +3 -13
  200. package/Source/Shaders/SkyAtmosphereCommon.js +3 -13
  201. package/Source/Shaders/SkyAtmosphereFS.glsl +5 -10
  202. package/Source/Shaders/SkyAtmosphereFS.js +5 -10
  203. package/Source/Shaders/SkyAtmosphereVS.glsl +3 -2
  204. package/Source/Shaders/SkyAtmosphereVS.js +3 -2
  205. package/Source/ThirdParty/Workers/z-worker-pako.js +1 -1
  206. package/Source/ThirdParty/draco_decoder.wasm +0 -0
  207. package/index.d.ts +283 -65
  208. package/index.js +260 -247
  209. package/package.json +3 -3
  210. package/Build/Workers/chunk-ATB2I7OS.js +0 -55
@@ -0,0 +1,12 @@
1
+ //This file is automatically rebuilt by the Cesium build process.
2
+ export default "/**\n\
3
+ * Compute a rational approximation to tanh(x)\n\
4
+ *\n\
5
+ * @param {float} x A real number input\n\
6
+ * @returns {float} An approximation for tanh(x)\n\
7
+ */\n\
8
+ float czm_approximateTanh(float x) {\n\
9
+ float x2 = x * x;\n\
10
+ return max(-1.0, min(1.0, x * (27.0 + x2) / (27.0 + 9.0 * x2)));\n\
11
+ }\n\
12
+ ";
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Compute the atmosphere color, applying Rayleigh and Mie scattering. This
3
+ * builtin uses automatic uniforms so the atmophere settings are synced with the
4
+ * state of the Scene, even in other contexts like Model.
5
+ *
6
+ * @name czm_computeAtmosphereColor
7
+ * @glslFunction
8
+ *
9
+ * @param {vec3} positionWC Position of the fragment in world coords (low precision)
10
+ * @param {vec3} lightDirection Light direction from the sun or other light source.
11
+ * @param {vec3} rayleighColor The Rayleigh scattering color computed by a scattering function
12
+ * @param {vec3} mieColor The Mie scattering color computed by a scattering function
13
+ * @param {float} opacity The opacity computed by a scattering function.
14
+ */
15
+ vec4 czm_computeAtmosphereColor(
16
+ vec3 positionWC,
17
+ vec3 lightDirection,
18
+ vec3 rayleighColor,
19
+ vec3 mieColor,
20
+ float opacity
21
+ ) {
22
+ // Setup the primary ray: from the camera position to the vertex position.
23
+ vec3 cameraToPositionWC = positionWC - czm_viewerPositionWC;
24
+ vec3 cameraToPositionWCDirection = normalize(cameraToPositionWC);
25
+
26
+ float cosAngle = dot(cameraToPositionWCDirection, lightDirection);
27
+ float cosAngleSq = cosAngle * cosAngle;
28
+
29
+ float G = czm_atmosphereMieAnisotropy;
30
+ float GSq = G * G;
31
+
32
+ // The Rayleigh phase function.
33
+ float rayleighPhase = 3.0 / (50.2654824574) * (1.0 + cosAngleSq);
34
+ // The Mie phase function.
35
+ float miePhase = 3.0 / (25.1327412287) * ((1.0 - GSq) * (cosAngleSq + 1.0)) / (pow(1.0 + GSq - 2.0 * cosAngle * G, 1.5) * (2.0 + GSq));
36
+
37
+ // The final color is generated by combining the effects of the Rayleigh and Mie scattering.
38
+ vec3 rayleigh = rayleighPhase * rayleighColor;
39
+ vec3 mie = miePhase * mieColor;
40
+
41
+ vec3 color = (rayleigh + mie) * czm_atmosphereLightIntensity;
42
+
43
+ return vec4(color, opacity);
44
+ }
@@ -0,0 +1,46 @@
1
+ //This file is automatically rebuilt by the Cesium build process.
2
+ export default "/**\n\
3
+ * Compute the atmosphere color, applying Rayleigh and Mie scattering. This\n\
4
+ * builtin uses automatic uniforms so the atmophere settings are synced with the\n\
5
+ * state of the Scene, even in other contexts like Model.\n\
6
+ *\n\
7
+ * @name czm_computeAtmosphereColor\n\
8
+ * @glslFunction\n\
9
+ *\n\
10
+ * @param {vec3} positionWC Position of the fragment in world coords (low precision)\n\
11
+ * @param {vec3} lightDirection Light direction from the sun or other light source.\n\
12
+ * @param {vec3} rayleighColor The Rayleigh scattering color computed by a scattering function\n\
13
+ * @param {vec3} mieColor The Mie scattering color computed by a scattering function\n\
14
+ * @param {float} opacity The opacity computed by a scattering function.\n\
15
+ */\n\
16
+ vec4 czm_computeAtmosphereColor(\n\
17
+ vec3 positionWC,\n\
18
+ vec3 lightDirection,\n\
19
+ vec3 rayleighColor,\n\
20
+ vec3 mieColor,\n\
21
+ float opacity\n\
22
+ ) {\n\
23
+ // Setup the primary ray: from the camera position to the vertex position.\n\
24
+ vec3 cameraToPositionWC = positionWC - czm_viewerPositionWC;\n\
25
+ vec3 cameraToPositionWCDirection = normalize(cameraToPositionWC);\n\
26
+ \n\
27
+ float cosAngle = dot(cameraToPositionWCDirection, lightDirection);\n\
28
+ float cosAngleSq = cosAngle * cosAngle;\n\
29
+ \n\
30
+ float G = czm_atmosphereMieAnisotropy;\n\
31
+ float GSq = G * G;\n\
32
+ \n\
33
+ // The Rayleigh phase function.\n\
34
+ float rayleighPhase = 3.0 / (50.2654824574) * (1.0 + cosAngleSq);\n\
35
+ // The Mie phase function.\n\
36
+ float miePhase = 3.0 / (25.1327412287) * ((1.0 - GSq) * (cosAngleSq + 1.0)) / (pow(1.0 + GSq - 2.0 * cosAngle * G, 1.5) * (2.0 + GSq));\n\
37
+ \n\
38
+ // The final color is generated by combining the effects of the Rayleigh and Mie scattering.\n\
39
+ vec3 rayleigh = rayleighPhase * rayleighColor;\n\
40
+ vec3 mie = miePhase * mieColor;\n\
41
+ \n\
42
+ vec3 color = (rayleigh + mie) * czm_atmosphereLightIntensity;\n\
43
+ \n\
44
+ return vec4(color, opacity);\n\
45
+ }\n\
46
+ ";
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Compute atmosphere scattering for the ground atmosphere and fog. This method
3
+ * uses automatic uniforms so it is always synced with the scene settings.
4
+ *
5
+ * @name czm_computeGroundAtmosphereScattering
6
+ * @glslfunction
7
+ *
8
+ * @param {vec3} positionWC The position of the fragment in world coordinates.
9
+ * @param {vec3} lightDirection The direction of the light to calculate the scattering from.
10
+ * @param {vec3} rayleighColor The variable the Rayleigh scattering will be written to.
11
+ * @param {vec3} mieColor The variable the Mie scattering will be written to.
12
+ * @param {float} opacity The variable the transmittance will be written to.
13
+ */
14
+ void czm_computeGroundAtmosphereScattering(vec3 positionWC, vec3 lightDirection, out vec3 rayleighColor, out vec3 mieColor, out float opacity) {
15
+ vec3 cameraToPositionWC = positionWC - czm_viewerPositionWC;
16
+ vec3 cameraToPositionWCDirection = normalize(cameraToPositionWC);
17
+ czm_ray primaryRay = czm_ray(czm_viewerPositionWC, cameraToPositionWCDirection);
18
+
19
+ float atmosphereInnerRadius = length(positionWC);
20
+
21
+ czm_computeScattering(
22
+ primaryRay,
23
+ length(cameraToPositionWC),
24
+ lightDirection,
25
+ atmosphereInnerRadius,
26
+ rayleighColor,
27
+ mieColor,
28
+ opacity
29
+ );
30
+ }
@@ -0,0 +1,32 @@
1
+ //This file is automatically rebuilt by the Cesium build process.
2
+ export default "/**\n\
3
+ * Compute atmosphere scattering for the ground atmosphere and fog. This method\n\
4
+ * uses automatic uniforms so it is always synced with the scene settings.\n\
5
+ *\n\
6
+ * @name czm_computeGroundAtmosphereScattering\n\
7
+ * @glslfunction\n\
8
+ *\n\
9
+ * @param {vec3} positionWC The position of the fragment in world coordinates.\n\
10
+ * @param {vec3} lightDirection The direction of the light to calculate the scattering from.\n\
11
+ * @param {vec3} rayleighColor The variable the Rayleigh scattering will be written to.\n\
12
+ * @param {vec3} mieColor The variable the Mie scattering will be written to.\n\
13
+ * @param {float} opacity The variable the transmittance will be written to.\n\
14
+ */\n\
15
+ void czm_computeGroundAtmosphereScattering(vec3 positionWC, vec3 lightDirection, out vec3 rayleighColor, out vec3 mieColor, out float opacity) {\n\
16
+ vec3 cameraToPositionWC = positionWC - czm_viewerPositionWC;\n\
17
+ vec3 cameraToPositionWCDirection = normalize(cameraToPositionWC);\n\
18
+ czm_ray primaryRay = czm_ray(czm_viewerPositionWC, cameraToPositionWCDirection);\n\
19
+ \n\
20
+ float atmosphereInnerRadius = length(positionWC);\n\
21
+ \n\
22
+ czm_computeScattering(\n\
23
+ primaryRay,\n\
24
+ length(cameraToPositionWC),\n\
25
+ lightDirection,\n\
26
+ atmosphereInnerRadius,\n\
27
+ rayleighColor,\n\
28
+ mieColor,\n\
29
+ opacity\n\
30
+ );\n\
31
+ }\n\
32
+ ";
@@ -0,0 +1,150 @@
1
+ /**
2
+ * This function computes the colors contributed by Rayliegh and Mie scattering on a given ray, as well as
3
+ * the transmittance value for the ray. This function uses automatic uniforms
4
+ * so the atmosphere settings are always synced with the current scene.
5
+ *
6
+ * @name czm_computeScattering
7
+ * @glslfunction
8
+ *
9
+ * @param {czm_ray} primaryRay The ray from the camera to the position.
10
+ * @param {float} primaryRayLength The length of the primary ray.
11
+ * @param {vec3} lightDirection The direction of the light to calculate the scattering from.
12
+ * @param {vec3} rayleighColor The variable the Rayleigh scattering will be written to.
13
+ * @param {vec3} mieColor The variable the Mie scattering will be written to.
14
+ * @param {float} opacity The variable the transmittance will be written to.
15
+ */
16
+ void czm_computeScattering(
17
+ czm_ray primaryRay,
18
+ float primaryRayLength,
19
+ vec3 lightDirection,
20
+ float atmosphereInnerRadius,
21
+ out vec3 rayleighColor,
22
+ out vec3 mieColor,
23
+ out float opacity
24
+ ) {
25
+ const float ATMOSPHERE_THICKNESS = 111e3; // The thickness of the atmosphere in meters.
26
+ const int PRIMARY_STEPS_MAX = 16; // Maximum number of times the ray from the camera to the world position (primary ray) is sampled.
27
+ const int LIGHT_STEPS_MAX = 4; // Maximum number of times the light is sampled from the light source's intersection with the atmosphere to a sample position on the primary ray.
28
+
29
+ // Initialize the default scattering amounts to 0.
30
+ rayleighColor = vec3(0.0);
31
+ mieColor = vec3(0.0);
32
+ opacity = 0.0;
33
+
34
+ float atmosphereOuterRadius = atmosphereInnerRadius + ATMOSPHERE_THICKNESS;
35
+
36
+ vec3 origin = vec3(0.0);
37
+
38
+ // Calculate intersection from the camera to the outer ring of the atmosphere.
39
+ czm_raySegment primaryRayAtmosphereIntersect = czm_raySphereIntersectionInterval(primaryRay, origin, atmosphereOuterRadius);
40
+
41
+ // Return empty colors if no intersection with the atmosphere geometry.
42
+ if (primaryRayAtmosphereIntersect == czm_emptyRaySegment) {
43
+ rayleighColor = vec3(1.0, 0.0, 1.0);
44
+ return;
45
+ }
46
+
47
+ // To deal with smaller values of PRIMARY_STEPS (e.g. 4)
48
+ // we implement a split strategy: sky or horizon.
49
+ // For performance reasons, instead of a if/else branch
50
+ // a soft choice is implemented through a weight 0.0 <= w_stop_gt_lprl <= 1.0
51
+ float x = 1e-7 * primaryRayAtmosphereIntersect.stop / length(primaryRayLength);
52
+ // Value close to 0.0: close to the horizon
53
+ // Value close to 1.0: above in the sky
54
+ float w_stop_gt_lprl = 0.5 * (1.0 + czm_approximateTanh(x));
55
+
56
+ // The ray should start from the first intersection with the outer atmopshere, or from the camera position, if it is inside the atmosphere.
57
+ float start_0 = primaryRayAtmosphereIntersect.start;
58
+ primaryRayAtmosphereIntersect.start = max(primaryRayAtmosphereIntersect.start, 0.0);
59
+ // The ray should end at the exit from the atmosphere or at the distance to the vertex, whichever is smaller.
60
+ primaryRayAtmosphereIntersect.stop = min(primaryRayAtmosphereIntersect.stop, length(primaryRayLength));
61
+
62
+ // For the number of ray steps, distinguish inside or outside atmosphere (outer space)
63
+ // (1) from outer space we have to use more ray steps to get a realistic rendering
64
+ // (2) within atmosphere we need fewer steps for faster rendering
65
+ float x_o_a = start_0 - ATMOSPHERE_THICKNESS; // ATMOSPHERE_THICKNESS used as an ad-hoc constant, no precise meaning here, only the order of magnitude matters
66
+ float w_inside_atmosphere = 1.0 - 0.5 * (1.0 + czm_approximateTanh(x_o_a));
67
+ int PRIMARY_STEPS = PRIMARY_STEPS_MAX - int(w_inside_atmosphere * 12.0); // Number of times the ray from the camera to the world position (primary ray) is sampled.
68
+ int LIGHT_STEPS = LIGHT_STEPS_MAX - int(w_inside_atmosphere * 2.0); // Number of times the light is sampled from the light source's intersection with the atmosphere to a sample position on the primary ray.
69
+
70
+ // Setup for sampling positions along the ray - starting from the intersection with the outer ring of the atmosphere.
71
+ float rayPositionLength = primaryRayAtmosphereIntersect.start;
72
+ // (1) Outside the atmosphere: constant rayStepLength
73
+ // (2) Inside atmosphere: variable rayStepLength to compensate the rough rendering of the smaller number of ray steps
74
+ float totalRayLength = primaryRayAtmosphereIntersect.stop - rayPositionLength;
75
+ float rayStepLengthIncrease = w_inside_atmosphere * ((1.0 - w_stop_gt_lprl) * totalRayLength / (float(PRIMARY_STEPS * (PRIMARY_STEPS + 1)) / 2.0));
76
+ float rayStepLength = max(1.0 - w_inside_atmosphere, w_stop_gt_lprl) * totalRayLength / max(7.0 * w_inside_atmosphere, float(PRIMARY_STEPS));
77
+
78
+ vec3 rayleighAccumulation = vec3(0.0);
79
+ vec3 mieAccumulation = vec3(0.0);
80
+ vec2 opticalDepth = vec2(0.0);
81
+ vec2 heightScale = vec2(czm_atmosphereRayleighScaleHeight, czm_atmosphereMieScaleHeight);
82
+
83
+ // Sample positions on the primary ray.
84
+ for (int i = 0; i < PRIMARY_STEPS_MAX; ++i) {
85
+
86
+ // The loop should be: for (int i = 0; i < PRIMARY_STEPS; ++i) {...} but WebGL1 cannot
87
+ // loop with non-constant condition, so it has to break early instead
88
+ if (i >= PRIMARY_STEPS) {
89
+ break;
90
+ }
91
+
92
+ // Calculate sample position along viewpoint ray.
93
+ vec3 samplePosition = primaryRay.origin + primaryRay.direction * (rayPositionLength + rayStepLength);
94
+
95
+ // Calculate height of sample position above ellipsoid.
96
+ float sampleHeight = length(samplePosition) - atmosphereInnerRadius;
97
+
98
+ // Calculate and accumulate density of particles at the sample position.
99
+ vec2 sampleDensity = exp(-sampleHeight / heightScale) * rayStepLength;
100
+ opticalDepth += sampleDensity;
101
+
102
+ // Generate ray from the sample position segment to the light source, up to the outer ring of the atmosphere.
103
+ czm_ray lightRay = czm_ray(samplePosition, lightDirection);
104
+ czm_raySegment lightRayAtmosphereIntersect = czm_raySphereIntersectionInterval(lightRay, origin, atmosphereOuterRadius);
105
+
106
+ float lightStepLength = lightRayAtmosphereIntersect.stop / float(LIGHT_STEPS);
107
+ float lightPositionLength = 0.0;
108
+
109
+ vec2 lightOpticalDepth = vec2(0.0);
110
+
111
+ // Sample positions along the light ray, to accumulate incidence of light on the latest sample segment.
112
+ for (int j = 0; j < LIGHT_STEPS_MAX; ++j) {
113
+
114
+ // The loop should be: for (int j = 0; i < LIGHT_STEPS; ++j) {...} but WebGL1 cannot
115
+ // loop with non-constant condition, so it has to break early instead
116
+ if (j >= LIGHT_STEPS) {
117
+ break;
118
+ }
119
+
120
+ // Calculate sample position along light ray.
121
+ vec3 lightPosition = samplePosition + lightDirection * (lightPositionLength + lightStepLength * 0.5);
122
+
123
+ // Calculate height of the light sample position above ellipsoid.
124
+ float lightHeight = length(lightPosition) - atmosphereInnerRadius;
125
+
126
+ // Calculate density of photons at the light sample position.
127
+ lightOpticalDepth += exp(-lightHeight / heightScale) * lightStepLength;
128
+
129
+ // Increment distance on light ray.
130
+ lightPositionLength += lightStepLength;
131
+ }
132
+
133
+ // Compute attenuation via the primary ray and the light ray.
134
+ vec3 attenuation = exp(-((czm_atmosphereMieCoefficient * (opticalDepth.y + lightOpticalDepth.y)) + (czm_atmosphereRayleighCoefficient * (opticalDepth.x + lightOpticalDepth.x))));
135
+
136
+ // Accumulate the scattering.
137
+ rayleighAccumulation += sampleDensity.x * attenuation;
138
+ mieAccumulation += sampleDensity.y * attenuation;
139
+
140
+ // Increment distance on primary ray.
141
+ rayPositionLength += (rayStepLength += rayStepLengthIncrease);
142
+ }
143
+
144
+ // Compute the scattering amount.
145
+ rayleighColor = czm_atmosphereRayleighCoefficient * rayleighAccumulation;
146
+ mieColor = czm_atmosphereMieCoefficient * mieAccumulation;
147
+
148
+ // Compute the transmittance i.e. how much light is passing through the atmosphere.
149
+ opacity = length(exp(-((czm_atmosphereMieCoefficient * opticalDepth.y) + (czm_atmosphereRayleighCoefficient * opticalDepth.x))));
150
+ }
@@ -0,0 +1,152 @@
1
+ //This file is automatically rebuilt by the Cesium build process.
2
+ export default "/**\n\
3
+ * This function computes the colors contributed by Rayliegh and Mie scattering on a given ray, as well as\n\
4
+ * the transmittance value for the ray. This function uses automatic uniforms\n\
5
+ * so the atmosphere settings are always synced with the current scene.\n\
6
+ *\n\
7
+ * @name czm_computeScattering\n\
8
+ * @glslfunction\n\
9
+ *\n\
10
+ * @param {czm_ray} primaryRay The ray from the camera to the position.\n\
11
+ * @param {float} primaryRayLength The length of the primary ray.\n\
12
+ * @param {vec3} lightDirection The direction of the light to calculate the scattering from.\n\
13
+ * @param {vec3} rayleighColor The variable the Rayleigh scattering will be written to.\n\
14
+ * @param {vec3} mieColor The variable the Mie scattering will be written to.\n\
15
+ * @param {float} opacity The variable the transmittance will be written to.\n\
16
+ */\n\
17
+ void czm_computeScattering(\n\
18
+ czm_ray primaryRay,\n\
19
+ float primaryRayLength,\n\
20
+ vec3 lightDirection,\n\
21
+ float atmosphereInnerRadius,\n\
22
+ out vec3 rayleighColor,\n\
23
+ out vec3 mieColor,\n\
24
+ out float opacity\n\
25
+ ) {\n\
26
+ const float ATMOSPHERE_THICKNESS = 111e3; // The thickness of the atmosphere in meters.\n\
27
+ const int PRIMARY_STEPS_MAX = 16; // Maximum number of times the ray from the camera to the world position (primary ray) is sampled.\n\
28
+ const int LIGHT_STEPS_MAX = 4; // Maximum number of times the light is sampled from the light source's intersection with the atmosphere to a sample position on the primary ray.\n\
29
+ \n\
30
+ // Initialize the default scattering amounts to 0.\n\
31
+ rayleighColor = vec3(0.0);\n\
32
+ mieColor = vec3(0.0);\n\
33
+ opacity = 0.0;\n\
34
+ \n\
35
+ float atmosphereOuterRadius = atmosphereInnerRadius + ATMOSPHERE_THICKNESS;\n\
36
+ \n\
37
+ vec3 origin = vec3(0.0);\n\
38
+ \n\
39
+ // Calculate intersection from the camera to the outer ring of the atmosphere.\n\
40
+ czm_raySegment primaryRayAtmosphereIntersect = czm_raySphereIntersectionInterval(primaryRay, origin, atmosphereOuterRadius);\n\
41
+ \n\
42
+ // Return empty colors if no intersection with the atmosphere geometry.\n\
43
+ if (primaryRayAtmosphereIntersect == czm_emptyRaySegment) {\n\
44
+ rayleighColor = vec3(1.0, 0.0, 1.0);\n\
45
+ return;\n\
46
+ }\n\
47
+ \n\
48
+ // To deal with smaller values of PRIMARY_STEPS (e.g. 4)\n\
49
+ // we implement a split strategy: sky or horizon.\n\
50
+ // For performance reasons, instead of a if/else branch\n\
51
+ // a soft choice is implemented through a weight 0.0 <= w_stop_gt_lprl <= 1.0\n\
52
+ float x = 1e-7 * primaryRayAtmosphereIntersect.stop / length(primaryRayLength);\n\
53
+ // Value close to 0.0: close to the horizon\n\
54
+ // Value close to 1.0: above in the sky\n\
55
+ float w_stop_gt_lprl = 0.5 * (1.0 + czm_approximateTanh(x));\n\
56
+ \n\
57
+ // The ray should start from the first intersection with the outer atmopshere, or from the camera position, if it is inside the atmosphere.\n\
58
+ float start_0 = primaryRayAtmosphereIntersect.start;\n\
59
+ primaryRayAtmosphereIntersect.start = max(primaryRayAtmosphereIntersect.start, 0.0);\n\
60
+ // The ray should end at the exit from the atmosphere or at the distance to the vertex, whichever is smaller.\n\
61
+ primaryRayAtmosphereIntersect.stop = min(primaryRayAtmosphereIntersect.stop, length(primaryRayLength));\n\
62
+ \n\
63
+ // For the number of ray steps, distinguish inside or outside atmosphere (outer space)\n\
64
+ // (1) from outer space we have to use more ray steps to get a realistic rendering\n\
65
+ // (2) within atmosphere we need fewer steps for faster rendering\n\
66
+ float x_o_a = start_0 - ATMOSPHERE_THICKNESS; // ATMOSPHERE_THICKNESS used as an ad-hoc constant, no precise meaning here, only the order of magnitude matters\n\
67
+ float w_inside_atmosphere = 1.0 - 0.5 * (1.0 + czm_approximateTanh(x_o_a));\n\
68
+ int PRIMARY_STEPS = PRIMARY_STEPS_MAX - int(w_inside_atmosphere * 12.0); // Number of times the ray from the camera to the world position (primary ray) is sampled.\n\
69
+ int LIGHT_STEPS = LIGHT_STEPS_MAX - int(w_inside_atmosphere * 2.0); // Number of times the light is sampled from the light source's intersection with the atmosphere to a sample position on the primary ray.\n\
70
+ \n\
71
+ // Setup for sampling positions along the ray - starting from the intersection with the outer ring of the atmosphere.\n\
72
+ float rayPositionLength = primaryRayAtmosphereIntersect.start;\n\
73
+ // (1) Outside the atmosphere: constant rayStepLength\n\
74
+ // (2) Inside atmosphere: variable rayStepLength to compensate the rough rendering of the smaller number of ray steps\n\
75
+ float totalRayLength = primaryRayAtmosphereIntersect.stop - rayPositionLength;\n\
76
+ float rayStepLengthIncrease = w_inside_atmosphere * ((1.0 - w_stop_gt_lprl) * totalRayLength / (float(PRIMARY_STEPS * (PRIMARY_STEPS + 1)) / 2.0));\n\
77
+ float rayStepLength = max(1.0 - w_inside_atmosphere, w_stop_gt_lprl) * totalRayLength / max(7.0 * w_inside_atmosphere, float(PRIMARY_STEPS));\n\
78
+ \n\
79
+ vec3 rayleighAccumulation = vec3(0.0);\n\
80
+ vec3 mieAccumulation = vec3(0.0);\n\
81
+ vec2 opticalDepth = vec2(0.0);\n\
82
+ vec2 heightScale = vec2(czm_atmosphereRayleighScaleHeight, czm_atmosphereMieScaleHeight);\n\
83
+ \n\
84
+ // Sample positions on the primary ray.\n\
85
+ for (int i = 0; i < PRIMARY_STEPS_MAX; ++i) {\n\
86
+ \n\
87
+ // The loop should be: for (int i = 0; i < PRIMARY_STEPS; ++i) {...} but WebGL1 cannot\n\
88
+ // loop with non-constant condition, so it has to break early instead\n\
89
+ if (i >= PRIMARY_STEPS) {\n\
90
+ break;\n\
91
+ }\n\
92
+ \n\
93
+ // Calculate sample position along viewpoint ray.\n\
94
+ vec3 samplePosition = primaryRay.origin + primaryRay.direction * (rayPositionLength + rayStepLength);\n\
95
+ \n\
96
+ // Calculate height of sample position above ellipsoid.\n\
97
+ float sampleHeight = length(samplePosition) - atmosphereInnerRadius;\n\
98
+ \n\
99
+ // Calculate and accumulate density of particles at the sample position.\n\
100
+ vec2 sampleDensity = exp(-sampleHeight / heightScale) * rayStepLength;\n\
101
+ opticalDepth += sampleDensity;\n\
102
+ \n\
103
+ // Generate ray from the sample position segment to the light source, up to the outer ring of the atmosphere.\n\
104
+ czm_ray lightRay = czm_ray(samplePosition, lightDirection);\n\
105
+ czm_raySegment lightRayAtmosphereIntersect = czm_raySphereIntersectionInterval(lightRay, origin, atmosphereOuterRadius);\n\
106
+ \n\
107
+ float lightStepLength = lightRayAtmosphereIntersect.stop / float(LIGHT_STEPS);\n\
108
+ float lightPositionLength = 0.0;\n\
109
+ \n\
110
+ vec2 lightOpticalDepth = vec2(0.0);\n\
111
+ \n\
112
+ // Sample positions along the light ray, to accumulate incidence of light on the latest sample segment.\n\
113
+ for (int j = 0; j < LIGHT_STEPS_MAX; ++j) {\n\
114
+ \n\
115
+ // The loop should be: for (int j = 0; i < LIGHT_STEPS; ++j) {...} but WebGL1 cannot\n\
116
+ // loop with non-constant condition, so it has to break early instead\n\
117
+ if (j >= LIGHT_STEPS) {\n\
118
+ break;\n\
119
+ }\n\
120
+ \n\
121
+ // Calculate sample position along light ray.\n\
122
+ vec3 lightPosition = samplePosition + lightDirection * (lightPositionLength + lightStepLength * 0.5);\n\
123
+ \n\
124
+ // Calculate height of the light sample position above ellipsoid.\n\
125
+ float lightHeight = length(lightPosition) - atmosphereInnerRadius;\n\
126
+ \n\
127
+ // Calculate density of photons at the light sample position.\n\
128
+ lightOpticalDepth += exp(-lightHeight / heightScale) * lightStepLength;\n\
129
+ \n\
130
+ // Increment distance on light ray.\n\
131
+ lightPositionLength += lightStepLength;\n\
132
+ }\n\
133
+ \n\
134
+ // Compute attenuation via the primary ray and the light ray.\n\
135
+ vec3 attenuation = exp(-((czm_atmosphereMieCoefficient * (opticalDepth.y + lightOpticalDepth.y)) + (czm_atmosphereRayleighCoefficient * (opticalDepth.x + lightOpticalDepth.x))));\n\
136
+ \n\
137
+ // Accumulate the scattering.\n\
138
+ rayleighAccumulation += sampleDensity.x * attenuation;\n\
139
+ mieAccumulation += sampleDensity.y * attenuation;\n\
140
+ \n\
141
+ // Increment distance on primary ray.\n\
142
+ rayPositionLength += (rayStepLength += rayStepLengthIncrease);\n\
143
+ }\n\
144
+ \n\
145
+ // Compute the scattering amount.\n\
146
+ rayleighColor = czm_atmosphereRayleighCoefficient * rayleighAccumulation;\n\
147
+ mieColor = czm_atmosphereMieCoefficient * mieAccumulation;\n\
148
+ \n\
149
+ // Compute the transmittance i.e. how much light is passing through the atmosphere.\n\
150
+ opacity = length(exp(-((czm_atmosphereMieCoefficient * opticalDepth.y) + (czm_atmosphereRayleighCoefficient * opticalDepth.x))));\n\
151
+ }\n\
152
+ ";
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Select which direction vector to use for dynamic atmosphere lighting based on an enum value
3
+ *
4
+ * @name czm_getDynamicAtmosphereLightDirection
5
+ * @glslfunction
6
+ * @see DynamicAtmosphereLightingType.js
7
+ *
8
+ * @param {vec3} positionWC the position of the vertex/fragment in world coordinates. This is normalized and returned when dynamic lighting is turned off.
9
+ * @param {float} lightEnum The enum value for selecting between light sources.
10
+ * @return {vec3} The normalized light direction vector. Depending on the enum value, it is either positionWC, czm_lightDirectionWC or czm_sunDirectionWC
11
+ */
12
+ vec3 czm_getDynamicAtmosphereLightDirection(vec3 positionWC, float lightEnum) {
13
+ const float NONE = 0.0;
14
+ const float SCENE_LIGHT = 1.0;
15
+ const float SUNLIGHT = 2.0;
16
+
17
+ vec3 lightDirection =
18
+ positionWC * float(lightEnum == NONE) +
19
+ czm_lightDirectionWC * float(lightEnum == SCENE_LIGHT) +
20
+ czm_sunDirectionWC * float(lightEnum == SUNLIGHT);
21
+ return normalize(lightDirection);
22
+ }
@@ -0,0 +1,24 @@
1
+ //This file is automatically rebuilt by the Cesium build process.
2
+ export default "/**\n\
3
+ * Select which direction vector to use for dynamic atmosphere lighting based on an enum value\n\
4
+ *\n\
5
+ * @name czm_getDynamicAtmosphereLightDirection\n\
6
+ * @glslfunction\n\
7
+ * @see DynamicAtmosphereLightingType.js\n\
8
+ *\n\
9
+ * @param {vec3} positionWC the position of the vertex/fragment in world coordinates. This is normalized and returned when dynamic lighting is turned off.\n\
10
+ * @param {float} lightEnum The enum value for selecting between light sources.\n\
11
+ * @return {vec3} The normalized light direction vector. Depending on the enum value, it is either positionWC, czm_lightDirectionWC or czm_sunDirectionWC\n\
12
+ */\n\
13
+ vec3 czm_getDynamicAtmosphereLightDirection(vec3 positionWC, float lightEnum) {\n\
14
+ const float NONE = 0.0;\n\
15
+ const float SCENE_LIGHT = 1.0;\n\
16
+ const float SUNLIGHT = 2.0;\n\
17
+ \n\
18
+ vec3 lightDirection =\n\
19
+ positionWC * float(lightEnum == NONE) +\n\
20
+ czm_lightDirectionWC * float(lightEnum == SCENE_LIGHT) +\n\
21
+ czm_sunDirectionWC * float(lightEnum == SUNLIGHT);\n\
22
+ return normalize(lightDirection);\n\
23
+ }\n\
24
+ ";
@@ -34,6 +34,11 @@
34
34
  vec4 czm_translateRelativeToEye(vec3 high, vec3 low)
35
35
  {
36
36
  vec3 highDifference = high - czm_encodedCameraPositionMCHigh;
37
+ // This check handles the case when NaN values have gotten into `highDifference`.
38
+ // Such a thing could happen on devices running iOS.
39
+ if (length(highDifference) == 0.0) {
40
+ highDifference = vec3(0);
41
+ }
37
42
  vec3 lowDifference = low - czm_encodedCameraPositionMCLow;
38
43
 
39
44
  return vec4(highDifference + lowDifference, 1.0);
@@ -35,6 +35,11 @@ export default "/**\n\
35
35
  vec4 czm_translateRelativeToEye(vec3 high, vec3 low)\n\
36
36
  {\n\
37
37
  vec3 highDifference = high - czm_encodedCameraPositionMCHigh;\n\
38
+ // This check handles the case when NaN values have gotten into `highDifference`.\n\
39
+ // Such a thing could happen on devices running iOS.\n\
40
+ if (length(highDifference) == 0.0) { \n\
41
+ highDifference = vec3(0); \n\
42
+ }\n\
38
43
  vec3 lowDifference = low - czm_encodedCameraPositionMCLow;\n\
39
44
  \n\
40
45
  return vec4(highDifference + lowDifference, 1.0);\n\
@@ -268,20 +268,6 @@ vec4 sampleAndBlend(
268
268
  return vec4(outColor, max(outAlpha, 0.0));
269
269
  }
270
270
 
271
- vec3 colorCorrect(vec3 rgb) {
272
- #ifdef COLOR_CORRECT
273
- // Convert rgb color to hsb
274
- vec3 hsb = czm_RGBToHSB(rgb);
275
- // Perform hsb shift
276
- hsb.x += u_hsbShift.x; // hue
277
- hsb.y = clamp(hsb.y + u_hsbShift.y, 0.0, 1.0); // saturation
278
- hsb.z = hsb.z > czm_epsilon7 ? hsb.z + u_hsbShift.z : 0.0; // brightness
279
- // Convert shifted hsb back to rgb
280
- rgb = czm_HSBToRGB(hsb);
281
- #endif
282
- return rgb;
283
- }
284
-
285
271
  vec4 computeDayColor(vec4 initialColor, vec3 textureCoordinates, float nightBlend);
286
272
  vec4 computeWaterColor(vec3 positionEyeCoordinates, vec2 textureCoordinates, mat3 enuToEye, vec4 imageryColor, float specularMapValue, float fade);
287
273
 
@@ -396,7 +382,7 @@ void main()
396
382
  materialInput.st = v_textureCoordinates.st;
397
383
  materialInput.normalEC = normalize(v_normalEC);
398
384
  materialInput.positionToEyeEC = -v_positionEC;
399
- materialInput.tangentToEyeMatrix = czm_eastNorthUpToEyeCoordinates(v_positionMC, normalize(v_normalEC));
385
+ materialInput.tangentToEyeMatrix = czm_eastNorthUpToEyeCoordinates(v_positionMC, normalize(v_normalEC));
400
386
  materialInput.slope = v_slope;
401
387
  materialInput.height = v_height;
402
388
  materialInput.aspect = v_aspect;
@@ -442,7 +428,7 @@ void main()
442
428
  {
443
429
  bool dynamicLighting = false;
444
430
  #if defined(DYNAMIC_ATMOSPHERE_LIGHTING) && (defined(ENABLE_DAYNIGHT_SHADING) || defined(ENABLE_VERTEX_LIGHTING))
445
- dynamicLighting = true;
431
+ dynamicLighting = true;
446
432
  #endif
447
433
 
448
434
  vec3 rayleighColor;
@@ -472,30 +458,35 @@ void main()
472
458
  opacity = v_atmosphereOpacity;
473
459
  #endif
474
460
 
475
- rayleighColor = colorCorrect(rayleighColor);
476
- mieColor = colorCorrect(mieColor);
461
+ #ifdef COLOR_CORRECT
462
+ const bool ignoreBlackPixels = true;
463
+ rayleighColor = czm_applyHSBShift(rayleighColor, u_hsbShift, ignoreBlackPixels);
464
+ mieColor = czm_applyHSBShift(mieColor, u_hsbShift, ignoreBlackPixels);
465
+ #endif
477
466
 
478
467
  vec4 groundAtmosphereColor = computeAtmosphereColor(positionWC, lightDirection, rayleighColor, mieColor, opacity);
479
468
 
480
469
  // Fog is applied to tiles selected for fog, close to the Earth.
481
470
  #ifdef FOG
482
471
  vec3 fogColor = groundAtmosphereColor.rgb;
483
-
472
+
484
473
  // If there is lighting, apply that to the fog.
485
474
  #if defined(DYNAMIC_ATMOSPHERE_LIGHTING) && (defined(ENABLE_VERTEX_LIGHTING) || defined(ENABLE_DAYNIGHT_SHADING))
486
475
  float darken = clamp(dot(normalize(czm_viewerPositionWC), atmosphereLightDirection), u_minimumBrightness, 1.0);
487
- fogColor *= darken;
476
+ fogColor *= darken;
488
477
  #endif
489
478
 
490
479
  #ifndef HDR
491
480
  fogColor.rgb = czm_acesTonemapping(fogColor.rgb);
492
481
  fogColor.rgb = czm_inverseGamma(fogColor.rgb);
493
482
  #endif
494
-
483
+
495
484
  const float modifier = 0.15;
496
485
  finalColor = vec4(czm_fog(v_distance, finalColor.rgb, fogColor.rgb, modifier), finalColor.a);
497
486
 
498
487
  #else
488
+ // Apply ground atmosphere. This happens when the camera is far away from the earth.
489
+
499
490
  // The transmittance is based on optical depth i.e. the length of segment of the ray inside the atmosphere.
500
491
  // This value is larger near the "circumference", as it is further away from the camera. We use it to
501
492
  // brighten up that area of the ground atmosphere.
@@ -507,20 +498,20 @@ void main()
507
498
  #if defined(DYNAMIC_ATMOSPHERE_LIGHTING) && (defined(ENABLE_VERTEX_LIGHTING) || defined(ENABLE_DAYNIGHT_SHADING))
508
499
  float fadeInDist = u_nightFadeDistance.x;
509
500
  float fadeOutDist = u_nightFadeDistance.y;
510
-
501
+
511
502
  float sunlitAtmosphereIntensity = clamp((cameraDist - fadeOutDist) / (fadeInDist - fadeOutDist), 0.05, 1.0);
512
503
  float darken = clamp(dot(normalize(positionWC), atmosphereLightDirection), 0.0, 1.0);
513
504
  vec3 darkenendGroundAtmosphereColor = mix(groundAtmosphereColor.rgb, finalAtmosphereColor.rgb, darken);
514
505
 
515
506
  finalAtmosphereColor = mix(darkenendGroundAtmosphereColor, finalAtmosphereColor, sunlitAtmosphereIntensity);
516
507
  #endif
517
-
508
+
518
509
  #ifndef HDR
519
510
  finalAtmosphereColor.rgb = vec3(1.0) - exp(-fExposure * finalAtmosphereColor.rgb);
520
511
  #else
521
512
  finalAtmosphereColor.rgb = czm_saturation(finalAtmosphereColor.rgb, 1.6);
522
513
  #endif
523
-
514
+
524
515
  finalColor.rgb = mix(finalColor.rgb, finalAtmosphereColor.rgb, fade);
525
516
  #endif
526
517
  }
@@ -544,7 +535,7 @@ void main()
544
535
  finalColor.a *= interpolateByDistance(alphaByDistance, v_distance);
545
536
  }
546
537
  #endif
547
-
538
+
548
539
  out_FragColor = finalColor;
549
540
  }
550
541