@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
@@ -18,6 +18,7 @@ import Event from "../Core/Event.js";
18
18
  import GeographicProjection from "../Core/GeographicProjection.js";
19
19
  import GeometryInstance from "../Core/GeometryInstance.js";
20
20
  import GeometryPipeline from "../Core/GeometryPipeline.js";
21
+ import HeightReference from "./HeightReference.js";
21
22
  import Intersect from "../Core/Intersect.js";
22
23
  import JulianDate from "../Core/JulianDate.js";
23
24
  import CesiumMath from "../Core/Math.js";
@@ -37,6 +38,7 @@ import Context from "../Renderer/Context.js";
37
38
  import ContextLimits from "../Renderer/ContextLimits.js";
38
39
  import Pass from "../Renderer/Pass.js";
39
40
  import RenderState from "../Renderer/RenderState.js";
41
+ import Atmosphere from "./Atmosphere.js";
40
42
  import BrdfLutGenerator from "./BrdfLutGenerator.js";
41
43
  import Camera from "./Camera.js";
42
44
  import Cesium3DTilePass from "./Cesium3DTilePass.js";
@@ -46,6 +48,7 @@ import DebugCameraPrimitive from "./DebugCameraPrimitive.js";
46
48
  import DepthPlane from "./DepthPlane.js";
47
49
  import DerivedCommand from "./DerivedCommand.js";
48
50
  import DeviceOrientationCameraController from "./DeviceOrientationCameraController.js";
51
+ import DynamicAtmosphereLightingType from "./DynamicAtmosphereLightingType.js";
49
52
  import Fog from "./Fog.js";
50
53
  import FrameState from "./FrameState.js";
51
54
  import GlobeTranslucencyState from "./GlobeTranslucencyState.js";
@@ -164,6 +167,7 @@ function Scene(options) {
164
167
  this._groundPrimitives = new PrimitiveCollection();
165
168
 
166
169
  this._globeHeight = undefined;
170
+ this._globeHeightDirty = undefined;
167
171
  this._cameraUnderground = false;
168
172
 
169
173
  this._logDepthBuffer = context.fragmentDepth;
@@ -512,6 +516,14 @@ function Scene(options) {
512
516
  */
513
517
  this.cameraEventWaitTime = 500.0;
514
518
 
519
+ /**
520
+ * Settings for atmosphere lighting effects affecting 3D Tiles and model rendering. This is not to be confused with
521
+ * {@link Scene#skyAtmosphere} which is responsible for rendering the sky.
522
+ *
523
+ * @type {Atmosphere}
524
+ */
525
+ this.atmosphere = new Atmosphere();
526
+
515
527
  /**
516
528
  * Blends the atmosphere to geometry far from the camera for horizon views. Allows for additional
517
529
  * performance improvements by rendering less geometry and dispatching less terrain requests.
@@ -738,6 +750,11 @@ function updateGlobeListeners(scene, globe) {
738
750
  requestRenderAfterFrame(scene)
739
751
  )
740
752
  );
753
+ removeGlobeCallbacks.push(
754
+ globe.tileLoadProgressEvent.addEventListener(() => {
755
+ scene._globeHeightDirty = true;
756
+ })
757
+ );
741
758
  }
742
759
  scene._removeGlobeCallbacks = removeGlobeCallbacks;
743
760
  }
@@ -3167,6 +3184,7 @@ Scene.prototype.updateEnvironment = function () {
3167
3184
  const environmentState = this._environmentState;
3168
3185
  const renderPass = frameState.passes.render;
3169
3186
  const offscreenPass = frameState.passes.offscreen;
3187
+ const atmosphere = this.atmosphere;
3170
3188
  const skyAtmosphere = this.skyAtmosphere;
3171
3189
  const globe = this.globe;
3172
3190
  const globeTranslucencyState = this._globeTranslucencyState;
@@ -3185,17 +3203,19 @@ Scene.prototype.updateEnvironment = function () {
3185
3203
  } else {
3186
3204
  if (defined(skyAtmosphere)) {
3187
3205
  if (defined(globe)) {
3188
- skyAtmosphere.setDynamicAtmosphereColor(
3189
- globe.enableLighting && globe.dynamicAtmosphereLighting,
3190
- globe.dynamicAtmosphereLightingFromSun
3206
+ skyAtmosphere.setDynamicLighting(
3207
+ DynamicAtmosphereLightingType.fromGlobeFlags(globe)
3191
3208
  );
3192
3209
  environmentState.isReadyForAtmosphere =
3193
3210
  environmentState.isReadyForAtmosphere ||
3194
3211
  !globe.show ||
3195
3212
  globe._surface._tilesToRender.length > 0;
3196
3213
  } else {
3214
+ const dynamicLighting = atmosphere.dynamicLighting;
3215
+ skyAtmosphere.setDynamicLighting(dynamicLighting);
3197
3216
  environmentState.isReadyForAtmosphere = true;
3198
3217
  }
3218
+
3199
3219
  environmentState.skyAtmosphereCommand = skyAtmosphere.update(
3200
3220
  frameState,
3201
3221
  globe
@@ -3601,19 +3621,178 @@ function callAfterRenderFunctions(scene) {
3601
3621
  }
3602
3622
 
3603
3623
  function getGlobeHeight(scene) {
3604
- const globe = scene._globe;
3624
+ if (scene.mode === SceneMode.MORPHING) {
3625
+ return;
3626
+ }
3627
+
3605
3628
  const camera = scene.camera;
3606
3629
  const cartographic = camera.positionCartographic;
3607
- if (defined(globe) && globe.show && defined(cartographic)) {
3608
- return globe.getHeight(cartographic);
3630
+ return scene.getHeight(cartographic);
3631
+ }
3632
+
3633
+ /**
3634
+ * Gets the height of the loaded surface at the cartographic position.
3635
+ * @param {Cartographic} cartographic The cartographic position.
3636
+ * @param {HeightReference} [heightReference=CLAMP_TO_GROUND] Based on the height reference value, determines whether to ignore heights from 3D Tiles or terrain.
3637
+ * @private
3638
+ */
3639
+ Scene.prototype.getHeight = function (cartographic, heightReference) {
3640
+ if (!defined(cartographic)) {
3641
+ return undefined;
3642
+ }
3643
+
3644
+ const ignore3dTiles =
3645
+ heightReference === HeightReference.CLAMP_TO_TERRAIN ||
3646
+ heightReference === HeightReference.RELATIVE_TO_TERRAIN;
3647
+
3648
+ const ignoreTerrain =
3649
+ heightReference === HeightReference.CLAMP_TO_3D_TILE ||
3650
+ heightReference === HeightReference.RELATIVE_TO_3D_TILE;
3651
+
3652
+ if (!defined(cartographic)) {
3653
+ return;
3609
3654
  }
3655
+
3656
+ let maxHeight = Number.NEGATIVE_INFINITY;
3657
+
3658
+ if (!ignore3dTiles) {
3659
+ const length = this.primitives.length;
3660
+ for (let i = 0; i < length; ++i) {
3661
+ const primitive = this.primitives.get(i);
3662
+ if (
3663
+ !primitive.isCesium3DTileset ||
3664
+ !primitive.show ||
3665
+ primitive.disableCollision
3666
+ ) {
3667
+ continue;
3668
+ }
3669
+
3670
+ const result = primitive.getHeight(cartographic, this);
3671
+ if (defined(result) && result > maxHeight) {
3672
+ maxHeight = result;
3673
+ }
3674
+ }
3675
+ }
3676
+
3677
+ const globe = this._globe;
3678
+ if (!ignoreTerrain && defined(globe) && globe.show) {
3679
+ const result = globe.getHeight(cartographic);
3680
+ if (result > maxHeight) {
3681
+ maxHeight = result;
3682
+ }
3683
+ }
3684
+
3685
+ if (maxHeight > Number.NEGATIVE_INFINITY) {
3686
+ return maxHeight;
3687
+ }
3688
+
3610
3689
  return undefined;
3611
- }
3690
+ };
3691
+
3692
+ const updateHeightScratchCartographic = new Cartographic();
3693
+ /**
3694
+ * Calls the callback when a new tile is rendered that contains the given cartographic. The only parameter
3695
+ * is the cartesian position on the tile.
3696
+ *
3697
+ * @private
3698
+ *
3699
+ * @param {Cartographic} cartographic The cartographic position.
3700
+ * @param {Function} callback The function to be called when a new tile is loaded containing the updated cartographic.
3701
+ * @param {HeightReference} [heightReference=CLAMP_TO_GROUND] Based on the height reference value, determines whether to ignore heights from 3D Tiles or terrain.
3702
+ * @returns {Function} The function to remove this callback from the quadtree.
3703
+ */
3704
+ Scene.prototype.updateHeight = function (
3705
+ cartographic,
3706
+ callback,
3707
+ heightReference
3708
+ ) {
3709
+ //>>includeStart('debug', pragmas.debug);
3710
+ Check.typeOf.func("callback", callback);
3711
+ //>>includeEnd('debug');
3712
+
3713
+ const callbackWrapper = () => {
3714
+ Cartographic.clone(cartographic, updateHeightScratchCartographic);
3715
+
3716
+ const height = this.getHeight(cartographic, heightReference);
3717
+ if (defined(height)) {
3718
+ updateHeightScratchCartographic.height = height;
3719
+ callback(updateHeightScratchCartographic);
3720
+ }
3721
+ };
3722
+
3723
+ const ignore3dTiles =
3724
+ heightReference === HeightReference.CLAMP_TO_TERRAIN ||
3725
+ heightReference === HeightReference.RELATIVE_TO_TERRAIN;
3726
+
3727
+ const ignoreTerrain =
3728
+ heightReference === HeightReference.CLAMP_TO_3D_TILE ||
3729
+ heightReference === HeightReference.RELATIVE_TO_3D_TILE;
3730
+
3731
+ let terrainRemoveCallback;
3732
+ if (!ignoreTerrain && defined(this.globe)) {
3733
+ terrainRemoveCallback = this.globe._surface.updateHeight(
3734
+ cartographic,
3735
+ callbackWrapper
3736
+ );
3737
+ }
3738
+
3739
+ let tilesetRemoveCallbacks = {};
3740
+ const ellipsoid = this.globe?.ellipsoid;
3741
+ const createPrimitiveEventListener = (primitive) => {
3742
+ if (
3743
+ ignore3dTiles ||
3744
+ !primitive.isCesium3DTileset ||
3745
+ primitive.disableCollision
3746
+ ) {
3747
+ return;
3748
+ }
3749
+
3750
+ const tilesetRemoveCallback = primitive.updateHeight(
3751
+ cartographic,
3752
+ callbackWrapper,
3753
+ ellipsoid
3754
+ );
3755
+ tilesetRemoveCallbacks[primitive.id] = tilesetRemoveCallback;
3756
+ };
3757
+
3758
+ if (!ignore3dTiles) {
3759
+ const length = this.primitives.length;
3760
+ for (let i = 0; i < length; ++i) {
3761
+ const primitive = this.primitives.get(i);
3762
+ createPrimitiveEventListener(primitive);
3763
+ }
3764
+ }
3765
+
3766
+ const removeAddedListener = this.primitives.primitiveAdded.addEventListener(
3767
+ createPrimitiveEventListener
3768
+ );
3769
+ const removeRemovedListener = this.primitives.primitiveRemoved.addEventListener(
3770
+ (primitive) => {
3771
+ if (!primitive.isCesium3DTileset) {
3772
+ return;
3773
+ }
3774
+
3775
+ tilesetRemoveCallbacks[primitive.id]();
3776
+ delete tilesetRemoveCallbacks[primitive.id];
3777
+ }
3778
+ );
3779
+
3780
+ const removeCallback = () => {
3781
+ terrainRemoveCallback = terrainRemoveCallback && terrainRemoveCallback();
3782
+ Object.values(tilesetRemoveCallbacks).forEach((tilesetRemoveCallback) =>
3783
+ tilesetRemoveCallback()
3784
+ );
3785
+ tilesetRemoveCallbacks = {};
3786
+ removeAddedListener();
3787
+ removeRemovedListener();
3788
+ };
3789
+
3790
+ return removeCallback;
3791
+ };
3612
3792
 
3613
3793
  function isCameraUnderground(scene) {
3614
3794
  const camera = scene.camera;
3615
3795
  const mode = scene._mode;
3616
- const globe = scene.globe;
3617
3796
  const cameraController = scene._screenSpaceCameraController;
3618
3797
  const cartographic = camera.positionCartographic;
3619
3798
 
@@ -3627,12 +3806,7 @@ function isCameraUnderground(scene) {
3627
3806
  return true;
3628
3807
  }
3629
3808
 
3630
- if (
3631
- !defined(globe) ||
3632
- !globe.show ||
3633
- mode === SceneMode.SCENE2D ||
3634
- mode === SceneMode.MORPHING
3635
- ) {
3809
+ if (mode === SceneMode.SCENE2D || mode === SceneMode.MORPHING) {
3636
3810
  return false;
3637
3811
  }
3638
3812
 
@@ -3653,7 +3827,10 @@ Scene.prototype.initializeFrame = function () {
3653
3827
 
3654
3828
  this._tweens.update();
3655
3829
 
3656
- this._globeHeight = getGlobeHeight(this);
3830
+ if (this._globeHeightDirty) {
3831
+ this._globeHeight = getGlobeHeight(this);
3832
+ this._globeHeightDirty = false;
3833
+ }
3657
3834
  this._cameraUnderground = isCameraUnderground(this);
3658
3835
  this._globeTranslucencyState.update(this);
3659
3836
 
@@ -3740,6 +3917,7 @@ function render(scene) {
3740
3917
  }
3741
3918
  frameState.backgroundColor = backgroundColor;
3742
3919
 
3920
+ frameState.atmosphere = scene.atmosphere;
3743
3921
  scene.fog.update(frameState);
3744
3922
 
3745
3923
  us.update(frameState);
@@ -3828,8 +4006,12 @@ Scene.prototype.render = function (time) {
3828
4006
  time = JulianDate.now();
3829
4007
  }
3830
4008
 
3831
- // Determine if shouldRender
3832
4009
  const cameraChanged = this._view.checkForCameraUpdates(this);
4010
+ if (cameraChanged) {
4011
+ this._globeHeightDirty = true;
4012
+ }
4013
+
4014
+ // Determine if should render a new frame in request render mode
3833
4015
  let shouldRender =
3834
4016
  !this.requestRenderMode ||
3835
4017
  this._renderRequested ||
@@ -2861,16 +2861,12 @@ function adjustHeightForTerrain(controller) {
2861
2861
  const mode = scene.mode;
2862
2862
  const globe = scene.globe;
2863
2863
 
2864
- if (
2865
- !defined(globe) ||
2866
- mode === SceneMode.SCENE2D ||
2867
- mode === SceneMode.MORPHING
2868
- ) {
2864
+ if (mode === SceneMode.SCENE2D || mode === SceneMode.MORPHING) {
2869
2865
  return;
2870
2866
  }
2871
2867
 
2872
2868
  const camera = scene.camera;
2873
- const ellipsoid = globe.ellipsoid;
2869
+ const ellipsoid = defaultValue(globe?.ellipsoid, Ellipsoid.WGS84);
2874
2870
  const projection = scene.mapProjection;
2875
2871
 
2876
2872
  let transform;
@@ -217,14 +217,13 @@ Object.defineProperties(SkyAtmosphere.prototype, {
217
217
  });
218
218
 
219
219
  /**
220
+ * Set the dynamic lighting enum value for the shader
221
+ * @param {DynamicAtmosphereLightingType} lightingEnum The enum that determines the dynamic atmosphere light source
222
+ *
220
223
  * @private
221
224
  */
222
- SkyAtmosphere.prototype.setDynamicAtmosphereColor = function (
223
- enableLighting,
224
- useSunDirection
225
- ) {
226
- const lightEnum = enableLighting ? (useSunDirection ? 2.0 : 1.0) : 0.0;
227
- this._radiiAndDynamicAtmosphereColor.z = lightEnum;
225
+ SkyAtmosphere.prototype.setDynamicLighting = function (lightingEnum) {
226
+ this._radiiAndDynamicAtmosphereColor.z = lightingEnum;
228
227
  };
229
228
 
230
229
  const scratchModelMatrix = new Matrix4();
@@ -1,5 +1,6 @@
1
1
  import Check from "../Core/Check.js";
2
2
  import Event from "../Core/Event.js";
3
+ import createWorldBathymetryAsync from "../Core/createWorldBathymetryAsync.js";
3
4
  import createWorldTerrainAsync from "../Core/createWorldTerrainAsync.js";
4
5
 
5
6
  /**
@@ -156,6 +157,54 @@ Terrain.fromWorldTerrain = function (options) {
156
157
  return new Terrain(createWorldTerrainAsync(options));
157
158
  };
158
159
 
160
+ /**
161
+ * Creates a {@link Terrain} instance for {@link https://cesium.com/content/#cesium-world-bathymetry|Cesium World Bathymetry}.
162
+ *
163
+ * @function
164
+ *
165
+ * @param {Object} [options] Object with the following properties:
166
+ * @param {Boolean} [options.requestVertexNormals=false] Flag that indicates if the client should request additional lighting information from the server if available.
167
+ * @returns {Terrain} An asynchronous helper object for a CesiumTerrainProvider
168
+ *
169
+ * @see Ion
170
+ * @see createWorldBathymetryAsync
171
+ *
172
+ * @example
173
+ * // Create Cesium World Bathymetry with default settings
174
+ * const viewer = new Cesium.Viewer("cesiumContainer", {
175
+ * terrain: Cesium.Terrain.fromWorldBathymetry)
176
+ * });
177
+ *
178
+ * @example
179
+ * // Create Cesium World Terrain with normals.
180
+ * const viewer1 = new Cesium.Viewer("cesiumContainer", {
181
+ * terrain: Cesium.Terrain.fromWorldBathymetry({
182
+ * requestVertexNormals: true
183
+ * });
184
+ * });
185
+ *
186
+ * @example
187
+ * // Handle loading events
188
+ * const bathymetry = Cesium.Terrain.fromWorldBathymetry();
189
+ *
190
+ * scene.setTerrain(bathymetry);
191
+ *
192
+ * bathymetry.readyEvent.addEventListener(provider => {
193
+ * scene.globe.enableLighting = true;
194
+ *
195
+ * bathymetry.provider.errorEvent.addEventListener(error => {
196
+ * alert(`Encountered an error while loading bathymetric terrain tiles! ${error}`);
197
+ * });
198
+ * });
199
+ *
200
+ * bathymetry.errorEvent.addEventListener(error => {
201
+ * alert(`Encountered an error while creating bathymetric terrain! ${error}`);
202
+ * });
203
+ */
204
+ Terrain.fromWorldBathymetry = function (options) {
205
+ return new Terrain(createWorldBathymetryAsync(options));
206
+ };
207
+
159
208
  function handleError(errorEvent, error) {
160
209
  if (errorEvent.numberOfListeners > 0) {
161
210
  errorEvent.raiseEvent(error);
@@ -330,7 +330,7 @@ Object.defineProperties(TileBoundingS2Cell.prototype, {
330
330
  /**
331
331
  * The underlying bounding volume.
332
332
  *
333
- * @memberof TileOrientedBoundingBox.prototype
333
+ * @memberof TileBoundingS2Cell.prototype
334
334
  *
335
335
  * @type {object}
336
336
  * @readonly
@@ -343,7 +343,7 @@ Object.defineProperties(TileBoundingS2Cell.prototype, {
343
343
  /**
344
344
  * The underlying bounding sphere.
345
345
  *
346
- * @memberof TileOrientedBoundingBox.prototype
346
+ * @memberof TileBoundingS2Cell.prototype
347
347
  *
348
348
  * @type {BoundingSphere}
349
349
  * @readonly
@@ -168,6 +168,10 @@ Tileset3DTileContent.prototype.applyStyle = function (style) {};
168
168
 
169
169
  Tileset3DTileContent.prototype.update = function (tileset, frameState) {};
170
170
 
171
+ Tileset3DTileContent.prototype.pick = function (ray, frameState, result) {
172
+ return undefined;
173
+ };
174
+
171
175
  Tileset3DTileContent.prototype.isDestroyed = function () {
172
176
  return false;
173
177
  };
@@ -727,6 +727,10 @@ Vector3DTileContent.prototype.update = function (tileset, frameState) {
727
727
  }
728
728
  };
729
729
 
730
+ Vector3DTileContent.prototype.pick = function (ray, frameState, result) {
731
+ return undefined;
732
+ };
733
+
730
734
  Vector3DTileContent.prototype.getPolylinePositions = function (batchId) {
731
735
  const polylines = this._polylines;
732
736
  if (!defined(polylines)) {
@@ -11,14 +11,6 @@ const float ATMOSPHERE_THICKNESS = 111e3; // The thickness of the atmosphere in
11
11
  const int PRIMARY_STEPS_MAX = 16; // Maximum number of times the ray from the camera to the world position (primary ray) is sampled.
12
12
  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.
13
13
 
14
- /**
15
- * Rational approximation to tanh(x)
16
- */
17
- float approximateTanh(float x) {
18
- float x2 = x * x;
19
- return max(-1.0, min(+1.0, x * (27.0 + x2) / (27.0 + 9.0 * x2)));
20
- }
21
-
22
14
  /**
23
15
  * This function computes the colors contributed by Rayliegh and Mie scattering on a given ray, as well as
24
16
  * the transmittance value for the ray.
@@ -65,8 +57,8 @@ void computeScattering(
65
57
  float x = 1e-7 * primaryRayAtmosphereIntersect.stop / length(primaryRayLength);
66
58
  // Value close to 0.0: close to the horizon
67
59
  // Value close to 1.0: above in the sky
68
- float w_stop_gt_lprl = 0.5 * (1.0 + approximateTanh(x));
69
-
60
+ float w_stop_gt_lprl = 0.5 * (1.0 + czm_approximateTanh(x));
61
+
70
62
  // The ray should start from the first intersection with the outer atmopshere, or from the camera position, if it is inside the atmosphere.
71
63
  float start_0 = primaryRayAtmosphereIntersect.start;
72
64
  primaryRayAtmosphereIntersect.start = max(primaryRayAtmosphereIntersect.start, 0.0);
@@ -77,7 +69,7 @@ void computeScattering(
77
69
  // (1) from outer space we have to use more ray steps to get a realistic rendering
78
70
  // (2) within atmosphere we need fewer steps for faster rendering
79
71
  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
80
- float w_inside_atmosphere = 1.0 - 0.5 * (1.0 + approximateTanh(x_o_a));
72
+ float w_inside_atmosphere = 1.0 - 0.5 * (1.0 + czm_approximateTanh(x_o_a));
81
73
  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.
82
74
  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.
83
75
 
@@ -12,14 +12,6 @@ const float ATMOSPHERE_THICKNESS = 111e3; // The thickness of the atmosphere in
12
12
  const int PRIMARY_STEPS_MAX = 16; // Maximum number of times the ray from the camera to the world position (primary ray) is sampled.\n\
13
13
  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\
14
14
  \n\
15
- /**\n\
16
- * Rational approximation to tanh(x)\n\
17
- */\n\
18
- float approximateTanh(float x) {\n\
19
- float x2 = x * x;\n\
20
- return max(-1.0, min(+1.0, x * (27.0 + x2) / (27.0 + 9.0 * x2)));\n\
21
- }\n\
22
- \n\
23
15
  /**\n\
24
16
  * This function computes the colors contributed by Rayliegh and Mie scattering on a given ray, as well as\n\
25
17
  * the transmittance value for the ray.\n\
@@ -66,8 +58,8 @@ void computeScattering(\n\
66
58
  float x = 1e-7 * primaryRayAtmosphereIntersect.stop / length(primaryRayLength);\n\
67
59
  // Value close to 0.0: close to the horizon\n\
68
60
  // Value close to 1.0: above in the sky\n\
69
- float w_stop_gt_lprl = 0.5 * (1.0 + approximateTanh(x));\n\
70
- \n\
61
+ float w_stop_gt_lprl = 0.5 * (1.0 + czm_approximateTanh(x));\n\
62
+ \n\
71
63
  // The ray should start from the first intersection with the outer atmopshere, or from the camera position, if it is inside the atmosphere.\n\
72
64
  float start_0 = primaryRayAtmosphereIntersect.start;\n\
73
65
  primaryRayAtmosphereIntersect.start = max(primaryRayAtmosphereIntersect.start, 0.0);\n\
@@ -78,7 +70,7 @@ void computeScattering(\n\
78
70
  // (1) from outer space we have to use more ray steps to get a realistic rendering\n\
79
71
  // (2) within atmosphere we need fewer steps for faster rendering\n\
80
72
  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\
81
- float w_inside_atmosphere = 1.0 - 0.5 * (1.0 + approximateTanh(x_o_a));\n\
73
+ float w_inside_atmosphere = 1.0 - 0.5 * (1.0 + czm_approximateTanh(x_o_a));\n\
82
74
  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\
83
75
  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\
84
76
  \n\
@@ -55,7 +55,9 @@ import czm_XYZToRGB from './Functions/XYZToRGB.js'
55
55
  import czm_acesTonemapping from './Functions/acesTonemapping.js'
56
56
  import czm_alphaWeight from './Functions/alphaWeight.js'
57
57
  import czm_antialias from './Functions/antialias.js'
58
+ import czm_applyHSBShift from './Functions/applyHSBShift.js'
58
59
  import czm_approximateSphericalCoordinates from './Functions/approximateSphericalCoordinates.js'
60
+ import czm_approximateTanh from './Functions/approximateTanh.js'
59
61
  import czm_backFacing from './Functions/backFacing.js'
60
62
  import czm_branchFreeTernary from './Functions/branchFreeTernary.js'
61
63
  import czm_cascadeColor from './Functions/cascadeColor.js'
@@ -63,7 +65,10 @@ import czm_cascadeDistance from './Functions/cascadeDistance.js'
63
65
  import czm_cascadeMatrix from './Functions/cascadeMatrix.js'
64
66
  import czm_cascadeWeights from './Functions/cascadeWeights.js'
65
67
  import czm_columbusViewMorph from './Functions/columbusViewMorph.js'
68
+ import czm_computeAtmosphereColor from './Functions/computeAtmosphereColor.js'
69
+ import czm_computeGroundAtmosphereScattering from './Functions/computeGroundAtmosphereScattering.js'
66
70
  import czm_computePosition from './Functions/computePosition.js'
71
+ import czm_computeScattering from './Functions/computeScattering.js'
67
72
  import czm_cosineAndSine from './Functions/cosineAndSine.js'
68
73
  import czm_decompressTextureCoordinates from './Functions/decompressTextureCoordinates.js'
69
74
  import czm_defaultPbrMaterial from './Functions/defaultPbrMaterial.js'
@@ -79,6 +84,7 @@ import czm_fog from './Functions/fog.js'
79
84
  import czm_gammaCorrect from './Functions/gammaCorrect.js'
80
85
  import czm_geodeticSurfaceNormal from './Functions/geodeticSurfaceNormal.js'
81
86
  import czm_getDefaultMaterial from './Functions/getDefaultMaterial.js'
87
+ import czm_getDynamicAtmosphereLightDirection from './Functions/getDynamicAtmosphereLightDirection.js'
82
88
  import czm_getLambertDiffuse from './Functions/getLambertDiffuse.js'
83
89
  import czm_getSpecular from './Functions/getSpecular.js'
84
90
  import czm_getWaterNoise from './Functions/getWaterNoise.js'
@@ -188,7 +194,9 @@ export default {
188
194
  czm_acesTonemapping : czm_acesTonemapping,
189
195
  czm_alphaWeight : czm_alphaWeight,
190
196
  czm_antialias : czm_antialias,
197
+ czm_applyHSBShift : czm_applyHSBShift,
191
198
  czm_approximateSphericalCoordinates : czm_approximateSphericalCoordinates,
199
+ czm_approximateTanh : czm_approximateTanh,
192
200
  czm_backFacing : czm_backFacing,
193
201
  czm_branchFreeTernary : czm_branchFreeTernary,
194
202
  czm_cascadeColor : czm_cascadeColor,
@@ -196,7 +204,10 @@ export default {
196
204
  czm_cascadeMatrix : czm_cascadeMatrix,
197
205
  czm_cascadeWeights : czm_cascadeWeights,
198
206
  czm_columbusViewMorph : czm_columbusViewMorph,
207
+ czm_computeAtmosphereColor : czm_computeAtmosphereColor,
208
+ czm_computeGroundAtmosphereScattering : czm_computeGroundAtmosphereScattering,
199
209
  czm_computePosition : czm_computePosition,
210
+ czm_computeScattering : czm_computeScattering,
200
211
  czm_cosineAndSine : czm_cosineAndSine,
201
212
  czm_decompressTextureCoordinates : czm_decompressTextureCoordinates,
202
213
  czm_defaultPbrMaterial : czm_defaultPbrMaterial,
@@ -212,6 +223,7 @@ export default {
212
223
  czm_gammaCorrect : czm_gammaCorrect,
213
224
  czm_geodeticSurfaceNormal : czm_geodeticSurfaceNormal,
214
225
  czm_getDefaultMaterial : czm_getDefaultMaterial,
226
+ czm_getDynamicAtmosphereLightDirection : czm_getDynamicAtmosphereLightDirection,
215
227
  czm_getLambertDiffuse : czm_getLambertDiffuse,
216
228
  czm_getSpecular : czm_getSpecular,
217
229
  czm_getWaterNoise : czm_getWaterNoise,
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Apply a HSB color shift to an RGB color.
3
+ *
4
+ * @param {vec3} rgb The color in RGB space.
5
+ * @param {vec3} hsbShift The amount to shift each component. The xyz components correspond to hue, saturation, and brightness. Shifting the hue by +/- 1.0 corresponds to shifting the hue by a full cycle. Saturation and brightness are clamped between 0 and 1 after the adjustment
6
+ * @param {bool} ignoreBlackPixels If true, black pixels will be unchanged. This is necessary in some shaders such as atmosphere-related effects.
7
+ *
8
+ * @return {vec3} The RGB color after shifting in HSB space and clamping saturation and brightness to a valid range.
9
+ */
10
+ vec3 czm_applyHSBShift(vec3 rgb, vec3 hsbShift, bool ignoreBlackPixels) {
11
+ // Convert rgb color to hsb
12
+ vec3 hsb = czm_RGBToHSB(rgb);
13
+
14
+ // Perform hsb shift
15
+ // Hue cycles around so no clamp is needed.
16
+ hsb.x += hsbShift.x; // hue
17
+ hsb.y = clamp(hsb.y + hsbShift.y, 0.0, 1.0); // saturation
18
+
19
+ // brightness
20
+ //
21
+ // Some shaders such as atmosphere-related effects need to leave black
22
+ // pixels unchanged
23
+ if (ignoreBlackPixels) {
24
+ hsb.z = hsb.z > czm_epsilon7 ? hsb.z + hsbShift.z : 0.0;
25
+ } else {
26
+ hsb.z = hsb.z + hsbShift.z;
27
+ }
28
+ hsb.z = clamp(hsb.z, 0.0, 1.0);
29
+
30
+ // Convert shifted hsb back to rgb
31
+ return czm_HSBToRGB(hsb);
32
+ }
@@ -0,0 +1,34 @@
1
+ //This file is automatically rebuilt by the Cesium build process.
2
+ export default "/**\n\
3
+ * Apply a HSB color shift to an RGB color.\n\
4
+ *\n\
5
+ * @param {vec3} rgb The color in RGB space.\n\
6
+ * @param {vec3} hsbShift The amount to shift each component. The xyz components correspond to hue, saturation, and brightness. Shifting the hue by +/- 1.0 corresponds to shifting the hue by a full cycle. Saturation and brightness are clamped between 0 and 1 after the adjustment\n\
7
+ * @param {bool} ignoreBlackPixels If true, black pixels will be unchanged. This is necessary in some shaders such as atmosphere-related effects.\n\
8
+ *\n\
9
+ * @return {vec3} The RGB color after shifting in HSB space and clamping saturation and brightness to a valid range.\n\
10
+ */\n\
11
+ vec3 czm_applyHSBShift(vec3 rgb, vec3 hsbShift, bool ignoreBlackPixels) {\n\
12
+ // Convert rgb color to hsb\n\
13
+ vec3 hsb = czm_RGBToHSB(rgb);\n\
14
+ \n\
15
+ // Perform hsb shift\n\
16
+ // Hue cycles around so no clamp is needed.\n\
17
+ hsb.x += hsbShift.x; // hue\n\
18
+ hsb.y = clamp(hsb.y + hsbShift.y, 0.0, 1.0); // saturation\n\
19
+ \n\
20
+ // brightness\n\
21
+ //\n\
22
+ // Some shaders such as atmosphere-related effects need to leave black\n\
23
+ // pixels unchanged\n\
24
+ if (ignoreBlackPixels) {\n\
25
+ hsb.z = hsb.z > czm_epsilon7 ? hsb.z + hsbShift.z : 0.0;\n\
26
+ } else {\n\
27
+ hsb.z = hsb.z + hsbShift.z;\n\
28
+ }\n\
29
+ hsb.z = clamp(hsb.z, 0.0, 1.0);\n\
30
+ \n\
31
+ // Convert shifted hsb back to rgb\n\
32
+ return czm_HSBToRGB(hsb);\n\
33
+ }\n\
34
+ ";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Compute a rational approximation to tanh(x)
3
+ *
4
+ * @param {float} x A real number input
5
+ * @returns {float} An approximation for tanh(x)
6
+ */
7
+ float czm_approximateTanh(float x) {
8
+ float x2 = x * x;
9
+ return max(-1.0, min(1.0, x * (27.0 + x2) / (27.0 + 9.0 * x2)));
10
+ }