@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
@@ -16,211 +16,482 @@ vec2 computeTextureTransform(vec2 texCoord, mat3 textureTransform)
16
16
  return vec2(textureTransform * vec3(texCoord, 1.0));
17
17
  }
18
18
 
19
- #ifdef HAS_NORMALS
20
- vec3 computeNormal(ProcessedAttributes attributes)
19
+ #ifdef HAS_NORMAL_TEXTURE
20
+ vec2 getNormalTexCoords()
21
21
  {
22
- // Geometry normal. This is already normalized
23
- vec3 ng = attributes.normalEC;
22
+ vec2 texCoord = TEXCOORD_NORMAL;
23
+ #ifdef HAS_NORMAL_TEXTURE_TRANSFORM
24
+ texCoord = vec2(u_normalTextureTransform * vec3(texCoord, 1.0));
25
+ #endif
26
+ return texCoord;
27
+ }
28
+ #endif
24
29
 
25
- vec3 normal = ng;
26
- #if defined(HAS_NORMAL_TEXTURE) && !defined(HAS_WIREFRAME)
27
- vec2 normalTexCoords = TEXCOORD_NORMAL;
28
- #ifdef HAS_NORMAL_TEXTURE_TRANSFORM
29
- normalTexCoords = computeTextureTransform(normalTexCoords, u_normalTextureTransform);
30
- #endif
30
+ #if defined(HAS_NORMAL_TEXTURE) || defined(HAS_CLEARCOAT_NORMAL_TEXTURE)
31
+ vec3 computeTangent(in vec3 position, in vec2 normalTexCoords)
32
+ {
33
+ vec2 tex_dx = dFdx(normalTexCoords);
34
+ vec2 tex_dy = dFdy(normalTexCoords);
35
+ float determinant = tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y;
36
+ vec3 tangent = tex_dy.t * dFdx(position) - tex_dx.t * dFdy(position);
37
+ return tangent / determinant;
38
+ }
39
+ #endif
31
40
 
32
- // If HAS_BITANGENTS is set, then HAS_TANGENTS is also set
33
- #ifdef HAS_BITANGENTS
34
- vec3 t = attributes.tangentEC;
35
- vec3 b = attributes.bitangentEC;
36
- mat3 tbn = mat3(t, b, ng);
37
- vec3 n = texture(u_normalTexture, normalTexCoords).rgb;
38
- normal = normalize(tbn * (2.0 * n - 1.0));
39
- #elif (__VERSION__ == 300 || defined(GL_OES_standard_derivatives))
40
- // If derivatives are available (not IE 10), compute tangents
41
- vec3 positionEC = attributes.positionEC;
42
- vec3 pos_dx = dFdx(positionEC);
43
- vec3 pos_dy = dFdy(positionEC);
44
- vec3 tex_dx = dFdx(vec3(normalTexCoords,0.0));
45
- vec3 tex_dy = dFdy(vec3(normalTexCoords,0.0));
46
- vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
47
- t = normalize(t - ng * dot(ng, t));
48
- vec3 b = normalize(cross(ng, t));
49
- mat3 tbn = mat3(t, b, ng);
50
- vec3 n = texture(u_normalTexture, normalTexCoords).rgb;
51
- normal = normalize(tbn * (2.0 * n - 1.0));
41
+ #ifdef USE_ANISOTROPY
42
+ struct NormalInfo {
43
+ vec3 tangent;
44
+ vec3 bitangent;
45
+ vec3 normal;
46
+ vec3 geometryNormal;
47
+ };
48
+
49
+ NormalInfo getNormalInfo(ProcessedAttributes attributes)
50
+ {
51
+ vec3 geometryNormal = attributes.normalEC;
52
+ #ifdef HAS_NORMAL_TEXTURE
53
+ vec2 normalTexCoords = getNormalTexCoords();
54
+ #endif
55
+
56
+ #ifdef HAS_BITANGENTS
57
+ vec3 tangent = attributes.tangentEC;
58
+ vec3 bitangent = attributes.bitangentEC;
59
+ #else // Assume HAS_NORMAL_TEXTURE
60
+ vec3 tangent = computeTangent(attributes.positionEC, normalTexCoords);
61
+ tangent = normalize(tangent - geometryNormal * dot(geometryNormal, tangent));
62
+ vec3 bitangent = normalize(cross(geometryNormal, tangent));
63
+ #endif
64
+
65
+ #ifdef HAS_NORMAL_TEXTURE
66
+ mat3 tbn = mat3(tangent, bitangent, geometryNormal);
67
+ vec3 normalSample = texture(u_normalTexture, normalTexCoords).rgb;
68
+ normalSample = 2.0 * normalSample - 1.0;
69
+ #ifdef HAS_NORMAL_TEXTURE_SCALE
70
+ normalSample.xy *= u_normalTextureScale;
52
71
  #endif
72
+ vec3 normal = normalize(tbn * normalSample);
73
+ #else
74
+ vec3 normal = geometryNormal;
53
75
  #endif
54
76
 
55
77
  #ifdef HAS_DOUBLE_SIDED_MATERIAL
56
- if (czm_backFacing()) {
57
- normal = -normal;
58
- }
78
+ if (czm_backFacing()) {
79
+ tangent *= -1.0;
80
+ bitangent *= -1.0;
81
+ normal *= -1.0;
82
+ geometryNormal *= -1.0;
83
+ }
59
84
  #endif
60
85
 
61
- return normal;
86
+ NormalInfo normalInfo;
87
+ normalInfo.tangent = tangent;
88
+ normalInfo.bitangent = bitangent;
89
+ normalInfo.normal = normal;
90
+ normalInfo.geometryNormal = geometryNormal;
91
+
92
+ return normalInfo;
62
93
  }
63
94
  #endif
64
95
 
65
- void materialStage(inout czm_modelMaterial material, ProcessedAttributes attributes, SelectedFeature feature)
96
+ #if defined(HAS_NORMAL_TEXTURE) && !defined(HAS_WIREFRAME)
97
+ vec3 getNormalFromTexture(ProcessedAttributes attributes, vec3 geometryNormal)
66
98
  {
67
- #ifdef HAS_NORMALS
68
- material.normalEC = computeNormal(attributes);
99
+ vec2 normalTexCoords = getNormalTexCoords();
100
+
101
+ // If HAS_BITANGENTS is set, then HAS_TANGENTS is also set
102
+ #ifdef HAS_BITANGENTS
103
+ vec3 t = attributes.tangentEC;
104
+ vec3 b = attributes.bitangentEC;
105
+ #else
106
+ vec3 t = computeTangent(attributes.positionEC, normalTexCoords);
107
+ t = normalize(t - geometryNormal * dot(geometryNormal, t));
108
+ vec3 b = normalize(cross(geometryNormal, t));
69
109
  #endif
70
110
 
71
- vec4 baseColorWithAlpha = vec4(1.0);
72
- // Regardless of whether we use PBR, set a base color
73
- #ifdef HAS_BASE_COLOR_TEXTURE
74
- vec2 baseColorTexCoords = TEXCOORD_BASE_COLOR;
111
+ mat3 tbn = mat3(t, b, geometryNormal);
112
+ vec3 normalSample = texture(u_normalTexture, normalTexCoords).rgb;
113
+ normalSample = 2.0 * normalSample - 1.0;
114
+ #ifdef HAS_NORMAL_TEXTURE_SCALE
115
+ normalSample.xy *= u_normalTextureScale;
116
+ #endif
117
+ return normalize(tbn * normalSample);
118
+ }
119
+ #endif
75
120
 
76
- #ifdef HAS_BASE_COLOR_TEXTURE_TRANSFORM
77
- baseColorTexCoords = computeTextureTransform(baseColorTexCoords, u_baseColorTextureTransform);
78
- #endif
121
+ #ifdef HAS_CLEARCOAT_NORMAL_TEXTURE
122
+ vec3 getClearcoatNormalFromTexture(ProcessedAttributes attributes, vec3 geometryNormal)
123
+ {
124
+ vec2 normalTexCoords = TEXCOORD_CLEARCOAT_NORMAL;
125
+ #ifdef HAS_CLEARCOAT_NORMAL_TEXTURE_TRANSFORM
126
+ normalTexCoords = vec2(u_clearcoatNormalTextureTransform * vec3(normalTexCoords, 1.0));
127
+ #endif
79
128
 
80
- baseColorWithAlpha = czm_srgbToLinear(texture(u_baseColorTexture, baseColorTexCoords));
129
+ // If HAS_BITANGENTS is set, then HAS_TANGENTS is also set
130
+ #ifdef HAS_BITANGENTS
131
+ vec3 t = attributes.tangentEC;
132
+ vec3 b = attributes.bitangentEC;
133
+ #else
134
+ vec3 t = computeTangent(attributes.positionEC, normalTexCoords);
135
+ t = normalize(t - geometryNormal * dot(geometryNormal, t));
136
+ vec3 b = normalize(cross(geometryNormal, t));
137
+ #endif
81
138
 
82
- #ifdef HAS_BASE_COLOR_FACTOR
83
- baseColorWithAlpha *= u_baseColorFactor;
84
- #endif
85
- #elif defined(HAS_BASE_COLOR_FACTOR)
86
- baseColorWithAlpha = u_baseColorFactor;
139
+ mat3 tbn = mat3(t, b, geometryNormal);
140
+ vec3 normalSample = texture(u_clearcoatNormalTexture, normalTexCoords).rgb;
141
+ normalSample = 2.0 * normalSample - 1.0;
142
+ #ifdef HAS_CLEARCOAT_NORMAL_TEXTURE_SCALE
143
+ normalSample.xy *= u_clearcoatNormalTextureScale;
87
144
  #endif
145
+ return normalize(tbn * normalSample);
146
+ }
147
+ #endif
88
148
 
89
- #ifdef HAS_POINT_CLOUD_COLOR_STYLE
90
- baseColorWithAlpha = v_pointCloudColor;
91
- #elif defined(HAS_COLOR_0)
92
- vec4 color = attributes.color_0;
93
- // .pnts files store colors in the sRGB color space
94
- #ifdef HAS_SRGB_COLOR
95
- color = czm_srgbToLinear(color);
96
- #endif
97
- baseColorWithAlpha *= color;
149
+ #ifdef HAS_NORMALS
150
+ vec3 computeNormal(ProcessedAttributes attributes)
151
+ {
152
+ // Geometry normal. This is already normalized
153
+ vec3 normal = attributes.normalEC;
154
+
155
+ #if defined(HAS_NORMAL_TEXTURE) && !defined(HAS_WIREFRAME)
156
+ normal = getNormalFromTexture(attributes, normal);
98
157
  #endif
99
158
 
100
- material.diffuse = baseColorWithAlpha.rgb;
101
- material.alpha = baseColorWithAlpha.a;
159
+ #ifdef HAS_DOUBLE_SIDED_MATERIAL
160
+ if (czm_backFacing()) {
161
+ normal = -normal;
162
+ }
163
+ #endif
102
164
 
103
- #ifdef USE_CPU_STYLING
104
- material.diffuse = blend(material.diffuse, feature.color.rgb, model_colorBlend);
165
+ return normal;
166
+ }
167
+ #endif
168
+
169
+ #ifdef HAS_BASE_COLOR_TEXTURE
170
+ vec4 getBaseColorFromTexture()
171
+ {
172
+ vec2 baseColorTexCoords = TEXCOORD_BASE_COLOR;
173
+ #ifdef HAS_BASE_COLOR_TEXTURE_TRANSFORM
174
+ baseColorTexCoords = computeTextureTransform(baseColorTexCoords, u_baseColorTextureTransform);
105
175
  #endif
106
176
 
107
- #ifdef HAS_OCCLUSION_TEXTURE
108
- vec2 occlusionTexCoords = TEXCOORD_OCCLUSION;
109
- #ifdef HAS_OCCLUSION_TEXTURE_TRANSFORM
110
- occlusionTexCoords = computeTextureTransform(occlusionTexCoords, u_occlusionTextureTransform);
111
- #endif
112
- material.occlusion = texture(u_occlusionTexture, occlusionTexCoords).r;
177
+ vec4 baseColorWithAlpha = czm_srgbToLinear(texture(u_baseColorTexture, baseColorTexCoords));
178
+
179
+ #ifdef HAS_BASE_COLOR_FACTOR
180
+ baseColorWithAlpha *= u_baseColorFactor;
113
181
  #endif
114
182
 
115
- #ifdef HAS_EMISSIVE_TEXTURE
183
+ return baseColorWithAlpha;
184
+ }
185
+ #endif
186
+
187
+ #ifdef HAS_EMISSIVE_TEXTURE
188
+ vec3 getEmissiveFromTexture()
189
+ {
116
190
  vec2 emissiveTexCoords = TEXCOORD_EMISSIVE;
117
- #ifdef HAS_EMISSIVE_TEXTURE_TRANSFORM
191
+ #ifdef HAS_EMISSIVE_TEXTURE_TRANSFORM
118
192
  emissiveTexCoords = computeTextureTransform(emissiveTexCoords, u_emissiveTextureTransform);
119
- #endif
193
+ #endif
120
194
 
121
195
  vec3 emissive = czm_srgbToLinear(texture(u_emissiveTexture, emissiveTexCoords).rgb);
122
- #ifdef HAS_EMISSIVE_FACTOR
196
+ #ifdef HAS_EMISSIVE_FACTOR
123
197
  emissive *= u_emissiveFactor;
124
- #endif
125
- material.emissive = emissive;
126
- #elif defined(HAS_EMISSIVE_FACTOR)
127
- material.emissive = u_emissiveFactor;
128
198
  #endif
129
199
 
130
- #if defined(LIGHTING_PBR) && defined(USE_SPECULAR_GLOSSINESS)
131
- #ifdef HAS_SPECULAR_GLOSSINESS_TEXTURE
200
+ return emissive;
201
+ }
202
+ #endif
203
+
204
+ #if defined(LIGHTING_PBR) && defined(USE_SPECULAR_GLOSSINESS)
205
+ void setSpecularGlossiness(inout czm_modelMaterial material)
206
+ {
207
+ #ifdef HAS_SPECULAR_GLOSSINESS_TEXTURE
132
208
  vec2 specularGlossinessTexCoords = TEXCOORD_SPECULAR_GLOSSINESS;
133
- #ifdef HAS_SPECULAR_GLOSSINESS_TEXTURE_TRANSFORM
134
- specularGlossinessTexCoords = computeTextureTransform(specularGlossinessTexCoords, u_specularGlossinessTextureTransform);
135
- #endif
209
+ #ifdef HAS_SPECULAR_GLOSSINESS_TEXTURE_TRANSFORM
210
+ specularGlossinessTexCoords = computeTextureTransform(specularGlossinessTexCoords, u_specularGlossinessTextureTransform);
211
+ #endif
136
212
 
137
213
  vec4 specularGlossiness = czm_srgbToLinear(texture(u_specularGlossinessTexture, specularGlossinessTexCoords));
138
214
  vec3 specular = specularGlossiness.rgb;
139
215
  float glossiness = specularGlossiness.a;
140
- #ifdef HAS_SPECULAR_FACTOR
141
- specular *= u_specularFactor;
142
- #endif
216
+ #ifdef HAS_LEGACY_SPECULAR_FACTOR
217
+ specular *= u_legacySpecularFactor;
218
+ #endif
143
219
 
144
- #ifdef HAS_GLOSSINESS_FACTOR
220
+ #ifdef HAS_GLOSSINESS_FACTOR
145
221
  glossiness *= u_glossinessFactor;
146
- #endif
222
+ #endif
223
+ #else
224
+ #ifdef HAS_LEGACY_SPECULAR_FACTOR
225
+ vec3 specular = clamp(u_legacySpecularFactor, vec3(0.0), vec3(1.0));
147
226
  #else
148
- #ifdef HAS_SPECULAR_FACTOR
149
- vec3 specular = clamp(u_specularFactor, vec3(0.0), vec3(1.0));
150
- #else
151
227
  vec3 specular = vec3(1.0);
152
- #endif
228
+ #endif
153
229
 
154
- #ifdef HAS_GLOSSINESS_FACTOR
230
+ #ifdef HAS_GLOSSINESS_FACTOR
155
231
  float glossiness = clamp(u_glossinessFactor, 0.0, 1.0);
156
- #else
232
+ #else
157
233
  float glossiness = 1.0;
158
- #endif
159
234
  #endif
235
+ #endif
160
236
 
161
- #ifdef HAS_DIFFUSE_TEXTURE
237
+ #ifdef HAS_DIFFUSE_TEXTURE
162
238
  vec2 diffuseTexCoords = TEXCOORD_DIFFUSE;
163
- #ifdef HAS_DIFFUSE_TEXTURE_TRANSFORM
239
+ #ifdef HAS_DIFFUSE_TEXTURE_TRANSFORM
164
240
  diffuseTexCoords = computeTextureTransform(diffuseTexCoords, u_diffuseTextureTransform);
165
- #endif
241
+ #endif
166
242
 
167
243
  vec4 diffuse = czm_srgbToLinear(texture(u_diffuseTexture, diffuseTexCoords));
168
- #ifdef HAS_DIFFUSE_FACTOR
244
+ #ifdef HAS_DIFFUSE_FACTOR
169
245
  diffuse *= u_diffuseFactor;
170
- #endif
171
- #elif defined(HAS_DIFFUSE_FACTOR)
246
+ #endif
247
+ #elif defined(HAS_DIFFUSE_FACTOR)
172
248
  vec4 diffuse = clamp(u_diffuseFactor, vec4(0.0), vec4(1.0));
173
- #else
249
+ #else
174
250
  vec4 diffuse = vec4(1.0);
175
- #endif
176
- czm_pbrParameters parameters = czm_pbrSpecularGlossinessMaterial(
177
- diffuse.rgb,
178
- specular,
179
- glossiness
180
- );
181
- material.diffuse = parameters.diffuseColor;
251
+ #endif
252
+
253
+ material.diffuse = diffuse.rgb * (1.0 - czm_maximumComponent(specular));
182
254
  // the specular glossiness extension's alpha overrides anything set
183
255
  // by the base material.
184
256
  material.alpha = diffuse.a;
185
- material.specular = parameters.f0;
186
- material.roughness = parameters.roughness;
187
- #elif defined(LIGHTING_PBR)
188
- #ifdef HAS_METALLIC_ROUGHNESS_TEXTURE
257
+
258
+ material.specular = specular;
259
+
260
+ // glossiness is the opposite of roughness, but easier for artists to use.
261
+ float roughness = 1.0 - glossiness;
262
+ material.roughness = roughness * roughness;
263
+ }
264
+ #elif defined(LIGHTING_PBR)
265
+ float setMetallicRoughness(inout czm_modelMaterial material)
266
+ {
267
+ #ifdef HAS_METALLIC_ROUGHNESS_TEXTURE
189
268
  vec2 metallicRoughnessTexCoords = TEXCOORD_METALLIC_ROUGHNESS;
190
- #ifdef HAS_METALLIC_ROUGHNESS_TEXTURE_TRANSFORM
269
+ #ifdef HAS_METALLIC_ROUGHNESS_TEXTURE_TRANSFORM
191
270
  metallicRoughnessTexCoords = computeTextureTransform(metallicRoughnessTexCoords, u_metallicRoughnessTextureTransform);
192
- #endif
271
+ #endif
193
272
 
194
273
  vec3 metallicRoughness = texture(u_metallicRoughnessTexture, metallicRoughnessTexCoords).rgb;
195
274
  float metalness = clamp(metallicRoughness.b, 0.0, 1.0);
196
275
  float roughness = clamp(metallicRoughness.g, 0.04, 1.0);
197
- #ifdef HAS_METALLIC_FACTOR
198
- metalness *= u_metallicFactor;
199
- #endif
276
+ #ifdef HAS_METALLIC_FACTOR
277
+ metalness = clamp(metalness * u_metallicFactor, 0.0, 1.0);
278
+ #endif
200
279
 
201
- #ifdef HAS_ROUGHNESS_FACTOR
202
- roughness *= u_roughnessFactor;
203
- #endif
204
- #else
205
- #ifdef HAS_METALLIC_FACTOR
280
+ #ifdef HAS_ROUGHNESS_FACTOR
281
+ roughness = clamp(roughness * u_roughnessFactor, 0.0, 1.0);
282
+ #endif
283
+ #else
284
+ #ifdef HAS_METALLIC_FACTOR
206
285
  float metalness = clamp(u_metallicFactor, 0.0, 1.0);
207
- #else
286
+ #else
208
287
  float metalness = 1.0;
209
- #endif
288
+ #endif
210
289
 
211
- #ifdef HAS_ROUGHNESS_FACTOR
290
+ #ifdef HAS_ROUGHNESS_FACTOR
212
291
  float roughness = clamp(u_roughnessFactor, 0.04, 1.0);
213
- #else
292
+ #else
214
293
  float roughness = 1.0;
215
- #endif
216
- #endif
217
- czm_pbrParameters parameters = czm_pbrMetallicRoughnessMaterial(
218
- material.diffuse,
219
- metalness,
220
- roughness
221
- );
222
- material.diffuse = parameters.diffuseColor;
223
- material.specular = parameters.f0;
224
- material.roughness = parameters.roughness;
294
+ #endif
295
+ #endif
296
+
297
+ // dielectrics use f0 = 0.04, metals use albedo as f0
298
+ const vec3 REFLECTANCE_DIELECTRIC = vec3(0.04);
299
+ vec3 f0 = mix(REFLECTANCE_DIELECTRIC, material.baseColor.rgb, metalness);
300
+
301
+ material.specular = f0;
302
+
303
+ // diffuse only applies to dielectrics.
304
+ material.diffuse = mix(material.baseColor.rgb, vec3(0.0), metalness);
305
+
306
+ // roughness is authored as perceptual roughness
307
+ // square it to get material roughness
308
+ material.roughness = roughness * roughness;
309
+
310
+ return metalness;
311
+ }
312
+ #ifdef USE_SPECULAR
313
+ void setSpecular(inout czm_modelMaterial material, in float metalness)
314
+ {
315
+ #ifdef HAS_SPECULAR_TEXTURE
316
+ vec2 specularTexCoords = TEXCOORD_SPECULAR;
317
+ #ifdef HAS_SPECULAR_TEXTURE_TRANSFORM
318
+ specularTexCoords = computeTextureTransform(specularTexCoords, u_specularTextureTransform);
319
+ #endif
320
+ float specularWeight = texture(u_specularTexture, specularTexCoords).a;
321
+ #ifdef HAS_SPECULAR_FACTOR
322
+ specularWeight *= u_specularFactor;
323
+ #endif
324
+ #else
325
+ #ifdef HAS_SPECULAR_FACTOR
326
+ float specularWeight = u_specularFactor;
327
+ #else
328
+ float specularWeight = 1.0;
329
+ #endif
330
+ #endif
331
+
332
+ #ifdef HAS_SPECULAR_COLOR_TEXTURE
333
+ vec2 specularColorTexCoords = TEXCOORD_SPECULAR_COLOR;
334
+ #ifdef HAS_SPECULAR_COLOR_TEXTURE_TRANSFORM
335
+ specularColorTexCoords = computeTextureTransform(specularColorTexCoords, u_specularColorTextureTransform);
336
+ #endif
337
+ vec3 specularColorSample = texture(u_specularColorTexture, specularColorTexCoords).rgb;
338
+ vec3 specularColorFactor = czm_srgbToLinear(specularColorSample);
339
+ #ifdef HAS_SPECULAR_COLOR_FACTOR
340
+ specularColorFactor *= u_specularColorFactor;
341
+ #endif
342
+ #else
343
+ #ifdef HAS_SPECULAR_COLOR_FACTOR
344
+ vec3 specularColorFactor = u_specularColorFactor;
345
+ #else
346
+ vec3 specularColorFactor = vec3(1.0);
347
+ #endif
348
+ #endif
349
+ material.specularWeight = specularWeight;
350
+ vec3 f0 = material.specular;
351
+ vec3 dielectricSpecularF0 = min(f0 * specularColorFactor, vec3(1.0));
352
+ material.specular = mix(dielectricSpecularF0, material.baseColor.rgb, metalness);
353
+ }
354
+ #endif
355
+ #ifdef USE_ANISOTROPY
356
+ void setAnisotropy(inout czm_modelMaterial material, in NormalInfo normalInfo)
357
+ {
358
+ mat2 rotation = mat2(u_anisotropy.xy, -u_anisotropy.y, u_anisotropy.x);
359
+ float anisotropyStrength = u_anisotropy.z;
360
+
361
+ vec2 direction = vec2(1.0, 0.0);
362
+ #ifdef HAS_ANISOTROPY_TEXTURE
363
+ vec2 anisotropyTexCoords = TEXCOORD_ANISOTROPY;
364
+ #ifdef HAS_ANISOTROPY_TEXTURE_TRANSFORM
365
+ anisotropyTexCoords = computeTextureTransform(anisotropyTexCoords, u_anisotropyTextureTransform);
366
+ #endif
367
+ vec3 anisotropySample = texture(u_anisotropyTexture, anisotropyTexCoords).rgb;
368
+ direction = anisotropySample.rg * 2.0 - vec2(1.0);
369
+ anisotropyStrength *= anisotropySample.b;
370
+ #endif
371
+
372
+ direction = rotation * direction;
373
+ mat3 tbn = mat3(normalInfo.tangent, normalInfo.bitangent, normalInfo.normal);
374
+ vec3 anisotropicT = tbn * normalize(vec3(direction, 0.0));
375
+ vec3 anisotropicB = cross(normalInfo.geometryNormal, anisotropicT);
376
+
377
+ material.anisotropicT = anisotropicT;
378
+ material.anisotropicB = anisotropicB;
379
+ material.anisotropyStrength = anisotropyStrength;
380
+ }
381
+ #endif
382
+ #ifdef USE_CLEARCOAT
383
+ void setClearcoat(inout czm_modelMaterial material, in ProcessedAttributes attributes)
384
+ {
385
+ #ifdef HAS_CLEARCOAT_TEXTURE
386
+ vec2 clearcoatTexCoords = TEXCOORD_CLEARCOAT;
387
+ #ifdef HAS_CLEARCOAT_TEXTURE_TRANSFORM
388
+ clearcoatTexCoords = computeTextureTransform(clearcoatTexCoords, u_clearcoatTextureTransform);
389
+ #endif
390
+ float clearcoatFactor = texture(u_clearcoatTexture, clearcoatTexCoords).r;
391
+ #ifdef HAS_CLEARCOAT_FACTOR
392
+ clearcoatFactor *= u_clearcoatFactor;
393
+ #endif
394
+ #else
395
+ #ifdef HAS_CLEARCOAT_FACTOR
396
+ float clearcoatFactor = u_clearcoatFactor;
397
+ #else
398
+ // PERFORMANCE_IDEA: this case should turn the whole extension off
399
+ float clearcoatFactor = 0.0;
400
+ #endif
401
+ #endif
402
+
403
+ #ifdef HAS_CLEARCOAT_ROUGHNESS_TEXTURE
404
+ vec2 clearcoatRoughnessTexCoords = TEXCOORD_CLEARCOAT_ROUGHNESS;
405
+ #ifdef HAS_CLEARCOAT_ROUGHNESS_TEXTURE_TRANSFORM
406
+ clearcoatRoughnessTexCoords = computeTextureTransform(clearcoatRoughnessTexCoords, u_clearcoatRoughnessTextureTransform);
407
+ #endif
408
+ float clearcoatRoughness = texture(u_clearcoatRoughnessTexture, clearcoatRoughnessTexCoords).g;
409
+ #ifdef HAS_CLEARCOAT_ROUGHNESS_FACTOR
410
+ clearcoatRoughness *= u_clearcoatRoughnessFactor;
411
+ #endif
412
+ #else
413
+ #ifdef HAS_CLEARCOAT_ROUGHNESS_FACTOR
414
+ float clearcoatRoughness = u_clearcoatRoughnessFactor;
415
+ #else
416
+ float clearcoatRoughness = 0.0;
417
+ #endif
418
+ #endif
419
+
420
+ material.clearcoatFactor = clearcoatFactor;
421
+ // roughness is authored as perceptual roughness
422
+ // square it to get material roughness
423
+ material.clearcoatRoughness = clearcoatRoughness * clearcoatRoughness;
424
+ #ifdef HAS_CLEARCOAT_NORMAL_TEXTURE
425
+ material.clearcoatNormal = getClearcoatNormalFromTexture(attributes, attributes.normalEC);
426
+ #else
427
+ material.clearcoatNormal = attributes.normalEC;
428
+ #endif
429
+ }
430
+ #endif
431
+ #endif
432
+
433
+ void materialStage(inout czm_modelMaterial material, ProcessedAttributes attributes, SelectedFeature feature)
434
+ {
435
+ #ifdef USE_ANISOTROPY
436
+ NormalInfo normalInfo = getNormalInfo(attributes);
437
+ material.normalEC = normalInfo.normal;
438
+ #elif defined(HAS_NORMALS)
439
+ material.normalEC = computeNormal(attributes);
440
+ #endif
441
+
442
+ vec4 baseColorWithAlpha = vec4(1.0);
443
+ // Regardless of whether we use PBR, set a base color
444
+ #ifdef HAS_BASE_COLOR_TEXTURE
445
+ baseColorWithAlpha = getBaseColorFromTexture();
446
+ #elif defined(HAS_BASE_COLOR_FACTOR)
447
+ baseColorWithAlpha = u_baseColorFactor;
448
+ #endif
449
+
450
+ #ifdef HAS_POINT_CLOUD_COLOR_STYLE
451
+ baseColorWithAlpha = v_pointCloudColor;
452
+ #elif defined(HAS_COLOR_0)
453
+ vec4 color = attributes.color_0;
454
+ // .pnts files store colors in the sRGB color space
455
+ #ifdef HAS_SRGB_COLOR
456
+ color = czm_srgbToLinear(color);
457
+ #endif
458
+ baseColorWithAlpha *= color;
459
+ #endif
460
+
461
+ material.baseColor = baseColorWithAlpha;
462
+ material.diffuse = baseColorWithAlpha.rgb;
463
+ material.alpha = baseColorWithAlpha.a;
464
+
465
+ #ifdef USE_CPU_STYLING
466
+ material.diffuse = blend(material.diffuse, feature.color.rgb, model_colorBlend);
467
+ #endif
468
+
469
+ #ifdef HAS_OCCLUSION_TEXTURE
470
+ vec2 occlusionTexCoords = TEXCOORD_OCCLUSION;
471
+ #ifdef HAS_OCCLUSION_TEXTURE_TRANSFORM
472
+ occlusionTexCoords = computeTextureTransform(occlusionTexCoords, u_occlusionTextureTransform);
473
+ #endif
474
+ material.occlusion = texture(u_occlusionTexture, occlusionTexCoords).r;
475
+ #endif
476
+
477
+ #ifdef HAS_EMISSIVE_TEXTURE
478
+ material.emissive = getEmissiveFromTexture();
479
+ #elif defined(HAS_EMISSIVE_FACTOR)
480
+ material.emissive = u_emissiveFactor;
481
+ #endif
482
+
483
+ #if defined(LIGHTING_PBR) && defined(USE_SPECULAR_GLOSSINESS)
484
+ setSpecularGlossiness(material);
485
+ #elif defined(LIGHTING_PBR)
486
+ float metalness = setMetallicRoughness(material);
487
+ #ifdef USE_SPECULAR
488
+ setSpecular(material, metalness);
489
+ #endif
490
+ #ifdef USE_ANISOTROPY
491
+ setAnisotropy(material, normalInfo);
492
+ #endif
493
+ #ifdef USE_CLEARCOAT
494
+ setClearcoat(material, attributes);
495
+ #endif
225
496
  #endif
226
497
  }