Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update self-shadowing function for direct lighting #12063

Merged
merged 4 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Apps/Sandcastle/gallery/glTF PBR Extensions.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,24 @@
onselect: () => {
imageBasedLighting.sphericalHarmonicCoefficients = coefficients;
imageBasedLighting.specularEnvironmentMaps = environmentMapURL;
imageBasedLighting.imageBasedLightingFactor =
Cesium.Cartesian2.ONE;
},
},
{
text: "Procedural sky lighting",
onselect: () => {
imageBasedLighting.sphericalHarmonicCoefficients = undefined;
imageBasedLighting.specularEnvironmentMaps = undefined;
imageBasedLighting.imageBasedLightingFactor =
Cesium.Cartesian2.ONE;
},
},
{
text: "Direct lighting only",
onselect: () => {
imageBasedLighting.imageBasedLightingFactor =
Cesium.Cartesian2.ZERO;
},
},
];
Expand Down Expand Up @@ -194,6 +205,10 @@
text: "Barn Lamp",
onselect: () => loadModel(2583726),
},
{
text: "Metal-Roughness Spheres",
onselect: () => loadModel(2635364),
},
];
Sandcastle.addToolbarMenu(modelOptions, "modelsToolbar");
loadModel(2584329);
Expand Down
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

### 1.120 - 2024-08-01

#### @cesium/engine

##### Fixes :wrench:

- Updated geometric self-shadowing function to improve direct lighting on models using physically-based rendering. [#12063](https://github.com/CesiumGS/cesium/pull/12063)

### 1.119 - 2024-07-01

#### @cesium/engine
Expand Down
36 changes: 18 additions & 18 deletions packages/engine/Source/Shaders/Builtin/Functions/pbrLighting.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,31 @@ float GGX_anisotropic(float roughness, float tangentialRoughness, vec3 halfwayDi
}
#endif

float smithVisibilityG1(float NdotV, float roughness)
{
// this is the k value for direct lighting.
// for image based lighting it will be roughness^2 / 2
float k = (roughness + 1.0) * (roughness + 1.0) / 8.0;
return NdotV / (NdotV * (1.0 - k) + k);
}

/**
* Estimate the geometric self-shadowing of the microfacets in a surface,
* using the Schlick GGX approximation of a Smith visibility function.
* using the Smith Joint GGX visibility function.
* Note: Vis = G / (4 * NdotL * NdotV)
* see Eric Heitz. 2014. Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs. Journal of Computer Graphics Techniques, 3
* see Real-Time Rendering. Page 331 to 336.
* see https://google.github.io/filament/Filament.md.html#materialsystem/specularbrdf/geometricshadowing(specularg)
*
* @param {float} roughness The roughness of the material.
* @param {float} alphaRoughness The roughness of the material, expressed as the square of perceptual roughness.
* @param {float} NdotL The cosine of the angle between the surface normal and the direction to the light source.
* @param {float} NdotV The cosine of the angle between the surface normal and the direction to the camera.
*/
float smithVisibilityGGX(float roughness, float NdotL, float NdotV)
float smithVisibilityGGX(float alphaRoughness, float NdotL, float NdotV)
{
// Avoid divide-by-zero errors
NdotL = clamp(NdotL, 0.001, 1.0);
NdotV += 0.001;
return (
smithVisibilityG1(NdotL, roughness) *
smithVisibilityG1(NdotV, roughness)
) / (4.0 * NdotL * NdotV);
float alphaRoughnessSq = alphaRoughness * alphaRoughness;

float GGXV = NdotL * sqrt(NdotV * NdotV * (1.0 - alphaRoughnessSq) + alphaRoughnessSq);
float GGXL = NdotV * sqrt(NdotL * NdotL * (1.0 - alphaRoughnessSq) + alphaRoughnessSq);

float GGX = GGXV + GGXL;
if (GGX > 0.0)
{
return 0.5 / GGX;
}
return 0.0;
}

/**
Expand Down