Skip to content

Commit a0ef08f

Browse files
authored
Merge pull request #12063 from CesiumGS/self-shadowing
Update self-shadowing function for direct lighting
2 parents 290f01d + 97959aa commit a0ef08f

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

Apps/Sandcastle/gallery/glTF PBR Extensions.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,24 @@
140140
onselect: () => {
141141
imageBasedLighting.sphericalHarmonicCoefficients = coefficients;
142142
imageBasedLighting.specularEnvironmentMaps = environmentMapURL;
143+
imageBasedLighting.imageBasedLightingFactor =
144+
Cesium.Cartesian2.ONE;
143145
},
144146
},
145147
{
146148
text: "Procedural sky lighting",
147149
onselect: () => {
148150
imageBasedLighting.sphericalHarmonicCoefficients = undefined;
149151
imageBasedLighting.specularEnvironmentMaps = undefined;
152+
imageBasedLighting.imageBasedLightingFactor =
153+
Cesium.Cartesian2.ONE;
154+
},
155+
},
156+
{
157+
text: "Direct lighting only",
158+
onselect: () => {
159+
imageBasedLighting.imageBasedLightingFactor =
160+
Cesium.Cartesian2.ZERO;
150161
},
151162
},
152163
];
@@ -194,6 +205,10 @@
194205
text: "Barn Lamp",
195206
onselect: () => loadModel(2583726),
196207
},
208+
{
209+
text: "Metal-Roughness Spheres",
210+
onselect: () => loadModel(2635364),
211+
},
197212
];
198213
Sandcastle.addToolbarMenu(modelOptions, "modelsToolbar");
199214
loadModel(2584329);

CHANGES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Change Log
22

3+
### 1.120 - 2024-08-01
4+
5+
#### @cesium/engine
6+
7+
##### Fixes :wrench:
8+
9+
- Updated geometric self-shadowing function to improve direct lighting on models using physically-based rendering. [#12063](https://github.com/CesiumGS/cesium/pull/12063)
10+
311
### 1.119 - 2024-07-01
412

513
#### @cesium/engine

packages/engine/Source/Shaders/Builtin/Functions/pbrLighting.glsl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,31 @@ float GGX_anisotropic(float roughness, float tangentialRoughness, vec3 halfwayDi
4141
}
4242
#endif
4343

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-
5244
/**
5345
* 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)
5551
*
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.
5753
* @param {float} NdotL The cosine of the angle between the surface normal and the direction to the light source.
5854
* @param {float} NdotV The cosine of the angle between the surface normal and the direction to the camera.
5955
*/
60-
float smithVisibilityGGX(float roughness, float NdotL, float NdotV)
56+
float smithVisibilityGGX(float alphaRoughness, float NdotL, float NdotV)
6157
{
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;
6969
}
7070

7171
/**

0 commit comments

Comments
 (0)