@cesium/engine 10.0.0 → 11.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 (234) hide show
  1. package/Build/Workers/{chunk-AA4GZKOT.js → chunk-2EDC3QGH.js} +1 -1
  2. package/Build/Workers/{chunk-DKVHRNFY.js → chunk-2MKRG7L7.js} +5 -5
  3. package/Build/Workers/{chunk-X23FRWHJ.js → chunk-2RZYNSMR.js} +6 -6
  4. package/Build/Workers/{chunk-TO2PVHKI.js → chunk-4NBRIKB3.js} +2 -2
  5. package/Build/Workers/{chunk-GRAT5GE7.js → chunk-4TK5YR6Q.js} +5 -5
  6. package/Build/Workers/{chunk-XD445VDH.js → chunk-54VC7SCM.js} +7 -7
  7. package/Build/Workers/{chunk-G3YR53LY.js → chunk-5IY5BXCT.js} +13 -13
  8. package/Build/Workers/{chunk-O3JCMSS3.js → chunk-6FFGOENI.js} +54 -7
  9. package/Build/Workers/{chunk-7XGC6YB2.js → chunk-6PJIHPQB.js} +13 -13
  10. package/Build/Workers/{chunk-GR3CDLCP.js → chunk-6ZREIBKS.js} +7 -7
  11. package/Build/Workers/{chunk-4MSUJ4I7.js → chunk-AI3O7UN2.js} +6 -6
  12. package/Build/Workers/{chunk-COYFZ5VA.js → chunk-AS7P4BHI.js} +6 -6
  13. package/Build/Workers/{chunk-JYAHOGGL.js → chunk-AUM45VEG.js} +16 -15
  14. package/Build/Workers/{chunk-BDFNKFOE.js → chunk-BBO6BGLC.js} +13 -13
  15. package/Build/Workers/{chunk-AVI4IUWC.js → chunk-BH5ZEN4I.js} +10 -10
  16. package/Build/Workers/{chunk-4BAE4PWO.js → chunk-BJ3WF5RW.js} +6 -6
  17. package/Build/Workers/{chunk-Q55ECN3Y.js → chunk-BUOFSNFW.js} +1 -1
  18. package/Build/Workers/{chunk-QX5XS4LC.js → chunk-BZXF3GNX.js} +2 -2
  19. package/Build/Workers/{chunk-PYHLO636.js → chunk-DJXXI7UF.js} +5 -5
  20. package/Build/Workers/{chunk-LCLJJ2MZ.js → chunk-DVAIU7A4.js} +17 -17
  21. package/Build/Workers/{chunk-SYCPRK3D.js → chunk-FJT3ERV7.js} +9 -9
  22. package/Build/Workers/{chunk-L6RTJ3RE.js → chunk-GOHDOWU5.js} +14 -14
  23. package/Build/Workers/{chunk-MSKXMXJI.js → chunk-HA6TZ3XT.js} +4 -4
  24. package/Build/Workers/{chunk-PCP4YQST.js → chunk-HBZSCVZC.js} +11 -11
  25. package/Build/Workers/{chunk-5S7OLEPK.js → chunk-HC7RYWPZ.js} +12 -12
  26. package/Build/Workers/{chunk-VE7BFUIX.js → chunk-HFMJM3SX.js} +1 -1
  27. package/Build/Workers/{chunk-OOK53QUQ.js → chunk-HFPMX5L2.js} +1 -1
  28. package/Build/Workers/{chunk-VFBNELXB.js → chunk-HO2NTC7I.js} +6 -6
  29. package/Build/Workers/{chunk-DOXCPOG4.js → chunk-HZPMWR4H.js} +7 -7
  30. package/Build/Workers/{chunk-I2RC4XVN.js → chunk-IBG5FVXC.js} +4 -4
  31. package/Build/Workers/{chunk-LEABCTLP.js → chunk-IXLNNST6.js} +4 -4
  32. package/Build/Workers/{chunk-4YSNMHZ4.js → chunk-JYUCC5NV.js} +6 -6
  33. package/Build/Workers/{chunk-BCL4PHHT.js → chunk-KFW4UNQH.js} +10 -10
  34. package/Build/Workers/{chunk-R6B7UCQB.js → chunk-KKAEXHDY.js} +2 -2
  35. package/Build/Workers/{chunk-BJF5LOWE.js → chunk-L6FARMF6.js} +7 -7
  36. package/Build/Workers/{chunk-C2CGMAIU.js → chunk-N3BIL6WA.js} +13 -13
  37. package/Build/Workers/{chunk-STBBMQGG.js → chunk-O5SSW3B3.js} +6 -6
  38. package/Build/Workers/{chunk-S3PI2KFM.js → chunk-OC4MYPVW.js} +2 -2
  39. package/Build/Workers/{chunk-MDHQR3ZS.js → chunk-OOA6GXKD.js} +7 -7
  40. package/Build/Workers/{chunk-AD5HBJ2F.js → chunk-OSCHEWSG.js} +7 -7
  41. package/Build/Workers/{chunk-NTXTUNEF.js → chunk-QGT2GMOK.js} +4 -4
  42. package/Build/Workers/{chunk-VO3ACQB2.js → chunk-RFQYEYAL.js} +17 -17
  43. package/Build/Workers/{chunk-KUN2ZA5X.js → chunk-RJF5ZP76.js} +4 -4
  44. package/Build/Workers/{chunk-QD4KM3GO.js → chunk-SIZXFNJY.js} +6 -5
  45. package/Build/Workers/{chunk-FXIHSF7O.js → chunk-SRZJCF7G.js} +9 -9
  46. package/Build/Workers/{chunk-T77JILCU.js → chunk-T4MB73MC.js} +2 -2
  47. package/Build/Workers/{chunk-3WUV74WM.js → chunk-TTI2SUWJ.js} +2 -2
  48. package/Build/Workers/{chunk-QMLTCCYG.js → chunk-VHJ5ESXF.js} +1 -1
  49. package/Build/Workers/{chunk-2J3JKXCP.js → chunk-VSFFJGTA.js} +9 -5
  50. package/Build/Workers/{chunk-DGS5QNIO.js → chunk-WQRXRDCZ.js} +11 -11
  51. package/Build/Workers/{chunk-OORVMGDU.js → chunk-WXDGOYTT.js} +12 -7
  52. package/Build/Workers/{chunk-RJYML24O.js → chunk-XLCZE6DD.js} +423 -448
  53. package/Build/Workers/combineGeometry.js +22 -22
  54. package/Build/Workers/createBoxGeometry.js +16 -16
  55. package/Build/Workers/createBoxOutlineGeometry.js +14 -14
  56. package/Build/Workers/createCircleGeometry.js +24 -24
  57. package/Build/Workers/createCircleOutlineGeometry.js +17 -17
  58. package/Build/Workers/createCoplanarPolygonGeometry.js +31 -31
  59. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +29 -29
  60. package/Build/Workers/createCorridorGeometry.js +27 -27
  61. package/Build/Workers/createCorridorOutlineGeometry.js +26 -26
  62. package/Build/Workers/createCylinderGeometry.js +18 -18
  63. package/Build/Workers/createCylinderOutlineGeometry.js +16 -16
  64. package/Build/Workers/createEllipseGeometry.js +24 -24
  65. package/Build/Workers/createEllipseOutlineGeometry.js +17 -17
  66. package/Build/Workers/createEllipsoidGeometry.js +17 -17
  67. package/Build/Workers/createEllipsoidOutlineGeometry.js +16 -16
  68. package/Build/Workers/createFrustumGeometry.js +16 -16
  69. package/Build/Workers/createFrustumOutlineGeometry.js +16 -16
  70. package/Build/Workers/createGeometry.js +22 -22
  71. package/Build/Workers/createGroundPolylineGeometry.js +20 -20
  72. package/Build/Workers/createPlaneGeometry.js +14 -14
  73. package/Build/Workers/createPlaneOutlineGeometry.js +13 -13
  74. package/Build/Workers/createPolygonGeometry.js +30 -30
  75. package/Build/Workers/createPolygonOutlineGeometry.js +28 -28
  76. package/Build/Workers/createPolylineGeometry.js +23 -23
  77. package/Build/Workers/createPolylineVolumeGeometry.js +29 -29
  78. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +25 -25
  79. package/Build/Workers/createRectangleGeometry.js +25 -25
  80. package/Build/Workers/createRectangleOutlineGeometry.js +18 -18
  81. package/Build/Workers/createSimplePolylineGeometry.js +21 -21
  82. package/Build/Workers/createSphereGeometry.js +17 -17
  83. package/Build/Workers/createSphereOutlineGeometry.js +16 -16
  84. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  85. package/Build/Workers/createVectorTileClampedPolylines.js +13 -13
  86. package/Build/Workers/createVectorTileGeometries.js +22 -22
  87. package/Build/Workers/createVectorTilePoints.js +12 -12
  88. package/Build/Workers/createVectorTilePolygons.js +20 -20
  89. package/Build/Workers/createVectorTilePolylines.js +13 -13
  90. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +20 -20
  91. package/Build/Workers/createVerticesFromHeightmap.js +24 -20
  92. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +17 -17
  93. package/Build/Workers/createWallGeometry.js +22 -22
  94. package/Build/Workers/createWallOutlineGeometry.js +21 -21
  95. package/Build/Workers/decodeDraco.js +11 -11
  96. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +28 -5
  97. package/Build/Workers/decodeI3S.js +10 -10
  98. package/Build/Workers/transcodeKTX2.js +20 -22
  99. package/Build/Workers/transferTypedArrayTest.js +1 -1
  100. package/Build/Workers/upsampleQuantizedTerrainMesh.js +20 -20
  101. package/Source/Core/CompressedTextureBuffer.js +11 -0
  102. package/Source/Core/Ion.js +1 -1
  103. package/Source/Core/KTX2Transcoder.js +9 -16
  104. package/Source/Core/PixelFormat.js +1 -15
  105. package/Source/Core/Simon1994PlanetaryPositions.js +2 -1
  106. package/Source/Core/Transforms.js +137 -2
  107. package/Source/DataSources/BillboardGraphics.js +16 -0
  108. package/Source/DataSources/BillboardVisualizer.js +7 -0
  109. package/Source/DataSources/CallbackProperty.js +8 -2
  110. package/Source/DataSources/CheckerboardMaterialProperty.js +7 -1
  111. package/Source/DataSources/ColorMaterialProperty.js +7 -1
  112. package/Source/DataSources/CompositeMaterialProperty.js +5 -4
  113. package/Source/DataSources/CompositePositionProperty.js +7 -1
  114. package/Source/DataSources/CompositeProperty.js +5 -5
  115. package/Source/DataSources/ConstantPositionProperty.js +7 -1
  116. package/Source/DataSources/Entity.js +1 -1
  117. package/Source/DataSources/GridMaterialProperty.js +7 -1
  118. package/Source/DataSources/ImageMaterialProperty.js +8 -1
  119. package/Source/DataSources/MaterialProperty.js +7 -1
  120. package/Source/DataSources/NodeTransformationProperty.js +7 -1
  121. package/Source/DataSources/PathVisualizer.js +4 -4
  122. package/Source/DataSources/PointGraphics.js +17 -0
  123. package/Source/DataSources/PointVisualizer.js +12 -0
  124. package/Source/DataSources/PolylineArrowMaterialProperty.js +7 -1
  125. package/Source/DataSources/PolylineDashMaterialProperty.js +7 -1
  126. package/Source/DataSources/PolylineGlowMaterialProperty.js +7 -1
  127. package/Source/DataSources/PolylineOutlineMaterialProperty.js +7 -1
  128. package/Source/DataSources/PositionProperty.js +5 -8
  129. package/Source/DataSources/PositionPropertyArray.js +7 -1
  130. package/Source/DataSources/Property.js +1 -1
  131. package/Source/DataSources/PropertyArray.js +5 -5
  132. package/Source/DataSources/PropertyBag.js +5 -4
  133. package/Source/DataSources/ReferenceProperty.js +7 -1
  134. package/Source/DataSources/SampledPositionProperty.js +7 -1
  135. package/Source/DataSources/SampledProperty.js +6 -4
  136. package/Source/DataSources/ScaledPositionProperty.js +6 -0
  137. package/Source/DataSources/StripeMaterialProperty.js +7 -1
  138. package/Source/DataSources/TerrainOffsetProperty.js +9 -0
  139. package/Source/DataSources/TimeIntervalCollectionPositionProperty.js +7 -1
  140. package/Source/DataSources/TimeIntervalCollectionProperty.js +5 -5
  141. package/Source/DataSources/VelocityOrientationProperty.js +6 -1
  142. package/Source/DataSources/VelocityVectorProperty.js +3 -5
  143. package/Source/Renderer/AutomaticUniforms.js +3 -18
  144. package/Source/Renderer/Context.js +15 -0
  145. package/Source/Renderer/CubeMap.js +326 -348
  146. package/Source/Renderer/CubeMapFace.js +26 -48
  147. package/Source/Renderer/PixelDatatype.js +23 -0
  148. package/Source/Renderer/Sampler.js +7 -13
  149. package/Source/Renderer/ShaderProgram.js +7 -0
  150. package/Source/Renderer/Texture.js +396 -332
  151. package/Source/Renderer/UniformState.js +8 -33
  152. package/Source/Renderer/demodernizeShader.js +2 -0
  153. package/Source/Renderer/loadCubeMap.js +3 -8
  154. package/Source/Scene/ArcGisMapService.js +1 -1
  155. package/Source/Scene/Billboard.js +29 -2
  156. package/Source/Scene/BillboardCollection.js +49 -0
  157. package/Source/Scene/BingMapsImageryProvider.js +10 -1
  158. package/Source/Scene/CameraEventAggregator.js +49 -5
  159. package/Source/Scene/Globe.js +1 -1
  160. package/Source/Scene/GlobeSurfaceShaderSet.js +29 -24
  161. package/Source/Scene/GlobeSurfaceTileProvider.js +5 -3
  162. package/Source/Scene/ImageBasedLighting.js +36 -36
  163. package/Source/Scene/Label.js +2 -2
  164. package/Source/Scene/Material.js +24 -2
  165. package/Source/Scene/Model/ImageBasedLightingPipelineStage.js +7 -15
  166. package/Source/Scene/Model/Model.js +1 -1
  167. package/Source/Scene/PointPrimitive.js +28 -2
  168. package/Source/Scene/PointPrimitiveCollection.js +22 -9
  169. package/Source/Scene/PostProcessStageCollection.js +45 -15
  170. package/Source/Scene/PostProcessStageLibrary.js +26 -0
  171. package/Source/Scene/Scene.js +20 -22
  172. package/Source/Scene/SceneTransforms.js +0 -62
  173. package/Source/Scene/ScreenSpaceCameraController.js +11 -4
  174. package/Source/Scene/SkyBox.js +13 -19
  175. package/Source/Scene/SpecularEnvironmentCubeMap.js +240 -0
  176. package/Source/Scene/Tonemapper.js +35 -23
  177. package/Source/Scene/VoxelPrimitive.js +0 -29
  178. package/Source/Scene/VoxelRenderResources.js +0 -3
  179. package/Source/Shaders/BillboardCollectionFS.glsl +4 -0
  180. package/Source/Shaders/BillboardCollectionFS.js +4 -0
  181. package/Source/Shaders/BillboardCollectionVS.glsl +3 -1
  182. package/Source/Shaders/BillboardCollectionVS.js +3 -1
  183. package/Source/Shaders/BrdfLutGeneratorFS.glsl +30 -13
  184. package/Source/Shaders/BrdfLutGeneratorFS.js +30 -13
  185. package/Source/Shaders/Builtin/CzmBuiltins.js +2 -2
  186. package/Source/Shaders/Builtin/Functions/pbrLighting.glsl +42 -41
  187. package/Source/Shaders/Builtin/Functions/pbrLighting.js +42 -41
  188. package/Source/Shaders/Builtin/Functions/pbrNeutralTonemapping.glsl +23 -0
  189. package/Source/Shaders/Builtin/Functions/pbrNeutralTonemapping.js +25 -0
  190. package/Source/Shaders/Builtin/Functions/textureCube.glsl +21 -2
  191. package/Source/Shaders/Builtin/Functions/textureCube.js +21 -2
  192. package/Source/Shaders/Builtin/Structs/materialInput.glsl +2 -0
  193. package/Source/Shaders/Builtin/Structs/materialInput.js +2 -0
  194. package/Source/Shaders/GlobeFS.glsl +10 -4
  195. package/Source/Shaders/GlobeFS.js +10 -4
  196. package/Source/Shaders/Materials/WaterMaskMaterial.glsl +15 -0
  197. package/Source/Shaders/Materials/WaterMaskMaterial.js +17 -0
  198. package/Source/Shaders/Model/AtmosphereStageFS.glsl +1 -1
  199. package/Source/Shaders/Model/AtmosphereStageFS.js +1 -1
  200. package/Source/Shaders/Model/ImageBasedLightingStageFS.glsl +57 -46
  201. package/Source/Shaders/Model/ImageBasedLightingStageFS.js +57 -46
  202. package/Source/Shaders/Model/LightingStageFS.glsl +8 -7
  203. package/Source/Shaders/Model/LightingStageFS.js +8 -7
  204. package/Source/Shaders/Model/MaterialStageFS.glsl +10 -14
  205. package/Source/Shaders/Model/MaterialStageFS.js +10 -14
  206. package/Source/Shaders/PointPrimitiveCollectionFS.glsl +4 -0
  207. package/Source/Shaders/PointPrimitiveCollectionFS.js +4 -0
  208. package/Source/Shaders/PointPrimitiveCollectionVS.glsl +9 -7
  209. package/Source/Shaders/PointPrimitiveCollectionVS.js +9 -7
  210. package/Source/Shaders/PostProcessStages/AcesTonemappingStage.glsl +4 -0
  211. package/Source/Shaders/PostProcessStages/AcesTonemappingStage.js +4 -0
  212. package/Source/Shaders/PostProcessStages/FilmicTonemapping.glsl +4 -0
  213. package/Source/Shaders/PostProcessStages/FilmicTonemapping.js +4 -0
  214. package/Source/Shaders/PostProcessStages/ModifiedReinhardTonemapping.glsl +4 -0
  215. package/Source/Shaders/PostProcessStages/ModifiedReinhardTonemapping.js +4 -0
  216. package/Source/Shaders/PostProcessStages/PbrNeutralTonemapping.glsl +25 -0
  217. package/Source/Shaders/PostProcessStages/PbrNeutralTonemapping.js +27 -0
  218. package/Source/Shaders/PostProcessStages/ReinhardTonemapping.glsl +4 -0
  219. package/Source/Shaders/PostProcessStages/ReinhardTonemapping.js +4 -0
  220. package/Source/Shaders/SkyAtmosphereFS.glsl +1 -1
  221. package/Source/Shaders/SkyAtmosphereFS.js +1 -1
  222. package/Source/Widget/CesiumWidget.js +1 -1
  223. package/index.d.ts +191 -106
  224. package/index.js +133 -134
  225. package/package.json +4 -4
  226. package/Source/Scene/OctahedralProjectedCubeMap.js +0 -445
  227. package/Source/Shaders/Builtin/Functions/sampleOctahedralProjection.glsl +0 -78
  228. package/Source/Shaders/Builtin/Functions/sampleOctahedralProjection.js +0 -80
  229. package/Source/Shaders/OctahedralProjectionAtlasFS.glsl +0 -89
  230. package/Source/Shaders/OctahedralProjectionAtlasFS.js +0 -91
  231. package/Source/Shaders/OctahedralProjectionFS.glsl +0 -14
  232. package/Source/Shaders/OctahedralProjectionFS.js +0 -16
  233. package/Source/Shaders/OctahedralProjectionVS.glsl +0 -10
  234. package/Source/Shaders/OctahedralProjectionVS.js +0 -12
@@ -6,12 +6,31 @@
6
6
  * @glslFunction
7
7
  *
8
8
  * @param {samplerCube} sampler The sampler.
9
- * @param {vec3} p The coordinates to sample the texture at.
9
+ * @param {vec3} p The coordinate at which to sample the texture.
10
10
  */
11
11
  vec4 czm_textureCube(samplerCube sampler, vec3 p) {
12
12
  #if __VERSION__ == 300
13
13
  return texture(sampler, p);
14
- #else
14
+ #else
15
15
  return textureCube(sampler, p);
16
16
  #endif
17
+ }
18
+
19
+ /**
20
+ * A wrapper around the textureLod (WebGL2) / textureCube (WebGL1)
21
+ * function to allow for WebGL 1 support in fragment shaders.
22
+ *
23
+ * @name czm_textureCubeLod
24
+ * @glslFunction
25
+ *
26
+ * @param {samplerCube} sampler The sampler.
27
+ * @param {vec3} p The coordinate at which to sample the texture.
28
+ * @param {float} lod The mipmap level from which to sample.
29
+ */
30
+ vec4 czm_textureCube(samplerCube sampler, vec3 p, float lod) {
31
+ #if __VERSION__ == 300
32
+ return textureLod(sampler, p, lod);
33
+ #elif defined(GL_EXT_shader_texture_lod)
34
+ return textureCubeLodEXT(sampler, p, lod);
35
+ #endif
17
36
  }
@@ -7,12 +7,31 @@ export default "/**\n\
7
7
  * @glslFunction\n\
8
8
  *\n\
9
9
  * @param {samplerCube} sampler The sampler.\n\
10
- * @param {vec3} p The coordinates to sample the texture at.\n\
10
+ * @param {vec3} p The coordinate at which to sample the texture.\n\
11
11
  */\n\
12
12
  vec4 czm_textureCube(samplerCube sampler, vec3 p) {\n\
13
13
  #if __VERSION__ == 300\n\
14
14
  return texture(sampler, p);\n\
15
- #else \n\
15
+ #else\n\
16
16
  return textureCube(sampler, p);\n\
17
17
  #endif\n\
18
+ }\n\
19
+ \n\
20
+ /**\n\
21
+ * A wrapper around the textureLod (WebGL2) / textureCube (WebGL1)\n\
22
+ * function to allow for WebGL 1 support in fragment shaders.\n\
23
+ *\n\
24
+ * @name czm_textureCubeLod\n\
25
+ * @glslFunction\n\
26
+ *\n\
27
+ * @param {samplerCube} sampler The sampler.\n\
28
+ * @param {vec3} p The coordinate at which to sample the texture.\n\
29
+ * @param {float} lod The mipmap level from which to sample.\n\
30
+ */\n\
31
+ vec4 czm_textureCube(samplerCube sampler, vec3 p, float lod) {\n\
32
+ #if __VERSION__ == 300\n\
33
+ return textureLod(sampler, p, lod);\n\
34
+ #elif defined(GL_EXT_shader_texture_lod)\n\
35
+ return textureCubeLodEXT(sampler, p, lod);\n\
36
+ #endif\n\
18
37
  }";
@@ -13,6 +13,7 @@
13
13
  * @property {float} height The height of the terrain in meters above or below the ellipsoid. Only available for globe materials.
14
14
  * @property {float} slope The slope of the terrain in radians. 0 is flat; pi/2 is vertical. Only available for globe materials.
15
15
  * @property {float} aspect The aspect of the terrain in radians. 0 is East, pi/2 is North, pi is West, 3pi/2 is South. Only available for globe materials.
16
+ * @property {float} waterMask The value of the water mask. 0 is land, 1 is water. Only available for globe materials.
16
17
  */
17
18
  struct czm_materialInput
18
19
  {
@@ -25,4 +26,5 @@ struct czm_materialInput
25
26
  float height;
26
27
  float slope;
27
28
  float aspect;
29
+ float waterMask;
28
30
  };
@@ -14,6 +14,7 @@ export default "/**\n\
14
14
  * @property {float} height The height of the terrain in meters above or below the ellipsoid. Only available for globe materials.\n\
15
15
  * @property {float} slope The slope of the terrain in radians. 0 is flat; pi/2 is vertical. Only available for globe materials.\n\
16
16
  * @property {float} aspect The aspect of the terrain in radians. 0 is East, pi/2 is North, pi is West, 3pi/2 is South. Only available for globe materials.\n\
17
+ * @property {float} waterMask The value of the water mask. 0 is land, 1 is water. Only available for globe materials.\n\
17
18
  */\n\
18
19
  struct czm_materialInput\n\
19
20
  {\n\
@@ -26,5 +27,6 @@ struct czm_materialInput\n\
26
27
  float height;\n\
27
28
  float slope;\n\
28
29
  float aspect;\n\
30
+ float waterMask;\n\
29
31
  };\n\
30
32
  ";
@@ -49,7 +49,7 @@ uniform vec4 u_colorsToAlpha[TEXTURE_UNITS];
49
49
  uniform vec4 u_dayTextureTexCoordsRectangle[TEXTURE_UNITS];
50
50
  #endif
51
51
 
52
- #ifdef SHOW_REFLECTIVE_OCEAN
52
+ #if defined(HAS_WATER_MASK) && (defined(SHOW_REFLECTIVE_OCEAN) || defined(APPLY_MATERIAL))
53
53
  uniform sampler2D u_waterMask;
54
54
  uniform vec4 u_waterMaskTranslationAndScale;
55
55
  uniform float u_zoomedOutOceanSpecularIntensity;
@@ -362,7 +362,7 @@ void main()
362
362
  float fade = 0.0;
363
363
  #endif
364
364
 
365
- #ifdef SHOW_REFLECTIVE_OCEAN
365
+ #if defined(HAS_WATER_MASK) && (defined(SHOW_REFLECTIVE_OCEAN) || defined(APPLY_MATERIAL))
366
366
  vec2 waterMaskTranslation = u_waterMaskTranslationAndScale.xy;
367
367
  vec2 waterMaskScale = u_waterMaskTranslationAndScale.zw;
368
368
  vec2 waterMaskTextureCoordinates = v_textureCoordinates.xy * waterMaskScale + waterMaskTranslation;
@@ -370,6 +370,7 @@ void main()
370
370
 
371
371
  float mask = texture(u_waterMask, waterMaskTextureCoordinates).r;
372
372
 
373
+ #ifdef SHOW_REFLECTIVE_OCEAN
373
374
  if (mask > 0.0)
374
375
  {
375
376
  mat3 enuToEye = czm_eastNorthUpToEyeCoordinates(v_positionMC, normalEC);
@@ -381,6 +382,7 @@ void main()
381
382
 
382
383
  color = computeWaterColor(v_positionEC, textureCoordinates, enuToEye, color, mask, fade);
383
384
  }
385
+ #endif
384
386
  #endif
385
387
 
386
388
  #ifdef APPLY_MATERIAL
@@ -392,6 +394,10 @@ void main()
392
394
  materialInput.slope = v_slope;
393
395
  materialInput.height = v_height;
394
396
  materialInput.aspect = v_aspect;
397
+ #ifdef HAS_WATER_MASK
398
+ materialInput.waterMask = mask;
399
+ #endif
400
+
395
401
  czm_material material = czm_getMaterial(materialInput);
396
402
  vec4 materialColor = vec4(material.diffuse, material.alpha);
397
403
  color = alphaBlend(materialColor, color);
@@ -422,7 +428,7 @@ void main()
422
428
  #ifdef ENABLE_CLIPPING_POLYGONS
423
429
  vec2 clippingPosition = v_clippingPosition;
424
430
  int regionIndex = v_regionIndex;
425
- clipPolygons(u_clippingDistance, CLIPPING_POLYGON_REGIONS_LENGTH, clippingPosition, regionIndex);
431
+ clipPolygons(u_clippingDistance, CLIPPING_POLYGON_REGIONS_LENGTH, clippingPosition, regionIndex);
426
432
  #endif
427
433
 
428
434
  #ifdef HIGHLIGHT_FILL_TILE
@@ -489,7 +495,7 @@ void main()
489
495
  #endif
490
496
 
491
497
  #ifndef HDR
492
- fogColor.rgb = czm_acesTonemapping(fogColor.rgb);
498
+ fogColor.rgb = czm_pbrNeutralTonemapping(fogColor.rgb);
493
499
  fogColor.rgb = czm_inverseGamma(fogColor.rgb);
494
500
  #endif
495
501
 
@@ -50,7 +50,7 @@ uniform vec4 u_colorsToAlpha[TEXTURE_UNITS];\n\
50
50
  uniform vec4 u_dayTextureTexCoordsRectangle[TEXTURE_UNITS];\n\
51
51
  #endif\n\
52
52
  \n\
53
- #ifdef SHOW_REFLECTIVE_OCEAN\n\
53
+ #if defined(HAS_WATER_MASK) && (defined(SHOW_REFLECTIVE_OCEAN) || defined(APPLY_MATERIAL))\n\
54
54
  uniform sampler2D u_waterMask;\n\
55
55
  uniform vec4 u_waterMaskTranslationAndScale;\n\
56
56
  uniform float u_zoomedOutOceanSpecularIntensity;\n\
@@ -363,7 +363,7 @@ void main()\n\
363
363
  float fade = 0.0;\n\
364
364
  #endif\n\
365
365
  \n\
366
- #ifdef SHOW_REFLECTIVE_OCEAN\n\
366
+ #if defined(HAS_WATER_MASK) && (defined(SHOW_REFLECTIVE_OCEAN) || defined(APPLY_MATERIAL))\n\
367
367
  vec2 waterMaskTranslation = u_waterMaskTranslationAndScale.xy;\n\
368
368
  vec2 waterMaskScale = u_waterMaskTranslationAndScale.zw;\n\
369
369
  vec2 waterMaskTextureCoordinates = v_textureCoordinates.xy * waterMaskScale + waterMaskTranslation;\n\
@@ -371,6 +371,7 @@ void main()\n\
371
371
  \n\
372
372
  float mask = texture(u_waterMask, waterMaskTextureCoordinates).r;\n\
373
373
  \n\
374
+ #ifdef SHOW_REFLECTIVE_OCEAN\n\
374
375
  if (mask > 0.0)\n\
375
376
  {\n\
376
377
  mat3 enuToEye = czm_eastNorthUpToEyeCoordinates(v_positionMC, normalEC);\n\
@@ -382,6 +383,7 @@ void main()\n\
382
383
  \n\
383
384
  color = computeWaterColor(v_positionEC, textureCoordinates, enuToEye, color, mask, fade);\n\
384
385
  }\n\
386
+ #endif\n\
385
387
  #endif\n\
386
388
  \n\
387
389
  #ifdef APPLY_MATERIAL\n\
@@ -393,6 +395,10 @@ void main()\n\
393
395
  materialInput.slope = v_slope;\n\
394
396
  materialInput.height = v_height;\n\
395
397
  materialInput.aspect = v_aspect;\n\
398
+ #ifdef HAS_WATER_MASK\n\
399
+ materialInput.waterMask = mask;\n\
400
+ #endif\n\
401
+ \n\
396
402
  czm_material material = czm_getMaterial(materialInput);\n\
397
403
  vec4 materialColor = vec4(material.diffuse, material.alpha);\n\
398
404
  color = alphaBlend(materialColor, color);\n\
@@ -423,7 +429,7 @@ void main()\n\
423
429
  #ifdef ENABLE_CLIPPING_POLYGONS\n\
424
430
  vec2 clippingPosition = v_clippingPosition;\n\
425
431
  int regionIndex = v_regionIndex;\n\
426
- clipPolygons(u_clippingDistance, CLIPPING_POLYGON_REGIONS_LENGTH, clippingPosition, regionIndex); \n\
432
+ clipPolygons(u_clippingDistance, CLIPPING_POLYGON_REGIONS_LENGTH, clippingPosition, regionIndex);\n\
427
433
  #endif\n\
428
434
  \n\
429
435
  #ifdef HIGHLIGHT_FILL_TILE\n\
@@ -490,7 +496,7 @@ void main()\n\
490
496
  #endif\n\
491
497
  \n\
492
498
  #ifndef HDR\n\
493
- fogColor.rgb = czm_acesTonemapping(fogColor.rgb);\n\
499
+ fogColor.rgb = czm_pbrNeutralTonemapping(fogColor.rgb);\n\
494
500
  fogColor.rgb = czm_inverseGamma(fogColor.rgb);\n\
495
501
  #endif\n\
496
502
  \n\
@@ -0,0 +1,15 @@
1
+ uniform vec4 waterColor;
2
+ uniform vec4 landColor;
3
+
4
+ czm_material czm_getMaterial(czm_materialInput materialInput)
5
+ {
6
+ czm_material material = czm_getDefaultMaterial(materialInput);
7
+
8
+ vec4 outColor = mix(landColor, waterColor, materialInput.waterMask);
9
+ outColor = czm_gammaCorrect(outColor);
10
+
11
+ material.diffuse = outColor.rgb;
12
+ material.alpha = outColor.a;
13
+
14
+ return material;
15
+ }
@@ -0,0 +1,17 @@
1
+ //This file is automatically rebuilt by the Cesium build process.
2
+ export default "uniform vec4 waterColor;\n\
3
+ uniform vec4 landColor;\n\
4
+ \n\
5
+ czm_material czm_getMaterial(czm_materialInput materialInput)\n\
6
+ {\n\
7
+ czm_material material = czm_getDefaultMaterial(materialInput);\n\
8
+ \n\
9
+ vec4 outColor = mix(landColor, waterColor, materialInput.waterMask);\n\
10
+ outColor = czm_gammaCorrect(outColor);\n\
11
+ \n\
12
+ material.diffuse = outColor.rgb;\n\
13
+ material.alpha = outColor.a;\n\
14
+ \n\
15
+ return material;\n\
16
+ }\n\
17
+ ";
@@ -52,7 +52,7 @@ void applyFog(inout vec4 color, vec4 groundAtmosphereColor, vec3 lightDirection,
52
52
 
53
53
  // Tonemap if HDR rendering is disabled
54
54
  #ifndef HDR
55
- fogColor.rgb = czm_acesTonemapping(fogColor.rgb);
55
+ fogColor.rgb = czm_pbrNeutralTonemapping(fogColor.rgb);
56
56
  fogColor.rgb = czm_inverseGamma(fogColor.rgb);
57
57
  #endif
58
58
 
@@ -53,7 +53,7 @@ void applyFog(inout vec4 color, vec4 groundAtmosphereColor, vec3 lightDirection,
53
53
  \n\
54
54
  // Tonemap if HDR rendering is disabled\n\
55
55
  #ifndef HDR\n\
56
- fogColor.rgb = czm_acesTonemapping(fogColor.rgb);\n\
56
+ fogColor.rgb = czm_pbrNeutralTonemapping(fogColor.rgb);\n\
57
57
  fogColor.rgb = czm_inverseGamma(fogColor.rgb);\n\
58
58
  #endif\n\
59
59
  \n\
@@ -16,10 +16,10 @@ vec3 getProceduralSkyMetrics(vec3 positionWC, vec3 reflectionWC)
16
16
  }
17
17
 
18
18
  /**
19
- * Compute the diffuse irradiance for a procedural sky lighting model
19
+ * Compute the diffuse irradiance for a procedural sky lighting model.
20
20
  *
21
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
22
+ * @return {vec3} The computed diffuse irradiance.
23
23
  */
24
24
  vec3 getProceduralDiffuseIrradiance(vec3 skyMetrics)
25
25
  {
@@ -30,10 +30,12 @@ vec3 getProceduralDiffuseIrradiance(vec3 skyMetrics)
30
30
  }
31
31
 
32
32
  /**
33
- * Compute the specular irradiance for a procedural sky lighting model
33
+ * Compute the specular irradiance for a procedural sky lighting model.
34
34
  *
35
+ * @param {vec3} reflectionWC The reflection vector in world coordinates.
35
36
  * @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
+ * @param {float} roughness The roughness of the material.
38
+ * @return {vec3} The computed specular irradiance.
37
39
  */
38
40
  vec3 getProceduralSpecularIrradiance(vec3 reflectionWC, vec3 skyMetrics, float roughness)
39
41
  {
@@ -42,7 +44,7 @@ vec3 getProceduralSpecularIrradiance(vec3 reflectionWC, vec3 skyMetrics, float r
42
44
  reflectionWC = -normalize(czm_temeToPseudoFixed * reflectionWC);
43
45
  reflectionWC.x = -reflectionWC.x;
44
46
 
45
- float inverseRoughness = 1.04 - roughness;
47
+ float inverseRoughness = 1.0 - roughness;
46
48
  inverseRoughness *= inverseRoughness;
47
49
  vec3 sceneSkyBox = czm_textureCube(czm_environmentMap, reflectionWC).rgb * inverseRoughness;
48
50
 
@@ -121,7 +123,7 @@ float getSunLuminance(vec3 positionWC, vec3 normalEC, vec3 lightDirectionEC)
121
123
  ) {
122
124
  vec3 viewDirectionEC = -normalize(positionEC);
123
125
  vec3 positionWC = vec3(czm_inverseView * vec4(positionEC, 1.0));
124
- vec3 reflectionWC = normalize(czm_inverseViewRotation * normalize(reflect(viewDirectionEC, normalEC)));
126
+ vec3 reflectionWC = normalize(czm_inverseViewRotation * reflect(viewDirectionEC, normalEC));
125
127
  vec3 skyMetrics = getProceduralSkyMetrics(positionWC, reflectionWC);
126
128
 
127
129
  float roughness = material.roughness;
@@ -150,7 +152,7 @@ float getSunLuminance(vec3 positionWC, vec3 normalEC, vec3 lightDirectionEC)
150
152
  }
151
153
 
152
154
  #ifdef DIFFUSE_IBL
153
- vec3 computeDiffuseIBL(vec3 cubeDir)
155
+ vec3 sampleDiffuseEnvironment(vec3 cubeDir)
154
156
  {
155
157
  #ifdef CUSTOM_SPHERICAL_HARMONICS
156
158
  return czm_sphericalHarmonics(cubeDir, model_sphericalHarmonicCoefficients);
@@ -164,20 +166,19 @@ vec3 computeDiffuseIBL(vec3 cubeDir)
164
166
  vec3 sampleSpecularEnvironment(vec3 cubeDir, float roughness)
165
167
  {
166
168
  #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);
169
+ float lod = roughness * model_specularEnvironmentMapsMaximumLOD;
170
+ return czm_textureCube(model_specularEnvironmentMaps, cubeDir, lod).rgb;
170
171
  #else
171
- float maxLod = czm_specularEnvironmentMapsMaximumLOD;
172
- float lod = roughness * maxLod;
173
- return czm_sampleOctahedralProjection(czm_specularEnvironmentMaps, czm_specularEnvironmentMapSize, cubeDir, lod, maxLod);
172
+ float lod = roughness * czm_specularEnvironmentMapsMaximumLOD;
173
+ return czm_textureCube(czm_specularEnvironmentMaps, cubeDir, lod).rgb;
174
174
  #endif
175
175
  }
176
- vec3 computeSpecularIBL(vec3 cubeDir, float NdotV, float VdotH, vec3 f0, float roughness)
176
+ vec3 computeSpecularIBL(vec3 cubeDir, float NdotV, vec3 f0, float roughness)
177
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);
178
+ // see https://bruop.github.io/ibl/ at Single Scattering Results
179
+ // Roughness dependent fresnel, from Fdez-Aguera
180
+ vec3 f90 = max(vec3(1.0 - roughness), f0);
181
+ vec3 F = fresnelSchlick2(f0, f90, NdotV);
181
182
 
182
183
  vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, roughness)).rg;
183
184
  vec3 specularSample = sampleSpecularEnvironment(cubeDir, roughness);
@@ -188,54 +189,64 @@ vec3 computeSpecularIBL(vec3 cubeDir, float NdotV, float VdotH, vec3 f0, float r
188
189
 
189
190
  #if defined(DIFFUSE_IBL) || defined(SPECULAR_IBL)
190
191
  /**
191
- * Compute the light contributions from environment maps and spherical harmonic coefficients
192
+ * Compute the light contributions from environment maps and spherical harmonic coefficients.
193
+ * See Fdez-Aguera, https://www.jcgt.org/published/0008/01/03/paper.pdf, for explanation
194
+ * of the single- and multi-scattering terms.
192
195
  *
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 {vec3} viewDirectionEC Unit vector pointing from the fragment to the eye position.
197
+ * @param {vec3} normalEC The surface normal in eye coordinates.
196
198
  * @param {czm_modelMaterial} The material properties.
197
- * @return {vec3} The computed HDR color
199
+ * @return {vec3} The computed HDR color.
198
200
  */
199
- vec3 textureIBL(
200
- vec3 viewDirectionEC,
201
- vec3 normalEC,
202
- vec3 lightDirectionEC,
203
- czm_modelMaterial material
204
- ) {
205
- // Find the direction in which to sample the environment map
206
- vec3 cubeDir = normalize(model_iblReferenceFrameMatrix * normalize(reflect(-viewDirectionEC, normalEC)));
201
+ vec3 textureIBL(vec3 viewDirectionEC, vec3 normalEC, czm_modelMaterial material) {
202
+ vec3 f0 = material.specular;
203
+ float roughness = material.roughness;
204
+ float specularWeight = 1.0;
205
+ #ifdef USE_SPECULAR
206
+ specularWeight = material.specularWeight;
207
+ #endif
208
+ float NdotV = clamp(dot(normalEC, viewDirectionEC), 0.0, 1.0);
209
+
210
+ // see https://bruop.github.io/ibl/ at Single Scattering Results
211
+ // Roughness dependent fresnel, from Fdez-Aguera
212
+ vec3 f90 = max(vec3(1.0 - roughness), f0);
213
+ vec3 singleScatterFresnel = fresnelSchlick2(f0, f90, NdotV);
214
+
215
+ vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, roughness)).rg;
216
+ vec3 FssEss = specularWeight * (singleScatterFresnel * brdfLut.x + brdfLut.y);
207
217
 
208
218
  #ifdef DIFFUSE_IBL
209
- vec3 diffuseContribution = computeDiffuseIBL(cubeDir) * material.diffuse;
219
+ vec3 normalMC = normalize(model_iblReferenceFrameMatrix * normalEC);
220
+ vec3 irradiance = sampleDiffuseEnvironment(normalMC);
221
+
222
+ vec3 averageFresnel = f0 + (1.0 - f0) / 21.0;
223
+ float Ems = specularWeight * (1.0 - brdfLut.x - brdfLut.y);
224
+ vec3 FmsEms = FssEss * averageFresnel * Ems / (1.0 - averageFresnel * Ems);
225
+ vec3 dielectricScattering = (1.0 - FssEss - FmsEms) * material.diffuse;
226
+ vec3 diffuseContribution = irradiance * (FmsEms + dielectricScattering);
210
227
  #else
211
- vec3 diffuseContribution = vec3(0.0);
228
+ vec3 diffuseContribution = vec3(0.0);
212
229
  #endif
213
230
 
214
- float roughness = material.roughness;
215
-
216
231
  #ifdef USE_ANISOTROPY
217
- // Update environment map sampling direction to account for anisotropic distortion of specular reflection
232
+ // Bend normal to account for anisotropic distortion of specular reflection
218
233
  vec3 anisotropyDirection = material.anisotropicB;
219
234
  vec3 anisotropicTangent = cross(anisotropyDirection, viewDirectionEC);
220
235
  vec3 anisotropicNormal = cross(anisotropicTangent, anisotropyDirection);
221
236
  float bendFactor = 1.0 - material.anisotropyStrength * (1.0 - roughness);
222
237
  float bendFactorPow4 = bendFactor * bendFactor * bendFactor * bendFactor;
223
238
  vec3 bentNormal = normalize(mix(anisotropicNormal, normalEC, bendFactorPow4));
224
- cubeDir = normalize(model_iblReferenceFrameMatrix * normalize(reflect(-viewDirectionEC, bentNormal)));
239
+ vec3 reflectEC = reflect(-viewDirectionEC, bentNormal);
240
+ #else
241
+ vec3 reflectEC = reflect(-viewDirectionEC, normalEC);
225
242
  #endif
226
243
 
227
244
  #ifdef SPECULAR_IBL
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);
245
+ vec3 reflectMC = normalize(model_iblReferenceFrameMatrix * reflectEC);
246
+ vec3 radiance = sampleSpecularEnvironment(reflectMC, roughness);
247
+ vec3 specularContribution = radiance * FssEss;
233
248
  #else
234
- vec3 specularContribution = vec3(0.0);
235
- #endif
236
-
237
- #ifdef USE_SPECULAR
238
- specularContribution *= material.specularWeight;
249
+ vec3 specularContribution = vec3(0.0);
239
250
  #endif
240
251
 
241
252
  return diffuseContribution + specularContribution;
@@ -17,10 +17,10 @@ vec3 getProceduralSkyMetrics(vec3 positionWC, vec3 reflectionWC)\n\
17
17
  }\n\
18
18
  \n\
19
19
  /**\n\
20
- * Compute the diffuse irradiance for a procedural sky lighting model\n\
20
+ * Compute the diffuse irradiance for a procedural sky lighting model.\n\
21
21
  *\n\
22
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\
23
+ * @return {vec3} The computed diffuse irradiance.\n\
24
24
  */\n\
25
25
  vec3 getProceduralDiffuseIrradiance(vec3 skyMetrics)\n\
26
26
  {\n\
@@ -31,10 +31,12 @@ vec3 getProceduralDiffuseIrradiance(vec3 skyMetrics)\n\
31
31
  }\n\
32
32
  \n\
33
33
  /**\n\
34
- * Compute the specular irradiance for a procedural sky lighting model\n\
34
+ * Compute the specular irradiance for a procedural sky lighting model.\n\
35
35
  *\n\
36
+ * @param {vec3} reflectionWC The reflection vector in world coordinates.\n\
36
37
  * @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
+ * @param {float} roughness The roughness of the material.\n\
39
+ * @return {vec3} The computed specular irradiance.\n\
38
40
  */\n\
39
41
  vec3 getProceduralSpecularIrradiance(vec3 reflectionWC, vec3 skyMetrics, float roughness)\n\
40
42
  {\n\
@@ -43,7 +45,7 @@ vec3 getProceduralSpecularIrradiance(vec3 reflectionWC, vec3 skyMetrics, float r
43
45
  reflectionWC = -normalize(czm_temeToPseudoFixed * reflectionWC);\n\
44
46
  reflectionWC.x = -reflectionWC.x;\n\
45
47
  \n\
46
- float inverseRoughness = 1.04 - roughness;\n\
48
+ float inverseRoughness = 1.0 - roughness;\n\
47
49
  inverseRoughness *= inverseRoughness;\n\
48
50
  vec3 sceneSkyBox = czm_textureCube(czm_environmentMap, reflectionWC).rgb * inverseRoughness;\n\
49
51
  \n\
@@ -122,7 +124,7 @@ float getSunLuminance(vec3 positionWC, vec3 normalEC, vec3 lightDirectionEC)\n\
122
124
  ) {\n\
123
125
  vec3 viewDirectionEC = -normalize(positionEC);\n\
124
126
  vec3 positionWC = vec3(czm_inverseView * vec4(positionEC, 1.0));\n\
125
- vec3 reflectionWC = normalize(czm_inverseViewRotation * normalize(reflect(viewDirectionEC, normalEC)));\n\
127
+ vec3 reflectionWC = normalize(czm_inverseViewRotation * reflect(viewDirectionEC, normalEC));\n\
126
128
  vec3 skyMetrics = getProceduralSkyMetrics(positionWC, reflectionWC);\n\
127
129
  \n\
128
130
  float roughness = material.roughness;\n\
@@ -151,7 +153,7 @@ float getSunLuminance(vec3 positionWC, vec3 normalEC, vec3 lightDirectionEC)\n\
151
153
  }\n\
152
154
  \n\
153
155
  #ifdef DIFFUSE_IBL\n\
154
- vec3 computeDiffuseIBL(vec3 cubeDir)\n\
156
+ vec3 sampleDiffuseEnvironment(vec3 cubeDir)\n\
155
157
  {\n\
156
158
  #ifdef CUSTOM_SPHERICAL_HARMONICS\n\
157
159
  return czm_sphericalHarmonics(cubeDir, model_sphericalHarmonicCoefficients); \n\
@@ -165,20 +167,19 @@ vec3 computeDiffuseIBL(vec3 cubeDir)\n\
165
167
  vec3 sampleSpecularEnvironment(vec3 cubeDir, float roughness)\n\
166
168
  {\n\
167
169
  #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\
170
+ float lod = roughness * model_specularEnvironmentMapsMaximumLOD;\n\
171
+ return czm_textureCube(model_specularEnvironmentMaps, cubeDir, lod).rgb;\n\
171
172
  #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\
173
+ float lod = roughness * czm_specularEnvironmentMapsMaximumLOD;\n\
174
+ return czm_textureCube(czm_specularEnvironmentMaps, cubeDir, lod).rgb;\n\
175
175
  #endif\n\
176
176
  }\n\
177
- vec3 computeSpecularIBL(vec3 cubeDir, float NdotV, float VdotH, vec3 f0, float roughness)\n\
177
+ vec3 computeSpecularIBL(vec3 cubeDir, float NdotV, vec3 f0, float roughness)\n\
178
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\
179
+ // see https://bruop.github.io/ibl/ at Single Scattering Results\n\
180
+ // Roughness dependent fresnel, from Fdez-Aguera\n\
181
+ vec3 f90 = max(vec3(1.0 - roughness), f0);\n\
182
+ vec3 F = fresnelSchlick2(f0, f90, NdotV);\n\
182
183
  \n\
183
184
  vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, roughness)).rg;\n\
184
185
  vec3 specularSample = sampleSpecularEnvironment(cubeDir, roughness);\n\
@@ -189,54 +190,64 @@ vec3 computeSpecularIBL(vec3 cubeDir, float NdotV, float VdotH, vec3 f0, float r
189
190
  \n\
190
191
  #if defined(DIFFUSE_IBL) || defined(SPECULAR_IBL)\n\
191
192
  /**\n\
192
- * Compute the light contributions from environment maps and spherical harmonic coefficients\n\
193
+ * Compute the light contributions from environment maps and spherical harmonic coefficients.\n\
194
+ * See Fdez-Aguera, https://www.jcgt.org/published/0008/01/03/paper.pdf, for explanation\n\
195
+ * of the single- and multi-scattering terms.\n\
193
196
  *\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 {vec3} viewDirectionEC Unit vector pointing from the fragment to the eye position.\n\
198
+ * @param {vec3} normalEC The surface normal in eye coordinates.\n\
197
199
  * @param {czm_modelMaterial} The material properties.\n\
198
- * @return {vec3} The computed HDR color\n\
200
+ * @return {vec3} The computed HDR color.\n\
199
201
  */\n\
200
- vec3 textureIBL(\n\
201
- vec3 viewDirectionEC,\n\
202
- vec3 normalEC,\n\
203
- vec3 lightDirectionEC,\n\
204
- czm_modelMaterial material\n\
205
- ) {\n\
206
- // Find the direction in which to sample the environment map\n\
207
- vec3 cubeDir = normalize(model_iblReferenceFrameMatrix * normalize(reflect(-viewDirectionEC, normalEC)));\n\
202
+ vec3 textureIBL(vec3 viewDirectionEC, vec3 normalEC, czm_modelMaterial material) {\n\
203
+ vec3 f0 = material.specular;\n\
204
+ float roughness = material.roughness;\n\
205
+ float specularWeight = 1.0;\n\
206
+ #ifdef USE_SPECULAR\n\
207
+ specularWeight = material.specularWeight;\n\
208
+ #endif\n\
209
+ float NdotV = clamp(dot(normalEC, viewDirectionEC), 0.0, 1.0);\n\
210
+ \n\
211
+ // see https://bruop.github.io/ibl/ at Single Scattering Results\n\
212
+ // Roughness dependent fresnel, from Fdez-Aguera\n\
213
+ vec3 f90 = max(vec3(1.0 - roughness), f0);\n\
214
+ vec3 singleScatterFresnel = fresnelSchlick2(f0, f90, NdotV);\n\
215
+ \n\
216
+ vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, roughness)).rg;\n\
217
+ vec3 FssEss = specularWeight * (singleScatterFresnel * brdfLut.x + brdfLut.y);\n\
208
218
  \n\
209
219
  #ifdef DIFFUSE_IBL\n\
210
- vec3 diffuseContribution = computeDiffuseIBL(cubeDir) * material.diffuse;\n\
220
+ vec3 normalMC = normalize(model_iblReferenceFrameMatrix * normalEC);\n\
221
+ vec3 irradiance = sampleDiffuseEnvironment(normalMC);\n\
222
+ \n\
223
+ vec3 averageFresnel = f0 + (1.0 - f0) / 21.0;\n\
224
+ float Ems = specularWeight * (1.0 - brdfLut.x - brdfLut.y);\n\
225
+ vec3 FmsEms = FssEss * averageFresnel * Ems / (1.0 - averageFresnel * Ems);\n\
226
+ vec3 dielectricScattering = (1.0 - FssEss - FmsEms) * material.diffuse;\n\
227
+ vec3 diffuseContribution = irradiance * (FmsEms + dielectricScattering);\n\
211
228
  #else\n\
212
- vec3 diffuseContribution = vec3(0.0); \n\
229
+ vec3 diffuseContribution = vec3(0.0);\n\
213
230
  #endif\n\
214
- \n\
215
- float roughness = material.roughness;\n\
216
231
  \n\
217
232
  #ifdef USE_ANISOTROPY\n\
218
- // Update environment map sampling direction to account for anisotropic distortion of specular reflection\n\
233
+ // Bend normal to account for anisotropic distortion of specular reflection\n\
219
234
  vec3 anisotropyDirection = material.anisotropicB;\n\
220
235
  vec3 anisotropicTangent = cross(anisotropyDirection, viewDirectionEC);\n\
221
236
  vec3 anisotropicNormal = cross(anisotropicTangent, anisotropyDirection);\n\
222
237
  float bendFactor = 1.0 - material.anisotropyStrength * (1.0 - roughness);\n\
223
238
  float bendFactorPow4 = bendFactor * bendFactor * bendFactor * bendFactor;\n\
224
239
  vec3 bentNormal = normalize(mix(anisotropicNormal, normalEC, bendFactorPow4));\n\
225
- cubeDir = normalize(model_iblReferenceFrameMatrix * normalize(reflect(-viewDirectionEC, bentNormal)));\n\
240
+ vec3 reflectEC = reflect(-viewDirectionEC, bentNormal);\n\
241
+ #else\n\
242
+ vec3 reflectEC = reflect(-viewDirectionEC, normalEC);\n\
226
243
  #endif\n\
227
244
  \n\
228
245
  #ifdef SPECULAR_IBL\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\
246
+ vec3 reflectMC = normalize(model_iblReferenceFrameMatrix * reflectEC);\n\
247
+ vec3 radiance = sampleSpecularEnvironment(reflectMC, roughness);\n\
248
+ vec3 specularContribution = radiance * FssEss;\n\
234
249
  #else\n\
235
- vec3 specularContribution = vec3(0.0); \n\
236
- #endif\n\
237
- \n\
238
- #ifdef USE_SPECULAR\n\
239
- specularContribution *= material.specularWeight;\n\
250
+ vec3 specularContribution = vec3(0.0);\n\
240
251
  #endif\n\
241
252
  \n\
242
253
  return diffuseContribution + specularContribution;\n\