@cesium/engine 9.1.0 → 10.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 (255) hide show
  1. package/Build/ThirdParty/Workers/pako_deflate.min.js +108 -210
  2. package/Build/ThirdParty/Workers/pako_inflate.min.js +466 -568
  3. package/Build/ThirdParty/Workers/z-worker-pako.js +54 -104
  4. package/Build/Workers/{chunk-TMMOULW3.js → chunk-2J3JKXCP.js} +5 -5
  5. package/Build/Workers/{chunk-ZDP32RQI.js → chunk-3WUV74WM.js} +95 -155
  6. package/Build/Workers/{chunk-FOZQIHZK.js → chunk-4BAE4PWO.js} +6 -6
  7. package/Build/Workers/{chunk-CYAJYEKW.js → chunk-4MSUJ4I7.js} +8 -8
  8. package/Build/Workers/{chunk-KPY4F4BW.js → chunk-4YSNMHZ4.js} +6 -6
  9. package/Build/Workers/{chunk-66E3H2KU.js → chunk-5S7OLEPK.js} +12 -12
  10. package/Build/Workers/{chunk-4AJGCQFX.js → chunk-7XGC6YB2.js} +14 -14
  11. package/Build/Workers/{chunk-BDUJXBVF.js → chunk-AA4GZKOT.js} +3 -5
  12. package/Build/Workers/{chunk-7LPEGKOF.js → chunk-AD5HBJ2F.js} +11 -8
  13. package/Build/Workers/{chunk-XHLDDE65.js → chunk-AVI4IUWC.js} +11 -11
  14. package/Build/Workers/{chunk-MWYZ64MH.js → chunk-BCL4PHHT.js} +10 -10
  15. package/Build/Workers/{chunk-PWF3YJJ5.js → chunk-BDFNKFOE.js} +13 -13
  16. package/Build/Workers/{chunk-7VZNXIKG.js → chunk-BJF5LOWE.js} +7 -7
  17. package/Build/Workers/{chunk-3S2MFY4B.js → chunk-C2CGMAIU.js} +13 -13
  18. package/Build/Workers/{chunk-UAJEGIWA.js → chunk-COYFZ5VA.js} +6 -6
  19. package/Build/Workers/{chunk-ZWPIM77Q.js → chunk-DGS5QNIO.js} +13 -13
  20. package/Build/Workers/{chunk-V7JB576Q.js → chunk-DKVHRNFY.js} +5 -5
  21. package/Build/Workers/{chunk-NI2R52QD.js → chunk-DOXCPOG4.js} +11 -9
  22. package/Build/Workers/{chunk-XWML5Y7N.js → chunk-FXIHSF7O.js} +9 -9
  23. package/Build/Workers/{chunk-LW7WGHEU.js → chunk-G3YR53LY.js} +13 -13
  24. package/Build/Workers/{chunk-34DGOKCO.js → chunk-GR3CDLCP.js} +7 -7
  25. package/Build/Workers/{chunk-AOIKO5Y7.js → chunk-GRAT5GE7.js} +5 -5
  26. package/Build/Workers/{chunk-AOFMPKUB.js → chunk-I2RC4XVN.js} +4 -4
  27. package/Build/Workers/{chunk-PK7TEP3J.js → chunk-JYAHOGGL.js} +15 -15
  28. package/Build/Workers/{chunk-4KIUON73.js → chunk-KUN2ZA5X.js} +4 -4
  29. package/Build/Workers/{chunk-POLFRINT.js → chunk-L6RTJ3RE.js} +14 -14
  30. package/Build/Workers/{chunk-LVJCR7DH.js → chunk-LCLJJ2MZ.js} +18 -18
  31. package/Build/Workers/{chunk-3RZK5NNV.js → chunk-LEABCTLP.js} +4 -4
  32. package/Build/Workers/{chunk-QKF7XXEQ.js → chunk-MDHQR3ZS.js} +10 -8
  33. package/Build/Workers/{chunk-4PHPQRSH.js → chunk-MSKXMXJI.js} +5 -6
  34. package/Build/Workers/{chunk-GIFJ77E4.js → chunk-NTXTUNEF.js} +4 -4
  35. package/Build/Workers/{chunk-I5TDPPC4.js → chunk-O3JCMSS3.js} +17 -17
  36. package/Build/Workers/{chunk-PEABJLCK.js → chunk-OOK53QUQ.js} +1 -1
  37. package/Build/Workers/{chunk-PS6AEMBR.js → chunk-OORVMGDU.js} +7 -7
  38. package/Build/Workers/{chunk-JI2445T5.js → chunk-PCP4YQST.js} +11 -11
  39. package/Build/Workers/{chunk-C5CE4OG6.js → chunk-PYHLO636.js} +42 -13
  40. package/Build/Workers/{chunk-S4XDCPKD.js → chunk-Q55ECN3Y.js} +1 -1
  41. package/Build/Workers/{chunk-WWP3I7R5.js → chunk-QD4KM3GO.js} +5 -5
  42. package/Build/Workers/{chunk-YLZTCEBJ.js → chunk-QMLTCCYG.js} +1 -1
  43. package/Build/Workers/{chunk-IBXGK4WV.js → chunk-QX5XS4LC.js} +2 -2
  44. package/Build/Workers/{chunk-RL73GOEF.js → chunk-R6B7UCQB.js} +2 -2
  45. package/Build/Workers/{chunk-RR7EOKGZ.js → chunk-RJYML24O.js} +48 -85
  46. package/Build/Workers/{chunk-U4IMCOF5.js → chunk-S3PI2KFM.js} +2 -2
  47. package/Build/Workers/{chunk-6HCAQOVK.js → chunk-STBBMQGG.js} +6 -6
  48. package/Build/Workers/{chunk-CE6GTZ4I.js → chunk-SYCPRK3D.js} +10 -10
  49. package/Build/Workers/{chunk-WFICTTOE.js → chunk-T77JILCU.js} +2 -2
  50. package/Build/Workers/{chunk-ZC4AGBZK.js → chunk-TO2PVHKI.js} +2 -2
  51. package/Build/Workers/{chunk-UCPPWV64.js → chunk-VE7BFUIX.js} +1 -1
  52. package/Build/Workers/{chunk-2CSEEWHN.js → chunk-VFBNELXB.js} +7 -7
  53. package/Build/Workers/{chunk-A6NCZSL3.js → chunk-VO3ACQB2.js} +19 -19
  54. package/Build/Workers/{chunk-WEGCQ5DY.js → chunk-X23FRWHJ.js} +6 -6
  55. package/Build/Workers/{chunk-G7CJQKKD.js → chunk-XD445VDH.js} +7 -7
  56. package/Build/Workers/combineGeometry.js +22 -22
  57. package/Build/Workers/createBoxGeometry.js +16 -16
  58. package/Build/Workers/createBoxOutlineGeometry.js +14 -14
  59. package/Build/Workers/createCircleGeometry.js +29 -25
  60. package/Build/Workers/createCircleOutlineGeometry.js +17 -17
  61. package/Build/Workers/createCoplanarPolygonGeometry.js +32 -32
  62. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +29 -29
  63. package/Build/Workers/createCorridorGeometry.js +29 -29
  64. package/Build/Workers/createCorridorOutlineGeometry.js +27 -27
  65. package/Build/Workers/createCylinderGeometry.js +18 -18
  66. package/Build/Workers/createCylinderOutlineGeometry.js +16 -16
  67. package/Build/Workers/createEllipseGeometry.js +24 -24
  68. package/Build/Workers/createEllipseOutlineGeometry.js +17 -17
  69. package/Build/Workers/createEllipsoidGeometry.js +17 -17
  70. package/Build/Workers/createEllipsoidOutlineGeometry.js +16 -16
  71. package/Build/Workers/createFrustumGeometry.js +16 -16
  72. package/Build/Workers/createFrustumOutlineGeometry.js +16 -16
  73. package/Build/Workers/createGeometry.js +22 -22
  74. package/Build/Workers/createGroundPolylineGeometry.js +24 -24
  75. package/Build/Workers/createPlaneGeometry.js +14 -14
  76. package/Build/Workers/createPlaneOutlineGeometry.js +13 -13
  77. package/Build/Workers/createPolygonGeometry.js +32 -32
  78. package/Build/Workers/createPolygonOutlineGeometry.js +29 -29
  79. package/Build/Workers/createPolylineGeometry.js +24 -24
  80. package/Build/Workers/createPolylineVolumeGeometry.js +30 -30
  81. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +26 -26
  82. package/Build/Workers/createRectangleGeometry.js +27 -27
  83. package/Build/Workers/createRectangleOutlineGeometry.js +19 -19
  84. package/Build/Workers/createSimplePolylineGeometry.js +22 -22
  85. package/Build/Workers/createSphereGeometry.js +17 -17
  86. package/Build/Workers/createSphereOutlineGeometry.js +16 -16
  87. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  88. package/Build/Workers/createVectorTileClampedPolylines.js +13 -13
  89. package/Build/Workers/createVectorTileGeometries.js +22 -22
  90. package/Build/Workers/createVectorTilePoints.js +12 -12
  91. package/Build/Workers/createVectorTilePolygons.js +20 -20
  92. package/Build/Workers/createVectorTilePolylines.js +13 -13
  93. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +20 -20
  94. package/Build/Workers/createVerticesFromHeightmap.js +21 -21
  95. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +17 -17
  96. package/Build/Workers/createWallGeometry.js +23 -23
  97. package/Build/Workers/createWallOutlineGeometry.js +22 -22
  98. package/Build/Workers/decodeDraco.js +11 -11
  99. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +12 -19
  100. package/Build/Workers/decodeI3S.js +10 -10
  101. package/Build/Workers/transcodeKTX2.js +43 -79
  102. package/Build/Workers/transferTypedArrayTest.js +1 -1
  103. package/Build/Workers/upsampleQuantizedTerrainMesh.js +20 -20
  104. package/Source/Core/ApproximateTerrainHeights.js +4 -4
  105. package/Source/Core/ArcGISTiledElevationTerrainProvider.js +12 -8
  106. package/Source/Core/BoundingRectangle.js +2 -0
  107. package/Source/Core/BoundingSphere.js +4 -2
  108. package/Source/Core/Cartesian3.js +13 -10
  109. package/Source/Core/Cartographic.js +11 -8
  110. package/Source/Core/CesiumTerrainProvider.js +3 -2
  111. package/Source/Core/CircleGeometry.js +6 -2
  112. package/Source/Core/CircleOutlineGeometry.js +1 -1
  113. package/Source/Core/CoplanarPolygonGeometry.js +3 -3
  114. package/Source/Core/CorridorGeometry.js +4 -4
  115. package/Source/Core/CorridorOutlineGeometry.js +2 -2
  116. package/Source/Core/Credit.js +3 -2
  117. package/Source/Core/CustomHeightmapTerrainProvider.js +17 -3
  118. package/Source/Core/EllipseGeometry.js +4 -4
  119. package/Source/Core/EllipseOutlineGeometry.js +2 -2
  120. package/Source/Core/Ellipsoid.js +34 -0
  121. package/Source/Core/EllipsoidGeodesic.js +2 -2
  122. package/Source/Core/EllipsoidRhumbLine.js +4 -4
  123. package/Source/Core/EllipsoidTangentPlane.js +3 -3
  124. package/Source/Core/EllipsoidTerrainProvider.js +3 -3
  125. package/Source/Core/GeographicProjection.js +4 -3
  126. package/Source/Core/GeographicTilingScheme.js +3 -3
  127. package/Source/Core/GeometryPipeline.js +2 -2
  128. package/Source/Core/GoogleEarthEnterpriseTerrainProvider.js +1 -1
  129. package/Source/Core/GoogleMaps.js +1 -1
  130. package/Source/Core/GroundPolylineGeometry.js +1 -1
  131. package/Source/Core/HeightmapTessellator.js +2 -2
  132. package/Source/Core/Ion.js +1 -1
  133. package/Source/Core/Math.js +0 -5
  134. package/Source/Core/Occluder.js +3 -3
  135. package/Source/Core/OrientedBoundingBox.js +2 -2
  136. package/Source/Core/PolygonGeometry.js +4 -4
  137. package/Source/Core/PolygonGeometryLibrary.js +1 -1
  138. package/Source/Core/PolygonOutlineGeometry.js +3 -3
  139. package/Source/Core/PolygonPipeline.js +2 -2
  140. package/Source/Core/PolylineGeometry.js +2 -2
  141. package/Source/Core/PolylinePipeline.js +6 -6
  142. package/Source/Core/PolylineVolumeGeometry.js +2 -2
  143. package/Source/Core/PolylineVolumeOutlineGeometry.js +2 -2
  144. package/Source/Core/Rectangle.js +6 -6
  145. package/Source/Core/RectangleGeometry.js +6 -6
  146. package/Source/Core/RectangleGeometryLibrary.js +3 -0
  147. package/Source/Core/RectangleOutlineGeometry.js +2 -2
  148. package/Source/Core/Simon1994PlanetaryPositions.js +3 -2
  149. package/Source/Core/SimplePolylineGeometry.js +2 -2
  150. package/Source/Core/Stereographic.js +2 -2
  151. package/Source/Core/TaskProcessor.js +19 -3
  152. package/Source/Core/Transforms.js +17 -17
  153. package/Source/Core/VRTheWorldTerrainProvider.js +2 -2
  154. package/Source/Core/WallGeometry.js +3 -3
  155. package/Source/Core/WallOutlineGeometry.js +3 -3
  156. package/Source/Core/WebMercatorTilingScheme.js +3 -3
  157. package/Source/Core/createWorldTerrainAsync.js +2 -0
  158. package/Source/Core/sampleTerrain.js +3 -3
  159. package/Source/DataSources/BoxGeometryUpdater.js +2 -2
  160. package/Source/DataSources/CylinderGeometryUpdater.js +2 -2
  161. package/Source/DataSources/CzmlDataSource.js +8 -8
  162. package/Source/DataSources/EllipsoidGeometryUpdater.js +3 -3
  163. package/Source/DataSources/EntityCluster.js +1 -1
  164. package/Source/DataSources/EntityView.js +2 -2
  165. package/Source/DataSources/KmlDataSource.js +4 -4
  166. package/Source/DataSources/ModelVisualizer.js +1 -2
  167. package/Source/DataSources/PolygonGeometryUpdater.js +1 -1
  168. package/Source/DataSources/PolylineGeometryUpdater.js +3 -2
  169. package/Source/DataSources/RectangleGeometryUpdater.js +1 -1
  170. package/Source/DataSources/ScaledPositionProperty.js +2 -2
  171. package/Source/DataSources/TerrainOffsetProperty.js +3 -7
  172. package/Source/DataSources/VelocityOrientationProperty.js +2 -2
  173. package/Source/DataSources/exportKml.js +2 -2
  174. package/Source/Renderer/UniformState.js +1 -1
  175. package/Source/Scene/ArcGisMapServerImageryProvider.js +2 -2
  176. package/Source/Scene/ArcGisMapService.js +1 -1
  177. package/Source/Scene/Billboard.js +8 -6
  178. package/Source/Scene/BingMapsImageryProvider.js +1 -1
  179. package/Source/Scene/Camera.js +16 -10
  180. package/Source/Scene/Cesium3DTileset.js +1 -1
  181. package/Source/Scene/ClippingPolygon.js +2 -2
  182. package/Source/Scene/ClippingPolygonCollection.js +1 -1
  183. package/Source/Scene/CreditDisplay.js +94 -104
  184. package/Source/Scene/Globe.js +16 -13
  185. package/Source/Scene/GltfLoader.js +458 -435
  186. package/Source/Scene/GltfLoaderUtil.js +5 -16
  187. package/Source/Scene/GltfPipeline/forEachTextureInMaterial.js +23 -7
  188. package/Source/Scene/GltfStructuralMetadataLoader.js +11 -9
  189. package/Source/Scene/GoogleEarthEnterpriseImageryProvider.js +1 -1
  190. package/Source/Scene/GoogleEarthEnterpriseMapsProvider.js +1 -1
  191. package/Source/Scene/GridImageryProvider.js +2 -2
  192. package/Source/Scene/ImageryLayerCollection.js +2 -2
  193. package/Source/Scene/Label.js +1 -1
  194. package/Source/Scene/MapboxImageryProvider.js +1 -1
  195. package/Source/Scene/MapboxStyleImageryProvider.js +1 -1
  196. package/Source/Scene/MetadataSemantic.js +4 -4
  197. package/Source/Scene/Model/AlphaPipelineStage.js +1 -1
  198. package/Source/Scene/Model/GeometryPipelineStage.js +15 -43
  199. package/Source/Scene/Model/ImageBasedLightingPipelineStage.js +7 -0
  200. package/Source/Scene/Model/InstancingPipelineStage.js +3 -3
  201. package/Source/Scene/Model/LightingPipelineStage.js +2 -4
  202. package/Source/Scene/Model/MaterialPipelineStage.js +395 -29
  203. package/Source/Scene/Model/Model.js +15 -7
  204. package/Source/Scene/Model/ModelSceneGraph.js +1 -1
  205. package/Source/Scene/Model/ModelUtility.js +3 -0
  206. package/Source/Scene/Model/SceneMode2DPipelineStage.js +3 -3
  207. package/Source/Scene/Model/VerticalExaggerationPipelineStage.js +4 -6
  208. package/Source/Scene/Model/pickModel.js +2 -2
  209. package/Source/Scene/ModelComponents.js +178 -1
  210. package/Source/Scene/PickDepth.js +23 -15
  211. package/Source/Scene/Picking.js +4 -13
  212. package/Source/Scene/PointPrimitive.js +5 -2
  213. package/Source/Scene/ResourceCache.js +41 -50
  214. package/Source/Scene/ResourceCacheKey.js +41 -53
  215. package/Source/Scene/Scene.js +39 -31
  216. package/Source/Scene/SceneTransforms.js +78 -20
  217. package/Source/Scene/SceneTransitioner.js +2 -2
  218. package/Source/Scene/ScreenSpaceCameraController.js +29 -19
  219. package/Source/Scene/SkyBox.js +26 -0
  220. package/Source/Scene/Sun.js +1 -1
  221. package/Source/Shaders/Builtin/CzmBuiltins.js +4 -10
  222. package/Source/Shaders/Builtin/Functions/ellipsoidTextureCoordinates.glsl +10 -0
  223. package/Source/Shaders/Builtin/Functions/{ellipsoidWgs84TextureCoordinates.js → ellipsoidTextureCoordinates.js} +3 -3
  224. package/Source/Shaders/Builtin/Functions/maximumComponent.glsl +21 -0
  225. package/Source/Shaders/Builtin/Functions/maximumComponent.js +23 -0
  226. package/Source/Shaders/Builtin/Functions/pbrLighting.glsl +108 -44
  227. package/Source/Shaders/Builtin/Functions/pbrLighting.js +108 -44
  228. package/Source/Shaders/Builtin/Structs/materialInput.glsl +1 -1
  229. package/Source/Shaders/Builtin/Structs/materialInput.js +1 -1
  230. package/Source/Shaders/Builtin/Structs/modelMaterial.glsl +16 -0
  231. package/Source/Shaders/Builtin/Structs/modelMaterial.js +16 -0
  232. package/Source/Shaders/EllipsoidFS.glsl +1 -1
  233. package/Source/Shaders/EllipsoidFS.js +1 -1
  234. package/Source/Shaders/GlobeFS.glsl +3 -3
  235. package/Source/Shaders/GlobeFS.js +3 -3
  236. package/Source/Shaders/Model/ImageBasedLightingStageFS.glsl +211 -133
  237. package/Source/Shaders/Model/ImageBasedLightingStageFS.js +212 -133
  238. package/Source/Shaders/Model/LightingStageFS.glsl +113 -48
  239. package/Source/Shaders/Model/LightingStageFS.js +113 -48
  240. package/Source/Shaders/Model/MaterialStageFS.glsl +407 -136
  241. package/Source/Shaders/Model/MaterialStageFS.js +407 -136
  242. package/Source/Widget/CesiumWidget.css +0 -5
  243. package/Source/Widget/CesiumWidget.js +29 -28
  244. package/index.d.ts +184 -116
  245. package/index.js +92 -95
  246. package/package.json +2 -2
  247. package/Source/Shaders/Builtin/Functions/defaultPbrMaterial.glsl +0 -16
  248. package/Source/Shaders/Builtin/Functions/defaultPbrMaterial.js +0 -18
  249. package/Source/Shaders/Builtin/Functions/ellipsoidWgs84TextureCoordinates.glsl +0 -10
  250. package/Source/Shaders/Builtin/Functions/pbrMetallicRoughnessMaterial.glsl +0 -37
  251. package/Source/Shaders/Builtin/Functions/pbrMetallicRoughnessMaterial.js +0 -39
  252. package/Source/Shaders/Builtin/Functions/pbrSpecularGlossinessMaterial.glsl +0 -30
  253. package/Source/Shaders/Builtin/Functions/pbrSpecularGlossinessMaterial.js +0 -32
  254. package/Source/Shaders/Builtin/Structs/pbrParameters.glsl +0 -16
  255. package/Source/Shaders/Builtin/Structs/pbrParameters.js +0 -18
@@ -1,165 +1,243 @@
1
- vec3 proceduralIBL(
2
- vec3 positionEC,
3
- vec3 normalEC,
4
- vec3 lightDirectionEC,
5
- vec3 lightColorHdr,
6
- czm_pbrParameters pbrParameters
7
- ) {
8
- vec3 v = -positionEC;
9
- vec3 positionWC = vec3(czm_inverseView * vec4(positionEC, 1.0));
10
- vec3 vWC = -normalize(positionWC);
11
- vec3 l = normalize(lightDirectionEC);
12
- vec3 n = normalEC;
13
- vec3 r = normalize(czm_inverseViewRotation * normalize(reflect(v, n)));
1
+ /**
2
+ * Compute some metrics for a procedural sky lighting model
3
+ *
4
+ * @param {vec3} positionWC The position of the fragment in world coordinates.
5
+ * @param {vec3} reflectionWC A unit vector in the direction of the reflection, in world coordinates.
6
+ * @return {vec3} The dot products of the horizon and reflection directions with the nadir, and an atmosphere boundary distance.
7
+ */
8
+ vec3 getProceduralSkyMetrics(vec3 positionWC, vec3 reflectionWC)
9
+ {
10
+ // Figure out if the reflection vector hits the ellipsoid
11
+ float horizonDotNadir = 1.0 - min(1.0, czm_ellipsoidRadii.x / length(positionWC));
12
+ float reflectionDotNadir = dot(reflectionWC, normalize(positionWC));
13
+ float atmosphereHeight = 0.05;
14
+ float smoothstepHeight = smoothstep(0.0, atmosphereHeight, horizonDotNadir);
15
+ return vec3(horizonDotNadir, reflectionDotNadir, smoothstepHeight);
16
+ }
14
17
 
15
- float NdotL = clamp(dot(n, l), 0.001, 1.0);
16
- float NdotV = abs(dot(n, v)) + 0.001;
18
+ /**
19
+ * Compute the diffuse irradiance for a procedural sky lighting model
20
+ *
21
+ * @param {vec3} skyMetrics The dot products of the horizon and reflection directions with the nadir, and an atmosphere boundary distance.
22
+ * @return {vec3} The computed diffuse irradiance
23
+ */
24
+ vec3 getProceduralDiffuseIrradiance(vec3 skyMetrics)
25
+ {
26
+ vec3 blueSkyDiffuseColor = vec3(0.7, 0.85, 0.9);
27
+ float diffuseIrradianceFromEarth = (1.0 - skyMetrics.x) * (skyMetrics.y * 0.25 + 0.75) * skyMetrics.z;
28
+ float diffuseIrradianceFromSky = (1.0 - skyMetrics.z) * (1.0 - (skyMetrics.y * 0.25 + 0.25));
29
+ return blueSkyDiffuseColor * clamp(diffuseIrradianceFromEarth + diffuseIrradianceFromSky, 0.0, 1.0);
30
+ }
17
31
 
18
- // Figure out if the reflection vector hits the ellipsoid
19
- float vertexRadius = length(positionWC);
20
- float horizonDotNadir = 1.0 - min(1.0, czm_ellipsoidRadii.x / vertexRadius);
21
- float reflectionDotNadir = dot(r, normalize(positionWC));
32
+ /**
33
+ * Compute the specular irradiance for a procedural sky lighting model
34
+ *
35
+ * @param {vec3} skyMetrics The dot products of the horizon and reflection directions with the nadir, and an atmosphere boundary distance.
36
+ * @return {vec3} The computed specular irradiance
37
+ */
38
+ vec3 getProceduralSpecularIrradiance(vec3 reflectionWC, vec3 skyMetrics, float roughness)
39
+ {
22
40
  // Flipping the X vector is a cheap way to get the inverse of czm_temeToPseudoFixed, since that's a rotation about Z.
23
- r.x = -r.x;
24
- r = -normalize(czm_temeToPseudoFixed * r);
25
- r.x = -r.x;
26
-
27
- vec3 diffuseColor = pbrParameters.diffuseColor;
28
- float roughness = pbrParameters.roughness;
29
- vec3 specularColor = pbrParameters.f0;
41
+ reflectionWC.x = -reflectionWC.x;
42
+ reflectionWC = -normalize(czm_temeToPseudoFixed * reflectionWC);
43
+ reflectionWC.x = -reflectionWC.x;
30
44
 
31
45
  float inverseRoughness = 1.04 - roughness;
32
46
  inverseRoughness *= inverseRoughness;
33
- vec3 sceneSkyBox = czm_textureCube(czm_environmentMap, r).rgb * inverseRoughness;
47
+ vec3 sceneSkyBox = czm_textureCube(czm_environmentMap, reflectionWC).rgb * inverseRoughness;
34
48
 
35
- float atmosphereHeight = 0.05;
36
- float blendRegionSize = 0.1 * ((1.0 - inverseRoughness) * 8.0 + 1.1 - horizonDotNadir);
37
- float blendRegionOffset = roughness * -1.0;
38
- float farAboveHorizon = clamp(horizonDotNadir - blendRegionSize * 0.5 + blendRegionOffset, 1.0e-10 - blendRegionSize, 0.99999);
39
- float aroundHorizon = clamp(horizonDotNadir + blendRegionSize * 0.5, 1.0e-10 - blendRegionSize, 0.99999);
40
- float farBelowHorizon = clamp(horizonDotNadir + blendRegionSize * 1.5, 1.0e-10 - blendRegionSize, 0.99999);
41
- float smoothstepHeight = smoothstep(0.0, atmosphereHeight, horizonDotNadir);
42
- vec3 belowHorizonColor = mix(vec3(0.1, 0.15, 0.25), vec3(0.4, 0.7, 0.9), smoothstepHeight);
49
+ // Compute colors at different angles relative to the horizon
50
+ vec3 belowHorizonColor = mix(vec3(0.1, 0.15, 0.25), vec3(0.4, 0.7, 0.9), skyMetrics.z);
43
51
  vec3 nadirColor = belowHorizonColor * 0.5;
44
52
  vec3 aboveHorizonColor = mix(vec3(0.9, 1.0, 1.2), belowHorizonColor, roughness * 0.5);
45
- vec3 blueSkyColor = mix(vec3(0.18, 0.26, 0.48), aboveHorizonColor, reflectionDotNadir * inverseRoughness * 0.5 + 0.75);
46
- vec3 zenithColor = mix(blueSkyColor, sceneSkyBox, smoothstepHeight);
47
- vec3 blueSkyDiffuseColor = vec3(0.7, 0.85, 0.9);
48
- float diffuseIrradianceFromEarth = (1.0 - horizonDotNadir) * (reflectionDotNadir * 0.25 + 0.75) * smoothstepHeight;
49
- float diffuseIrradianceFromSky = (1.0 - smoothstepHeight) * (1.0 - (reflectionDotNadir * 0.25 + 0.25));
50
- vec3 diffuseIrradiance = blueSkyDiffuseColor * clamp(diffuseIrradianceFromEarth + diffuseIrradianceFromSky, 0.0, 1.0);
51
- float notDistantRough = (1.0 - horizonDotNadir * roughness * 0.8);
52
- vec3 specularIrradiance = mix(zenithColor, aboveHorizonColor, smoothstep(farAboveHorizon, aroundHorizon, reflectionDotNadir) * notDistantRough);
53
- specularIrradiance = mix(specularIrradiance, belowHorizonColor, smoothstep(aroundHorizon, farBelowHorizon, reflectionDotNadir) * inverseRoughness);
54
- specularIrradiance = mix(specularIrradiance, nadirColor, smoothstep(farBelowHorizon, 1.0, reflectionDotNadir) * inverseRoughness);
55
-
56
- // Luminance model from page 40 of http://silviojemma.com/public/papers/lighting/spherical-harmonic-lighting.pdf
57
- #ifdef USE_SUN_LUMINANCE
58
- // Angle between sun and zenith
59
- float LdotZenith = clamp(dot(normalize(czm_inverseViewRotation * l), vWC), 0.001, 1.0);
53
+ vec3 blueSkyColor = mix(vec3(0.18, 0.26, 0.48), aboveHorizonColor, skyMetrics.y * inverseRoughness * 0.5 + 0.75);
54
+ vec3 zenithColor = mix(blueSkyColor, sceneSkyBox, skyMetrics.z);
55
+
56
+ // Compute blend zones
57
+ float blendRegionSize = 0.1 * ((1.0 - inverseRoughness) * 8.0 + 1.1 - skyMetrics.x);
58
+ float blendRegionOffset = roughness * -1.0;
59
+ float farAboveHorizon = clamp(skyMetrics.x - blendRegionSize * 0.5 + blendRegionOffset, 1.0e-10 - blendRegionSize, 0.99999);
60
+ float aroundHorizon = clamp(skyMetrics.x + blendRegionSize * 0.5, 1.0e-10 - blendRegionSize, 0.99999);
61
+ float farBelowHorizon = clamp(skyMetrics.x + blendRegionSize * 1.5, 1.0e-10 - blendRegionSize, 0.99999);
62
+
63
+ // Blend colors
64
+ float notDistantRough = (1.0 - skyMetrics.x * roughness * 0.8);
65
+ vec3 specularIrradiance = mix(zenithColor, aboveHorizonColor, smoothstep(farAboveHorizon, aroundHorizon, skyMetrics.y) * notDistantRough);
66
+ specularIrradiance = mix(specularIrradiance, belowHorizonColor, smoothstep(aroundHorizon, farBelowHorizon, skyMetrics.y) * inverseRoughness);
67
+ specularIrradiance = mix(specularIrradiance, nadirColor, smoothstep(farBelowHorizon, 1.0, skyMetrics.y) * inverseRoughness);
68
+
69
+ return specularIrradiance;
70
+ }
71
+
72
+ #ifdef USE_SUN_LUMINANCE
73
+ float clampedDot(vec3 x, vec3 y)
74
+ {
75
+ return clamp(dot(x, y), 0.001, 1.0);
76
+ }
77
+ /**
78
+ * Sun luminance following the "CIE Clear Sky Model"
79
+ * See page 40 of https://3dvar.com/Green2003Spherical.pdf
80
+ *
81
+ * @param {vec3} positionWC The position of the fragment in world coordinates.
82
+ * @param {vec3} normalEC The surface normal in eye coordinates.
83
+ * @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates.
84
+ * @return {float} The computed sun luminance.
85
+ */
86
+ float getSunLuminance(vec3 positionWC, vec3 normalEC, vec3 lightDirectionEC)
87
+ {
88
+ vec3 normalWC = normalize(czm_inverseViewRotation * normalEC);
89
+ vec3 lightDirectionWC = normalize(czm_inverseViewRotation * lightDirectionEC);
90
+ vec3 vWC = -normalize(positionWC);
91
+
92
+ // Angle between sun and zenith.
93
+ float LdotZenith = clampedDot(lightDirectionWC, vWC);
60
94
  float S = acos(LdotZenith);
61
95
  // Angle between zenith and current pixel
62
- float NdotZenith = clamp(dot(normalize(czm_inverseViewRotation * n), vWC), 0.001, 1.0);
96
+ float NdotZenith = clampedDot(normalWC, vWC);
63
97
  // Angle between sun and current pixel
98
+ float NdotL = clampedDot(normalEC, lightDirectionEC);
64
99
  float gamma = acos(NdotL);
65
- float numerator = ((0.91 + 10.0 * exp(-3.0 * gamma) + 0.45 * pow(NdotL, 2.0)) * (1.0 - exp(-0.32 / NdotZenith)));
66
- float denominator = (0.91 + 10.0 * exp(-3.0 * S) + 0.45 * pow(LdotZenith,2.0)) * (1.0 - exp(-0.32));
67
- float luminance = model_luminanceAtZenith * (numerator / denominator);
68
- #endif
69
100
 
101
+ float numerator = ((0.91 + 10.0 * exp(-3.0 * gamma) + 0.45 * NdotL * NdotL) * (1.0 - exp(-0.32 / NdotZenith)));
102
+ float denominator = (0.91 + 10.0 * exp(-3.0 * S) + 0.45 * LdotZenith * LdotZenith) * (1.0 - exp(-0.32));
103
+ return model_luminanceAtZenith * (numerator / denominator);
104
+ }
105
+ #endif
106
+
107
+ /**
108
+ * Compute the light contribution from a procedural sky model
109
+ *
110
+ * @param {vec3} positionEC The position of the fragment in eye coordinates.
111
+ * @param {vec3} normalEC The surface normal in eye coordinates.
112
+ * @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates.
113
+ * @param {czm_modelMaterial} The material properties.
114
+ * @return {vec3} The computed HDR color
115
+ */
116
+ vec3 proceduralIBL(
117
+ vec3 positionEC,
118
+ vec3 normalEC,
119
+ vec3 lightDirectionEC,
120
+ czm_modelMaterial material
121
+ ) {
122
+ vec3 viewDirectionEC = -normalize(positionEC);
123
+ vec3 positionWC = vec3(czm_inverseView * vec4(positionEC, 1.0));
124
+ vec3 reflectionWC = normalize(czm_inverseViewRotation * normalize(reflect(viewDirectionEC, normalEC)));
125
+ vec3 skyMetrics = getProceduralSkyMetrics(positionWC, reflectionWC);
126
+
127
+ float roughness = material.roughness;
128
+ vec3 f0 = material.specular;
129
+
130
+ vec3 specularIrradiance = getProceduralSpecularIrradiance(reflectionWC, skyMetrics, roughness);
131
+ float NdotV = abs(dot(normalEC, viewDirectionEC)) + 0.001;
70
132
  vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, roughness)).rg;
71
- vec3 iblColor = (diffuseIrradiance * diffuseColor * model_iblFactor.x) + (specularIrradiance * czm_srgbToLinear(specularColor * brdfLut.x + brdfLut.y) * model_iblFactor.y);
72
- float maximumComponent = max(max(lightColorHdr.x, lightColorHdr.y), lightColorHdr.z);
73
- vec3 lightColor = lightColorHdr / max(maximumComponent, 1.0);
74
- iblColor *= lightColor;
133
+ vec3 specularColor = czm_srgbToLinear(f0 * brdfLut.x + brdfLut.y);
134
+ vec3 specularContribution = specularIrradiance * specularColor * model_iblFactor.y;
135
+ #ifdef USE_SPECULAR
136
+ specularContribution *= material.specularWeight;
137
+ #endif
138
+
139
+ vec3 diffuseIrradiance = getProceduralDiffuseIrradiance(skyMetrics);
140
+ vec3 diffuseColor = material.diffuse;
141
+ vec3 diffuseContribution = diffuseIrradiance * diffuseColor * model_iblFactor.x;
75
142
 
76
- #ifdef USE_SUN_LUMINANCE
77
- iblColor *= luminance;
143
+ vec3 iblColor = specularContribution + diffuseContribution;
144
+
145
+ #ifdef USE_SUN_LUMINANCE
146
+ iblColor *= getSunLuminance(positionWC, normalEC, lightDirectionEC);
78
147
  #endif
79
148
 
80
149
  return iblColor;
81
150
  }
82
151
 
152
+ #ifdef DIFFUSE_IBL
153
+ vec3 computeDiffuseIBL(vec3 cubeDir)
154
+ {
155
+ #ifdef CUSTOM_SPHERICAL_HARMONICS
156
+ return czm_sphericalHarmonics(cubeDir, model_sphericalHarmonicCoefficients);
157
+ #else
158
+ return czm_sphericalHarmonics(cubeDir, czm_sphericalHarmonicCoefficients);
159
+ #endif
160
+ }
161
+ #endif
162
+
163
+ #ifdef SPECULAR_IBL
164
+ vec3 sampleSpecularEnvironment(vec3 cubeDir, float roughness)
165
+ {
166
+ #ifdef CUSTOM_SPECULAR_IBL
167
+ float maxLod = model_specularEnvironmentMapsMaximumLOD;
168
+ float lod = roughness * maxLod;
169
+ return czm_sampleOctahedralProjection(model_specularEnvironmentMaps, model_specularEnvironmentMapsSize, cubeDir, lod, maxLod);
170
+ #else
171
+ float maxLod = czm_specularEnvironmentMapsMaximumLOD;
172
+ float lod = roughness * maxLod;
173
+ return czm_sampleOctahedralProjection(czm_specularEnvironmentMaps, czm_specularEnvironmentMapSize, cubeDir, lod, maxLod);
174
+ #endif
175
+ }
176
+ vec3 computeSpecularIBL(vec3 cubeDir, float NdotV, float VdotH, vec3 f0, float roughness)
177
+ {
178
+ float reflectance = czm_maximumComponent(f0);
179
+ vec3 f90 = vec3(clamp(reflectance * 25.0, 0.0, 1.0));
180
+ vec3 F = fresnelSchlick2(f0, f90, VdotH);
181
+
182
+ vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, roughness)).rg;
183
+ vec3 specularSample = sampleSpecularEnvironment(cubeDir, roughness);
184
+
185
+ return specularSample * (F * brdfLut.x + brdfLut.y);
186
+ }
187
+ #endif
188
+
83
189
  #if defined(DIFFUSE_IBL) || defined(SPECULAR_IBL)
190
+ /**
191
+ * Compute the light contributions from environment maps and spherical harmonic coefficients
192
+ *
193
+ * @param {vec3} viewDirectionEC Unit vector pointing from the fragment to the eye position
194
+ * @param {vec3} normalEC The surface normal in eye coordinates
195
+ * @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates.
196
+ * @param {czm_modelMaterial} The material properties.
197
+ * @return {vec3} The computed HDR color
198
+ */
84
199
  vec3 textureIBL(
85
- vec3 positionEC,
200
+ vec3 viewDirectionEC,
86
201
  vec3 normalEC,
87
202
  vec3 lightDirectionEC,
88
- czm_pbrParameters pbrParameters
203
+ czm_modelMaterial material
89
204
  ) {
90
- vec3 diffuseColor = pbrParameters.diffuseColor;
91
- float roughness = pbrParameters.roughness;
92
- vec3 specularColor = pbrParameters.f0;
93
-
94
- vec3 v = -positionEC;
95
- vec3 n = normalEC;
96
- vec3 l = normalize(lightDirectionEC);
97
- vec3 h = normalize(v + l);
98
-
99
- float NdotV = abs(dot(n, v)) + 0.001;
100
- float VdotH = clamp(dot(v, h), 0.0, 1.0);
101
-
102
- const mat3 yUpToZUp = mat3(
103
- -1.0, 0.0, 0.0,
104
- 0.0, 0.0, -1.0,
105
- 0.0, 1.0, 0.0
106
- );
107
- vec3 cubeDir = normalize(yUpToZUp * model_iblReferenceFrameMatrix * normalize(reflect(-v, n)));
108
-
109
- #ifdef DIFFUSE_IBL
110
- #ifdef CUSTOM_SPHERICAL_HARMONICS
111
- vec3 diffuseIrradiance = czm_sphericalHarmonics(cubeDir, model_sphericalHarmonicCoefficients);
112
- #else
113
- vec3 diffuseIrradiance = czm_sphericalHarmonics(cubeDir, czm_sphericalHarmonicCoefficients);
114
- #endif
115
- #else
116
- vec3 diffuseIrradiance = vec3(0.0);
117
- #endif
205
+ // Find the direction in which to sample the environment map
206
+ vec3 cubeDir = normalize(model_iblReferenceFrameMatrix * normalize(reflect(-viewDirectionEC, normalEC)));
207
+
208
+ #ifdef DIFFUSE_IBL
209
+ vec3 diffuseContribution = computeDiffuseIBL(cubeDir) * material.diffuse;
210
+ #else
211
+ vec3 diffuseContribution = vec3(0.0);
212
+ #endif
213
+
214
+ float roughness = material.roughness;
215
+
216
+ #ifdef USE_ANISOTROPY
217
+ // Update environment map sampling direction to account for anisotropic distortion of specular reflection
218
+ vec3 anisotropyDirection = material.anisotropicB;
219
+ vec3 anisotropicTangent = cross(anisotropyDirection, viewDirectionEC);
220
+ vec3 anisotropicNormal = cross(anisotropicTangent, anisotropyDirection);
221
+ float bendFactor = 1.0 - material.anisotropyStrength * (1.0 - roughness);
222
+ float bendFactorPow4 = bendFactor * bendFactor * bendFactor * bendFactor;
223
+ vec3 bentNormal = normalize(mix(anisotropicNormal, normalEC, bendFactorPow4));
224
+ cubeDir = normalize(model_iblReferenceFrameMatrix * normalize(reflect(-viewDirectionEC, bentNormal)));
225
+ #endif
118
226
 
119
227
  #ifdef SPECULAR_IBL
120
- vec3 r0 = specularColor.rgb;
121
- float reflectance = max(max(r0.r, r0.g), r0.b);
122
- vec3 r90 = vec3(clamp(reflectance * 25.0, 0.0, 1.0));
123
- vec3 F = fresnelSchlick2(r0, r90, VdotH);
124
-
125
- vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, roughness)).rg;
126
- #ifdef CUSTOM_SPECULAR_IBL
127
- vec3 specularIBL = czm_sampleOctahedralProjection(model_specularEnvironmentMaps, model_specularEnvironmentMapsSize, cubeDir, roughness * model_specularEnvironmentMapsMaximumLOD, model_specularEnvironmentMapsMaximumLOD);
128
- #else
129
- vec3 specularIBL = czm_sampleOctahedralProjection(czm_specularEnvironmentMaps, czm_specularEnvironmentMapSize, cubeDir, roughness * czm_specularEnvironmentMapsMaximumLOD, czm_specularEnvironmentMapsMaximumLOD);
130
- #endif
131
- specularIBL *= F * brdfLut.x + brdfLut.y;
132
- #else
133
- vec3 specularIBL = vec3(0.0);
228
+ float NdotV = abs(dot(normalEC, viewDirectionEC)) + 0.001;
229
+ vec3 halfwayDirectionEC = normalize(viewDirectionEC + lightDirectionEC);
230
+ float VdotH = clamp(dot(viewDirectionEC, halfwayDirectionEC), 0.0, 1.0);
231
+ vec3 f0 = material.specular;
232
+ vec3 specularContribution = computeSpecularIBL(cubeDir, NdotV, VdotH, f0, roughness);
233
+ #else
234
+ vec3 specularContribution = vec3(0.0);
235
+ #endif
236
+
237
+ #ifdef USE_SPECULAR
238
+ specularContribution *= material.specularWeight;
134
239
  #endif
135
240
 
136
- return diffuseColor * diffuseIrradiance + specularColor * specularIBL;
241
+ return diffuseContribution + specularContribution;
137
242
  }
138
243
  #endif
139
-
140
- vec3 imageBasedLightingStage(
141
- vec3 positionEC,
142
- vec3 normalEC,
143
- vec3 lightDirectionEC,
144
- vec3 lightColorHdr,
145
- czm_pbrParameters pbrParameters
146
- ) {
147
- #if defined(DIFFUSE_IBL) || defined(SPECULAR_IBL)
148
- // Environment maps were provided, use them for IBL
149
- return textureIBL(
150
- positionEC,
151
- normalEC,
152
- lightDirectionEC,
153
- pbrParameters
154
- );
155
- #else
156
- // Use the procedural IBL if there are no environment maps
157
- return proceduralIBL(
158
- positionEC,
159
- normalEC,
160
- lightDirectionEC,
161
- lightColorHdr,
162
- pbrParameters
163
- );
164
- #endif
165
- }