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

Normalization error in image-based lighting #11994

Closed
jjhembd opened this issue May 17, 2024 · 0 comments · Fixed by #11988
Closed

Normalization error in image-based lighting #11994

jjhembd opened this issue May 17, 2024 · 0 comments · Fixed by #11988

Comments

@jjhembd
Copy link
Contributor

jjhembd commented May 17, 2024

Our image-based lighting codes do not normalize the view vector, leading to (slightly) incorrect lighting calculations.

For example, in ImageBasedLightingStageFS,

vec3 proceduralIBL(...)
{
    vec3 v = -positionEC;
    vec3 n = normalEC;
    vec3 r = normalize(czm_inverseViewRotation * normalize(reflect(v, n)));
    float NdotV = abs(dot(n, v)) + 0.001;

NdotV should represent the cosine of the angle between normal and view vectors. But with v being unnormalized, NdotV can potentially be greater than 1 at normal incidence, and too large at angles between 0 and 90°.
The first line should read as follows:

    vec3 v = -normalize(positionEC);

There is a similar problem in the textureIBL function.

Here are a few images showing the impact of the error, as noticed while working on #11988.

Default environmental lighting (textureIBL), current code:
image

Default environmental lighting, corrected code. Note the additional light at the edges of the spheres in the right column, as well as a slightly more linear trend in brightness from left to right.
image

Procedural lighting (proceduralIBL), current code:
image

Procedural lighting, corrected code. Note the more linear trend in brightness from left to right.
image

Local Sandcastle for testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant