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 depth sampling for ambient occlusion #12201

Merged
merged 7 commits into from
Sep 20, 2024
Merged

Fix depth sampling for ambient occlusion #12201

merged 7 commits into from
Sep 20, 2024

Conversation

jjhembd
Copy link
Contributor

@jjhembd jjhembd commented Sep 17, 2024

Description

This PR fixes sampling of the depth texture in AmbientOcclusionGenerate.glsl.

Our ambient occlusion shader was developed when depth buffers still used linear sampling. After #9966, the depth buffer uses nearest sampling. And in a WebGL2 context, linear sampling of a depth buffer is not allowed. This meant that:

  • The depth value read from depthTexture actually corresponded to the center of the pixel.
  • X and Y values were still assumed to be at un-centered positions.

The inconsistency between depth and XY values produced enough geometry error to create a background occlusion factor everywhere, including on flat surfaces which should have no occlusion.

This PR adjusts the shader calculations to explicitly shift all sampling points to pixel centers.

Along the way, I rewrote the shader to better reflect the geometry of the various inputs.

Rendering results

Before this PR:
image

After this PR, with a WebGL2 context (default):
image

After this PR, with a WebGL1 context:
image

Issue number and link

Partially addresses #10106.

Testing plan

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

Copy link

Thank you for the pull request, @jjhembd!

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

Copy link
Contributor

@ggetz ggetz left a comment

Choose a reason for hiding this comment

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

This looks great @jjhembd! I just have some small comments, but the code itself looks great!

CHANGES.md Outdated Show resolved Hide resolved
@@ -6,109 +8,107 @@ uniform float lengthCap;
uniform float stepSize;
uniform float frustumLength;

in vec2 v_textureCoordinates;
Copy link
Contributor

Choose a reason for hiding this comment

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

I recall we talked offline that this is probably not the best solution for post processing across the board. If that's correct, could you make sure we have an open issue documenting the suggested for other post processing stages?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #12208

Co-authored-by: Gabby Getz <gabby@cesium.com>
@jjhembd
Copy link
Contributor Author

jjhembd commented Sep 20, 2024

@ggetz thanks for the feedback! I think I addressed it above.

@ggetz
Copy link
Contributor

ggetz commented Sep 20, 2024

Awesome, thanks @jjhembd!

@ggetz ggetz merged commit bbd6afd into main Sep 20, 2024
9 checks passed
@ggetz ggetz deleted the ao-depth-sampling branch September 20, 2024 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants