@cesium/engine 6.1.1 → 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 (229) hide show
  1. package/Build/ThirdParty/Workers/z-worker-pako.js +568 -407
  2. package/Build/Workers/{chunk-FRG2Z7DE.js → chunk-2HJWSU7B.js} +4 -4
  3. package/Build/Workers/{chunk-ZTYE74E2.js → chunk-46UD5ABS.js} +4 -4
  4. package/Build/Workers/{chunk-VODWDCX6.js → chunk-4EBHOMFX.js} +18 -20
  5. package/Build/Workers/{chunk-N7TYCDTR.js → chunk-5HDYHG3F.js} +13 -13
  6. package/Build/Workers/{chunk-C53JYYKX.js → chunk-5M3U6ZMA.js} +1 -1
  7. package/Build/Workers/{chunk-GTEXWEAP.js → chunk-5WQ523AW.js} +5 -5
  8. package/Build/Workers/{chunk-SEFDWMCW.js → chunk-5YLJ77FF.js} +31 -21
  9. package/Build/Workers/{chunk-VNRUVNIK.js → chunk-6HZQPRUS.js} +1 -1
  10. package/Build/Workers/{chunk-PB7BIXHI.js → chunk-6VJVYK2V.js} +2 -2
  11. package/Build/Workers/{chunk-PHQVHDVI.js → chunk-72SANQJV.js} +325 -5
  12. package/Build/Workers/{chunk-D325WRAY.js → chunk-7XEAYGZK.js} +35 -11
  13. package/Build/Workers/{chunk-FGUP2QEP.js → chunk-AIPU2VSX.js} +6 -6
  14. package/Build/Workers/{chunk-QUXSQQEF.js → chunk-AR5DNBJ4.js} +6 -6
  15. package/Build/Workers/{chunk-ZVUAJKAL.js → chunk-BZP4T2JJ.js} +11 -13
  16. package/Build/Workers/{chunk-K6Q5IRBK.js → chunk-DTAIXKTO.js} +6 -6
  17. package/Build/Workers/{chunk-D4YHO4NZ.js → chunk-F6SE42BK.js} +133 -101
  18. package/Build/Workers/{chunk-QY2WY5XJ.js → chunk-FP6GYBFX.js} +11 -11
  19. package/Build/Workers/{chunk-Z6LPXA7S.js → chunk-GEJTYLCO.js} +5 -5
  20. package/Build/Workers/{chunk-VKTKOIYG.js → chunk-GV56Q4LU.js} +11 -11
  21. package/Build/Workers/{chunk-KUB2HQXR.js → chunk-IQBYFRVW.js} +8 -8
  22. package/Build/Workers/{chunk-235MRXLH.js → chunk-IX2JCCNM.js} +1 -1
  23. package/Build/Workers/{chunk-3FCUUN6M.js → chunk-JCNXK6EL.js} +11 -11
  24. package/Build/Workers/{chunk-364TQORK.js → chunk-JJ4VBOQ3.js} +5 -7
  25. package/Build/Workers/{chunk-66CXKODF.js → chunk-JXDC723O.js} +2 -2
  26. package/Build/Workers/{chunk-OTBRPBCC.js → chunk-JY5YEZFA.js} +9 -9
  27. package/Build/Workers/{chunk-LSGUCCKJ.js → chunk-L2ZN645J.js} +6 -6
  28. package/Build/Workers/{chunk-VLDDXYKI.js → chunk-LZ7JIV3K.js} +18 -18
  29. package/Build/Workers/{chunk-36ESDRIZ.js → chunk-LZGHD6NY.js} +16 -16
  30. package/Build/Workers/{chunk-PXLFBN2Q.js → chunk-MY3VNFGQ.js} +7 -7
  31. package/Build/Workers/{chunk-W7F5VTH6.js → chunk-NKPBIX7F.js} +1 -1
  32. package/Build/Workers/{chunk-XBZSOW3F.js → chunk-NY3K4IM3.js} +12 -12
  33. package/Build/Workers/{chunk-AI3KSNM6.js → chunk-ODW7WYM4.js} +2 -2
  34. package/Build/Workers/{chunk-6PWSSCRA.js → chunk-OVLG3FRS.js} +6 -6
  35. package/Build/Workers/{chunk-MOLGJDJV.js → chunk-PNBGBETF.js} +11 -11
  36. package/Build/Workers/{chunk-T73B27DG.js → chunk-PTQQUQC3.js} +13 -13
  37. package/Build/Workers/{chunk-RSWBNJPT.js → chunk-QZAD5O7I.js} +8 -304
  38. package/Build/Workers/{chunk-I6TVJ6T7.js → chunk-R5X4OQT4.js} +8 -8
  39. package/Build/Workers/{chunk-DTNN3ODA.js → chunk-RAEV7K66.js} +5 -5
  40. package/Build/Workers/{chunk-IZED7ODV.js → chunk-RV7ZYPFT.js} +4 -4
  41. package/Build/Workers/{chunk-7FEGZO3D.js → chunk-S4MAZ3SS.js} +2 -2
  42. package/Build/Workers/{chunk-J3U6Z5YQ.js → chunk-S6SKF6DT.js} +5 -5
  43. package/Build/Workers/{chunk-CHDJ66UM.js → chunk-U2VCRRQW.js} +6 -6
  44. package/Build/Workers/{chunk-R22RQAAM.js → chunk-UAEW6HKG.js} +13 -13
  45. package/Build/Workers/{chunk-S7IBK36I.js → chunk-UDO6BFSF.js} +14 -16
  46. package/Build/Workers/{chunk-YS4KPNLC.js → chunk-UGK3FCDY.js} +1 -1
  47. package/Build/Workers/{chunk-SJDXMQSP.js → chunk-VK3EJHWI.js} +2 -2
  48. package/Build/Workers/{chunk-HEROVJML.js → chunk-VRGFV2UO.js} +7 -7
  49. package/Build/Workers/{chunk-VOAZN4IP.js → chunk-WBQCVXR3.js} +4 -4
  50. package/Build/Workers/{chunk-HSW63JN4.js → chunk-WZU2YLWG.js} +3 -3
  51. package/Build/Workers/{chunk-4EYB62WJ.js → chunk-XWXM2O2R.js} +6 -6
  52. package/Build/Workers/{chunk-ZGMOBRTG.js → chunk-YUCVWAY6.js} +7 -7
  53. package/Build/Workers/{chunk-CLVEIRXT.js → chunk-ZK5JOS3D.js} +15 -17
  54. package/Build/Workers/{chunk-5NZTU5YL.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 +33 -34
  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 +18 -19
  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 +22 -22
  74. package/Build/Workers/createPlaneGeometry.js +15 -15
  75. package/Build/Workers/createPlaneOutlineGeometry.js +14 -14
  76. package/Build/Workers/createPolygonGeometry.js +32 -167
  77. package/Build/Workers/createPolygonOutlineGeometry.js +29 -29
  78. package/Build/Workers/createPolylineGeometry.js +24 -24
  79. package/Build/Workers/createPolylineVolumeGeometry.js +32 -35
  80. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +27 -29
  81. package/Build/Workers/createRectangleGeometry.js +27 -27
  82. package/Build/Workers/createRectangleOutlineGeometry.js +21 -23
  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 +22 -22
  93. package/Build/Workers/createVerticesFromHeightmap.js +22 -22
  94. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +19 -19
  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 +22 -22
  103. package/LICENSE.md +1 -1
  104. package/Source/Assets/approximateTerrainHeights.json +1 -1
  105. package/Source/Core/Ellipsoid.js +45 -0
  106. package/Source/Core/GregorianDate.js +85 -0
  107. package/Source/Core/HeadingPitchRange.js +2 -2
  108. package/Source/Core/Ion.js +1 -1
  109. package/Source/Core/PolygonGeometry.js +0 -169
  110. package/Source/Core/Quaternion.js +6 -2
  111. package/Source/Core/RectangleOutlineGeometry.js +2 -4
  112. package/Source/Core/RequestScheduler.js +3 -9
  113. package/Source/Core/Resource.js +30 -69
  114. package/Source/Core/TerrainEncoding.js +2 -2
  115. package/Source/Core/Transforms.js +27 -18
  116. package/Source/Core/VerticalExaggeration.js +69 -0
  117. package/Source/Core/createWorldBathymetryAsync.js +45 -0
  118. package/Source/DataSources/EllipsoidGeometryUpdater.js +3 -4
  119. package/Source/DataSources/Entity.js +8 -5
  120. package/Source/DataSources/EntityCollection.js +1 -2
  121. package/Source/DataSources/GeometryUpdater.js +1 -2
  122. package/Source/DataSources/GroundGeometryUpdater.js +6 -3
  123. package/Source/DataSources/ModelVisualizer.js +19 -98
  124. package/Source/DataSources/PolygonGeometryUpdater.js +14 -2
  125. package/Source/DataSources/PolylineGeometryUpdater.js +9 -8
  126. package/Source/DataSources/TerrainOffsetProperty.js +15 -23
  127. package/Source/Renderer/AutomaticUniforms.js +173 -0
  128. package/Source/Renderer/UniformState.js +246 -1
  129. package/Source/Scene/ArcGisMapService.js +1 -1
  130. package/Source/Scene/Atmosphere.js +127 -0
  131. package/Source/Scene/Billboard.js +29 -26
  132. package/Source/Scene/BillboardCollection.js +3 -3
  133. package/Source/Scene/Camera.js +1 -1
  134. package/Source/Scene/Cesium3DTile.js +123 -10
  135. package/Source/Scene/Cesium3DTileContent.js +14 -0
  136. package/Source/Scene/Cesium3DTileset.js +326 -45
  137. package/Source/Scene/Cesium3DTilesetTraversal.js +4 -0
  138. package/Source/Scene/Composite3DTileContent.js +42 -0
  139. package/Source/Scene/DynamicAtmosphereLightingType.js +56 -0
  140. package/Source/Scene/Empty3DTileContent.js +4 -0
  141. package/Source/Scene/Fog.js +1 -0
  142. package/Source/Scene/FrameState.js +13 -5
  143. package/Source/Scene/Geometry3DTileContent.js +4 -0
  144. package/Source/Scene/Globe.js +69 -21
  145. package/Source/Scene/GlobeSurfaceTile.js +4 -4
  146. package/Source/Scene/GlobeSurfaceTileProvider.js +24 -22
  147. package/Source/Scene/GltfLoader.js +15 -5
  148. package/Source/Scene/GroundPrimitive.js +5 -5
  149. package/Source/Scene/HeightReference.js +59 -2
  150. package/Source/Scene/ImageryLayer.js +3 -3
  151. package/Source/Scene/Implicit3DTileContent.js +4 -0
  152. package/Source/Scene/LabelCollection.js +2 -2
  153. package/Source/Scene/MapboxImageryProvider.js +2 -2
  154. package/Source/Scene/Megatexture.js +1 -1
  155. package/Source/Scene/Model/AtmospherePipelineStage.js +59 -0
  156. package/Source/Scene/Model/B3dmLoader.js +4 -0
  157. package/Source/Scene/Model/FeatureIdPipelineStage.js +25 -2
  158. package/Source/Scene/Model/I3dmLoader.js +4 -0
  159. package/Source/Scene/Model/InstancingPipelineStage.js +24 -6
  160. package/Source/Scene/Model/MetadataPipelineStage.js +31 -3
  161. package/Source/Scene/Model/Model.js +93 -32
  162. package/Source/Scene/Model/Model3DTileContent.js +31 -0
  163. package/Source/Scene/Model/ModelAnimationChannel.js +16 -15
  164. package/Source/Scene/Model/ModelRuntimePrimitive.js +6 -0
  165. package/Source/Scene/Model/ModelSceneGraph.js +6 -0
  166. package/Source/Scene/Model/VerticalExaggerationPipelineStage.js +60 -0
  167. package/Source/Scene/Model/pickModel.js +408 -0
  168. package/Source/Scene/Multiple3DTileContent.js +42 -0
  169. package/Source/Scene/QuadtreePrimitive.js +1 -1
  170. package/Source/Scene/Scene.js +226 -19
  171. package/Source/Scene/ScreenSpaceCameraController.js +14 -25
  172. package/Source/Scene/SkyAtmosphere.js +5 -6
  173. package/Source/Scene/Terrain.js +49 -0
  174. package/Source/Scene/TerrainFillMesh.js +2 -2
  175. package/Source/Scene/TileBoundingS2Cell.js +2 -2
  176. package/Source/Scene/TileOrientedBoundingBox.js +1 -1
  177. package/Source/Scene/Tileset3DTileContent.js +4 -0
  178. package/Source/Scene/Vector3DTileContent.js +4 -0
  179. package/Source/Scene/VoxelPrimitive.js +73 -2
  180. package/Source/Shaders/AtmosphereCommon.glsl +3 -11
  181. package/Source/Shaders/AtmosphereCommon.js +3 -11
  182. package/Source/Shaders/Builtin/CzmBuiltins.js +12 -0
  183. package/Source/Shaders/Builtin/Functions/applyHSBShift.glsl +32 -0
  184. package/Source/Shaders/Builtin/Functions/applyHSBShift.js +34 -0
  185. package/Source/Shaders/Builtin/Functions/approximateTanh.glsl +10 -0
  186. package/Source/Shaders/Builtin/Functions/approximateTanh.js +12 -0
  187. package/Source/Shaders/Builtin/Functions/computeAtmosphereColor.glsl +44 -0
  188. package/Source/Shaders/Builtin/Functions/computeAtmosphereColor.js +46 -0
  189. package/Source/Shaders/Builtin/Functions/computeGroundAtmosphereScattering.glsl +30 -0
  190. package/Source/Shaders/Builtin/Functions/computeGroundAtmosphereScattering.js +32 -0
  191. package/Source/Shaders/Builtin/Functions/computeScattering.glsl +150 -0
  192. package/Source/Shaders/Builtin/Functions/computeScattering.js +152 -0
  193. package/Source/Shaders/Builtin/Functions/getDynamicAtmosphereLightDirection.glsl +22 -0
  194. package/Source/Shaders/Builtin/Functions/getDynamicAtmosphereLightDirection.js +24 -0
  195. package/Source/Shaders/Builtin/Functions/translateRelativeToEye.glsl +5 -0
  196. package/Source/Shaders/Builtin/Functions/translateRelativeToEye.js +5 -0
  197. package/Source/Shaders/GlobeFS.glsl +16 -25
  198. package/Source/Shaders/GlobeFS.js +16 -25
  199. package/Source/Shaders/GlobeVS.glsl +4 -4
  200. package/Source/Shaders/GlobeVS.js +4 -4
  201. package/Source/Shaders/Model/AtmosphereStageFS.glsl +111 -0
  202. package/Source/Shaders/Model/AtmosphereStageFS.js +113 -0
  203. package/Source/Shaders/Model/AtmosphereStageVS.glsl +12 -0
  204. package/Source/Shaders/Model/AtmosphereStageVS.js +14 -0
  205. package/Source/Shaders/Model/GeometryStageFS.glsl +1 -1
  206. package/Source/Shaders/Model/GeometryStageFS.js +1 -1
  207. package/Source/Shaders/Model/GeometryStageVS.glsl +4 -4
  208. package/Source/Shaders/Model/GeometryStageVS.js +4 -4
  209. package/Source/Shaders/Model/ModelColorStageFS.glsl +1 -1
  210. package/Source/Shaders/Model/ModelColorStageFS.js +2 -1
  211. package/Source/Shaders/Model/ModelFS.glsl +4 -0
  212. package/Source/Shaders/Model/ModelFS.js +4 -0
  213. package/Source/Shaders/Model/ModelVS.glsl +13 -4
  214. package/Source/Shaders/Model/ModelVS.js +13 -4
  215. package/Source/Shaders/Model/VerticalExaggerationStageVS.glsl +39 -0
  216. package/Source/Shaders/Model/VerticalExaggerationStageVS.js +41 -0
  217. package/Source/Shaders/SkyAtmosphereCommon.glsl +3 -13
  218. package/Source/Shaders/SkyAtmosphereCommon.js +3 -13
  219. package/Source/Shaders/SkyAtmosphereFS.glsl +5 -10
  220. package/Source/Shaders/SkyAtmosphereFS.js +5 -10
  221. package/Source/Shaders/SkyAtmosphereVS.glsl +3 -2
  222. package/Source/Shaders/SkyAtmosphereVS.js +3 -2
  223. package/Source/ThirdParty/Workers/z-worker-pako.js +1 -1
  224. package/Source/ThirdParty/draco_decoder.wasm +0 -0
  225. package/index.d.ts +318 -83
  226. package/index.js +77 -62
  227. package/package.json +3 -3
  228. package/Build/Workers/chunk-7ONRI7T4.js +0 -55
  229. package/Source/Core/TerrainExaggeration.js +0 -49
@@ -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
 
@@ -269,20 +269,6 @@ vec4 sampleAndBlend(\n\
269
269
  return vec4(outColor, max(outAlpha, 0.0));\n\
270
270
  }\n\
271
271
  \n\
272
- vec3 colorCorrect(vec3 rgb) {\n\
273
- #ifdef COLOR_CORRECT\n\
274
- // Convert rgb color to hsb\n\
275
- vec3 hsb = czm_RGBToHSB(rgb);\n\
276
- // Perform hsb shift\n\
277
- hsb.x += u_hsbShift.x; // hue\n\
278
- hsb.y = clamp(hsb.y + u_hsbShift.y, 0.0, 1.0); // saturation\n\
279
- hsb.z = hsb.z > czm_epsilon7 ? hsb.z + u_hsbShift.z : 0.0; // brightness\n\
280
- // Convert shifted hsb back to rgb\n\
281
- rgb = czm_HSBToRGB(hsb);\n\
282
- #endif\n\
283
- return rgb;\n\
284
- }\n\
285
- \n\
286
272
  vec4 computeDayColor(vec4 initialColor, vec3 textureCoordinates, float nightBlend);\n\
287
273
  vec4 computeWaterColor(vec3 positionEyeCoordinates, vec2 textureCoordinates, mat3 enuToEye, vec4 imageryColor, float specularMapValue, float fade);\n\
288
274
  \n\
@@ -397,7 +383,7 @@ void main()\n\
397
383
  materialInput.st = v_textureCoordinates.st;\n\
398
384
  materialInput.normalEC = normalize(v_normalEC);\n\
399
385
  materialInput.positionToEyeEC = -v_positionEC;\n\
400
- materialInput.tangentToEyeMatrix = czm_eastNorthUpToEyeCoordinates(v_positionMC, normalize(v_normalEC)); \n\
386
+ materialInput.tangentToEyeMatrix = czm_eastNorthUpToEyeCoordinates(v_positionMC, normalize(v_normalEC));\n\
401
387
  materialInput.slope = v_slope;\n\
402
388
  materialInput.height = v_height;\n\
403
389
  materialInput.aspect = v_aspect;\n\
@@ -443,7 +429,7 @@ void main()\n\
443
429
  {\n\
444
430
  bool dynamicLighting = false;\n\
445
431
  #if defined(DYNAMIC_ATMOSPHERE_LIGHTING) && (defined(ENABLE_DAYNIGHT_SHADING) || defined(ENABLE_VERTEX_LIGHTING))\n\
446
- dynamicLighting = true; \n\
432
+ dynamicLighting = true;\n\
447
433
  #endif\n\
448
434
  \n\
449
435
  vec3 rayleighColor;\n\
@@ -473,30 +459,35 @@ void main()\n\
473
459
  opacity = v_atmosphereOpacity;\n\
474
460
  #endif\n\
475
461
  \n\
476
- rayleighColor = colorCorrect(rayleighColor);\n\
477
- mieColor = colorCorrect(mieColor);\n\
462
+ #ifdef COLOR_CORRECT\n\
463
+ const bool ignoreBlackPixels = true;\n\
464
+ rayleighColor = czm_applyHSBShift(rayleighColor, u_hsbShift, ignoreBlackPixels);\n\
465
+ mieColor = czm_applyHSBShift(mieColor, u_hsbShift, ignoreBlackPixels);\n\
466
+ #endif\n\
478
467
  \n\
479
468
  vec4 groundAtmosphereColor = computeAtmosphereColor(positionWC, lightDirection, rayleighColor, mieColor, opacity);\n\
480
469
  \n\
481
470
  // Fog is applied to tiles selected for fog, close to the Earth.\n\
482
471
  #ifdef FOG\n\
483
472
  vec3 fogColor = groundAtmosphereColor.rgb;\n\
484
- \n\
473
+ \n\
485
474
  // If there is lighting, apply that to the fog.\n\
486
475
  #if defined(DYNAMIC_ATMOSPHERE_LIGHTING) && (defined(ENABLE_VERTEX_LIGHTING) || defined(ENABLE_DAYNIGHT_SHADING))\n\
487
476
  float darken = clamp(dot(normalize(czm_viewerPositionWC), atmosphereLightDirection), u_minimumBrightness, 1.0);\n\
488
- fogColor *= darken; \n\
477
+ fogColor *= darken;\n\
489
478
  #endif\n\
490
479
  \n\
491
480
  #ifndef HDR\n\
492
481
  fogColor.rgb = czm_acesTonemapping(fogColor.rgb);\n\
493
482
  fogColor.rgb = czm_inverseGamma(fogColor.rgb);\n\
494
483
  #endif\n\
495
- \n\
484
+ \n\
496
485
  const float modifier = 0.15;\n\
497
486
  finalColor = vec4(czm_fog(v_distance, finalColor.rgb, fogColor.rgb, modifier), finalColor.a);\n\
498
487
  \n\
499
488
  #else\n\
489
+ // Apply ground atmosphere. This happens when the camera is far away from the earth.\n\
490
+ \n\
500
491
  // The transmittance is based on optical depth i.e. the length of segment of the ray inside the atmosphere.\n\
501
492
  // This value is larger near the \"circumference\", as it is further away from the camera. We use it to\n\
502
493
  // brighten up that area of the ground atmosphere.\n\
@@ -508,20 +499,20 @@ void main()\n\
508
499
  #if defined(DYNAMIC_ATMOSPHERE_LIGHTING) && (defined(ENABLE_VERTEX_LIGHTING) || defined(ENABLE_DAYNIGHT_SHADING))\n\
509
500
  float fadeInDist = u_nightFadeDistance.x;\n\
510
501
  float fadeOutDist = u_nightFadeDistance.y;\n\
511
- \n\
502
+ \n\
512
503
  float sunlitAtmosphereIntensity = clamp((cameraDist - fadeOutDist) / (fadeInDist - fadeOutDist), 0.05, 1.0);\n\
513
504
  float darken = clamp(dot(normalize(positionWC), atmosphereLightDirection), 0.0, 1.0);\n\
514
505
  vec3 darkenendGroundAtmosphereColor = mix(groundAtmosphereColor.rgb, finalAtmosphereColor.rgb, darken);\n\
515
506
  \n\
516
507
  finalAtmosphereColor = mix(darkenendGroundAtmosphereColor, finalAtmosphereColor, sunlitAtmosphereIntensity);\n\
517
508
  #endif\n\
518
- \n\
509
+ \n\
519
510
  #ifndef HDR\n\
520
511
  finalAtmosphereColor.rgb = vec3(1.0) - exp(-fExposure * finalAtmosphereColor.rgb);\n\
521
512
  #else\n\
522
513
  finalAtmosphereColor.rgb = czm_saturation(finalAtmosphereColor.rgb, 1.6);\n\
523
514
  #endif\n\
524
- \n\
515
+ \n\
525
516
  finalColor.rgb = mix(finalColor.rgb, finalAtmosphereColor.rgb, fade);\n\
526
517
  #endif\n\
527
518
  }\n\
@@ -545,7 +536,7 @@ void main()\n\
545
536
  finalColor.a *= interpolateByDistance(alphaByDistance, v_distance);\n\
546
537
  }\n\
547
538
  #endif\n\
548
- \n\
539
+ \n\
549
540
  out_FragColor = finalColor;\n\
550
541
  }\n\
551
542
  \n\
@@ -11,7 +11,7 @@ in vec3 geodeticSurfaceNormal;
11
11
  #endif
12
12
 
13
13
  #ifdef EXAGGERATION
14
- uniform vec2 u_terrainExaggerationAndRelativeHeight;
14
+ uniform vec2 u_verticalExaggerationAndRelativeHeight;
15
15
  #endif
16
16
 
17
17
  uniform vec3 u_center3D;
@@ -128,7 +128,7 @@ void main()
128
128
  height = height * (u_minMaxHeight.y - u_minMaxHeight.x) + u_minMaxHeight.x;
129
129
  position = (u_scaleAndBias * vec4(position, 1.0)).xyz;
130
130
 
131
- #if (defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL)) && defined(INCLUDE_WEB_MERCATOR_Y)
131
+ #if (defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL)) && defined(INCLUDE_WEB_MERCATOR_Y) || defined(APPLY_MATERIAL)
132
132
  float webMercatorT = czm_decompressTextureCoordinates(compressed0.w).x;
133
133
  float encodedNormal = compressed1;
134
134
  #elif defined(INCLUDE_WEB_MERCATOR_Y)
@@ -173,8 +173,8 @@ void main()
173
173
  #endif
174
174
 
175
175
  #if defined(EXAGGERATION) && defined(GEODETIC_SURFACE_NORMALS)
176
- float exaggeration = u_terrainExaggerationAndRelativeHeight.x;
177
- float relativeHeight = u_terrainExaggerationAndRelativeHeight.y;
176
+ float exaggeration = u_verticalExaggerationAndRelativeHeight.x;
177
+ float relativeHeight = u_verticalExaggerationAndRelativeHeight.y;
178
178
  float newHeight = (height - relativeHeight) * exaggeration + relativeHeight;
179
179
 
180
180
  // stop from going through center of earth
@@ -12,7 +12,7 @@ in vec3 geodeticSurfaceNormal;\n\
12
12
  #endif\n\
13
13
  \n\
14
14
  #ifdef EXAGGERATION\n\
15
- uniform vec2 u_terrainExaggerationAndRelativeHeight;\n\
15
+ uniform vec2 u_verticalExaggerationAndRelativeHeight;\n\
16
16
  #endif\n\
17
17
  \n\
18
18
  uniform vec3 u_center3D;\n\
@@ -129,7 +129,7 @@ void main()\n\
129
129
  height = height * (u_minMaxHeight.y - u_minMaxHeight.x) + u_minMaxHeight.x;\n\
130
130
  position = (u_scaleAndBias * vec4(position, 1.0)).xyz;\n\
131
131
  \n\
132
- #if (defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL)) && defined(INCLUDE_WEB_MERCATOR_Y)\n\
132
+ #if (defined(ENABLE_VERTEX_LIGHTING) || defined(GENERATE_POSITION_AND_NORMAL)) && defined(INCLUDE_WEB_MERCATOR_Y) || defined(APPLY_MATERIAL)\n\
133
133
  float webMercatorT = czm_decompressTextureCoordinates(compressed0.w).x;\n\
134
134
  float encodedNormal = compressed1;\n\
135
135
  #elif defined(INCLUDE_WEB_MERCATOR_Y)\n\
@@ -174,8 +174,8 @@ void main()\n\
174
174
  #endif\n\
175
175
  \n\
176
176
  #if defined(EXAGGERATION) && defined(GEODETIC_SURFACE_NORMALS)\n\
177
- float exaggeration = u_terrainExaggerationAndRelativeHeight.x;\n\
178
- float relativeHeight = u_terrainExaggerationAndRelativeHeight.y;\n\
177
+ float exaggeration = u_verticalExaggerationAndRelativeHeight.x;\n\
178
+ float relativeHeight = u_verticalExaggerationAndRelativeHeight.y;\n\
179
179
  float newHeight = (height - relativeHeight) * exaggeration + relativeHeight;\n\
180
180
  \n\
181
181
  // stop from going through center of earth\n\
@@ -0,0 +1,111 @@
1
+ // robust iterative solution without trig functions
2
+ // https://github.com/0xfaded/ellipse_demo/issues/1
3
+ // https://stackoverflow.com/questions/22959698/distance-from-given-point-to-given-ellipse
4
+ //
5
+ // This version uses only a single iteration for best performance. For fog
6
+ // rendering, the difference is negligible.
7
+ vec2 nearestPointOnEllipseFast(vec2 pos, vec2 radii) {
8
+ vec2 p = abs(pos);
9
+ vec2 inverseRadii = 1.0 / radii;
10
+ vec2 evoluteScale = (radii.x * radii.x - radii.y * radii.y) * vec2(1.0, -1.0) * inverseRadii;
11
+
12
+ // We describe the ellipse parametrically: v = radii * vec2(cos(t), sin(t))
13
+ // but store the cos and sin of t in a vec2 for efficiency.
14
+ // Initial guess: t = cos(pi/4)
15
+ vec2 tTrigs = vec2(0.70710678118);
16
+ vec2 v = radii * tTrigs;
17
+
18
+ // Find the evolute of the ellipse (center of curvature) at v.
19
+ vec2 evolute = evoluteScale * tTrigs * tTrigs * tTrigs;
20
+ // Find the (approximate) intersection of p - evolute with the ellipsoid.
21
+ vec2 q = normalize(p - evolute) * length(v - evolute);
22
+ // Update the estimate of t.
23
+ tTrigs = (q + evolute) * inverseRadii;
24
+ tTrigs = normalize(clamp(tTrigs, 0.0, 1.0));
25
+ v = radii * tTrigs;
26
+
27
+ return v * sign(pos);
28
+ }
29
+
30
+ vec3 computeEllipsoidPositionWC(vec3 positionMC) {
31
+ // Get the world-space position and project onto a meridian plane of
32
+ // the ellipsoid
33
+ vec3 positionWC = (czm_model * vec4(positionMC, 1.0)).xyz;
34
+
35
+ vec2 positionEllipse = vec2(length(positionWC.xy), positionWC.z);
36
+ vec2 nearestPoint = nearestPointOnEllipseFast(positionEllipse, czm_ellipsoidRadii.xz);
37
+
38
+ // Reconstruct a 3D point in world space
39
+ return vec3(nearestPoint.x * normalize(positionWC.xy), nearestPoint.y);
40
+ }
41
+
42
+ void applyFog(inout vec4 color, vec4 groundAtmosphereColor, vec3 lightDirection, float distanceToCamera) {
43
+
44
+ vec3 fogColor = groundAtmosphereColor.rgb;
45
+
46
+ // If there is dynamic lighting, apply that to the fog.
47
+ const float NONE = 0.0;
48
+ if (czm_atmosphereDynamicLighting != NONE) {
49
+ float darken = clamp(dot(normalize(czm_viewerPositionWC), lightDirection), czm_fogMinimumBrightness, 1.0);
50
+ fogColor *= darken;
51
+ }
52
+
53
+ // Tonemap if HDR rendering is disabled
54
+ #ifndef HDR
55
+ fogColor.rgb = czm_acesTonemapping(fogColor.rgb);
56
+ fogColor.rgb = czm_inverseGamma(fogColor.rgb);
57
+ #endif
58
+
59
+ // Matches the constant in GlobeFS.glsl. This makes the fog falloff
60
+ // more gradual.
61
+ const float fogModifier = 0.15;
62
+ vec3 withFog = czm_fog(distanceToCamera, color.rgb, fogColor, fogModifier);
63
+ color = vec4(withFog, color.a);
64
+ }
65
+
66
+ void atmosphereStage(inout vec4 color, in ProcessedAttributes attributes) {
67
+ vec3 rayleighColor;
68
+ vec3 mieColor;
69
+ float opacity;
70
+
71
+ vec3 positionWC;
72
+ vec3 lightDirection;
73
+
74
+ // When the camera is in space, compute the position per-fragment for
75
+ // more accurate ground atmosphere. All other cases will use
76
+ //
77
+ // The if condition will be added in https://github.com/CesiumGS/cesium/issues/11717
78
+ if (false) {
79
+ positionWC = computeEllipsoidPositionWC(attributes.positionMC);
80
+ lightDirection = czm_getDynamicAtmosphereLightDirection(positionWC, czm_atmosphereDynamicLighting);
81
+
82
+ // The fog color is derived from the ground atmosphere color
83
+ czm_computeGroundAtmosphereScattering(
84
+ positionWC,
85
+ lightDirection,
86
+ rayleighColor,
87
+ mieColor,
88
+ opacity
89
+ );
90
+ } else {
91
+ positionWC = attributes.positionWC;
92
+ lightDirection = czm_getDynamicAtmosphereLightDirection(positionWC, czm_atmosphereDynamicLighting);
93
+ rayleighColor = v_atmosphereRayleighColor;
94
+ mieColor = v_atmosphereMieColor;
95
+ opacity = v_atmosphereOpacity;
96
+ }
97
+
98
+ //color correct rayleigh and mie colors
99
+ const bool ignoreBlackPixels = true;
100
+ rayleighColor = czm_applyHSBShift(rayleighColor, czm_atmosphereHsbShift, ignoreBlackPixels);
101
+ mieColor = czm_applyHSBShift(mieColor, czm_atmosphereHsbShift, ignoreBlackPixels);
102
+
103
+ vec4 groundAtmosphereColor = czm_computeAtmosphereColor(positionWC, lightDirection, rayleighColor, mieColor, opacity);
104
+
105
+ if (u_isInFog) {
106
+ float distanceToCamera = length(attributes.positionEC);
107
+ applyFog(color, groundAtmosphereColor, lightDirection, distanceToCamera);
108
+ } else {
109
+ // Ground atmosphere
110
+ }
111
+ }