@cesium/engine 6.2.0 → 8.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 (268) hide show
  1. package/Build/ThirdParty/Workers/z-worker-pako.js +568 -407
  2. package/Build/Workers/{chunk-RH4N2ONY.js → chunk-23UFSGND.js} +7 -7
  3. package/Build/Workers/{chunk-HPP4JLNH.js → chunk-2A75IWRS.js} +7 -7
  4. package/Build/Workers/{chunk-5IRLXUTA.js → chunk-2FRVPMCS.js} +10 -10
  5. package/Build/Workers/{chunk-ZQRZBHYI.js → chunk-2FWRMUTY.js} +4 -4
  6. package/Build/Workers/{chunk-Z2SIPUKB.js → chunk-2UPKWTMJ.js} +6 -6
  7. package/Build/Workers/{chunk-434ZTTFX.js → chunk-34FXV7D7.js} +2 -2
  8. package/Build/Workers/{chunk-MW3CJYLX.js → chunk-3VAZEH7M.js} +2 -2
  9. package/Build/Workers/{chunk-HUPNRBWW.js → chunk-4DO5W5XZ.js} +6 -6
  10. package/Build/Workers/{chunk-PIXK6KHB.js → chunk-4H7PY4U5.js} +2 -2
  11. package/Build/Workers/{chunk-BP467WX3.js → chunk-5QULIR53.js} +4 -4
  12. package/Build/Workers/{chunk-R3HUGXBH.js → chunk-7TC63SJW.js} +8 -8
  13. package/Build/Workers/{chunk-SQVTYRZY.js → chunk-7ZFGPDJA.js} +4 -4
  14. package/Build/Workers/{chunk-TIXXVKUY.js → chunk-A5DWLWCY.js} +10 -10
  15. package/Build/Workers/{chunk-CWJQGBWT.js → chunk-BBWDMCVU.js} +1 -1
  16. package/Build/Workers/{chunk-4KP73B43.js → chunk-BG4UCVXN.js} +3 -3
  17. package/Build/Workers/{chunk-Y4OJ4B23.js → chunk-BIKA3NRA.js} +5 -5
  18. package/Build/Workers/{chunk-DR5XZ6K5.js → chunk-BROJAZRZ.js} +13 -13
  19. package/Build/Workers/{chunk-FWGNCYP6.js → chunk-DDUQAJ4P.js} +7 -7
  20. package/Build/Workers/{chunk-QRBRVGZC.js → chunk-EERJKOAF.js} +4 -4
  21. package/Build/Workers/{chunk-52VSIKEA.js → chunk-EG6PTBY2.js} +15 -15
  22. package/Build/Workers/{chunk-O43GWBSF.js → chunk-EHWHNOEX.js} +1 -1
  23. package/Build/Workers/{chunk-MN34FIF5.js → chunk-F3YA3Y2Z.js} +1 -1
  24. package/Build/Workers/{chunk-GF5TNNKP.js → chunk-F4HFJMGM.js} +6 -6
  25. package/Build/Workers/{chunk-HOT2SNXP.js → chunk-FJKNFAKQ.js} +133 -553
  26. package/Build/Workers/{chunk-TMPVBFJQ.js → chunk-FNIRWHJB.js} +10 -10
  27. package/Build/Workers/{chunk-DMCSY5BU.js → chunk-FZRIVR7Y.js} +5 -5
  28. package/Build/Workers/{chunk-Z4JUBRHP.js → chunk-G43QFN4Q.js} +6 -6
  29. package/Build/Workers/{chunk-HPH5HSFE.js → chunk-GATZHF3K.js} +2 -2
  30. package/Build/Workers/{chunk-CSIZ3BGT.js → chunk-GRC2ZTAF.js} +14 -14
  31. package/Build/Workers/{chunk-NE4JNU6H.js → chunk-HU6N6EXB.js} +10 -10
  32. package/Build/Workers/{chunk-GVL5I7TC.js → chunk-I46ZRR5W.js} +17 -17
  33. package/Build/Workers/{chunk-5GDBZTHX.js → chunk-JURN7NPV.js} +17 -17
  34. package/Build/Workers/{chunk-H5DUXHCV.js → chunk-KKCR2YOP.js} +11 -11
  35. package/Build/Workers/{chunk-LX6XV4DK.js → chunk-LPR3YNP2.js} +5 -5
  36. package/Build/Workers/{chunk-HFKSAB5K.js → chunk-M7ERACJJ.js} +13 -13
  37. package/Build/Workers/{chunk-BUZDZBUH.js → chunk-MDWEGWPA.js} +10 -10
  38. package/Build/Workers/{chunk-LGJUI2CE.js → chunk-OGXZVPPM.js} +9 -5
  39. package/Build/Workers/{chunk-PZ2WJWUG.js → chunk-PGSJK77E.js} +6 -6
  40. package/Build/Workers/{chunk-ARPTYYKS.js → chunk-PPH7OFP3.js} +5 -5
  41. package/Build/Workers/{chunk-R4OZKBXH.js → chunk-SH5USDPI.js} +6 -6
  42. package/Build/Workers/{chunk-SV7DDPAC.js → chunk-SOWMRMWA.js} +1 -1
  43. package/Build/Workers/{chunk-RIDPF7PO.js → chunk-STW2DGFI.js} +2 -2
  44. package/Build/Workers/{chunk-CDGHUKQ4.js → chunk-T3XIFPYR.js} +13 -13
  45. package/Build/Workers/chunk-TTUZP4BO.js +501 -0
  46. package/Build/Workers/{chunk-QTZQZY2C.js → chunk-UEXTBDBE.js} +34 -10
  47. package/Build/Workers/{chunk-XUTVA4K5.js → chunk-VOXYEYJT.js} +11 -11
  48. package/Build/Workers/{chunk-AXFRNOVC.js → chunk-X4356LRH.js} +12 -12
  49. package/Build/Workers/{chunk-5HLGKKG3.js → chunk-XGI5BXZY.js} +2 -2
  50. package/Build/Workers/{chunk-SNN7WOC2.js → chunk-Y2ME2IJV.js} +13 -13
  51. package/Build/Workers/{chunk-LGL4P5KL.js → chunk-Y5UQJLYE.js} +6 -6
  52. package/Build/Workers/{chunk-3PW6ZBN4.js → chunk-YJEBABKH.js} +7 -7
  53. package/Build/Workers/{chunk-YBKFS53K.js → chunk-YWTJ2B4B.js} +1 -1
  54. package/Build/Workers/{chunk-5SK36PU4.js → chunk-Z3TIFFGF.js} +7 -7
  55. package/Build/Workers/{chunk-JGG36SQV.js → chunk-ZT7KWISZ.js} +4 -4
  56. package/Build/Workers/combineGeometry.js +24 -23
  57. package/Build/Workers/createBoxGeometry.js +18 -17
  58. package/Build/Workers/createBoxOutlineGeometry.js +16 -15
  59. package/Build/Workers/createCircleGeometry.js +26 -25
  60. package/Build/Workers/createCircleOutlineGeometry.js +19 -18
  61. package/Build/Workers/createCoplanarPolygonGeometry.js +33 -32
  62. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +31 -30
  63. package/Build/Workers/createCorridorGeometry.js +29 -29
  64. package/Build/Workers/createCorridorOutlineGeometry.js +28 -28
  65. package/Build/Workers/createCylinderGeometry.js +20 -19
  66. package/Build/Workers/createCylinderOutlineGeometry.js +18 -17
  67. package/Build/Workers/createEllipseGeometry.js +26 -25
  68. package/Build/Workers/createEllipseOutlineGeometry.js +19 -18
  69. package/Build/Workers/createEllipsoidGeometry.js +19 -18
  70. package/Build/Workers/createEllipsoidOutlineGeometry.js +18 -17
  71. package/Build/Workers/createFrustumGeometry.js +18 -17
  72. package/Build/Workers/createFrustumOutlineGeometry.js +18 -17
  73. package/Build/Workers/createGeometry.js +54 -33
  74. package/Build/Workers/createGroundPolylineGeometry.js +22 -21
  75. package/Build/Workers/createPlaneGeometry.js +16 -15
  76. package/Build/Workers/createPlaneOutlineGeometry.js +15 -14
  77. package/Build/Workers/createPolygonGeometry.js +32 -166
  78. package/Build/Workers/createPolygonOutlineGeometry.js +30 -29
  79. package/Build/Workers/createPolylineGeometry.js +25 -24
  80. package/Build/Workers/createPolylineVolumeGeometry.js +32 -33
  81. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +27 -27
  82. package/Build/Workers/createRectangleGeometry.js +27 -26
  83. package/Build/Workers/createRectangleOutlineGeometry.js +20 -19
  84. package/Build/Workers/createSimplePolylineGeometry.js +23 -22
  85. package/Build/Workers/createSphereGeometry.js +19 -18
  86. package/Build/Workers/createSphereOutlineGeometry.js +18 -17
  87. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  88. package/Build/Workers/createVectorTileClampedPolylines.js +14 -14
  89. package/Build/Workers/createVectorTileGeometries.js +24 -23
  90. package/Build/Workers/createVectorTilePoints.js +12 -12
  91. package/Build/Workers/createVectorTilePolygons.js +22 -21
  92. package/Build/Workers/createVectorTilePolylines.js +14 -14
  93. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +22 -21
  94. package/Build/Workers/createVerticesFromHeightmap.js +22 -21
  95. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +19 -18
  96. package/Build/Workers/createWallGeometry.js +24 -23
  97. package/Build/Workers/createWallOutlineGeometry.js +23 -22
  98. package/Build/Workers/decodeDraco.js +11 -11
  99. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
  100. package/Build/Workers/decodeI3S.js +601 -92
  101. package/Build/Workers/transcodeKTX2.js +7 -7
  102. package/Build/Workers/transferTypedArrayTest.js +1 -1
  103. package/Build/Workers/upsampleQuantizedTerrainMesh.js +22 -21
  104. package/LICENSE.md +1 -1
  105. package/Source/Assets/approximateTerrainHeights.json +1 -1
  106. package/Source/Core/Ellipsoid.js +6 -0
  107. package/Source/Core/GregorianDate.js +85 -0
  108. package/Source/Core/HeadingPitchRange.js +2 -2
  109. package/Source/Core/IntersectionTests.js +6 -3
  110. package/Source/Core/Ion.js +1 -1
  111. package/Source/Core/PixelFormat.js +5 -0
  112. package/Source/Core/PolygonGeometry.js +0 -169
  113. package/Source/Core/Resource.js +30 -69
  114. package/Source/Core/Transforms.js +30 -18
  115. package/Source/Core/createWorldBathymetryAsync.js +45 -0
  116. package/Source/Core/srgbToLinear.js +32 -0
  117. package/Source/DataSources/CzmlDataSource.js +51 -23
  118. package/Source/DataSources/DataSourceDisplay.js +27 -0
  119. package/Source/DataSources/EllipsoidGeometryUpdater.js +3 -4
  120. package/Source/DataSources/Entity.js +28 -7
  121. package/Source/DataSources/EntityCollection.js +1 -2
  122. package/Source/DataSources/GeometryUpdater.js +1 -2
  123. package/Source/DataSources/GeometryUpdaterSet.js +114 -0
  124. package/Source/DataSources/GeometryVisualizer.js +19 -83
  125. package/Source/DataSources/GroundGeometryUpdater.js +6 -3
  126. package/Source/DataSources/ModelVisualizer.js +19 -98
  127. package/Source/DataSources/PolygonGeometryUpdater.js +14 -2
  128. package/Source/DataSources/PolylineGeometryUpdater.js +9 -8
  129. package/Source/DataSources/TerrainOffsetProperty.js +15 -23
  130. package/Source/Renderer/AutomaticUniforms.js +121 -1
  131. package/Source/Renderer/Context.js +10 -0
  132. package/Source/Renderer/ContextLimits.js +2 -0
  133. package/Source/Renderer/UniformState.js +127 -0
  134. package/Source/Renderer/demodernizeShader.js +4 -1
  135. package/Source/Scene/ArcGisMapService.js +1 -1
  136. package/Source/Scene/Atmosphere.js +127 -0
  137. package/Source/Scene/Axis.js +12 -7
  138. package/Source/Scene/Billboard.js +29 -26
  139. package/Source/Scene/BillboardCollection.js +3 -3
  140. package/Source/Scene/Camera.js +47 -5
  141. package/Source/Scene/Cesium3DTile.js +1 -0
  142. package/Source/Scene/Cesium3DTileContent.js +14 -0
  143. package/Source/Scene/Cesium3DTileset.js +364 -45
  144. package/Source/Scene/Cesium3DTilesetBaseTraversal.js +2 -4
  145. package/Source/Scene/Cesium3DTilesetTraversal.js +4 -0
  146. package/Source/Scene/Composite3DTileContent.js +42 -0
  147. package/Source/Scene/DynamicAtmosphereLightingType.js +56 -0
  148. package/Source/Scene/Empty3DTileContent.js +4 -0
  149. package/Source/Scene/Fog.js +1 -0
  150. package/Source/Scene/FrameState.js +14 -1
  151. package/Source/Scene/Geometry3DTileContent.js +4 -0
  152. package/Source/Scene/Globe.js +3 -2
  153. package/Source/Scene/GlobeSurfaceTileProvider.js +3 -1
  154. package/Source/Scene/GlobeTranslucencyState.js +1 -1
  155. package/Source/Scene/GltfLoader.js +15 -5
  156. package/Source/Scene/GltfPipeline/updateVersion.js +69 -68
  157. package/Source/Scene/HeightReference.js +59 -2
  158. package/Source/Scene/I3SDataProvider.js +270 -53
  159. package/Source/Scene/I3SDecoder.js +8 -1
  160. package/Source/Scene/I3SFeature.js +2 -5
  161. package/Source/Scene/I3SField.js +136 -31
  162. package/Source/Scene/I3SGeometry.js +70 -2
  163. package/Source/Scene/I3SLayer.js +55 -10
  164. package/Source/Scene/I3SNode.js +175 -18
  165. package/Source/Scene/I3SStatistics.js +94 -0
  166. package/Source/Scene/I3SSublayer.js +176 -0
  167. package/Source/Scene/I3SSymbology.js +337 -0
  168. package/Source/Scene/Implicit3DTileContent.js +4 -0
  169. package/Source/Scene/KeyframeNode.js +1 -1
  170. package/Source/Scene/LabelCollection.js +2 -2
  171. package/Source/Scene/Model/AtmospherePipelineStage.js +59 -0
  172. package/Source/Scene/Model/B3dmLoader.js +4 -0
  173. package/Source/Scene/Model/FeatureIdPipelineStage.js +25 -2
  174. package/Source/Scene/Model/I3dmLoader.js +4 -0
  175. package/Source/Scene/Model/InstancingPipelineStage.js +24 -6
  176. package/Source/Scene/Model/MetadataPipelineStage.js +31 -3
  177. package/Source/Scene/Model/Model.js +82 -32
  178. package/Source/Scene/Model/Model3DTileContent.js +31 -0
  179. package/Source/Scene/Model/ModelAnimationChannel.js +16 -15
  180. package/Source/Scene/Model/ModelSceneGraph.js +6 -0
  181. package/Source/Scene/Model/pickModel.js +426 -0
  182. package/Source/Scene/Multiple3DTileContent.js +42 -0
  183. package/Source/Scene/PickFramebuffer.js +37 -2
  184. package/Source/Scene/Picking.js +113 -39
  185. package/Source/Scene/Primitive.js +6 -2
  186. package/Source/Scene/QuadtreePrimitive.js +1 -1
  187. package/Source/Scene/Scene.js +312 -46
  188. package/Source/Scene/ScreenSpaceCameraController.js +23 -13
  189. package/Source/Scene/SensorVolumePortionToDisplay.js +69 -0
  190. package/Source/Scene/SkyAtmosphere.js +5 -6
  191. package/Source/Scene/SpatialNode.js +12 -19
  192. package/Source/Scene/StructuralMetadata.js +1 -1
  193. package/Source/Scene/Terrain.js +49 -0
  194. package/Source/Scene/TileBoundingS2Cell.js +2 -2
  195. package/Source/Scene/Tileset3DTileContent.js +4 -0
  196. package/Source/Scene/Vector3DTileContent.js +4 -0
  197. package/Source/Scene/VoxelBoxShape.js +76 -0
  198. package/Source/Scene/VoxelCell.js +273 -0
  199. package/Source/Scene/VoxelCylinderShape.js +114 -43
  200. package/Source/Scene/VoxelEllipsoidShape.js +158 -116
  201. package/Source/Scene/VoxelPrimitive.js +3 -1
  202. package/Source/Scene/VoxelRenderResources.js +3 -0
  203. package/Source/Scene/VoxelShape.js +13 -0
  204. package/Source/Scene/VoxelTraversal.js +76 -54
  205. package/Source/Scene/buildVoxelDrawCommands.js +23 -0
  206. package/Source/Scene/createGooglePhotorealistic3DTileset.js +1 -0
  207. package/Source/Scene/processVoxelProperties.js +2 -0
  208. package/Source/Shaders/AtmosphereCommon.glsl +3 -11
  209. package/Source/Shaders/AtmosphereCommon.js +3 -11
  210. package/Source/Shaders/Builtin/CzmBuiltins.js +12 -0
  211. package/Source/Shaders/Builtin/Functions/applyHSBShift.glsl +32 -0
  212. package/Source/Shaders/Builtin/Functions/applyHSBShift.js +34 -0
  213. package/Source/Shaders/Builtin/Functions/approximateTanh.glsl +10 -0
  214. package/Source/Shaders/Builtin/Functions/approximateTanh.js +12 -0
  215. package/Source/Shaders/Builtin/Functions/computeAtmosphereColor.glsl +44 -0
  216. package/Source/Shaders/Builtin/Functions/computeAtmosphereColor.js +46 -0
  217. package/Source/Shaders/Builtin/Functions/computeGroundAtmosphereScattering.glsl +30 -0
  218. package/Source/Shaders/Builtin/Functions/computeGroundAtmosphereScattering.js +32 -0
  219. package/Source/Shaders/Builtin/Functions/computeScattering.glsl +150 -0
  220. package/Source/Shaders/Builtin/Functions/computeScattering.js +152 -0
  221. package/Source/Shaders/Builtin/Functions/getDynamicAtmosphereLightDirection.glsl +22 -0
  222. package/Source/Shaders/Builtin/Functions/getDynamicAtmosphereLightDirection.js +24 -0
  223. package/Source/Shaders/Builtin/Functions/translateRelativeToEye.glsl +5 -0
  224. package/Source/Shaders/Builtin/Functions/translateRelativeToEye.js +5 -0
  225. package/Source/Shaders/GlobeFS.glsl +16 -25
  226. package/Source/Shaders/GlobeFS.js +16 -25
  227. package/Source/Shaders/GlobeVS.glsl +1 -1
  228. package/Source/Shaders/GlobeVS.js +1 -1
  229. package/Source/Shaders/Model/AtmosphereStageFS.glsl +111 -0
  230. package/Source/Shaders/Model/AtmosphereStageFS.js +113 -0
  231. package/Source/Shaders/Model/AtmosphereStageVS.glsl +12 -0
  232. package/Source/Shaders/Model/AtmosphereStageVS.js +14 -0
  233. package/Source/Shaders/Model/GeometryStageFS.glsl +1 -1
  234. package/Source/Shaders/Model/GeometryStageFS.js +1 -1
  235. package/Source/Shaders/Model/GeometryStageVS.glsl +4 -4
  236. package/Source/Shaders/Model/GeometryStageVS.js +4 -4
  237. package/Source/Shaders/Model/ModelColorStageFS.glsl +1 -1
  238. package/Source/Shaders/Model/ModelColorStageFS.js +2 -1
  239. package/Source/Shaders/Model/ModelFS.glsl +4 -0
  240. package/Source/Shaders/Model/ModelFS.js +4 -0
  241. package/Source/Shaders/Model/ModelVS.glsl +9 -4
  242. package/Source/Shaders/Model/ModelVS.js +9 -4
  243. package/Source/Shaders/SkyAtmosphereCommon.glsl +3 -13
  244. package/Source/Shaders/SkyAtmosphereCommon.js +3 -13
  245. package/Source/Shaders/SkyAtmosphereFS.glsl +5 -10
  246. package/Source/Shaders/SkyAtmosphereFS.js +5 -10
  247. package/Source/Shaders/SkyAtmosphereVS.glsl +3 -2
  248. package/Source/Shaders/SkyAtmosphereVS.js +3 -2
  249. package/Source/Shaders/Voxels/IntersectCylinder.glsl +14 -111
  250. package/Source/Shaders/Voxels/IntersectCylinder.js +14 -111
  251. package/Source/Shaders/Voxels/IntersectEllipsoid.glsl +32 -113
  252. package/Source/Shaders/Voxels/IntersectEllipsoid.js +32 -113
  253. package/Source/Shaders/Voxels/IntersectLongitude.glsl +102 -0
  254. package/Source/Shaders/Voxels/IntersectLongitude.js +104 -0
  255. package/Source/Shaders/Voxels/VoxelFS.glsl +39 -1
  256. package/Source/Shaders/Voxels/VoxelFS.js +39 -1
  257. package/Source/Shaders/Voxels/convertUvToCylinder.glsl +19 -37
  258. package/Source/Shaders/Voxels/convertUvToCylinder.js +19 -37
  259. package/Source/Shaders/Voxels/convertUvToEllipsoid.glsl +24 -44
  260. package/Source/Shaders/Voxels/convertUvToEllipsoid.js +24 -44
  261. package/Source/ThirdParty/Workers/z-worker-pako.js +1 -1
  262. package/Source/ThirdParty/draco_decoder.wasm +0 -0
  263. package/Source/Workers/createGeometry.js +40 -11
  264. package/Source/Workers/decodeI3S.js +720 -94
  265. package/index.d.ts +574 -71
  266. package/index.js +217 -196
  267. package/package.json +3 -3
  268. package/Build/Workers/chunk-ATB2I7OS.js +0 -55
@@ -49,16 +49,14 @@ function VoxelTraversal(
49
49
  */
50
50
  this._primitive = primitive;
51
51
 
52
- const length = types.length;
53
-
54
52
  /**
55
53
  * @type {Megatexture[]}
56
54
  * @readonly
57
55
  */
58
- this.megatextures = new Array(length);
56
+ this.megatextures = new Array(types.length);
59
57
 
60
58
  // TODO make sure to split the maximumTextureMemoryByteLength across all the megatextures
61
- for (let i = 0; i < length; i++) {
59
+ for (let i = 0; i < types.length; i++) {
62
60
  const type = types[i];
63
61
  const componentCount = MetadataType.getComponentCount(type);
64
62
  const componentType = componentTypes[i];
@@ -218,6 +216,18 @@ function VoxelTraversal(
218
216
  this.leafNodeTexelSizeUv = new Cartesian2();
219
217
  }
220
218
 
219
+ /**
220
+ * Finds a keyframe node in the traversal
221
+ *
222
+ * @param {number} megatextureIndex
223
+ * @returns {KeyframeNode}
224
+ */
225
+ VoxelTraversal.prototype.findKeyframeNode = function (megatextureIndex) {
226
+ return this._keyframeNodesInMegatexture.find(function (keyframeNode) {
227
+ return keyframeNode.megatextureIndex === megatextureIndex;
228
+ });
229
+ };
230
+
221
231
  function binaryTreeWeightingRecursive(arr, start, end, depth) {
222
232
  if (start > end) {
223
233
  return;
@@ -382,10 +392,7 @@ VoxelTraversal.prototype.destroy = function () {
382
392
  * @private
383
393
  */
384
394
  function recomputeBoundingVolumesRecursive(that, node) {
385
- const primitive = that._primitive;
386
- const shape = primitive._shape;
387
- const dimensions = primitive._provider.dimensions;
388
- node.computeBoundingVolumes(shape, dimensions);
395
+ node.computeBoundingVolumes(that._primitive._shape);
389
396
  if (defined(node.children)) {
390
397
  for (let i = 0; i < 8; i++) {
391
398
  const child = node.children[i];
@@ -410,12 +417,11 @@ function requestData(that, keyframeNode) {
410
417
  return;
411
418
  }
412
419
 
413
- const primitive = that._primitive;
414
- const provider = primitive._provider;
420
+ const provider = that._primitive._provider;
415
421
 
416
422
  function postRequestSuccess(result) {
417
423
  that._simultaneousRequestCount--;
418
- const length = primitive._provider.types.length;
424
+ const length = provider.types.length;
419
425
 
420
426
  if (!defined(result)) {
421
427
  keyframeNode.state = KeyframeNode.LoadState.UNAVAILABLE;
@@ -434,7 +440,7 @@ function requestData(that, keyframeNode) {
434
440
  const data = result[i];
435
441
  const expectedLength = tileVoxelCount * channelCount;
436
442
  if (data.length === expectedLength) {
437
- keyframeNode.metadatas[i] = data;
443
+ keyframeNode.metadata[i] = data;
438
444
  // State is received only when all metadata requests have been received
439
445
  keyframeNode.state = KeyframeNode.LoadState.RECEIVED;
440
446
  } else {
@@ -492,42 +498,22 @@ function loadAndUnload(that, frameState) {
492
498
  const frameNumber = that._frameNumber;
493
499
  const primitive = that._primitive;
494
500
  const shape = primitive._shape;
495
- const { dimensions } = primitive;
496
501
  const targetScreenSpaceError = primitive.screenSpaceError;
497
502
  const priorityQueue = that._priorityQueue;
498
- const keyframeLocation = that._keyframeLocation;
499
503
  const keyframeCount = that._keyframeCount;
500
- const rootNode = that.rootNode;
504
+
505
+ const previousKeyframe = CesiumMath.clamp(
506
+ Math.floor(that._keyframeLocation),
507
+ 0,
508
+ keyframeCount - 2
509
+ );
510
+ const nextKeyframe = previousKeyframe + 1;
501
511
 
502
512
  const { camera, context, pixelRatio } = frameState;
503
513
  const { positionWC, frustum } = camera;
504
514
  const screenHeight = context.drawingBufferHeight / pixelRatio;
505
515
  const screenSpaceErrorMultiplier = screenHeight / frustum.sseDenominator;
506
516
 
507
- function keyframePriority(previousKeyframe, keyframe, nextKeyframe) {
508
- const keyframeDifference = Math.min(
509
- Math.abs(keyframe - previousKeyframe),
510
- Math.abs(keyframe - nextKeyframe)
511
- );
512
- const maxKeyframeDifference = Math.max(
513
- previousKeyframe,
514
- keyframeCount - nextKeyframe - 1,
515
- 1
516
- );
517
- const keyframeFactor = Math.pow(
518
- 1.0 - keyframeDifference / maxKeyframeDifference,
519
- 4.0
520
- );
521
- const binaryTreeFactor = Math.exp(
522
- -that._binaryTreeKeyframeWeighting[keyframe]
523
- );
524
- return CesiumMath.lerp(
525
- binaryTreeFactor,
526
- keyframeFactor,
527
- 0.15 + 0.85 * keyframeFactor
528
- );
529
- }
530
-
531
517
  /**
532
518
  * @ignore
533
519
  * @param {SpatialNode} spatialNode
@@ -545,13 +531,6 @@ function loadAndUnload(that, frameState) {
545
531
  }
546
532
  spatialNode.visitedFrameNumber = frameNumber;
547
533
 
548
- const previousKeyframe = CesiumMath.clamp(
549
- Math.floor(keyframeLocation),
550
- 0,
551
- keyframeCount - 2
552
- );
553
- const nextKeyframe = previousKeyframe + 1;
554
-
555
534
  // Create keyframe nodes at the playhead.
556
535
  // If they already exist, nothing will be created.
557
536
  if (keyframeCount === 1) {
@@ -561,16 +540,21 @@ function loadAndUnload(that, frameState) {
561
540
  spatialNode.createKeyframeNode(k);
562
541
  }
563
542
  }
564
- const ssePriority = mapInfiniteRangeToZeroOne(spatialNode.screenSpaceError);
543
+ const { screenSpaceError, keyframeNodes } = spatialNode;
544
+ const ssePriority = mapInfiniteRangeToZeroOne(screenSpaceError);
565
545
 
566
546
  let hasLoadedKeyframe = false;
567
- const keyframeNodes = spatialNode.keyframeNodes;
568
547
  for (let i = 0; i < keyframeNodes.length; i++) {
569
548
  const keyframeNode = keyframeNodes[i];
570
549
 
571
550
  keyframeNode.priority =
572
551
  10.0 * ssePriority +
573
- keyframePriority(previousKeyframe, keyframeNode.keyframe, nextKeyframe);
552
+ keyframePriority(
553
+ previousKeyframe,
554
+ keyframeNode.keyframe,
555
+ nextKeyframe,
556
+ that
557
+ );
574
558
 
575
559
  if (
576
560
  keyframeNode.state !== KeyframeNode.LoadState.UNAVAILABLE &&
@@ -584,16 +568,14 @@ function loadAndUnload(that, frameState) {
584
568
  }
585
569
  }
586
570
 
587
- const meetsScreenSpaceError =
588
- spatialNode.screenSpaceError < targetScreenSpaceError;
589
- if (meetsScreenSpaceError || !hasLoadedKeyframe) {
571
+ if (screenSpaceError < targetScreenSpaceError || !hasLoadedKeyframe) {
590
572
  // Free up memory
591
573
  spatialNode.children = undefined;
592
574
  return;
593
575
  }
594
576
 
595
577
  if (!defined(spatialNode.children)) {
596
- spatialNode.constructChildNodes(shape, dimensions);
578
+ spatialNode.constructChildNodes(shape);
597
579
  }
598
580
  for (let childIndex = 0; childIndex < 8; childIndex++) {
599
581
  const child = spatialNode.children[childIndex];
@@ -601,9 +583,11 @@ function loadAndUnload(that, frameState) {
601
583
  }
602
584
  }
603
585
 
586
+ // Add all the nodes to the queue, to sort them by priority.
604
587
  priorityQueue.reset();
605
- addToQueueRecursive(rootNode, CullingVolume.MASK_INDETERMINATE);
588
+ addToQueueRecursive(that.rootNode, CullingVolume.MASK_INDETERMINATE);
606
589
 
590
+ // Move the nodes from the queue to array of high priority nodes.
607
591
  const highPriorityKeyframeNodes = that._highPriorityKeyframeNodes;
608
592
  let highPriorityKeyframeNodeCount = 0;
609
593
  let highPriorityKeyframeNode;
@@ -616,6 +600,8 @@ function loadAndUnload(that, frameState) {
616
600
  highPriorityKeyframeNodeCount++;
617
601
  }
618
602
 
603
+ // Sort the list of keyframe nodes in the megatexture by priority, so
604
+ // we can remove the lowest priority nodes if we need space.
619
605
  const keyframeNodesInMegatexture = that._keyframeNodesInMegatexture;
620
606
  // TODO: some of the megatexture state should be stored once, not duplicate for each megatexture
621
607
  const megatexture = that.megatextures[0];
@@ -628,6 +614,8 @@ function loadAndUnload(that, frameState) {
628
614
  return b.highPriorityFrameNumber - a.highPriorityFrameNumber;
629
615
  });
630
616
 
617
+ // Add the high priority nodes to the megatexture,
618
+ // removing existing lower-priority nodes if necessary.
631
619
  let destroyedCount = 0;
632
620
  let addedCount = 0;
633
621
 
@@ -675,6 +663,40 @@ function loadAndUnload(that, frameState) {
675
663
  }
676
664
  }
677
665
 
666
+ /**
667
+ * Compute a priority for a keyframe node.
668
+ *
669
+ * @private
670
+ * @param {number} previousKeyframe
671
+ * @param {number} keyframe
672
+ * @param {number} nextKeyframe
673
+ * @param {VoxelTraversal} traversal
674
+ * @returns {number} The computed priority
675
+ */
676
+ function keyframePriority(previousKeyframe, keyframe, nextKeyframe, traversal) {
677
+ const keyframeDifference = Math.min(
678
+ Math.abs(keyframe - previousKeyframe),
679
+ Math.abs(keyframe - nextKeyframe)
680
+ );
681
+ const maxKeyframeDifference = Math.max(
682
+ previousKeyframe,
683
+ traversal._keyframeCount - nextKeyframe - 1,
684
+ 1
685
+ );
686
+ const keyframeFactor = Math.pow(
687
+ 1.0 - keyframeDifference / maxKeyframeDifference,
688
+ 4.0
689
+ );
690
+ const binaryTreeFactor = Math.exp(
691
+ -traversal._binaryTreeKeyframeWeighting[keyframe]
692
+ );
693
+ return CesiumMath.lerp(
694
+ binaryTreeFactor,
695
+ keyframeFactor,
696
+ 0.15 + 0.85 * keyframeFactor
697
+ );
698
+ }
699
+
678
700
  /**
679
701
  * @function
680
702
  *
@@ -58,8 +58,17 @@ function buildVoxelDrawCommands(primitive, context) {
58
58
  // Compile shaders
59
59
  const shaderBuilderPick = shaderBuilder.clone();
60
60
  shaderBuilderPick.addDefine("PICKING", undefined, ShaderDestination.FRAGMENT);
61
+ const shaderBuilderPickVoxel = shaderBuilder.clone();
62
+ shaderBuilderPickVoxel.addDefine(
63
+ "PICKING_VOXEL",
64
+ undefined,
65
+ ShaderDestination.FRAGMENT
66
+ );
61
67
  const shaderProgram = shaderBuilder.buildShaderProgram(context);
62
68
  const shaderProgramPick = shaderBuilderPick.buildShaderProgram(context);
69
+ const shaderProgramPickVoxel = shaderBuilderPickVoxel.buildShaderProgram(
70
+ context
71
+ );
63
72
  const renderState = RenderState.fromCache({
64
73
  cull: {
65
74
  enabled: true,
@@ -98,6 +107,14 @@ function buildVoxelDrawCommands(primitive, context) {
98
107
  drawCommandPick.shaderProgram = shaderProgramPick;
99
108
  drawCommandPick.pickOnly = true;
100
109
 
110
+ // Create the pick voxels draw command
111
+ const drawCommandPickVoxel = DrawCommand.shallowClone(
112
+ drawCommand,
113
+ new DrawCommand()
114
+ );
115
+ drawCommandPickVoxel.shaderProgram = shaderProgramPickVoxel;
116
+ drawCommandPickVoxel.pickOnly = true;
117
+
101
118
  // Delete the old shader programs
102
119
  if (defined(primitive._drawCommand)) {
103
120
  const command = primitive._drawCommand;
@@ -109,9 +126,15 @@ function buildVoxelDrawCommands(primitive, context) {
109
126
  command.shaderProgram =
110
127
  command.shaderProgram && command.shaderProgram.destroy();
111
128
  }
129
+ if (defined(primitive._drawCommandPickVoxel)) {
130
+ const command = primitive._drawCommandPickVoxel;
131
+ command.shaderProgram =
132
+ command.shaderProgram && command.shaderProgram.destroy();
133
+ }
112
134
 
113
135
  primitive._drawCommand = drawCommand;
114
136
  primitive._drawCommandPick = drawCommandPick;
137
+ primitive._drawCommandPickVoxel = drawCommandPickVoxel;
115
138
  }
116
139
 
117
140
  export default buildVoxelDrawCommands;
@@ -46,6 +46,7 @@ async function createGooglePhotorealistic3DTileset(key, options) {
46
46
  options.maximumCacheOverflowBytes,
47
47
  1024 * 1024 * 1024
48
48
  );
49
+ options.enableCollision = defaultValue(options.enableCollision, true);
49
50
 
50
51
  key = defaultValue(key, GoogleMaps.defaultApiKey);
51
52
  if (!defined(key)) {
@@ -153,6 +153,8 @@ function processVoxelProperties(renderResources, primitive) {
153
153
  shaderBuilder.addStructField(voxelStructId, "vec3", "viewDirWorld");
154
154
  shaderBuilder.addStructField(voxelStructId, "vec3", "surfaceNormal");
155
155
  shaderBuilder.addStructField(voxelStructId, "float", "travelDistance");
156
+ shaderBuilder.addStructField(voxelStructId, "int", "tileIndex");
157
+ shaderBuilder.addStructField(voxelStructId, "int", "sampleIndex");
156
158
 
157
159
  // FragmentInput struct
158
160
  const fragmentInputStructId = "FragmentInput";
@@ -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
+ }
@@ -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
+ }