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

Fix specular reflection artifact in PBR direct lighting #12116

Merged
merged 2 commits into from
Aug 9, 2024
Merged

Conversation

jjhembd
Copy link
Contributor

@jjhembd jjhembd commented Aug 8, 2024

Description

When computing the specular contribution from PBR direct lighting, the dot products used in the BRDF need to be clamped to the range [0.0, 1.0]. Our code was missing the clamp, but the artifacts didn't appear until we updated the BRDF in #12063.

This PR adds the clamps in computeDirectSpecularStrength in pbrLighting.glsl.

Rendering results

Before this PR:
image

After this PR:
image

Issue number and link

Fixes #12109.

Testing plan

  1. Load @javagl 's Sandcastle and verify that the artifacts are gone after this PR.
  2. Load the glTF PBR Extensions Sandcastle and view models with "Direct lighting only", rotating them to the side opposite the light source.

Author checklist

  • I have submitted a Contributor License Agreement
  • I have added my name to CONTRIBUTORS.md
  • I have updated CHANGES.md with a short summary of my change
  • I have added or updated unit tests to ensure consistent code coverage
  • I have updated the inline documentation, and included code examples where relevant
  • I have performed a self-review of my code
@jjhembd jjhembd requested a review from javagl August 8, 2024 20:09
@jjhembd jjhembd changed the title Fix artifact in from specular calculation in PBR direct lighting Aug 8, 2024
@jjhembd jjhembd changed the title Fix artifact in specular calculation in PBR direct lighting Aug 8, 2024
Copy link

github-actions bot commented Aug 8, 2024

Thank you for the pull request, @jjhembd!

✅ We can confirm we have a CLA on file for you.

Copy link
Contributor

@javagl javagl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the user-facing perspective:
I tried it out with my test sandcastle and the "WaterBottle"+directional light (that you mentioned in the issue), and I don't see the artifacts any more.

From the code perspective:
The artifacts looked like "some division-by-epsilon" or ~"some missing clamping" (we roughly know how these things look like 🙂 ). So the change looks reasonable.

But I don't say that with a "deep understanding". For example, that abs was removed from the NdotV . If that line had been changed to something like
clamp(dot(normal, viewDirection)), -1.0, 1.0);
then it would also look reasonable for me, by quickly skimming over it.

(Or to put it simply: I didn't do the math...)

A ping @bertt for the case that you want to try this out early.

@jjhembd jjhembd marked this pull request as ready for review August 8, 2024 21:44
@ggetz
Copy link
Contributor

ggetz commented Aug 9, 2024

Looks good to me! Thanks @jjhembd and @javagl!

@ggetz ggetz merged commit 5ee2f01 into main Aug 9, 2024
9 checks passed
@ggetz ggetz deleted the pbr-artifact-fix branch August 9, 2024 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants