@cesium/engine 9.0.0 → 9.2.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 (189) 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 +56 -105
  4. package/Build/Workers/{chunk-VR5RBW52.js → chunk-26NE4LRW.js} +7 -7
  5. package/Build/Workers/{chunk-P2YAAMT2.js → chunk-26XJDV3D.js} +15 -15
  6. package/Build/Workers/{chunk-L4BW3RUA.js → chunk-2TRB253J.js} +7 -7
  7. package/Build/Workers/{chunk-NP2GYYE5.js → chunk-3PV5HQ2R.js} +6 -6
  8. package/Build/Workers/{chunk-BCU2LH5T.js → chunk-3VDHTBY5.js} +10 -10
  9. package/Build/Workers/{chunk-WHUSTDIB.js → chunk-4RG6WOXH.js} +10 -10
  10. package/Build/Workers/{chunk-P4XKB3QZ.js → chunk-5OK5JFDP.js} +5 -5
  11. package/Build/Workers/{chunk-2ZBL3MVO.js → chunk-7HLZRYGD.js} +10 -12
  12. package/Build/Workers/chunk-7PFZ4Z7C.js +961 -0
  13. package/Build/Workers/{chunk-24YTYWNB.js → chunk-A5CSB5ZE.js} +11 -13
  14. package/Build/Workers/{chunk-RMOEYCZW.js → chunk-AROLUUGS.js} +2 -2
  15. package/Build/Workers/{chunk-3NCVAGDA.js → chunk-BBBTT36L.js} +14 -14
  16. package/Build/Workers/{chunk-QKBGRKKG.js → chunk-BNT2SNWU.js} +4 -4
  17. package/Build/Workers/{chunk-LQJ5FFFR.js → chunk-CFBGPZU6.js} +11 -13
  18. package/Build/Workers/{chunk-C6OI26DR.js → chunk-CVCVMOQA.js} +1 -1
  19. package/Build/Workers/{chunk-SS4ESNE3.js → chunk-DIVFF6DK.js} +2 -2
  20. package/Build/Workers/{chunk-PXB7T27O.js → chunk-EJZVBTX4.js} +6 -6
  21. package/Build/Workers/{chunk-TZORKRNK.js → chunk-EODIOQ35.js} +1 -1
  22. package/Build/Workers/{chunk-QCQUZGXI.js → chunk-ETC45PHH.js} +5 -6
  23. package/Build/Workers/{chunk-E6WXPSJS.js → chunk-G7IAO7CW.js} +7 -7
  24. package/Build/Workers/{chunk-X2F6BEPY.js → chunk-GOQEANLM.js} +16 -16
  25. package/Build/Workers/{chunk-7COR472O.js → chunk-GUFV24F4.js} +7197 -5096
  26. package/Build/Workers/{chunk-5TIV3L26.js → chunk-GX2BWBN2.js} +13 -13
  27. package/Build/Workers/{chunk-ADOVHYWO.js → chunk-GX5LMUGZ.js} +469 -6
  28. package/Build/Workers/{chunk-2632RVPI.js → chunk-I6CW7ZE5.js} +7 -7
  29. package/Build/Workers/{chunk-YDVSBWEO.js → chunk-IF2OX6R4.js} +3 -5
  30. package/Build/Workers/{chunk-RSJXEO2A.js → chunk-IXYFH7DV.js} +95 -155
  31. package/Build/Workers/{chunk-ZNVSKMQ2.js → chunk-K5F23SZO.js} +6 -6
  32. package/Build/Workers/{chunk-MWV7IZK4.js → chunk-KTZK2UDR.js} +7 -7
  33. package/Build/Workers/{chunk-HBQPB6IH.js → chunk-LZFFO4KB.js} +12 -12
  34. package/Build/Workers/{chunk-GFA4SMXV.js → chunk-OYP23VAL.js} +11 -11
  35. package/Build/Workers/{chunk-ZYPTP7GS.js → chunk-PHT53MCH.js} +11 -11
  36. package/Build/Workers/{chunk-TJBU6GML.js → chunk-PUQR43HZ.js} +6 -6
  37. package/Build/Workers/{chunk-CO35JNNE.js → chunk-QZIWFSRM.js} +4 -4
  38. package/Build/Workers/{chunk-C3XBUYBO.js → chunk-RDR4KVPA.js} +17 -17
  39. package/Build/Workers/{chunk-YV4H2Y7M.js → chunk-RRUO4QEK.js} +4 -4
  40. package/Build/Workers/{chunk-LAQP3SCC.js → chunk-RTIT7UDN.js} +2 -2
  41. package/Build/Workers/{chunk-Z7FQLK6N.js → chunk-SC3TBKST.js} +4 -4
  42. package/Build/Workers/{chunk-GXUXEOE2.js → chunk-TDIGL45B.js} +1 -1
  43. package/Build/Workers/{chunk-EOXYZ34O.js → chunk-TP4FFUAH.js} +2 -2
  44. package/Build/Workers/{chunk-N4KXMWQU.js → chunk-U2LSTOMA.js} +2 -2
  45. package/Build/Workers/{chunk-6WF3KIF5.js → chunk-U6MTSO6A.js} +47 -84
  46. package/Build/Workers/{chunk-I37B3MZ2.js → chunk-UICVDDCQ.js} +1 -1
  47. package/Build/Workers/{chunk-DPUSFA7S.js → chunk-UKJCFXVV.js} +6 -6
  48. package/Build/Workers/{chunk-EPKE7GE3.js → chunk-UYKG3UFK.js} +5 -5
  49. package/Build/Workers/{chunk-RV7ZOSS6.js → chunk-W4OS542B.js} +13 -13
  50. package/Build/Workers/{chunk-DGDUKCJJ.js → chunk-WHDEZSAL.js} +6 -6
  51. package/Build/Workers/{chunk-NZWNZA6S.js → chunk-WOYQB5HM.js} +5 -5
  52. package/Build/Workers/{chunk-M2AYBTNH.js → chunk-WP3LCUOE.js} +13 -13
  53. package/Build/Workers/{chunk-73FKKY52.js → chunk-YGNQJ4YI.js} +5 -5
  54. package/Build/Workers/{chunk-SE4PXOEA.js → chunk-YGTWKLFY.js} +19 -19
  55. package/Build/Workers/{chunk-5R6VWLMH.js → chunk-ZHJDE6JN.js} +6 -6
  56. package/Build/Workers/combineGeometry.js +22 -24
  57. package/Build/Workers/createBoxGeometry.js +16 -18
  58. package/Build/Workers/createBoxOutlineGeometry.js +14 -16
  59. package/Build/Workers/createCircleGeometry.js +24 -26
  60. package/Build/Workers/createCircleOutlineGeometry.js +17 -19
  61. package/Build/Workers/createCoplanarPolygonGeometry.js +33 -34
  62. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +29 -31
  63. package/Build/Workers/createCorridorGeometry.js +27 -29
  64. package/Build/Workers/createCorridorOutlineGeometry.js +26 -28
  65. package/Build/Workers/createCylinderGeometry.js +18 -20
  66. package/Build/Workers/createCylinderOutlineGeometry.js +16 -18
  67. package/Build/Workers/createEllipseGeometry.js +24 -26
  68. package/Build/Workers/createEllipseOutlineGeometry.js +17 -19
  69. package/Build/Workers/createEllipsoidGeometry.js +17 -19
  70. package/Build/Workers/createEllipsoidOutlineGeometry.js +16 -18
  71. package/Build/Workers/createFrustumGeometry.js +16 -18
  72. package/Build/Workers/createFrustumOutlineGeometry.js +18 -19
  73. package/Build/Workers/createGeometry.js +22 -24
  74. package/Build/Workers/createGroundPolylineGeometry.js +23 -25
  75. package/Build/Workers/createPlaneGeometry.js +14 -16
  76. package/Build/Workers/createPlaneOutlineGeometry.js +13 -15
  77. package/Build/Workers/createPolygonGeometry.js +32 -34
  78. package/Build/Workers/createPolygonOutlineGeometry.js +28 -30
  79. package/Build/Workers/createPolylineGeometry.js +23 -25
  80. package/Build/Workers/createPolylineVolumeGeometry.js +29 -31
  81. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +25 -27
  82. package/Build/Workers/createRectangleGeometry.js +27 -29
  83. package/Build/Workers/createRectangleOutlineGeometry.js +18 -20
  84. package/Build/Workers/createSimplePolylineGeometry.js +21 -23
  85. package/Build/Workers/createSphereGeometry.js +17 -19
  86. package/Build/Workers/createSphereOutlineGeometry.js +16 -18
  87. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  88. package/Build/Workers/createVectorTileClampedPolylines.js +14 -16
  89. package/Build/Workers/createVectorTileGeometries.js +22 -24
  90. package/Build/Workers/createVectorTilePoints.js +12 -12
  91. package/Build/Workers/createVectorTilePolygons.js +20 -22
  92. package/Build/Workers/createVectorTilePolylines.js +14 -16
  93. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +23 -25
  94. package/Build/Workers/createVerticesFromHeightmap.js +23 -25
  95. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +19 -22
  96. package/Build/Workers/createWallGeometry.js +22 -24
  97. package/Build/Workers/createWallOutlineGeometry.js +21 -23
  98. package/Build/Workers/decodeDraco.js +11 -11
  99. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +12 -19
  100. package/Build/Workers/decodeI3S.js +10 -11
  101. package/Build/Workers/transcodeKTX2.js +44 -80
  102. package/Build/Workers/transferTypedArrayTest.js +1 -1
  103. package/Build/Workers/upsampleQuantizedTerrainMesh.js +20 -22
  104. package/Source/Core/Ion.js +1 -1
  105. package/Source/Core/Math.js +0 -5
  106. package/Source/Core/PixelFormat.js +1 -0
  107. package/Source/Core/Rectangle.js +89 -0
  108. package/Source/Core/TaskProcessor.js +19 -3
  109. package/Source/Core/sampleTerrain.js +3 -3
  110. package/Source/DataSources/DataSourceDisplay.js +5 -0
  111. package/Source/Renderer/ShaderBuilder.js +6 -3
  112. package/Source/Scene/ArcGisMapService.js +1 -1
  113. package/Source/Scene/Billboard.js +7 -5
  114. package/Source/Scene/Cesium3DTile.js +65 -0
  115. package/Source/Scene/Cesium3DTileset.js +48 -1
  116. package/Source/Scene/ClippingPolygon.js +212 -0
  117. package/Source/Scene/ClippingPolygonCollection.js +968 -0
  118. package/Source/Scene/Globe.js +14 -0
  119. package/Source/Scene/GlobeSurfaceShaderSet.js +81 -15
  120. package/Source/Scene/GlobeSurfaceTileProvider.js +81 -1
  121. package/Source/Scene/GltfLoader.js +458 -435
  122. package/Source/Scene/GltfLoaderUtil.js +3 -12
  123. package/Source/Scene/GltfPipeline/forEachTextureInMaterial.js +23 -7
  124. package/Source/Scene/GltfStructuralMetadataLoader.js +11 -9
  125. package/Source/Scene/Label.js +1 -1
  126. package/Source/Scene/Model/AlphaPipelineStage.js +1 -1
  127. package/Source/Scene/Model/GeometryPipelineStage.js +15 -43
  128. package/Source/Scene/Model/ImageBasedLightingPipelineStage.js +7 -0
  129. package/Source/Scene/Model/LightingPipelineStage.js +2 -4
  130. package/Source/Scene/Model/MaterialPipelineStage.js +346 -29
  131. package/Source/Scene/Model/Model.js +91 -3
  132. package/Source/Scene/Model/Model3DTileContent.js +21 -0
  133. package/Source/Scene/Model/ModelClippingPolygonsPipelineStage.js +92 -0
  134. package/Source/Scene/Model/ModelSceneGraph.js +5 -0
  135. package/Source/Scene/Model/ModelUtility.js +3 -0
  136. package/Source/Scene/Model/VerticalExaggerationPipelineStage.js +4 -6
  137. package/Source/Scene/ModelComponents.js +169 -1
  138. package/Source/Scene/PickDepth.js +23 -15
  139. package/Source/Scene/ResourceCache.js +41 -50
  140. package/Source/Scene/ResourceCacheKey.js +41 -53
  141. package/Source/Scene/Terrain.js +2 -2
  142. package/Source/Shaders/Builtin/CzmBuiltins.js +6 -8
  143. package/Source/Shaders/Builtin/Functions/clipPolygons.glsl +37 -0
  144. package/Source/Shaders/Builtin/Functions/clipPolygons.js +39 -0
  145. package/Source/Shaders/Builtin/Functions/maximumComponent.glsl +21 -0
  146. package/Source/Shaders/Builtin/Functions/maximumComponent.js +23 -0
  147. package/Source/Shaders/Builtin/Functions/pbrLighting.glsl +108 -44
  148. package/Source/Shaders/Builtin/Functions/pbrLighting.js +108 -44
  149. package/Source/Shaders/Builtin/Functions/unpackClippingExtents.glsl +14 -0
  150. package/Source/Shaders/Builtin/Functions/unpackClippingExtents.js +15 -0
  151. package/Source/Shaders/Builtin/Structs/modelMaterial.glsl +14 -0
  152. package/Source/Shaders/Builtin/Structs/modelMaterial.js +14 -0
  153. package/Source/Shaders/GlobeFS.glsl +13 -1
  154. package/Source/Shaders/GlobeFS.js +13 -1
  155. package/Source/Shaders/GlobeVS.glsl +32 -0
  156. package/Source/Shaders/GlobeVS.js +32 -0
  157. package/Source/Shaders/Model/GeometryStageVS.glsl +1 -1
  158. package/Source/Shaders/Model/GeometryStageVS.js +1 -1
  159. package/Source/Shaders/Model/ImageBasedLightingStageFS.glsl +211 -133
  160. package/Source/Shaders/Model/ImageBasedLightingStageFS.js +212 -133
  161. package/Source/Shaders/Model/LightingStageFS.glsl +113 -48
  162. package/Source/Shaders/Model/LightingStageFS.js +113 -48
  163. package/Source/Shaders/Model/MaterialStageFS.glsl +399 -137
  164. package/Source/Shaders/Model/MaterialStageFS.js +399 -137
  165. package/Source/Shaders/Model/ModelClippingPolygonsStageFS.glsl +6 -0
  166. package/Source/Shaders/Model/ModelClippingPolygonsStageFS.js +8 -0
  167. package/Source/Shaders/Model/ModelClippingPolygonsStageVS.glsl +27 -0
  168. package/Source/Shaders/Model/ModelClippingPolygonsStageVS.js +29 -0
  169. package/Source/Shaders/Model/ModelFS.glsl +6 -0
  170. package/Source/Shaders/Model/ModelFS.js +7 -1
  171. package/Source/Shaders/Model/ModelVS.glsl +4 -0
  172. package/Source/Shaders/Model/ModelVS.js +4 -0
  173. package/Source/Shaders/PolygonSignedDistanceFS.glsl +100 -0
  174. package/Source/Shaders/PolygonSignedDistanceFS.js +101 -0
  175. package/Source/ThirdParty/Workers/z-worker-pako.js +1 -1
  176. package/index.d.ts +230 -4
  177. package/index.js +234 -229
  178. package/package.json +1 -1
  179. package/Build/Workers/chunk-2KACWKS4.js +0 -501
  180. package/Build/Workers/chunk-2XPLH3JY.js +0 -2977
  181. package/Build/Workers/chunk-X6XOMPWL.js +0 -73
  182. package/Source/Shaders/Builtin/Functions/defaultPbrMaterial.glsl +0 -16
  183. package/Source/Shaders/Builtin/Functions/defaultPbrMaterial.js +0 -18
  184. package/Source/Shaders/Builtin/Functions/pbrMetallicRoughnessMaterial.glsl +0 -37
  185. package/Source/Shaders/Builtin/Functions/pbrMetallicRoughnessMaterial.js +0 -39
  186. package/Source/Shaders/Builtin/Functions/pbrSpecularGlossinessMaterial.glsl +0 -30
  187. package/Source/Shaders/Builtin/Functions/pbrSpecularGlossinessMaterial.js +0 -32
  188. package/Source/Shaders/Builtin/Structs/pbrParameters.glsl +0 -16
  189. package/Source/Shaders/Builtin/Structs/pbrParameters.js +0 -18
@@ -16,211 +16,473 @@ 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));
52
- #endif
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
+ vec3 normal = normalize(tbn * (2.0 * normalSample - 1.0));
69
+ #else
70
+ vec3 normal = geometryNormal;
53
71
  #endif
54
72
 
55
73
  #ifdef HAS_DOUBLE_SIDED_MATERIAL
56
- if (czm_backFacing()) {
57
- normal = -normal;
58
- }
74
+ if (czm_backFacing()) {
75
+ tangent *= -1.0;
76
+ bitangent *= -1.0;
77
+ normal *= -1.0;
78
+ geometryNormal *= -1.0;
79
+ }
59
80
  #endif
60
81
 
61
- return normal;
82
+ NormalInfo normalInfo;
83
+ normalInfo.tangent = tangent;
84
+ normalInfo.bitangent = bitangent;
85
+ normalInfo.normal = normal;
86
+ normalInfo.geometryNormal = geometryNormal;
87
+
88
+ return normalInfo;
62
89
  }
63
90
  #endif
64
91
 
65
- void materialStage(inout czm_modelMaterial material, ProcessedAttributes attributes, SelectedFeature feature)
92
+ #if defined(HAS_NORMAL_TEXTURE) && !defined(HAS_WIREFRAME)
93
+ vec3 getNormalFromTexture(ProcessedAttributes attributes, vec3 geometryNormal)
66
94
  {
67
- #ifdef HAS_NORMALS
68
- material.normalEC = computeNormal(attributes);
95
+ vec2 normalTexCoords = getNormalTexCoords();
96
+
97
+ // If HAS_BITANGENTS is set, then HAS_TANGENTS is also set
98
+ #ifdef HAS_BITANGENTS
99
+ vec3 t = attributes.tangentEC;
100
+ vec3 b = attributes.bitangentEC;
101
+ #else
102
+ vec3 t = computeTangent(attributes.positionEC, normalTexCoords);
103
+ t = normalize(t - geometryNormal * dot(geometryNormal, t));
104
+ vec3 b = normalize(cross(geometryNormal, t));
69
105
  #endif
70
106
 
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;
107
+ mat3 tbn = mat3(t, b, geometryNormal);
108
+ vec3 n = texture(u_normalTexture, normalTexCoords).rgb;
109
+ vec3 textureNormal = normalize(tbn * (2.0 * n - 1.0));
75
110
 
76
- #ifdef HAS_BASE_COLOR_TEXTURE_TRANSFORM
77
- baseColorTexCoords = computeTextureTransform(baseColorTexCoords, u_baseColorTextureTransform);
78
- #endif
111
+ return textureNormal;
112
+ }
113
+ #endif
79
114
 
80
- baseColorWithAlpha = czm_srgbToLinear(texture(u_baseColorTexture, baseColorTexCoords));
115
+ #ifdef HAS_CLEARCOAT_NORMAL_TEXTURE
116
+ vec3 getClearcoatNormalFromTexture(ProcessedAttributes attributes, vec3 geometryNormal)
117
+ {
118
+ vec2 normalTexCoords = TEXCOORD_CLEARCOAT_NORMAL;
119
+ #ifdef HAS_CLEARCOAT_NORMAL_TEXTURE_TRANSFORM
120
+ normalTexCoords = vec2(u_clearcoatNormalTextureTransform * vec3(normalTexCoords, 1.0));
121
+ #endif
81
122
 
82
- #ifdef HAS_BASE_COLOR_FACTOR
83
- baseColorWithAlpha *= u_baseColorFactor;
84
- #endif
85
- #elif defined(HAS_BASE_COLOR_FACTOR)
86
- baseColorWithAlpha = u_baseColorFactor;
123
+ // If HAS_BITANGENTS is set, then HAS_TANGENTS is also set
124
+ #ifdef HAS_BITANGENTS
125
+ vec3 t = attributes.tangentEC;
126
+ vec3 b = attributes.bitangentEC;
127
+ #else
128
+ vec3 t = computeTangent(attributes.positionEC, normalTexCoords);
129
+ t = normalize(t - geometryNormal * dot(geometryNormal, t));
130
+ vec3 b = normalize(cross(geometryNormal, t));
87
131
  #endif
88
132
 
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;
133
+ mat3 tbn = mat3(t, b, geometryNormal);
134
+ vec3 n = texture(u_clearcoatNormalTexture, normalTexCoords).rgb;
135
+ vec3 textureNormal = normalize(tbn * (2.0 * n - 1.0));
136
+
137
+ return textureNormal;
138
+ }
139
+ #endif
140
+
141
+ #ifdef HAS_NORMALS
142
+ vec3 computeNormal(ProcessedAttributes attributes)
143
+ {
144
+ // Geometry normal. This is already normalized
145
+ vec3 normal = attributes.normalEC;
146
+
147
+ #if defined(HAS_NORMAL_TEXTURE) && !defined(HAS_WIREFRAME)
148
+ normal = getNormalFromTexture(attributes, normal);
98
149
  #endif
99
150
 
100
- material.diffuse = baseColorWithAlpha.rgb;
101
- material.alpha = baseColorWithAlpha.a;
151
+ #ifdef HAS_DOUBLE_SIDED_MATERIAL
152
+ if (czm_backFacing()) {
153
+ normal = -normal;
154
+ }
155
+ #endif
102
156
 
103
- #ifdef USE_CPU_STYLING
104
- material.diffuse = blend(material.diffuse, feature.color.rgb, model_colorBlend);
157
+ return normal;
158
+ }
159
+ #endif
160
+
161
+ #ifdef HAS_BASE_COLOR_TEXTURE
162
+ vec4 getBaseColorFromTexture()
163
+ {
164
+ vec2 baseColorTexCoords = TEXCOORD_BASE_COLOR;
165
+ #ifdef HAS_BASE_COLOR_TEXTURE_TRANSFORM
166
+ baseColorTexCoords = computeTextureTransform(baseColorTexCoords, u_baseColorTextureTransform);
105
167
  #endif
106
168
 
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;
169
+ vec4 baseColorWithAlpha = czm_srgbToLinear(texture(u_baseColorTexture, baseColorTexCoords));
170
+
171
+ #ifdef HAS_BASE_COLOR_FACTOR
172
+ baseColorWithAlpha *= u_baseColorFactor;
113
173
  #endif
114
174
 
115
- #ifdef HAS_EMISSIVE_TEXTURE
175
+ return baseColorWithAlpha;
176
+ }
177
+ #endif
178
+
179
+ #ifdef HAS_EMISSIVE_TEXTURE
180
+ vec3 getEmissiveFromTexture()
181
+ {
116
182
  vec2 emissiveTexCoords = TEXCOORD_EMISSIVE;
117
- #ifdef HAS_EMISSIVE_TEXTURE_TRANSFORM
183
+ #ifdef HAS_EMISSIVE_TEXTURE_TRANSFORM
118
184
  emissiveTexCoords = computeTextureTransform(emissiveTexCoords, u_emissiveTextureTransform);
119
- #endif
185
+ #endif
120
186
 
121
187
  vec3 emissive = czm_srgbToLinear(texture(u_emissiveTexture, emissiveTexCoords).rgb);
122
- #ifdef HAS_EMISSIVE_FACTOR
188
+ #ifdef HAS_EMISSIVE_FACTOR
123
189
  emissive *= u_emissiveFactor;
124
- #endif
125
- material.emissive = emissive;
126
- #elif defined(HAS_EMISSIVE_FACTOR)
127
- material.emissive = u_emissiveFactor;
128
190
  #endif
129
191
 
130
- #if defined(LIGHTING_PBR) && defined(USE_SPECULAR_GLOSSINESS)
131
- #ifdef HAS_SPECULAR_GLOSSINESS_TEXTURE
192
+ return emissive;
193
+ }
194
+ #endif
195
+
196
+ #if defined(LIGHTING_PBR) && defined(USE_SPECULAR_GLOSSINESS)
197
+ void setSpecularGlossiness(inout czm_modelMaterial material)
198
+ {
199
+ #ifdef HAS_SPECULAR_GLOSSINESS_TEXTURE
132
200
  vec2 specularGlossinessTexCoords = TEXCOORD_SPECULAR_GLOSSINESS;
133
- #ifdef HAS_SPECULAR_GLOSSINESS_TEXTURE_TRANSFORM
134
- specularGlossinessTexCoords = computeTextureTransform(specularGlossinessTexCoords, u_specularGlossinessTextureTransform);
135
- #endif
201
+ #ifdef HAS_SPECULAR_GLOSSINESS_TEXTURE_TRANSFORM
202
+ specularGlossinessTexCoords = computeTextureTransform(specularGlossinessTexCoords, u_specularGlossinessTextureTransform);
203
+ #endif
136
204
 
137
205
  vec4 specularGlossiness = czm_srgbToLinear(texture(u_specularGlossinessTexture, specularGlossinessTexCoords));
138
206
  vec3 specular = specularGlossiness.rgb;
139
207
  float glossiness = specularGlossiness.a;
140
- #ifdef HAS_SPECULAR_FACTOR
141
- specular *= u_specularFactor;
142
- #endif
208
+ #ifdef HAS_LEGACY_SPECULAR_FACTOR
209
+ specular *= u_legacySpecularFactor;
210
+ #endif
143
211
 
144
- #ifdef HAS_GLOSSINESS_FACTOR
212
+ #ifdef HAS_GLOSSINESS_FACTOR
145
213
  glossiness *= u_glossinessFactor;
146
- #endif
214
+ #endif
215
+ #else
216
+ #ifdef HAS_LEGACY_SPECULAR_FACTOR
217
+ vec3 specular = clamp(u_legacySpecularFactor, vec3(0.0), vec3(1.0));
147
218
  #else
148
- #ifdef HAS_SPECULAR_FACTOR
149
- vec3 specular = clamp(u_specularFactor, vec3(0.0), vec3(1.0));
150
- #else
151
219
  vec3 specular = vec3(1.0);
152
- #endif
220
+ #endif
153
221
 
154
- #ifdef HAS_GLOSSINESS_FACTOR
222
+ #ifdef HAS_GLOSSINESS_FACTOR
155
223
  float glossiness = clamp(u_glossinessFactor, 0.0, 1.0);
156
- #else
224
+ #else
157
225
  float glossiness = 1.0;
158
- #endif
159
226
  #endif
227
+ #endif
160
228
 
161
- #ifdef HAS_DIFFUSE_TEXTURE
229
+ #ifdef HAS_DIFFUSE_TEXTURE
162
230
  vec2 diffuseTexCoords = TEXCOORD_DIFFUSE;
163
- #ifdef HAS_DIFFUSE_TEXTURE_TRANSFORM
231
+ #ifdef HAS_DIFFUSE_TEXTURE_TRANSFORM
164
232
  diffuseTexCoords = computeTextureTransform(diffuseTexCoords, u_diffuseTextureTransform);
165
- #endif
233
+ #endif
166
234
 
167
235
  vec4 diffuse = czm_srgbToLinear(texture(u_diffuseTexture, diffuseTexCoords));
168
- #ifdef HAS_DIFFUSE_FACTOR
236
+ #ifdef HAS_DIFFUSE_FACTOR
169
237
  diffuse *= u_diffuseFactor;
170
- #endif
171
- #elif defined(HAS_DIFFUSE_FACTOR)
238
+ #endif
239
+ #elif defined(HAS_DIFFUSE_FACTOR)
172
240
  vec4 diffuse = clamp(u_diffuseFactor, vec4(0.0), vec4(1.0));
173
- #else
241
+ #else
174
242
  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;
243
+ #endif
244
+
245
+ material.diffuse = diffuse.rgb * (1.0 - czm_maximumComponent(specular));
182
246
  // the specular glossiness extension's alpha overrides anything set
183
247
  // by the base material.
184
248
  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
249
+
250
+ material.specular = specular;
251
+
252
+ // glossiness is the opposite of roughness, but easier for artists to use.
253
+ float roughness = 1.0 - glossiness;
254
+ material.roughness = roughness * roughness;
255
+ }
256
+ #elif defined(LIGHTING_PBR)
257
+ float setMetallicRoughness(inout czm_modelMaterial material)
258
+ {
259
+ #ifdef HAS_METALLIC_ROUGHNESS_TEXTURE
189
260
  vec2 metallicRoughnessTexCoords = TEXCOORD_METALLIC_ROUGHNESS;
190
- #ifdef HAS_METALLIC_ROUGHNESS_TEXTURE_TRANSFORM
261
+ #ifdef HAS_METALLIC_ROUGHNESS_TEXTURE_TRANSFORM
191
262
  metallicRoughnessTexCoords = computeTextureTransform(metallicRoughnessTexCoords, u_metallicRoughnessTextureTransform);
192
- #endif
263
+ #endif
193
264
 
194
265
  vec3 metallicRoughness = texture(u_metallicRoughnessTexture, metallicRoughnessTexCoords).rgb;
195
266
  float metalness = clamp(metallicRoughness.b, 0.0, 1.0);
196
267
  float roughness = clamp(metallicRoughness.g, 0.04, 1.0);
197
- #ifdef HAS_METALLIC_FACTOR
198
- metalness *= u_metallicFactor;
199
- #endif
268
+ #ifdef HAS_METALLIC_FACTOR
269
+ metalness = clamp(metalness * u_metallicFactor, 0.0, 1.0);
270
+ #endif
200
271
 
201
- #ifdef HAS_ROUGHNESS_FACTOR
202
- roughness *= u_roughnessFactor;
203
- #endif
204
- #else
205
- #ifdef HAS_METALLIC_FACTOR
272
+ #ifdef HAS_ROUGHNESS_FACTOR
273
+ roughness = clamp(roughness * u_roughnessFactor, 0.0, 1.0);
274
+ #endif
275
+ #else
276
+ #ifdef HAS_METALLIC_FACTOR
206
277
  float metalness = clamp(u_metallicFactor, 0.0, 1.0);
207
- #else
278
+ #else
208
279
  float metalness = 1.0;
209
- #endif
280
+ #endif
210
281
 
211
- #ifdef HAS_ROUGHNESS_FACTOR
282
+ #ifdef HAS_ROUGHNESS_FACTOR
212
283
  float roughness = clamp(u_roughnessFactor, 0.04, 1.0);
213
- #else
284
+ #else
214
285
  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;
286
+ #endif
287
+ #endif
288
+
289
+ // dielectrics use f0 = 0.04, metals use albedo as f0
290
+ const vec3 REFLECTANCE_DIELECTRIC = vec3(0.04);
291
+ vec3 f0 = mix(REFLECTANCE_DIELECTRIC, material.diffuse, metalness);
292
+
293
+ material.specular = f0;
294
+
295
+ // diffuse only applies to dielectrics.
296
+ material.diffuse = material.diffuse * (1.0 - f0) * (1.0 - metalness);
297
+
298
+ // roughness is authored as perceptual roughness
299
+ // square it to get material roughness
300
+ material.roughness = roughness * roughness;
301
+
302
+ return metalness;
303
+ }
304
+ #ifdef USE_SPECULAR
305
+ void setSpecular(inout czm_modelMaterial material, in float metalness)
306
+ {
307
+ #ifdef HAS_SPECULAR_TEXTURE
308
+ vec2 specularTexCoords = TEXCOORD_SPECULAR;
309
+ #ifdef HAS_SPECULAR_TEXTURE_TRANSFORM
310
+ specularTexCoords = computeTextureTransform(specularTexCoords, u_specularTextureTransform);
311
+ #endif
312
+ float specularWeight = texture(u_specularTexture, specularTexCoords).a;
313
+ #ifdef HAS_SPECULAR_FACTOR
314
+ specularWeight *= u_specularFactor;
315
+ #endif
316
+ #else
317
+ #ifdef HAS_SPECULAR_FACTOR
318
+ float specularWeight = u_specularFactor;
319
+ #else
320
+ float specularWeight = 1.0;
321
+ #endif
322
+ #endif
323
+
324
+ #ifdef HAS_SPECULAR_COLOR_TEXTURE
325
+ vec2 specularColorTexCoords = TEXCOORD_SPECULAR_COLOR;
326
+ #ifdef HAS_SPECULAR_COLOR_TEXTURE_TRANSFORM
327
+ specularColorTexCoords = computeTextureTransform(specularColorTexCoords, u_specularColorTextureTransform);
328
+ #endif
329
+ vec3 specularColorSample = texture(u_specularColorTexture, specularColorTexCoords).rgb;
330
+ vec3 specularColorFactor = czm_srgbToLinear(specularColorSample);
331
+ #ifdef HAS_SPECULAR_COLOR_FACTOR
332
+ specularColorFactor *= u_specularColorFactor;
333
+ #endif
334
+ #else
335
+ #ifdef HAS_SPECULAR_COLOR_FACTOR
336
+ vec3 specularColorFactor = u_specularColorFactor;
337
+ #else
338
+ vec3 specularColorFactor = vec3(1.0);
339
+ #endif
340
+ #endif
341
+ material.specularWeight = specularWeight;
342
+ vec3 f0 = material.specular;
343
+ vec3 dielectricSpecularF0 = min(f0 * specularColorFactor, vec3(1.0));
344
+ material.specular = mix(dielectricSpecularF0, material.diffuse, metalness);
345
+ }
346
+ #endif
347
+ #ifdef USE_ANISOTROPY
348
+ void setAnisotropy(inout czm_modelMaterial material, in NormalInfo normalInfo)
349
+ {
350
+ mat2 rotation = mat2(u_anisotropy.xy, -u_anisotropy.y, u_anisotropy.x);
351
+ float anisotropyStrength = u_anisotropy.z;
352
+
353
+ vec2 direction = vec2(1.0, 0.0);
354
+ #ifdef HAS_ANISOTROPY_TEXTURE
355
+ vec2 anisotropyTexCoords = TEXCOORD_ANISOTROPY;
356
+ #ifdef HAS_ANISOTROPY_TEXTURE_TRANSFORM
357
+ anisotropyTexCoords = computeTextureTransform(anisotropyTexCoords, u_anisotropyTextureTransform);
358
+ #endif
359
+ vec3 anisotropySample = texture(u_anisotropyTexture, anisotropyTexCoords).rgb;
360
+ direction = anisotropySample.rg * 2.0 - vec2(1.0);
361
+ anisotropyStrength *= anisotropySample.b;
362
+ #endif
363
+
364
+ direction = rotation * direction;
365
+ mat3 tbn = mat3(normalInfo.tangent, normalInfo.bitangent, normalInfo.normal);
366
+ vec3 anisotropicT = tbn * normalize(vec3(direction, 0.0));
367
+ vec3 anisotropicB = cross(normalInfo.geometryNormal, anisotropicT);
368
+
369
+ material.anisotropicT = anisotropicT;
370
+ material.anisotropicB = anisotropicB;
371
+ material.anisotropyStrength = anisotropyStrength;
372
+ }
373
+ #endif
374
+ #ifdef USE_CLEARCOAT
375
+ void setClearcoat(inout czm_modelMaterial material, in ProcessedAttributes attributes)
376
+ {
377
+ #ifdef HAS_CLEARCOAT_TEXTURE
378
+ vec2 clearcoatTexCoords = TEXCOORD_CLEARCOAT;
379
+ #ifdef HAS_CLEARCOAT_TEXTURE_TRANSFORM
380
+ clearcoatTexCoords = computeTextureTransform(clearcoatTexCoords, u_clearcoatTextureTransform);
381
+ #endif
382
+ float clearcoatFactor = texture(u_clearcoatTexture, clearcoatTexCoords).r;
383
+ #ifdef HAS_CLEARCOAT_FACTOR
384
+ clearcoatFactor *= u_clearcoatFactor;
385
+ #endif
386
+ #else
387
+ #ifdef HAS_CLEARCOAT_FACTOR
388
+ float clearcoatFactor = u_clearcoatFactor;
389
+ #else
390
+ // PERFORMANCE_IDEA: this case should turn the whole extension off
391
+ float clearcoatFactor = 0.0;
392
+ #endif
393
+ #endif
394
+
395
+ #ifdef HAS_CLEARCOAT_ROUGHNESS_TEXTURE
396
+ vec2 clearcoatRoughnessTexCoords = TEXCOORD_CLEARCOAT_ROUGHNESS;
397
+ #ifdef HAS_CLEARCOAT_ROUGHNESS_TEXTURE_TRANSFORM
398
+ clearcoatRoughnessTexCoords = computeTextureTransform(clearcoatRoughnessTexCoords, u_clearcoatRoughnessTextureTransform);
399
+ #endif
400
+ float clearcoatRoughness = texture(u_clearcoatRoughnessTexture, clearcoatRoughnessTexCoords).g;
401
+ #ifdef HAS_CLEARCOAT_ROUGHNESS_FACTOR
402
+ clearcoatRoughness *= u_clearcoatRoughnessFactor;
403
+ #endif
404
+ #else
405
+ #ifdef HAS_CLEARCOAT_ROUGHNESS_FACTOR
406
+ float clearcoatRoughness = u_clearcoatRoughnessFactor;
407
+ #else
408
+ float clearcoatRoughness = 0.0;
409
+ #endif
410
+ #endif
411
+
412
+ material.clearcoatFactor = clearcoatFactor;
413
+ // roughness is authored as perceptual roughness
414
+ // square it to get material roughness
415
+ material.clearcoatRoughness = clearcoatRoughness * clearcoatRoughness;
416
+ #ifdef HAS_CLEARCOAT_NORMAL_TEXTURE
417
+ material.clearcoatNormal = getClearcoatNormalFromTexture(attributes, attributes.normalEC);
418
+ #else
419
+ material.clearcoatNormal = attributes.normalEC;
420
+ #endif
421
+ }
422
+ #endif
423
+ #endif
424
+
425
+ void materialStage(inout czm_modelMaterial material, ProcessedAttributes attributes, SelectedFeature feature)
426
+ {
427
+ #ifdef USE_ANISOTROPY
428
+ NormalInfo normalInfo = getNormalInfo(attributes);
429
+ material.normalEC = normalInfo.normal;
430
+ #elif defined(HAS_NORMALS)
431
+ material.normalEC = computeNormal(attributes);
432
+ #endif
433
+
434
+ vec4 baseColorWithAlpha = vec4(1.0);
435
+ // Regardless of whether we use PBR, set a base color
436
+ #ifdef HAS_BASE_COLOR_TEXTURE
437
+ baseColorWithAlpha = getBaseColorFromTexture();
438
+ #elif defined(HAS_BASE_COLOR_FACTOR)
439
+ baseColorWithAlpha = u_baseColorFactor;
440
+ #endif
441
+
442
+ #ifdef HAS_POINT_CLOUD_COLOR_STYLE
443
+ baseColorWithAlpha = v_pointCloudColor;
444
+ #elif defined(HAS_COLOR_0)
445
+ vec4 color = attributes.color_0;
446
+ // .pnts files store colors in the sRGB color space
447
+ #ifdef HAS_SRGB_COLOR
448
+ color = czm_srgbToLinear(color);
449
+ #endif
450
+ baseColorWithAlpha *= color;
451
+ #endif
452
+
453
+ material.diffuse = baseColorWithAlpha.rgb;
454
+ material.alpha = baseColorWithAlpha.a;
455
+
456
+ #ifdef USE_CPU_STYLING
457
+ material.diffuse = blend(material.diffuse, feature.color.rgb, model_colorBlend);
458
+ #endif
459
+
460
+ #ifdef HAS_OCCLUSION_TEXTURE
461
+ vec2 occlusionTexCoords = TEXCOORD_OCCLUSION;
462
+ #ifdef HAS_OCCLUSION_TEXTURE_TRANSFORM
463
+ occlusionTexCoords = computeTextureTransform(occlusionTexCoords, u_occlusionTextureTransform);
464
+ #endif
465
+ material.occlusion = texture(u_occlusionTexture, occlusionTexCoords).r;
466
+ #endif
467
+
468
+ #ifdef HAS_EMISSIVE_TEXTURE
469
+ material.emissive = getEmissiveFromTexture();
470
+ #elif defined(HAS_EMISSIVE_FACTOR)
471
+ material.emissive = u_emissiveFactor;
472
+ #endif
473
+
474
+ #if defined(LIGHTING_PBR) && defined(USE_SPECULAR_GLOSSINESS)
475
+ setSpecularGlossiness(material);
476
+ #elif defined(LIGHTING_PBR)
477
+ float metalness = setMetallicRoughness(material);
478
+ #ifdef USE_SPECULAR
479
+ setSpecular(material, metalness);
480
+ #endif
481
+ #ifdef USE_ANISOTROPY
482
+ setAnisotropy(material, normalInfo);
483
+ #endif
484
+ #ifdef USE_CLEARCOAT
485
+ setClearcoat(material, attributes);
486
+ #endif
225
487
  #endif
226
488
  }