@cesium/engine 10.0.0 → 10.1.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 (173) hide show
  1. package/Build/Workers/chunk-2GEAGYUY.js +1477 -0
  2. package/Build/Workers/chunk-4RMIRG6T.js +1800 -0
  3. package/Build/Workers/chunk-4VFBBNQ3.js +55 -0
  4. package/Build/Workers/{chunk-GRAT5GE7.js → chunk-5BLJ5ZM6.js} +1 -1
  5. package/Build/Workers/{chunk-AVI4IUWC.js → chunk-5KWHSZYL.js} +4 -4
  6. package/Build/Workers/chunk-5O6JWQ4E.js +398 -0
  7. package/Build/Workers/chunk-65MZOUNU.js +390 -0
  8. package/Build/Workers/chunk-6D66DPRV.js +353 -0
  9. package/Build/Workers/{chunk-XD445VDH.js → chunk-6OFDHMHR.js} +1 -1
  10. package/Build/Workers/chunk-76BYYG7N.js +945 -0
  11. package/Build/Workers/chunk-A5CODJ4M.js +171 -0
  12. package/Build/Workers/chunk-ACRTCBN5.js +684 -0
  13. package/Build/Workers/{chunk-7XGC6YB2.js → chunk-B75IEX2S.js} +3 -3
  14. package/Build/Workers/chunk-BAVI3ZS2.js +39 -0
  15. package/Build/Workers/{chunk-SYCPRK3D.js → chunk-BBDZYSZB.js} +4 -4
  16. package/Build/Workers/chunk-BGE4QVG7.js +368 -0
  17. package/Build/Workers/chunk-BY3E4ONI.js +456 -0
  18. package/Build/Workers/{chunk-LCLJJ2MZ.js → chunk-C3Z23UUJ.js} +6 -6
  19. package/Build/Workers/{chunk-MDHQR3ZS.js → chunk-C45MU4GZ.js} +2 -2
  20. package/Build/Workers/{chunk-PCP4YQST.js → chunk-CF7P7K7E.js} +2 -2
  21. package/Build/Workers/chunk-D2U4RI64.js +476 -0
  22. package/Build/Workers/chunk-D4K27X2M.js +305 -0
  23. package/Build/Workers/chunk-EB7PNZTK.js +138 -0
  24. package/Build/Workers/chunk-ELI4BUOT.js +963 -0
  25. package/Build/Workers/{chunk-DOXCPOG4.js → chunk-F3NDOSTZ.js} +1 -1
  26. package/Build/Workers/{chunk-BCL4PHHT.js → chunk-FDCLACT5.js} +3 -3
  27. package/Build/Workers/chunk-FEVVHITK.js +122 -0
  28. package/Build/Workers/{chunk-GR3CDLCP.js → chunk-FOZWUH4T.js} +1 -1
  29. package/Build/Workers/chunk-FQPSOOPH.js +258 -0
  30. package/Build/Workers/chunk-G5V4GPZE.js +691 -0
  31. package/Build/Workers/chunk-GNHZH7HP.js +37 -0
  32. package/Build/Workers/{chunk-AD5HBJ2F.js → chunk-GPJR7MPQ.js} +2 -2
  33. package/Build/Workers/{chunk-4BAE4PWO.js → chunk-GWT64LKY.js} +1 -1
  34. package/Build/Workers/{chunk-STBBMQGG.js → chunk-HGEEOMSC.js} +1 -1
  35. package/Build/Workers/chunk-IUROUBPA.js +300 -0
  36. package/Build/Workers/chunk-J7MQUQJY.js +430 -0
  37. package/Build/Workers/{chunk-BJF5LOWE.js → chunk-JNLWLSTP.js} +3 -3
  38. package/Build/Workers/chunk-JYQNWIQQ.js +44 -0
  39. package/Build/Workers/{chunk-G3YR53LY.js → chunk-KV4EQHK4.js} +4 -4
  40. package/Build/Workers/chunk-LSSWVB2X.js +138 -0
  41. package/Build/Workers/chunk-LXQ5QAEJ.js +196 -0
  42. package/Build/Workers/{chunk-RJYML24O.js → chunk-MBZH7YZ7.js} +414 -439
  43. package/Build/Workers/{chunk-BDFNKFOE.js → chunk-MKXWJTFQ.js} +4 -4
  44. package/Build/Workers/chunk-MMV6TO3P.js +101 -0
  45. package/Build/Workers/chunk-N4QEHO3U.js +75 -0
  46. package/Build/Workers/chunk-NVOABL76.js +100 -0
  47. package/Build/Workers/chunk-OAPA2RTG.js +239 -0
  48. package/Build/Workers/chunk-OE4MCOC7.js +421 -0
  49. package/Build/Workers/chunk-OJF4RTJG.js +634 -0
  50. package/Build/Workers/{chunk-C2CGMAIU.js → chunk-OOMCT7OL.js} +2 -2
  51. package/Build/Workers/{chunk-VO3ACQB2.js → chunk-OWGTMVDB.js} +6 -6
  52. package/Build/Workers/chunk-OXALEQPI.js +10364 -0
  53. package/Build/Workers/chunk-OXSI7N4C.js +768 -0
  54. package/Build/Workers/chunk-PNFHVBSF.js +2716 -0
  55. package/Build/Workers/chunk-POSRARY7.js +834 -0
  56. package/Build/Workers/chunk-QYQIVZBU.js +117 -0
  57. package/Build/Workers/chunk-R3TKLC6E.js +1075 -0
  58. package/Build/Workers/chunk-R4OIEIPE.js +500 -0
  59. package/Build/Workers/{chunk-LEABCTLP.js → chunk-R4ZEWO4I.js} +1 -1
  60. package/Build/Workers/{chunk-FXIHSF7O.js → chunk-RCK55EDX.js} +3 -3
  61. package/Build/Workers/chunk-RHBWXX7C.js +629 -0
  62. package/Build/Workers/{chunk-NTXTUNEF.js → chunk-RZLZWKFN.js} +1 -1
  63. package/Build/Workers/chunk-SAPFXU5X.js +102 -0
  64. package/Build/Workers/chunk-T6LPN7RI.js +2857 -0
  65. package/Build/Workers/{chunk-5S7OLEPK.js → chunk-TBBFDFCS.js} +2 -2
  66. package/Build/Workers/chunk-TF776XCO.js +1258 -0
  67. package/Build/Workers/chunk-TGY6H6N6.js +163 -0
  68. package/Build/Workers/{chunk-L6RTJ3RE.js → chunk-UCIPJSZX.js} +2 -2
  69. package/Build/Workers/chunk-UOEUCKKU.js +59 -0
  70. package/Build/Workers/chunk-VRZ46QZ5.js +781 -0
  71. package/Build/Workers/chunk-VYWUFRRR.js +1052 -0
  72. package/Build/Workers/{chunk-JYAHOGGL.js → chunk-WVSELU6O.js} +6 -6
  73. package/Build/Workers/chunk-X2ZQ7RJR.js +287 -0
  74. package/Build/Workers/{chunk-O3JCMSS3.js → chunk-X43SJLQL.js} +44 -0
  75. package/Build/Workers/chunk-XLTOBCDI.js +220 -0
  76. package/Build/Workers/{chunk-COYFZ5VA.js → chunk-XQI7XZHX.js} +1 -1
  77. package/Build/Workers/chunk-XUOJCLOH.js +511 -0
  78. package/Build/Workers/chunk-XZZNKIEV.js +157 -0
  79. package/Build/Workers/chunk-YLYBLJ3Y.js +73 -0
  80. package/Build/Workers/{chunk-OORVMGDU.js → chunk-ZEE2EIFD.js} +1 -1
  81. package/Build/Workers/chunk-ZIKGV7EL.js +58 -0
  82. package/Build/Workers/{chunk-DGS5QNIO.js → chunk-ZU334IDQ.js} +3 -3
  83. package/Build/Workers/combineGeometry.js +22 -22
  84. package/Build/Workers/createBoxGeometry.js +16 -16
  85. package/Build/Workers/createBoxOutlineGeometry.js +14 -14
  86. package/Build/Workers/createCircleGeometry.js +24 -24
  87. package/Build/Workers/createCircleOutlineGeometry.js +17 -17
  88. package/Build/Workers/createCoplanarPolygonGeometry.js +31 -31
  89. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +29 -29
  90. package/Build/Workers/createCorridorGeometry.js +27 -27
  91. package/Build/Workers/createCorridorOutlineGeometry.js +26 -26
  92. package/Build/Workers/createCylinderGeometry.js +18 -18
  93. package/Build/Workers/createCylinderOutlineGeometry.js +16 -16
  94. package/Build/Workers/createEllipseGeometry.js +24 -24
  95. package/Build/Workers/createEllipseOutlineGeometry.js +17 -17
  96. package/Build/Workers/createEllipsoidGeometry.js +17 -17
  97. package/Build/Workers/createEllipsoidOutlineGeometry.js +16 -16
  98. package/Build/Workers/createFrustumGeometry.js +16 -16
  99. package/Build/Workers/createFrustumOutlineGeometry.js +16 -16
  100. package/Build/Workers/createGeometry.js +22 -22
  101. package/Build/Workers/createGroundPolylineGeometry.js +20 -20
  102. package/Build/Workers/createPlaneGeometry.js +14 -14
  103. package/Build/Workers/createPlaneOutlineGeometry.js +13 -13
  104. package/Build/Workers/createPolygonGeometry.js +30 -30
  105. package/Build/Workers/createPolygonOutlineGeometry.js +28 -28
  106. package/Build/Workers/createPolylineGeometry.js +23 -23
  107. package/Build/Workers/createPolylineVolumeGeometry.js +29 -29
  108. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +25 -25
  109. package/Build/Workers/createRectangleGeometry.js +25 -25
  110. package/Build/Workers/createRectangleOutlineGeometry.js +18 -18
  111. package/Build/Workers/createSimplePolylineGeometry.js +21 -21
  112. package/Build/Workers/createSphereGeometry.js +17 -17
  113. package/Build/Workers/createSphereOutlineGeometry.js +16 -16
  114. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  115. package/Build/Workers/createVectorTileClampedPolylines.js +13 -13
  116. package/Build/Workers/createVectorTileGeometries.js +22 -22
  117. package/Build/Workers/createVectorTilePoints.js +12 -12
  118. package/Build/Workers/createVectorTilePolygons.js +20 -20
  119. package/Build/Workers/createVectorTilePolylines.js +13 -13
  120. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +20 -20
  121. package/Build/Workers/createVerticesFromHeightmap.js +20 -20
  122. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +17 -17
  123. package/Build/Workers/createWallGeometry.js +22 -22
  124. package/Build/Workers/createWallOutlineGeometry.js +21 -21
  125. package/Build/Workers/decodeDraco.js +11 -11
  126. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
  127. package/Build/Workers/decodeI3S.js +10 -10
  128. package/Build/Workers/transcodeKTX2.js +8 -11
  129. package/Build/Workers/transferTypedArrayTest.js +1 -1
  130. package/Build/Workers/upsampleQuantizedTerrainMesh.js +20 -20
  131. package/Source/Core/Ion.js +1 -1
  132. package/Source/Core/Simon1994PlanetaryPositions.js +2 -1
  133. package/Source/Core/Transforms.js +137 -2
  134. package/Source/DataSources/BillboardGraphics.js +16 -0
  135. package/Source/DataSources/BillboardVisualizer.js +7 -0
  136. package/Source/DataSources/PathVisualizer.js +4 -4
  137. package/Source/DataSources/PointGraphics.js +17 -0
  138. package/Source/DataSources/PointVisualizer.js +12 -0
  139. package/Source/DataSources/PositionProperty.js +4 -7
  140. package/Source/Renderer/AutomaticUniforms.js +1 -1
  141. package/Source/Renderer/UniformState.js +5 -11
  142. package/Source/Scene/ArcGisMapService.js +1 -1
  143. package/Source/Scene/Billboard.js +29 -2
  144. package/Source/Scene/BillboardCollection.js +49 -0
  145. package/Source/Scene/BingMapsImageryProvider.js +10 -1
  146. package/Source/Scene/ImageBasedLighting.js +2 -2
  147. package/Source/Scene/Model/Model.js +1 -1
  148. package/Source/Scene/OctahedralProjectedCubeMap.js +5 -6
  149. package/Source/Scene/PointPrimitive.js +28 -2
  150. package/Source/Scene/PointPrimitiveCollection.js +22 -9
  151. package/Source/Shaders/BillboardCollectionFS.glsl +4 -0
  152. package/Source/Shaders/BillboardCollectionFS.js +4 -0
  153. package/Source/Shaders/BillboardCollectionVS.glsl +3 -1
  154. package/Source/Shaders/BillboardCollectionVS.js +3 -1
  155. package/Source/Shaders/BrdfLutGeneratorFS.glsl +30 -13
  156. package/Source/Shaders/BrdfLutGeneratorFS.js +30 -13
  157. package/Source/Shaders/Builtin/Functions/pbrLighting.glsl +40 -39
  158. package/Source/Shaders/Builtin/Functions/pbrLighting.js +40 -39
  159. package/Source/Shaders/Builtin/Functions/sampleOctahedralProjection.glsl +1 -1
  160. package/Source/Shaders/Builtin/Functions/sampleOctahedralProjection.js +1 -1
  161. package/Source/Shaders/Model/ImageBasedLightingStageFS.glsl +23 -23
  162. package/Source/Shaders/Model/ImageBasedLightingStageFS.js +23 -23
  163. package/Source/Shaders/Model/LightingStageFS.glsl +6 -5
  164. package/Source/Shaders/Model/LightingStageFS.js +6 -5
  165. package/Source/Shaders/Model/MaterialStageFS.glsl +10 -14
  166. package/Source/Shaders/Model/MaterialStageFS.js +10 -14
  167. package/Source/Shaders/PointPrimitiveCollectionFS.glsl +4 -0
  168. package/Source/Shaders/PointPrimitiveCollectionFS.js +4 -0
  169. package/Source/Shaders/PointPrimitiveCollectionVS.glsl +9 -7
  170. package/Source/Shaders/PointPrimitiveCollectionVS.js +9 -7
  171. package/index.d.ts +74 -5
  172. package/index.js +207 -207
  173. package/package.json +3 -3
@@ -27,11 +27,11 @@ vec2 hammersley2D(int i, int N)
27
27
  return vec2(float(i) / float(N), vdcRadicalInverse(i));
28
28
  }
29
29
 
30
- vec3 importanceSampleGGX(vec2 xi, float roughness, vec3 N)
30
+ vec3 importanceSampleGGX(vec2 xi, float alphaRoughness, vec3 N)
31
31
  {
32
- float a = roughness * roughness;
32
+ float alphaRoughnessSquared = alphaRoughness * alphaRoughness;
33
33
  float phi = 2.0 * M_PI * xi.x;
34
- float cosTheta = sqrt((1.0 - xi.y) / (1.0 + (a * a - 1.0) * xi.y));
34
+ float cosTheta = sqrt((1.0 - xi.y) / (1.0 + (alphaRoughnessSquared - 1.0) * xi.y));
35
35
  float sinTheta = sqrt(1.0 - cosTheta * cosTheta);
36
36
  vec3 H = vec3(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);
37
37
  vec3 upVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
@@ -40,15 +40,31 @@ vec3 importanceSampleGGX(vec2 xi, float roughness, vec3 N)
40
40
  return tangentX * H.x + tangentY * H.y + N * H.z;
41
41
  }
42
42
 
43
- float G1_Smith(float NdotV, float k)
43
+ /**
44
+ * Estimate the geometric self-shadowing of the microfacets in a surface,
45
+ * using the Smith Joint GGX visibility function.
46
+ * Note: Vis = G / (4 * NdotL * NdotV)
47
+ * see Eric Heitz. 2014. Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs. Journal of Computer Graphics Techniques, 3
48
+ * see Real-Time Rendering. Page 331 to 336.
49
+ * see https://google.github.io/filament/Filament.md.html#materialsystem/specularbrdf/geometricshadowing(specularg)
50
+ *
51
+ * @param {float} alphaRoughness The roughness of the material, expressed as the square of perceptual roughness.
52
+ * @param {float} NdotL The cosine of the angle between the surface normal and the direction to the light source.
53
+ * @param {float} NdotV The cosine of the angle between the surface normal and the direction to the camera.
54
+ */
55
+ float smithVisibilityGGX(float alphaRoughness, float NdotL, float NdotV)
44
56
  {
45
- return NdotV / (NdotV * (1.0 - k) + k);
46
- }
57
+ float alphaRoughnessSq = alphaRoughness * alphaRoughness;
47
58
 
48
- float G_Smith(float roughness, float NdotV, float NdotL)
49
- {
50
- float k = roughness * roughness / 2.0;
51
- return G1_Smith(NdotV, k) * G1_Smith(NdotL, k);
59
+ float GGXV = NdotL * sqrt(NdotV * NdotV * (1.0 - alphaRoughnessSq) + alphaRoughnessSq);
60
+ float GGXL = NdotV * sqrt(NdotL * NdotL * (1.0 - alphaRoughnessSq) + alphaRoughnessSq);
61
+
62
+ float GGX = GGXV + GGXL; // 2.0 if NdotL = NdotV = 1.0
63
+ if (GGX > 0.0)
64
+ {
65
+ return 0.5 / GGX; // 1/4 if NdotL = NdotV = 1.0
66
+ }
67
+ return 0.0;
52
68
  }
53
69
 
54
70
  vec2 integrateBrdf(float roughness, float NdotV)
@@ -57,18 +73,19 @@ vec2 integrateBrdf(float roughness, float NdotV)
57
73
  float A = 0.0;
58
74
  float B = 0.0;
59
75
  const int NumSamples = 1024;
76
+ float alphaRoughness = roughness * roughness;
60
77
  for (int i = 0; i < NumSamples; i++)
61
78
  {
62
79
  vec2 xi = hammersley2D(i, NumSamples);
63
- vec3 H = importanceSampleGGX(xi, roughness, vec3(0.0, 0.0, 1.0));
80
+ vec3 H = importanceSampleGGX(xi, alphaRoughness, vec3(0.0, 0.0, 1.0));
64
81
  vec3 L = 2.0 * dot(V, H) * H - V;
65
82
  float NdotL = clamp(L.z, 0.0, 1.0);
66
83
  float NdotH = clamp(H.z, 0.0, 1.0);
67
84
  float VdotH = clamp(dot(V, H), 0.0, 1.0);
68
85
  if (NdotL > 0.0)
69
86
  {
70
- float G = G_Smith(roughness, NdotV, NdotL);
71
- float G_Vis = G * VdotH / (NdotH * NdotV);
87
+ float G = smithVisibilityGGX(alphaRoughness, NdotL, NdotV);
88
+ float G_Vis = 4.0 * G * VdotH * NdotL / NdotH;
72
89
  float Fc = pow(1.0 - VdotH, 5.0);
73
90
  A += (1.0 - Fc) * G_Vis;
74
91
  B += Fc * G_Vis;
@@ -28,11 +28,11 @@ vec2 hammersley2D(int i, int N)\n\
28
28
  return vec2(float(i) / float(N), vdcRadicalInverse(i));\n\
29
29
  }\n\
30
30
  \n\
31
- vec3 importanceSampleGGX(vec2 xi, float roughness, vec3 N)\n\
31
+ vec3 importanceSampleGGX(vec2 xi, float alphaRoughness, vec3 N)\n\
32
32
  {\n\
33
- float a = roughness * roughness;\n\
33
+ float alphaRoughnessSquared = alphaRoughness * alphaRoughness;\n\
34
34
  float phi = 2.0 * M_PI * xi.x;\n\
35
- float cosTheta = sqrt((1.0 - xi.y) / (1.0 + (a * a - 1.0) * xi.y));\n\
35
+ float cosTheta = sqrt((1.0 - xi.y) / (1.0 + (alphaRoughnessSquared - 1.0) * xi.y));\n\
36
36
  float sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n\
37
37
  vec3 H = vec3(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);\n\
38
38
  vec3 upVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);\n\
@@ -41,15 +41,31 @@ vec3 importanceSampleGGX(vec2 xi, float roughness, vec3 N)\n\
41
41
  return tangentX * H.x + tangentY * H.y + N * H.z;\n\
42
42
  }\n\
43
43
  \n\
44
- float G1_Smith(float NdotV, float k)\n\
44
+ /**\n\
45
+ * Estimate the geometric self-shadowing of the microfacets in a surface,\n\
46
+ * using the Smith Joint GGX visibility function.\n\
47
+ * Note: Vis = G / (4 * NdotL * NdotV)\n\
48
+ * see Eric Heitz. 2014. Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs. Journal of Computer Graphics Techniques, 3\n\
49
+ * see Real-Time Rendering. Page 331 to 336.\n\
50
+ * see https://google.github.io/filament/Filament.md.html#materialsystem/specularbrdf/geometricshadowing(specularg)\n\
51
+ *\n\
52
+ * @param {float} alphaRoughness The roughness of the material, expressed as the square of perceptual roughness.\n\
53
+ * @param {float} NdotL The cosine of the angle between the surface normal and the direction to the light source.\n\
54
+ * @param {float} NdotV The cosine of the angle between the surface normal and the direction to the camera.\n\
55
+ */\n\
56
+ float smithVisibilityGGX(float alphaRoughness, float NdotL, float NdotV)\n\
45
57
  {\n\
46
- return NdotV / (NdotV * (1.0 - k) + k);\n\
47
- }\n\
58
+ float alphaRoughnessSq = alphaRoughness * alphaRoughness;\n\
48
59
  \n\
49
- float G_Smith(float roughness, float NdotV, float NdotL)\n\
50
- {\n\
51
- float k = roughness * roughness / 2.0;\n\
52
- return G1_Smith(NdotV, k) * G1_Smith(NdotL, k);\n\
60
+ float GGXV = NdotL * sqrt(NdotV * NdotV * (1.0 - alphaRoughnessSq) + alphaRoughnessSq);\n\
61
+ float GGXL = NdotV * sqrt(NdotL * NdotL * (1.0 - alphaRoughnessSq) + alphaRoughnessSq);\n\
62
+ \n\
63
+ float GGX = GGXV + GGXL; // 2.0 if NdotL = NdotV = 1.0\n\
64
+ if (GGX > 0.0)\n\
65
+ {\n\
66
+ return 0.5 / GGX; // 1/4 if NdotL = NdotV = 1.0\n\
67
+ }\n\
68
+ return 0.0;\n\
53
69
  }\n\
54
70
  \n\
55
71
  vec2 integrateBrdf(float roughness, float NdotV)\n\
@@ -58,18 +74,19 @@ vec2 integrateBrdf(float roughness, float NdotV)\n\
58
74
  float A = 0.0;\n\
59
75
  float B = 0.0;\n\
60
76
  const int NumSamples = 1024;\n\
77
+ float alphaRoughness = roughness * roughness;\n\
61
78
  for (int i = 0; i < NumSamples; i++)\n\
62
79
  {\n\
63
80
  vec2 xi = hammersley2D(i, NumSamples);\n\
64
- vec3 H = importanceSampleGGX(xi, roughness, vec3(0.0, 0.0, 1.0));\n\
81
+ vec3 H = importanceSampleGGX(xi, alphaRoughness, vec3(0.0, 0.0, 1.0));\n\
65
82
  vec3 L = 2.0 * dot(V, H) * H - V;\n\
66
83
  float NdotL = clamp(L.z, 0.0, 1.0);\n\
67
84
  float NdotH = clamp(H.z, 0.0, 1.0);\n\
68
85
  float VdotH = clamp(dot(V, H), 0.0, 1.0);\n\
69
86
  if (NdotL > 0.0)\n\
70
87
  {\n\
71
- float G = G_Smith(roughness, NdotV, NdotL);\n\
72
- float G_Vis = G * VdotH / (NdotH * NdotV);\n\
88
+ float G = smithVisibilityGGX(alphaRoughness, NdotL, NdotV);\n\
89
+ float G_Vis = 4.0 * G * VdotH * NdotL / NdotH;\n\
73
90
  float Fc = pow(1.0 - VdotH, 5.0);\n\
74
91
  A += (1.0 - Fc) * G_Vis;\n\
75
92
  B += Fc * G_Vis;\n\
@@ -13,14 +13,14 @@ vec3 fresnelSchlick2(vec3 f0, vec3 f90, float VdotH)
13
13
 
14
14
  #ifdef USE_ANISOTROPY
15
15
  /**
16
- * @param {float} roughness Material roughness (along the anisotropy bitangent)
16
+ * @param {float} bitangentRoughness Material roughness (along the anisotropy bitangent)
17
17
  * @param {float} tangentialRoughness Anisotropic roughness (along the anisotropy tangent)
18
18
  * @param {vec3} lightDirection The direction from the fragment to the light source, transformed to tangent-bitangent-normal coordinates
19
19
  * @param {vec3} viewDirection The direction from the fragment to the camera, transformed to tangent-bitangent-normal coordinates
20
20
  */
21
- float smithVisibilityGGX_anisotropic(float roughness, float tangentialRoughness, vec3 lightDirection, vec3 viewDirection)
21
+ float smithVisibilityGGX_anisotropic(float bitangentRoughness, float tangentialRoughness, vec3 lightDirection, vec3 viewDirection)
22
22
  {
23
- vec3 roughnessScale = vec3(tangentialRoughness, roughness, 1.0);
23
+ vec3 roughnessScale = vec3(tangentialRoughness, bitangentRoughness, 1.0);
24
24
  float GGXV = lightDirection.z * length(roughnessScale * viewDirection);
25
25
  float GGXL = viewDirection.z * length(roughnessScale * lightDirection);
26
26
  float v = 0.5 / (GGXV + GGXL);
@@ -28,44 +28,44 @@ float smithVisibilityGGX_anisotropic(float roughness, float tangentialRoughness,
28
28
  }
29
29
 
30
30
  /**
31
- * @param {float} roughness Material roughness (along the anisotropy bitangent)
31
+ * @param {float} bitangentRoughness Material roughness (along the anisotropy bitangent)
32
32
  * @param {float} tangentialRoughness Anisotropic roughness (along the anisotropy tangent)
33
33
  * @param {vec3} halfwayDirection The unit vector halfway between light and view directions, transformed to tangent-bitangent-normal coordinates
34
34
  */
35
- float GGX_anisotropic(float roughness, float tangentialRoughness, vec3 halfwayDirection)
35
+ float GGX_anisotropic(float bitangentRoughness, float tangentialRoughness, vec3 halfwayDirection)
36
36
  {
37
- float roughnessSquared = roughness * tangentialRoughness;
38
- vec3 f = halfwayDirection * vec3(roughness, tangentialRoughness, roughnessSquared);
37
+ float roughnessSquared = bitangentRoughness * tangentialRoughness;
38
+ vec3 f = halfwayDirection * vec3(bitangentRoughness, tangentialRoughness, roughnessSquared);
39
39
  float w2 = roughnessSquared / dot(f, f);
40
40
  return roughnessSquared * w2 * w2 / czm_pi;
41
41
  }
42
42
  #endif
43
43
 
44
- float smithVisibilityG1(float NdotV, float roughness)
45
- {
46
- // this is the k value for direct lighting.
47
- // for image based lighting it will be roughness^2 / 2
48
- float k = (roughness + 1.0) * (roughness + 1.0) / 8.0;
49
- return NdotV / (NdotV * (1.0 - k) + k);
50
- }
51
-
52
44
  /**
53
45
  * Estimate the geometric self-shadowing of the microfacets in a surface,
54
- * using the Schlick GGX approximation of a Smith visibility function.
46
+ * using the Smith Joint GGX visibility function.
47
+ * Note: Vis = G / (4 * NdotL * NdotV)
48
+ * see Eric Heitz. 2014. Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs. Journal of Computer Graphics Techniques, 3
49
+ * see Real-Time Rendering. Page 331 to 336.
50
+ * see https://google.github.io/filament/Filament.md.html#materialsystem/specularbrdf/geometricshadowing(specularg)
55
51
  *
56
- * @param {float} roughness The roughness of the material.
52
+ * @param {float} alphaRoughness The roughness of the material, expressed as the square of perceptual roughness.
57
53
  * @param {float} NdotL The cosine of the angle between the surface normal and the direction to the light source.
58
54
  * @param {float} NdotV The cosine of the angle between the surface normal and the direction to the camera.
59
55
  */
60
- float smithVisibilityGGX(float roughness, float NdotL, float NdotV)
56
+ float smithVisibilityGGX(float alphaRoughness, float NdotL, float NdotV)
61
57
  {
62
- // Avoid divide-by-zero errors
63
- NdotL = clamp(NdotL, 0.001, 1.0);
64
- NdotV += 0.001;
65
- return (
66
- smithVisibilityG1(NdotL, roughness) *
67
- smithVisibilityG1(NdotV, roughness)
68
- ) / (4.0 * NdotL * NdotV);
58
+ float alphaRoughnessSq = alphaRoughness * alphaRoughness;
59
+
60
+ float GGXV = NdotL * sqrt(NdotV * NdotV * (1.0 - alphaRoughnessSq) + alphaRoughnessSq);
61
+ float GGXL = NdotV * sqrt(NdotL * NdotL * (1.0 - alphaRoughnessSq) + alphaRoughnessSq);
62
+
63
+ float GGX = GGXV + GGXL;
64
+ if (GGX > 0.0)
65
+ {
66
+ return 0.5 / GGX;
67
+ }
68
+ return 0.0;
69
69
  }
70
70
 
71
71
  /**
@@ -73,15 +73,15 @@ float smithVisibilityGGX(float roughness, float NdotL, float NdotV)
73
73
  * the halfway vector, which is aligned halfway between the directions from
74
74
  * the fragment to the camera and from the fragment to the light source.
75
75
  *
76
- * @param {float} roughness The roughness of the material.
76
+ * @param {float} alphaRoughness The roughness of the material, expressed as the square of perceptual roughness.
77
77
  * @param {float} NdotH The cosine of the angle between the surface normal and the halfway vector.
78
78
  * @return {float} The fraction of microfacets aligned to the halfway vector.
79
79
  */
80
- float GGX(float roughness, float NdotH)
80
+ float GGX(float alphaRoughness, float NdotH)
81
81
  {
82
- float roughnessSquared = roughness * roughness;
83
- float f = (NdotH * roughnessSquared - NdotH) * NdotH + 1.0;
84
- return roughnessSquared / (czm_pi * f * f);
82
+ float alphaRoughnessSquared = alphaRoughness * alphaRoughness;
83
+ float f = (NdotH * alphaRoughnessSquared - NdotH) * NdotH + 1.0;
84
+ return alphaRoughnessSquared / (czm_pi * f * f);
85
85
  }
86
86
 
87
87
  /**
@@ -91,16 +91,16 @@ float GGX(float roughness, float NdotH)
91
91
  * @param {vec3} lightDirection The unit vector pointing from the fragment to the light source.
92
92
  * @param {vec3} viewDirection The unit vector pointing from the fragment to the camera.
93
93
  * @param {vec3} halfwayDirection The unit vector pointing from the fragment to halfway between the light source and the camera.
94
- * @param {float} roughness The roughness of the material.
94
+ * @param {float} alphaRoughness The roughness of the material, expressed as the square of perceptual roughness.
95
95
  * @return {float} The strength of the specular reflection.
96
96
  */
97
- float computeDirectSpecularStrength(vec3 normal, vec3 lightDirection, vec3 viewDirection, vec3 halfwayDirection, float roughness)
97
+ float computeDirectSpecularStrength(vec3 normal, vec3 lightDirection, vec3 viewDirection, vec3 halfwayDirection, float alphaRoughness)
98
98
  {
99
99
  float NdotL = dot(normal, lightDirection);
100
100
  float NdotV = abs(dot(normal, viewDirection));
101
- float G = smithVisibilityGGX(roughness, NdotL, NdotV);
101
+ float G = smithVisibilityGGX(alphaRoughness, NdotL, NdotV);
102
102
  float NdotH = clamp(dot(normal, halfwayDirection), 0.0, 1.0);
103
- float D = GGX(roughness, NdotH);
103
+ float D = GGX(alphaRoughness, NdotH);
104
104
  return G * D;
105
105
  }
106
106
 
@@ -138,19 +138,20 @@ vec3 czm_pbrLighting(vec3 viewDirectionEC, vec3 normalEC, vec3 lightDirectionEC,
138
138
  F *= material.specularWeight;
139
139
  #endif
140
140
 
141
- float alpha = material.roughness;
141
+ float alphaRoughness = material.roughness * material.roughness;
142
142
  #ifdef USE_ANISOTROPY
143
143
  mat3 tbn = mat3(material.anisotropicT, material.anisotropicB, normalEC);
144
144
  vec3 lightDirection = lightDirectionEC * tbn;
145
145
  vec3 viewDirection = viewDirectionEC * tbn;
146
146
  vec3 halfwayDirection = halfwayDirectionEC * tbn;
147
147
  float anisotropyStrength = material.anisotropyStrength;
148
- float tangentialRoughness = mix(alpha, 1.0, anisotropyStrength * anisotropyStrength);
149
- float G = smithVisibilityGGX_anisotropic(alpha, tangentialRoughness, lightDirection, viewDirection);
150
- float D = GGX_anisotropic(alpha, tangentialRoughness, halfwayDirection);
148
+ float tangentialRoughness = mix(alphaRoughness, 1.0, anisotropyStrength * anisotropyStrength);
149
+ float bitangentRoughness = clamp(alphaRoughness, 0.001, 1.0);
150
+ float G = smithVisibilityGGX_anisotropic(bitangentRoughness, tangentialRoughness, lightDirection, viewDirection);
151
+ float D = GGX_anisotropic(bitangentRoughness, tangentialRoughness, halfwayDirection);
151
152
  vec3 specularContribution = F * G * D;
152
153
  #else
153
- float specularStrength = computeDirectSpecularStrength(normalEC, lightDirectionEC, viewDirectionEC, halfwayDirectionEC, alpha);
154
+ float specularStrength = computeDirectSpecularStrength(normalEC, lightDirectionEC, viewDirectionEC, halfwayDirectionEC, alphaRoughness);
154
155
  vec3 specularContribution = F * specularStrength;
155
156
  #endif
156
157
 
@@ -14,14 +14,14 @@ vec3 fresnelSchlick2(vec3 f0, vec3 f90, float VdotH)\n\
14
14
  \n\
15
15
  #ifdef USE_ANISOTROPY\n\
16
16
  /**\n\
17
- * @param {float} roughness Material roughness (along the anisotropy bitangent)\n\
17
+ * @param {float} bitangentRoughness Material roughness (along the anisotropy bitangent)\n\
18
18
  * @param {float} tangentialRoughness Anisotropic roughness (along the anisotropy tangent)\n\
19
19
  * @param {vec3} lightDirection The direction from the fragment to the light source, transformed to tangent-bitangent-normal coordinates\n\
20
20
  * @param {vec3} viewDirection The direction from the fragment to the camera, transformed to tangent-bitangent-normal coordinates\n\
21
21
  */\n\
22
- float smithVisibilityGGX_anisotropic(float roughness, float tangentialRoughness, vec3 lightDirection, vec3 viewDirection)\n\
22
+ float smithVisibilityGGX_anisotropic(float bitangentRoughness, float tangentialRoughness, vec3 lightDirection, vec3 viewDirection)\n\
23
23
  {\n\
24
- vec3 roughnessScale = vec3(tangentialRoughness, roughness, 1.0);\n\
24
+ vec3 roughnessScale = vec3(tangentialRoughness, bitangentRoughness, 1.0);\n\
25
25
  float GGXV = lightDirection.z * length(roughnessScale * viewDirection);\n\
26
26
  float GGXL = viewDirection.z * length(roughnessScale * lightDirection);\n\
27
27
  float v = 0.5 / (GGXV + GGXL);\n\
@@ -29,44 +29,44 @@ float smithVisibilityGGX_anisotropic(float roughness, float tangentialRoughness,
29
29
  }\n\
30
30
  \n\
31
31
  /**\n\
32
- * @param {float} roughness Material roughness (along the anisotropy bitangent)\n\
32
+ * @param {float} bitangentRoughness Material roughness (along the anisotropy bitangent)\n\
33
33
  * @param {float} tangentialRoughness Anisotropic roughness (along the anisotropy tangent)\n\
34
34
  * @param {vec3} halfwayDirection The unit vector halfway between light and view directions, transformed to tangent-bitangent-normal coordinates\n\
35
35
  */\n\
36
- float GGX_anisotropic(float roughness, float tangentialRoughness, vec3 halfwayDirection)\n\
36
+ float GGX_anisotropic(float bitangentRoughness, float tangentialRoughness, vec3 halfwayDirection)\n\
37
37
  {\n\
38
- float roughnessSquared = roughness * tangentialRoughness;\n\
39
- vec3 f = halfwayDirection * vec3(roughness, tangentialRoughness, roughnessSquared);\n\
38
+ float roughnessSquared = bitangentRoughness * tangentialRoughness;\n\
39
+ vec3 f = halfwayDirection * vec3(bitangentRoughness, tangentialRoughness, roughnessSquared);\n\
40
40
  float w2 = roughnessSquared / dot(f, f);\n\
41
41
  return roughnessSquared * w2 * w2 / czm_pi;\n\
42
42
  }\n\
43
43
  #endif\n\
44
44
  \n\
45
- float smithVisibilityG1(float NdotV, float roughness)\n\
46
- {\n\
47
- // this is the k value for direct lighting.\n\
48
- // for image based lighting it will be roughness^2 / 2\n\
49
- float k = (roughness + 1.0) * (roughness + 1.0) / 8.0;\n\
50
- return NdotV / (NdotV * (1.0 - k) + k);\n\
51
- }\n\
52
- \n\
53
45
  /**\n\
54
46
  * Estimate the geometric self-shadowing of the microfacets in a surface,\n\
55
- * using the Schlick GGX approximation of a Smith visibility function.\n\
47
+ * using the Smith Joint GGX visibility function.\n\
48
+ * Note: Vis = G / (4 * NdotL * NdotV)\n\
49
+ * see Eric Heitz. 2014. Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs. Journal of Computer Graphics Techniques, 3\n\
50
+ * see Real-Time Rendering. Page 331 to 336.\n\
51
+ * see https://google.github.io/filament/Filament.md.html#materialsystem/specularbrdf/geometricshadowing(specularg)\n\
56
52
  *\n\
57
- * @param {float} roughness The roughness of the material.\n\
53
+ * @param {float} alphaRoughness The roughness of the material, expressed as the square of perceptual roughness.\n\
58
54
  * @param {float} NdotL The cosine of the angle between the surface normal and the direction to the light source.\n\
59
55
  * @param {float} NdotV The cosine of the angle between the surface normal and the direction to the camera.\n\
60
56
  */\n\
61
- float smithVisibilityGGX(float roughness, float NdotL, float NdotV)\n\
57
+ float smithVisibilityGGX(float alphaRoughness, float NdotL, float NdotV)\n\
62
58
  {\n\
63
- // Avoid divide-by-zero errors\n\
64
- NdotL = clamp(NdotL, 0.001, 1.0);\n\
65
- NdotV += 0.001;\n\
66
- return (\n\
67
- smithVisibilityG1(NdotL, roughness) *\n\
68
- smithVisibilityG1(NdotV, roughness)\n\
69
- ) / (4.0 * NdotL * NdotV);\n\
59
+ float alphaRoughnessSq = alphaRoughness * alphaRoughness;\n\
60
+ \n\
61
+ float GGXV = NdotL * sqrt(NdotV * NdotV * (1.0 - alphaRoughnessSq) + alphaRoughnessSq);\n\
62
+ float GGXL = NdotV * sqrt(NdotL * NdotL * (1.0 - alphaRoughnessSq) + alphaRoughnessSq);\n\
63
+ \n\
64
+ float GGX = GGXV + GGXL;\n\
65
+ if (GGX > 0.0)\n\
66
+ {\n\
67
+ return 0.5 / GGX;\n\
68
+ }\n\
69
+ return 0.0;\n\
70
70
  }\n\
71
71
  \n\
72
72
  /**\n\
@@ -74,15 +74,15 @@ float smithVisibilityGGX(float roughness, float NdotL, float NdotV)\n\
74
74
  * the halfway vector, which is aligned halfway between the directions from\n\
75
75
  * the fragment to the camera and from the fragment to the light source.\n\
76
76
  *\n\
77
- * @param {float} roughness The roughness of the material.\n\
77
+ * @param {float} alphaRoughness The roughness of the material, expressed as the square of perceptual roughness.\n\
78
78
  * @param {float} NdotH The cosine of the angle between the surface normal and the halfway vector.\n\
79
79
  * @return {float} The fraction of microfacets aligned to the halfway vector.\n\
80
80
  */\n\
81
- float GGX(float roughness, float NdotH)\n\
81
+ float GGX(float alphaRoughness, float NdotH)\n\
82
82
  {\n\
83
- float roughnessSquared = roughness * roughness;\n\
84
- float f = (NdotH * roughnessSquared - NdotH) * NdotH + 1.0;\n\
85
- return roughnessSquared / (czm_pi * f * f);\n\
83
+ float alphaRoughnessSquared = alphaRoughness * alphaRoughness;\n\
84
+ float f = (NdotH * alphaRoughnessSquared - NdotH) * NdotH + 1.0;\n\
85
+ return alphaRoughnessSquared / (czm_pi * f * f);\n\
86
86
  }\n\
87
87
  \n\
88
88
  /**\n\
@@ -92,16 +92,16 @@ float GGX(float roughness, float NdotH)\n\
92
92
  * @param {vec3} lightDirection The unit vector pointing from the fragment to the light source.\n\
93
93
  * @param {vec3} viewDirection The unit vector pointing from the fragment to the camera.\n\
94
94
  * @param {vec3} halfwayDirection The unit vector pointing from the fragment to halfway between the light source and the camera.\n\
95
- * @param {float} roughness The roughness of the material.\n\
95
+ * @param {float} alphaRoughness The roughness of the material, expressed as the square of perceptual roughness.\n\
96
96
  * @return {float} The strength of the specular reflection.\n\
97
97
  */\n\
98
- float computeDirectSpecularStrength(vec3 normal, vec3 lightDirection, vec3 viewDirection, vec3 halfwayDirection, float roughness)\n\
98
+ float computeDirectSpecularStrength(vec3 normal, vec3 lightDirection, vec3 viewDirection, vec3 halfwayDirection, float alphaRoughness)\n\
99
99
  {\n\
100
100
  float NdotL = dot(normal, lightDirection);\n\
101
101
  float NdotV = abs(dot(normal, viewDirection));\n\
102
- float G = smithVisibilityGGX(roughness, NdotL, NdotV);\n\
102
+ float G = smithVisibilityGGX(alphaRoughness, NdotL, NdotV);\n\
103
103
  float NdotH = clamp(dot(normal, halfwayDirection), 0.0, 1.0);\n\
104
- float D = GGX(roughness, NdotH);\n\
104
+ float D = GGX(alphaRoughness, NdotH);\n\
105
105
  return G * D;\n\
106
106
  }\n\
107
107
  \n\
@@ -139,19 +139,20 @@ vec3 czm_pbrLighting(vec3 viewDirectionEC, vec3 normalEC, vec3 lightDirectionEC,
139
139
  F *= material.specularWeight;\n\
140
140
  #endif\n\
141
141
  \n\
142
- float alpha = material.roughness;\n\
142
+ float alphaRoughness = material.roughness * material.roughness;\n\
143
143
  #ifdef USE_ANISOTROPY\n\
144
144
  mat3 tbn = mat3(material.anisotropicT, material.anisotropicB, normalEC);\n\
145
145
  vec3 lightDirection = lightDirectionEC * tbn;\n\
146
146
  vec3 viewDirection = viewDirectionEC * tbn;\n\
147
147
  vec3 halfwayDirection = halfwayDirectionEC * tbn;\n\
148
148
  float anisotropyStrength = material.anisotropyStrength;\n\
149
- float tangentialRoughness = mix(alpha, 1.0, anisotropyStrength * anisotropyStrength);\n\
150
- float G = smithVisibilityGGX_anisotropic(alpha, tangentialRoughness, lightDirection, viewDirection);\n\
151
- float D = GGX_anisotropic(alpha, tangentialRoughness, halfwayDirection);\n\
149
+ float tangentialRoughness = mix(alphaRoughness, 1.0, anisotropyStrength * anisotropyStrength);\n\
150
+ float bitangentRoughness = clamp(alphaRoughness, 0.001, 1.0);\n\
151
+ float G = smithVisibilityGGX_anisotropic(bitangentRoughness, tangentialRoughness, lightDirection, viewDirection);\n\
152
+ float D = GGX_anisotropic(bitangentRoughness, tangentialRoughness, halfwayDirection);\n\
152
153
  vec3 specularContribution = F * G * D;\n\
153
154
  #else\n\
154
- float specularStrength = computeDirectSpecularStrength(normalEC, lightDirectionEC, viewDirectionEC, halfwayDirectionEC, alpha);\n\
155
+ float specularStrength = computeDirectSpecularStrength(normalEC, lightDirectionEC, viewDirectionEC, halfwayDirectionEC, alphaRoughness);\n\
155
156
  vec3 specularContribution = F * specularStrength;\n\
156
157
  #endif\n\
157
158
  \n\
@@ -68,7 +68,7 @@ vec3 czm_sampleOctahedralProjectionWithFiltering(sampler2D projectedMap, vec2 te
68
68
  * @returns {vec3} The color of the cube map at the direction.
69
69
  */
70
70
  vec3 czm_sampleOctahedralProjection(sampler2D projectedMap, vec2 textureSize, vec3 direction, float lod, float maxLod) {
71
- float currentLod = floor(lod + 0.5);
71
+ float currentLod = floor(lod);
72
72
  float nextLod = min(currentLod + 1.0, maxLod);
73
73
 
74
74
  vec3 colorCurrentLod = czm_sampleOctahedralProjectionWithFiltering(projectedMap, textureSize, direction, currentLod);
@@ -69,7 +69,7 @@ vec3 czm_sampleOctahedralProjectionWithFiltering(sampler2D projectedMap, vec2 te
69
69
  * @returns {vec3} The color of the cube map at the direction.\n\
70
70
  */\n\
71
71
  vec3 czm_sampleOctahedralProjection(sampler2D projectedMap, vec2 textureSize, vec3 direction, float lod, float maxLod) {\n\
72
- float currentLod = floor(lod + 0.5);\n\
72
+ float currentLod = floor(lod);\n\
73
73
  float nextLod = min(currentLod + 1.0, maxLod);\n\
74
74
  \n\
75
75
  vec3 colorCurrentLod = czm_sampleOctahedralProjectionWithFiltering(projectedMap, textureSize, direction, currentLod);\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;
@@ -173,11 +175,12 @@ vec3 sampleSpecularEnvironment(vec3 cubeDir, float roughness)
173
175
  return czm_sampleOctahedralProjection(czm_specularEnvironmentMaps, czm_specularEnvironmentMapSize, cubeDir, lod, maxLod);
174
176
  #endif
175
177
  }
176
- vec3 computeSpecularIBL(vec3 cubeDir, float NdotV, float VdotH, vec3 f0, float roughness)
178
+ vec3 computeSpecularIBL(vec3 cubeDir, float NdotV, vec3 f0, float roughness)
177
179
  {
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);
180
+ // see https://bruop.github.io/ibl/ at Single Scattering Results
181
+ // Roughness dependent fresnel, from Fdez-Aguera
182
+ vec3 f90 = max(vec3(1.0 - roughness), f0);
183
+ vec3 F = fresnelSchlick2(f0, f90, NdotV);
181
184
 
182
185
  vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, roughness)).rg;
183
186
  vec3 specularSample = sampleSpecularEnvironment(cubeDir, roughness);
@@ -202,34 +205,31 @@ vec3 textureIBL(
202
205
  vec3 lightDirectionEC,
203
206
  czm_modelMaterial material
204
207
  ) {
205
- // Find the direction in which to sample the environment map
206
- vec3 cubeDir = normalize(model_iblReferenceFrameMatrix * normalize(reflect(-viewDirectionEC, normalEC)));
207
-
208
208
  #ifdef DIFFUSE_IBL
209
- vec3 diffuseContribution = computeDiffuseIBL(cubeDir) * material.diffuse;
209
+ vec3 normalMC = normalize(model_iblReferenceFrameMatrix * normalEC);
210
+ vec3 diffuseContribution = computeDiffuseIBL(normalMC) * material.diffuse;
210
211
  #else
211
212
  vec3 diffuseContribution = vec3(0.0);
212
213
  #endif
213
214
 
214
- float roughness = material.roughness;
215
-
216
215
  #ifdef USE_ANISOTROPY
217
- // Update environment map sampling direction to account for anisotropic distortion of specular reflection
216
+ // Bend normal to account for anisotropic distortion of specular reflection
218
217
  vec3 anisotropyDirection = material.anisotropicB;
219
218
  vec3 anisotropicTangent = cross(anisotropyDirection, viewDirectionEC);
220
219
  vec3 anisotropicNormal = cross(anisotropicTangent, anisotropyDirection);
221
- float bendFactor = 1.0 - material.anisotropyStrength * (1.0 - roughness);
220
+ float bendFactor = 1.0 - material.anisotropyStrength * (1.0 - material.roughness);
222
221
  float bendFactorPow4 = bendFactor * bendFactor * bendFactor * bendFactor;
223
222
  vec3 bentNormal = normalize(mix(anisotropicNormal, normalEC, bendFactorPow4));
224
- cubeDir = normalize(model_iblReferenceFrameMatrix * normalize(reflect(-viewDirectionEC, bentNormal)));
223
+ vec3 reflectEC = reflect(-viewDirectionEC, bentNormal);
224
+ #else
225
+ vec3 reflectEC = reflect(-viewDirectionEC, normalEC);
225
226
  #endif
226
227
 
227
228
  #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);
229
+ vec3 reflectMC = normalize(model_iblReferenceFrameMatrix * reflectEC);
230
+ float NdotV = clamp(dot(normalEC, viewDirectionEC), 0.0, 1.0);
231
231
  vec3 f0 = material.specular;
232
- vec3 specularContribution = computeSpecularIBL(cubeDir, NdotV, VdotH, f0, roughness);
232
+ vec3 specularContribution = computeSpecularIBL(reflectMC, NdotV, f0, material.roughness);
233
233
  #else
234
234
  vec3 specularContribution = vec3(0.0);
235
235
  #endif