@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,166 +1,245 @@
1
1
  //This file is automatically rebuilt by the Cesium build process.
2
- export default "vec3 proceduralIBL(\n\
3
- vec3 positionEC,\n\
4
- vec3 normalEC,\n\
5
- vec3 lightDirectionEC,\n\
6
- vec3 lightColorHdr,\n\
7
- czm_pbrParameters pbrParameters\n\
8
- ) {\n\
9
- vec3 v = -positionEC;\n\
10
- vec3 positionWC = vec3(czm_inverseView * vec4(positionEC, 1.0));\n\
11
- vec3 vWC = -normalize(positionWC);\n\
12
- vec3 l = normalize(lightDirectionEC);\n\
13
- vec3 n = normalEC;\n\
14
- vec3 r = normalize(czm_inverseViewRotation * normalize(reflect(v, n)));\n\
2
+ export default "/**\n\
3
+ * Compute some metrics for a procedural sky lighting model\n\
4
+ *\n\
5
+ * @param {vec3} positionWC The position of the fragment in world coordinates.\n\
6
+ * @param {vec3} reflectionWC A unit vector in the direction of the reflection, in world coordinates.\n\
7
+ * @return {vec3} The dot products of the horizon and reflection directions with the nadir, and an atmosphere boundary distance.\n\
8
+ */\n\
9
+ vec3 getProceduralSkyMetrics(vec3 positionWC, vec3 reflectionWC)\n\
10
+ {\n\
11
+ // Figure out if the reflection vector hits the ellipsoid\n\
12
+ float horizonDotNadir = 1.0 - min(1.0, czm_ellipsoidRadii.x / length(positionWC));\n\
13
+ float reflectionDotNadir = dot(reflectionWC, normalize(positionWC));\n\
14
+ float atmosphereHeight = 0.05;\n\
15
+ float smoothstepHeight = smoothstep(0.0, atmosphereHeight, horizonDotNadir);\n\
16
+ return vec3(horizonDotNadir, reflectionDotNadir, smoothstepHeight);\n\
17
+ }\n\
15
18
  \n\
16
- float NdotL = clamp(dot(n, l), 0.001, 1.0);\n\
17
- float NdotV = abs(dot(n, v)) + 0.001;\n\
19
+ /**\n\
20
+ * Compute the diffuse irradiance for a procedural sky lighting model\n\
21
+ *\n\
22
+ * @param {vec3} skyMetrics The dot products of the horizon and reflection directions with the nadir, and an atmosphere boundary distance.\n\
23
+ * @return {vec3} The computed diffuse irradiance\n\
24
+ */\n\
25
+ vec3 getProceduralDiffuseIrradiance(vec3 skyMetrics)\n\
26
+ {\n\
27
+ vec3 blueSkyDiffuseColor = vec3(0.7, 0.85, 0.9); \n\
28
+ float diffuseIrradianceFromEarth = (1.0 - skyMetrics.x) * (skyMetrics.y * 0.25 + 0.75) * skyMetrics.z; \n\
29
+ float diffuseIrradianceFromSky = (1.0 - skyMetrics.z) * (1.0 - (skyMetrics.y * 0.25 + 0.25));\n\
30
+ return blueSkyDiffuseColor * clamp(diffuseIrradianceFromEarth + diffuseIrradianceFromSky, 0.0, 1.0);\n\
31
+ }\n\
18
32
  \n\
19
- // Figure out if the reflection vector hits the ellipsoid\n\
20
- float vertexRadius = length(positionWC);\n\
21
- float horizonDotNadir = 1.0 - min(1.0, czm_ellipsoidRadii.x / vertexRadius);\n\
22
- float reflectionDotNadir = dot(r, normalize(positionWC));\n\
33
+ /**\n\
34
+ * Compute the specular irradiance for a procedural sky lighting model\n\
35
+ *\n\
36
+ * @param {vec3} skyMetrics The dot products of the horizon and reflection directions with the nadir, and an atmosphere boundary distance.\n\
37
+ * @return {vec3} The computed specular irradiance\n\
38
+ */\n\
39
+ vec3 getProceduralSpecularIrradiance(vec3 reflectionWC, vec3 skyMetrics, float roughness)\n\
40
+ {\n\
23
41
  // Flipping the X vector is a cheap way to get the inverse of czm_temeToPseudoFixed, since that's a rotation about Z.\n\
24
- r.x = -r.x;\n\
25
- r = -normalize(czm_temeToPseudoFixed * r);\n\
26
- r.x = -r.x;\n\
27
- \n\
28
- vec3 diffuseColor = pbrParameters.diffuseColor;\n\
29
- float roughness = pbrParameters.roughness;\n\
30
- vec3 specularColor = pbrParameters.f0;\n\
42
+ reflectionWC.x = -reflectionWC.x;\n\
43
+ reflectionWC = -normalize(czm_temeToPseudoFixed * reflectionWC);\n\
44
+ reflectionWC.x = -reflectionWC.x;\n\
31
45
  \n\
32
46
  float inverseRoughness = 1.04 - roughness;\n\
33
47
  inverseRoughness *= inverseRoughness;\n\
34
- vec3 sceneSkyBox = czm_textureCube(czm_environmentMap, r).rgb * inverseRoughness;\n\
48
+ vec3 sceneSkyBox = czm_textureCube(czm_environmentMap, reflectionWC).rgb * inverseRoughness;\n\
35
49
  \n\
36
- float atmosphereHeight = 0.05;\n\
37
- float blendRegionSize = 0.1 * ((1.0 - inverseRoughness) * 8.0 + 1.1 - horizonDotNadir);\n\
38
- float blendRegionOffset = roughness * -1.0;\n\
39
- float farAboveHorizon = clamp(horizonDotNadir - blendRegionSize * 0.5 + blendRegionOffset, 1.0e-10 - blendRegionSize, 0.99999);\n\
40
- float aroundHorizon = clamp(horizonDotNadir + blendRegionSize * 0.5, 1.0e-10 - blendRegionSize, 0.99999);\n\
41
- float farBelowHorizon = clamp(horizonDotNadir + blendRegionSize * 1.5, 1.0e-10 - blendRegionSize, 0.99999);\n\
42
- float smoothstepHeight = smoothstep(0.0, atmosphereHeight, horizonDotNadir);\n\
43
- vec3 belowHorizonColor = mix(vec3(0.1, 0.15, 0.25), vec3(0.4, 0.7, 0.9), smoothstepHeight);\n\
50
+ // Compute colors at different angles relative to the horizon\n\
51
+ vec3 belowHorizonColor = mix(vec3(0.1, 0.15, 0.25), vec3(0.4, 0.7, 0.9), skyMetrics.z);\n\
44
52
  vec3 nadirColor = belowHorizonColor * 0.5;\n\
45
53
  vec3 aboveHorizonColor = mix(vec3(0.9, 1.0, 1.2), belowHorizonColor, roughness * 0.5);\n\
46
- vec3 blueSkyColor = mix(vec3(0.18, 0.26, 0.48), aboveHorizonColor, reflectionDotNadir * inverseRoughness * 0.5 + 0.75);\n\
47
- vec3 zenithColor = mix(blueSkyColor, sceneSkyBox, smoothstepHeight);\n\
48
- vec3 blueSkyDiffuseColor = vec3(0.7, 0.85, 0.9); \n\
49
- float diffuseIrradianceFromEarth = (1.0 - horizonDotNadir) * (reflectionDotNadir * 0.25 + 0.75) * smoothstepHeight; \n\
50
- float diffuseIrradianceFromSky = (1.0 - smoothstepHeight) * (1.0 - (reflectionDotNadir * 0.25 + 0.25));\n\
51
- vec3 diffuseIrradiance = blueSkyDiffuseColor * clamp(diffuseIrradianceFromEarth + diffuseIrradianceFromSky, 0.0, 1.0);\n\
52
- float notDistantRough = (1.0 - horizonDotNadir * roughness * 0.8);\n\
53
- vec3 specularIrradiance = mix(zenithColor, aboveHorizonColor, smoothstep(farAboveHorizon, aroundHorizon, reflectionDotNadir) * notDistantRough);\n\
54
- specularIrradiance = mix(specularIrradiance, belowHorizonColor, smoothstep(aroundHorizon, farBelowHorizon, reflectionDotNadir) * inverseRoughness);\n\
55
- specularIrradiance = mix(specularIrradiance, nadirColor, smoothstep(farBelowHorizon, 1.0, reflectionDotNadir) * inverseRoughness);\n\
56
- \n\
57
- // Luminance model from page 40 of http://silviojemma.com/public/papers/lighting/spherical-harmonic-lighting.pdf\n\
58
- #ifdef USE_SUN_LUMINANCE \n\
59
- // Angle between sun and zenith\n\
60
- float LdotZenith = clamp(dot(normalize(czm_inverseViewRotation * l), vWC), 0.001, 1.0);\n\
54
+ vec3 blueSkyColor = mix(vec3(0.18, 0.26, 0.48), aboveHorizonColor, skyMetrics.y * inverseRoughness * 0.5 + 0.75);\n\
55
+ vec3 zenithColor = mix(blueSkyColor, sceneSkyBox, skyMetrics.z);\n\
56
+ \n\
57
+ // Compute blend zones\n\
58
+ float blendRegionSize = 0.1 * ((1.0 - inverseRoughness) * 8.0 + 1.1 - skyMetrics.x);\n\
59
+ float blendRegionOffset = roughness * -1.0;\n\
60
+ float farAboveHorizon = clamp(skyMetrics.x - blendRegionSize * 0.5 + blendRegionOffset, 1.0e-10 - blendRegionSize, 0.99999);\n\
61
+ float aroundHorizon = clamp(skyMetrics.x + blendRegionSize * 0.5, 1.0e-10 - blendRegionSize, 0.99999);\n\
62
+ float farBelowHorizon = clamp(skyMetrics.x + blendRegionSize * 1.5, 1.0e-10 - blendRegionSize, 0.99999);\n\
63
+ \n\
64
+ // Blend colors\n\
65
+ float notDistantRough = (1.0 - skyMetrics.x * roughness * 0.8);\n\
66
+ vec3 specularIrradiance = mix(zenithColor, aboveHorizonColor, smoothstep(farAboveHorizon, aroundHorizon, skyMetrics.y) * notDistantRough);\n\
67
+ specularIrradiance = mix(specularIrradiance, belowHorizonColor, smoothstep(aroundHorizon, farBelowHorizon, skyMetrics.y) * inverseRoughness);\n\
68
+ specularIrradiance = mix(specularIrradiance, nadirColor, smoothstep(farBelowHorizon, 1.0, skyMetrics.y) * inverseRoughness);\n\
69
+ \n\
70
+ return specularIrradiance;\n\
71
+ }\n\
72
+ \n\
73
+ #ifdef USE_SUN_LUMINANCE\n\
74
+ float clampedDot(vec3 x, vec3 y)\n\
75
+ {\n\
76
+ return clamp(dot(x, y), 0.001, 1.0);\n\
77
+ }\n\
78
+ /**\n\
79
+ * Sun luminance following the \"CIE Clear Sky Model\"\n\
80
+ * See page 40 of https://3dvar.com/Green2003Spherical.pdf\n\
81
+ *\n\
82
+ * @param {vec3} positionWC The position of the fragment in world coordinates.\n\
83
+ * @param {vec3} normalEC The surface normal in eye coordinates.\n\
84
+ * @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates.\n\
85
+ * @return {float} The computed sun luminance.\n\
86
+ */\n\
87
+ float getSunLuminance(vec3 positionWC, vec3 normalEC, vec3 lightDirectionEC)\n\
88
+ {\n\
89
+ vec3 normalWC = normalize(czm_inverseViewRotation * normalEC);\n\
90
+ vec3 lightDirectionWC = normalize(czm_inverseViewRotation * lightDirectionEC);\n\
91
+ vec3 vWC = -normalize(positionWC);\n\
92
+ \n\
93
+ // Angle between sun and zenith.\n\
94
+ float LdotZenith = clampedDot(lightDirectionWC, vWC);\n\
61
95
  float S = acos(LdotZenith);\n\
62
96
  // Angle between zenith and current pixel\n\
63
- float NdotZenith = clamp(dot(normalize(czm_inverseViewRotation * n), vWC), 0.001, 1.0);\n\
97
+ float NdotZenith = clampedDot(normalWC, vWC);\n\
64
98
  // Angle between sun and current pixel\n\
99
+ float NdotL = clampedDot(normalEC, lightDirectionEC);\n\
65
100
  float gamma = acos(NdotL);\n\
66
- float numerator = ((0.91 + 10.0 * exp(-3.0 * gamma) + 0.45 * pow(NdotL, 2.0)) * (1.0 - exp(-0.32 / NdotZenith)));\n\
67
- float denominator = (0.91 + 10.0 * exp(-3.0 * S) + 0.45 * pow(LdotZenith,2.0)) * (1.0 - exp(-0.32));\n\
68
- float luminance = model_luminanceAtZenith * (numerator / denominator);\n\
69
- #endif \n\
70
101
  \n\
102
+ float numerator = ((0.91 + 10.0 * exp(-3.0 * gamma) + 0.45 * NdotL * NdotL) * (1.0 - exp(-0.32 / NdotZenith)));\n\
103
+ float denominator = (0.91 + 10.0 * exp(-3.0 * S) + 0.45 * LdotZenith * LdotZenith) * (1.0 - exp(-0.32));\n\
104
+ return model_luminanceAtZenith * (numerator / denominator);\n\
105
+ }\n\
106
+ #endif\n\
107
+ \n\
108
+ /**\n\
109
+ * Compute the light contribution from a procedural sky model\n\
110
+ *\n\
111
+ * @param {vec3} positionEC The position of the fragment in eye coordinates.\n\
112
+ * @param {vec3} normalEC The surface normal in eye coordinates.\n\
113
+ * @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates.\n\
114
+ * @param {czm_modelMaterial} The material properties.\n\
115
+ * @return {vec3} The computed HDR color\n\
116
+ */\n\
117
+ vec3 proceduralIBL(\n\
118
+ vec3 positionEC,\n\
119
+ vec3 normalEC,\n\
120
+ vec3 lightDirectionEC,\n\
121
+ czm_modelMaterial material\n\
122
+ ) {\n\
123
+ vec3 viewDirectionEC = -normalize(positionEC);\n\
124
+ vec3 positionWC = vec3(czm_inverseView * vec4(positionEC, 1.0));\n\
125
+ vec3 reflectionWC = normalize(czm_inverseViewRotation * normalize(reflect(viewDirectionEC, normalEC)));\n\
126
+ vec3 skyMetrics = getProceduralSkyMetrics(positionWC, reflectionWC);\n\
127
+ \n\
128
+ float roughness = material.roughness;\n\
129
+ vec3 f0 = material.specular;\n\
130
+ \n\
131
+ vec3 specularIrradiance = getProceduralSpecularIrradiance(reflectionWC, skyMetrics, roughness);\n\
132
+ float NdotV = abs(dot(normalEC, viewDirectionEC)) + 0.001;\n\
71
133
  vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, roughness)).rg;\n\
72
- vec3 iblColor = (diffuseIrradiance * diffuseColor * model_iblFactor.x) + (specularIrradiance * czm_srgbToLinear(specularColor * brdfLut.x + brdfLut.y) * model_iblFactor.y);\n\
73
- float maximumComponent = max(max(lightColorHdr.x, lightColorHdr.y), lightColorHdr.z);\n\
74
- vec3 lightColor = lightColorHdr / max(maximumComponent, 1.0);\n\
75
- iblColor *= lightColor;\n\
134
+ vec3 specularColor = czm_srgbToLinear(f0 * brdfLut.x + brdfLut.y);\n\
135
+ vec3 specularContribution = specularIrradiance * specularColor * model_iblFactor.y;\n\
136
+ #ifdef USE_SPECULAR\n\
137
+ specularContribution *= material.specularWeight;\n\
138
+ #endif\n\
139
+ \n\
140
+ vec3 diffuseIrradiance = getProceduralDiffuseIrradiance(skyMetrics);\n\
141
+ vec3 diffuseColor = material.diffuse;\n\
142
+ vec3 diffuseContribution = diffuseIrradiance * diffuseColor * model_iblFactor.x;\n\
76
143
  \n\
77
- #ifdef USE_SUN_LUMINANCE \n\
78
- iblColor *= luminance;\n\
144
+ vec3 iblColor = specularContribution + diffuseContribution;\n\
145
+ \n\
146
+ #ifdef USE_SUN_LUMINANCE\n\
147
+ iblColor *= getSunLuminance(positionWC, normalEC, lightDirectionEC);\n\
79
148
  #endif\n\
80
149
  \n\
81
150
  return iblColor;\n\
82
151
  }\n\
83
152
  \n\
153
+ #ifdef DIFFUSE_IBL\n\
154
+ vec3 computeDiffuseIBL(vec3 cubeDir)\n\
155
+ {\n\
156
+ #ifdef CUSTOM_SPHERICAL_HARMONICS\n\
157
+ return czm_sphericalHarmonics(cubeDir, model_sphericalHarmonicCoefficients); \n\
158
+ #else\n\
159
+ return czm_sphericalHarmonics(cubeDir, czm_sphericalHarmonicCoefficients); \n\
160
+ #endif\n\
161
+ }\n\
162
+ #endif\n\
163
+ \n\
164
+ #ifdef SPECULAR_IBL\n\
165
+ vec3 sampleSpecularEnvironment(vec3 cubeDir, float roughness)\n\
166
+ {\n\
167
+ #ifdef CUSTOM_SPECULAR_IBL\n\
168
+ float maxLod = model_specularEnvironmentMapsMaximumLOD;\n\
169
+ float lod = roughness * maxLod;\n\
170
+ return czm_sampleOctahedralProjection(model_specularEnvironmentMaps, model_specularEnvironmentMapsSize, cubeDir, lod, maxLod);\n\
171
+ #else\n\
172
+ float maxLod = czm_specularEnvironmentMapsMaximumLOD;\n\
173
+ float lod = roughness * maxLod;\n\
174
+ return czm_sampleOctahedralProjection(czm_specularEnvironmentMaps, czm_specularEnvironmentMapSize, cubeDir, lod, maxLod);\n\
175
+ #endif\n\
176
+ }\n\
177
+ vec3 computeSpecularIBL(vec3 cubeDir, float NdotV, float VdotH, vec3 f0, float roughness)\n\
178
+ {\n\
179
+ float reflectance = czm_maximumComponent(f0);\n\
180
+ vec3 f90 = vec3(clamp(reflectance * 25.0, 0.0, 1.0));\n\
181
+ vec3 F = fresnelSchlick2(f0, f90, VdotH);\n\
182
+ \n\
183
+ vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, roughness)).rg;\n\
184
+ vec3 specularSample = sampleSpecularEnvironment(cubeDir, roughness);\n\
185
+ \n\
186
+ return specularSample * (F * brdfLut.x + brdfLut.y);\n\
187
+ }\n\
188
+ #endif\n\
189
+ \n\
84
190
  #if defined(DIFFUSE_IBL) || defined(SPECULAR_IBL)\n\
191
+ /**\n\
192
+ * Compute the light contributions from environment maps and spherical harmonic coefficients\n\
193
+ *\n\
194
+ * @param {vec3} viewDirectionEC Unit vector pointing from the fragment to the eye position\n\
195
+ * @param {vec3} normalEC The surface normal in eye coordinates\n\
196
+ * @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates.\n\
197
+ * @param {czm_modelMaterial} The material properties.\n\
198
+ * @return {vec3} The computed HDR color\n\
199
+ */\n\
85
200
  vec3 textureIBL(\n\
86
- vec3 positionEC,\n\
201
+ vec3 viewDirectionEC,\n\
87
202
  vec3 normalEC,\n\
88
203
  vec3 lightDirectionEC,\n\
89
- czm_pbrParameters pbrParameters\n\
204
+ czm_modelMaterial material\n\
90
205
  ) {\n\
91
- vec3 diffuseColor = pbrParameters.diffuseColor;\n\
92
- float roughness = pbrParameters.roughness;\n\
93
- vec3 specularColor = pbrParameters.f0;\n\
94
- \n\
95
- vec3 v = -positionEC;\n\
96
- vec3 n = normalEC;\n\
97
- vec3 l = normalize(lightDirectionEC);\n\
98
- vec3 h = normalize(v + l);\n\
99
- \n\
100
- float NdotV = abs(dot(n, v)) + 0.001;\n\
101
- float VdotH = clamp(dot(v, h), 0.0, 1.0);\n\
102
- \n\
103
- const mat3 yUpToZUp = mat3(\n\
104
- -1.0, 0.0, 0.0,\n\
105
- 0.0, 0.0, -1.0, \n\
106
- 0.0, 1.0, 0.0\n\
107
- ); \n\
108
- vec3 cubeDir = normalize(yUpToZUp * model_iblReferenceFrameMatrix * normalize(reflect(-v, n))); \n\
109
- \n\
110
- #ifdef DIFFUSE_IBL \n\
111
- #ifdef CUSTOM_SPHERICAL_HARMONICS\n\
112
- vec3 diffuseIrradiance = czm_sphericalHarmonics(cubeDir, model_sphericalHarmonicCoefficients); \n\
113
- #else\n\
114
- vec3 diffuseIrradiance = czm_sphericalHarmonics(cubeDir, czm_sphericalHarmonicCoefficients); \n\
115
- #endif \n\
116
- #else \n\
117
- vec3 diffuseIrradiance = vec3(0.0); \n\
118
- #endif \n\
206
+ // Find the direction in which to sample the environment map\n\
207
+ vec3 cubeDir = normalize(model_iblReferenceFrameMatrix * normalize(reflect(-viewDirectionEC, normalEC)));\n\
208
+ \n\
209
+ #ifdef DIFFUSE_IBL\n\
210
+ vec3 diffuseContribution = computeDiffuseIBL(cubeDir) * material.diffuse;\n\
211
+ #else\n\
212
+ vec3 diffuseContribution = vec3(0.0); \n\
213
+ #endif\n\
214
+ \n\
215
+ float roughness = material.roughness;\n\
216
+ \n\
217
+ #ifdef USE_ANISOTROPY\n\
218
+ // Update environment map sampling direction to account for anisotropic distortion of specular reflection\n\
219
+ vec3 anisotropyDirection = material.anisotropicB;\n\
220
+ vec3 anisotropicTangent = cross(anisotropyDirection, viewDirectionEC);\n\
221
+ vec3 anisotropicNormal = cross(anisotropicTangent, anisotropyDirection);\n\
222
+ float bendFactor = 1.0 - material.anisotropyStrength * (1.0 - roughness);\n\
223
+ float bendFactorPow4 = bendFactor * bendFactor * bendFactor * bendFactor;\n\
224
+ vec3 bentNormal = normalize(mix(anisotropicNormal, normalEC, bendFactorPow4));\n\
225
+ cubeDir = normalize(model_iblReferenceFrameMatrix * normalize(reflect(-viewDirectionEC, bentNormal)));\n\
226
+ #endif\n\
119
227
  \n\
120
228
  #ifdef SPECULAR_IBL\n\
121
- vec3 r0 = specularColor.rgb;\n\
122
- float reflectance = max(max(r0.r, r0.g), r0.b);\n\
123
- vec3 r90 = vec3(clamp(reflectance * 25.0, 0.0, 1.0));\n\
124
- vec3 F = fresnelSchlick2(r0, r90, VdotH);\n\
125
- \n\
126
- vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, roughness)).rg;\n\
127
- #ifdef CUSTOM_SPECULAR_IBL \n\
128
- vec3 specularIBL = czm_sampleOctahedralProjection(model_specularEnvironmentMaps, model_specularEnvironmentMapsSize, cubeDir, roughness * model_specularEnvironmentMapsMaximumLOD, model_specularEnvironmentMapsMaximumLOD);\n\
129
- #else \n\
130
- vec3 specularIBL = czm_sampleOctahedralProjection(czm_specularEnvironmentMaps, czm_specularEnvironmentMapSize, cubeDir, roughness * czm_specularEnvironmentMapsMaximumLOD, czm_specularEnvironmentMapsMaximumLOD);\n\
131
- #endif \n\
132
- specularIBL *= F * brdfLut.x + brdfLut.y;\n\
133
- #else \n\
134
- vec3 specularIBL = vec3(0.0); \n\
229
+ float NdotV = abs(dot(normalEC, viewDirectionEC)) + 0.001;\n\
230
+ vec3 halfwayDirectionEC = normalize(viewDirectionEC + lightDirectionEC);\n\
231
+ float VdotH = clamp(dot(viewDirectionEC, halfwayDirectionEC), 0.0, 1.0);\n\
232
+ vec3 f0 = material.specular;\n\
233
+ vec3 specularContribution = computeSpecularIBL(cubeDir, NdotV, VdotH, f0, roughness);\n\
234
+ #else\n\
235
+ vec3 specularContribution = vec3(0.0); \n\
236
+ #endif\n\
237
+ \n\
238
+ #ifdef USE_SPECULAR\n\
239
+ specularContribution *= material.specularWeight;\n\
135
240
  #endif\n\
136
241
  \n\
137
- return diffuseColor * diffuseIrradiance + specularColor * specularIBL;\n\
242
+ return diffuseContribution + specularContribution;\n\
138
243
  }\n\
139
244
  #endif\n\
140
- \n\
141
- vec3 imageBasedLightingStage(\n\
142
- vec3 positionEC,\n\
143
- vec3 normalEC,\n\
144
- vec3 lightDirectionEC,\n\
145
- vec3 lightColorHdr,\n\
146
- czm_pbrParameters pbrParameters\n\
147
- ) {\n\
148
- #if defined(DIFFUSE_IBL) || defined(SPECULAR_IBL)\n\
149
- // Environment maps were provided, use them for IBL\n\
150
- return textureIBL(\n\
151
- positionEC,\n\
152
- normalEC,\n\
153
- lightDirectionEC,\n\
154
- pbrParameters\n\
155
- );\n\
156
- #else\n\
157
- // Use the procedural IBL if there are no environment maps\n\
158
- return proceduralIBL(\n\
159
- positionEC,\n\
160
- normalEC,\n\
161
- lightDirectionEC,\n\
162
- lightColorHdr,\n\
163
- pbrParameters\n\
164
- );\n\
165
- #endif\n\
166
- }";
245
+ ";
@@ -1,72 +1,137 @@
1
- #ifdef LIGHTING_PBR
2
- vec3 computePbrLighting(czm_modelMaterial inputMaterial, ProcessedAttributes attributes)
1
+ #ifdef USE_IBL_LIGHTING
2
+ vec3 computeIBL(vec3 position, vec3 normal, vec3 lightDirection, vec3 lightColorHdr, czm_modelMaterial material)
3
3
  {
4
- czm_pbrParameters pbrParameters;
5
- pbrParameters.diffuseColor = inputMaterial.diffuse;
6
- pbrParameters.f0 = inputMaterial.specular;
7
- pbrParameters.roughness = inputMaterial.roughness;
8
-
9
- #ifdef USE_CUSTOM_LIGHT_COLOR
10
- vec3 lightColorHdr = model_lightColorHdr;
4
+ #if defined(DIFFUSE_IBL) || defined(SPECULAR_IBL)
5
+ // Environment maps were provided, use them for IBL
6
+ vec3 viewDirection = -normalize(position);
7
+ vec3 iblColor = textureIBL(viewDirection, normal, lightDirection, material);
11
8
  #else
12
- vec3 lightColorHdr = czm_lightColorHdr;
9
+ // Use procedural IBL if there are no environment maps
10
+ vec3 imageBasedLighting = proceduralIBL(position, normal, lightDirection, material);
11
+ float maximumComponent = czm_maximumComponent(lightColorHdr);
12
+ vec3 clampedLightColor = lightColorHdr / max(maximumComponent, 1.0);
13
+ vec3 iblColor = clampedLightColor * imageBasedLighting;
13
14
  #endif
15
+ return iblColor * material.occlusion;
16
+ }
17
+ #endif
18
+
19
+ #ifdef USE_CLEARCOAT
20
+ vec3 addClearcoatReflection(vec3 baseLayerColor, vec3 position, vec3 lightDirection, vec3 lightColorHdr, czm_modelMaterial material)
21
+ {
22
+ vec3 viewDirection = -normalize(position);
23
+ vec3 halfwayDirection = normalize(viewDirection + lightDirection);
24
+ vec3 normal = material.clearcoatNormal;
25
+ float NdotL = clamp(dot(normal, lightDirection), 0.001, 1.0);
26
+
27
+ // clearcoatF0 = vec3(pow((ior - 1.0) / (ior + 1.0), 2.0)), but without KHR_materials_ior, ior is a constant 1.5.
28
+ vec3 f0 = vec3(0.04);
29
+ vec3 f90 = vec3(1.0);
30
+ // Note: clearcoat Fresnel computed with dot(n, v) instead of dot(v, h).
31
+ // This is to make it energy conserving with a simple layering function.
32
+ float NdotV = clamp(dot(normal, viewDirection), 0.0, 1.0);
33
+ vec3 F = fresnelSchlick2(f0, f90, NdotV);
14
34
 
15
- vec3 color = inputMaterial.diffuse;
16
- #ifdef HAS_NORMALS
17
- color = czm_pbrLighting(
18
- attributes.positionEC,
19
- inputMaterial.normalEC,
20
- czm_lightDirectionEC,
21
- lightColorHdr,
22
- pbrParameters
23
- );
24
-
25
- #ifdef USE_IBL_LIGHTING
26
- color += imageBasedLightingStage(
27
- attributes.positionEC,
28
- inputMaterial.normalEC,
29
- czm_lightDirectionEC,
30
- lightColorHdr,
31
- pbrParameters
32
- );
35
+ // compute specular reflection from direct lighting
36
+ float roughness = material.clearcoatRoughness;
37
+ float directStrength = computeDirectSpecularStrength(normal, lightDirection, viewDirection, halfwayDirection, roughness);
38
+ vec3 directReflection = F * directStrength * NdotL;
39
+ vec3 color = lightColorHdr * directReflection;
40
+
41
+ #ifdef SPECULAR_IBL
42
+ // Find the direction in which to sample the environment map
43
+ vec3 cubeDir = normalize(model_iblReferenceFrameMatrix * normalize(reflect(-viewDirection, normal)));
44
+ vec3 iblColor = computeSpecularIBL(cubeDir, NdotV, NdotV, f0, roughness);
45
+ color += iblColor * material.occlusion;
46
+ #elif defined(USE_IBL_LIGHTING)
47
+ vec3 positionWC = vec3(czm_inverseView * vec4(position, 1.0));
48
+ vec3 reflectionWC = normalize(czm_inverseViewRotation * normalize(reflect(viewDirection, normal)));
49
+ vec3 skyMetrics = getProceduralSkyMetrics(positionWC, reflectionWC);
50
+
51
+ vec3 specularIrradiance = getProceduralSpecularIrradiance(reflectionWC, skyMetrics, roughness);
52
+ vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, roughness)).rg;
53
+ vec3 specularColor = czm_srgbToLinear(f0 * brdfLut.x + brdfLut.y);
54
+ vec3 iblColor = specularIrradiance * specularColor * model_iblFactor.y;
55
+ #ifdef USE_SUN_LUMINANCE
56
+ iblColor *= getSunLuminance(positionWC, normal, lightDirection);
33
57
  #endif
58
+ float maximumComponent = czm_maximumComponent(lightColorHdr);
59
+ vec3 clampedLightColor = lightColorHdr / max(maximumComponent, 1.0);
60
+ color += clampedLightColor* iblColor * material.occlusion;
61
+ #endif
62
+
63
+ float clearcoatFactor = material.clearcoatFactor;
64
+ vec3 clearcoatColor = color * clearcoatFactor;
65
+
66
+ // Dim base layer based on transmission loss through clearcoat
67
+ return baseLayerColor * (1.0 - clearcoatFactor * F) + clearcoatColor;
68
+ }
69
+ #endif
70
+
71
+ #if defined(LIGHTING_PBR) && defined(HAS_NORMALS)
72
+ vec3 computePbrLighting(in czm_modelMaterial material, in vec3 position)
73
+ {
74
+ #ifdef USE_CUSTOM_LIGHT_COLOR
75
+ vec3 lightColorHdr = model_lightColorHdr;
76
+ #else
77
+ vec3 lightColorHdr = czm_lightColorHdr;
34
78
  #endif
35
79
 
36
- color *= inputMaterial.occlusion;
37
- color += inputMaterial.emissive;
80
+ vec3 viewDirection = -normalize(position);
81
+ vec3 normal = material.normalEC;
82
+ vec3 lightDirection = normalize(czm_lightDirectionEC);
83
+
84
+ vec3 directLighting = czm_pbrLighting(viewDirection, normal, lightDirection, material);
85
+ vec3 directColor = lightColorHdr * directLighting;
38
86
 
39
- // In HDR mode, the frame buffer is in linear color space. The
40
- // post-processing stages (see PostProcessStageCollection) will handle
41
- // tonemapping. However, if HDR is not enabled, we must tonemap else large
42
- // values may be clamped to 1.0
43
- #ifndef HDR
44
- color = czm_acesTonemapping(color);
45
- #endif
87
+ // Accumulate colors from base layer
88
+ vec3 color = directColor + material.emissive;
89
+ #ifdef USE_IBL_LIGHTING
90
+ color += computeIBL(position, normal, lightDirection, lightColorHdr, material);
91
+ #endif
92
+
93
+ #ifdef USE_CLEARCOAT
94
+ color = addClearcoatReflection(color, position, lightDirection, lightColorHdr, material);
95
+ #endif
46
96
 
47
97
  return color;
48
98
  }
49
99
  #endif
50
100
 
101
+ /**
102
+ * Compute the material color under the current lighting conditions.
103
+ * All other material properties are passed through so further stages
104
+ * have access to them.
105
+ *
106
+ * @param {czm_modelMaterial} material The material properties from {@MaterialStageFS}
107
+ * @param {ProcessedAttributes} attributes
108
+ */
51
109
  void lightingStage(inout czm_modelMaterial material, ProcessedAttributes attributes)
52
110
  {
53
- // Even though the lighting will only set the diffuse color,
54
- // pass all other properties so further stages have access to them.
55
- vec3 color = vec3(0.0);
56
-
57
111
  #ifdef LIGHTING_PBR
58
- color = computePbrLighting(material, attributes);
112
+ #ifdef HAS_NORMALS
113
+ vec3 color = computePbrLighting(material, attributes.positionEC);
114
+ #else
115
+ vec3 color = material.diffuse * material.occlusion + material.emissive;
116
+ #endif
117
+ // In HDR mode, the frame buffer is in linear color space. The
118
+ // post-processing stages (see PostProcessStageCollection) will handle
119
+ // tonemapping. However, if HDR is not enabled, we must tonemap else large
120
+ // values may be clamped to 1.0
121
+ #ifndef HDR
122
+ color = czm_acesTonemapping(color);
123
+ #endif
59
124
  #else // unlit
60
- color = material.diffuse;
125
+ vec3 color = material.diffuse;
61
126
  #endif
62
127
 
63
128
  #ifdef HAS_POINT_CLOUD_COLOR_STYLE
64
- // The colors resulting from point cloud styles are adjusted differently.
65
- color = czm_gammaCorrect(color);
129
+ // The colors resulting from point cloud styles are adjusted differently.
130
+ color = czm_gammaCorrect(color);
66
131
  #elif !defined(HDR)
67
- // If HDR is not enabled, the frame buffer stores sRGB colors rather than
68
- // linear colors so the linear value must be converted.
69
- color = czm_linearToSrgb(color);
132
+ // If HDR is not enabled, the frame buffer stores sRGB colors rather than
133
+ // linear colors so the linear value must be converted.
134
+ color = czm_linearToSrgb(color);
70
135
  #endif
71
136
 
72
137
  material.diffuse = color;