-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
Thank you for the pull request, @jjhembd! ✅ We can confirm we have a CLA on file for you. |
There was a problem hiding this 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!
@@ -6,109 +8,107 @@ uniform float lengthCap; | |||
uniform float stepSize; | |||
uniform float frustumLength; | |||
|
|||
in vec2 v_textureCoordinates; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 <[email protected]>
@ggetz thanks for the feedback! I think I addressed it above. |
Awesome, thanks @jjhembd! |
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:
depthTexture
actually corresponded to the center of the pixel.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](https://private-user-images.githubusercontent.com/41167620/368363293-d26e6664-2af0-4729-a3b4-22dd2e38f76b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk3NTMwNzQsIm5iZiI6MTczOTc1Mjc3NCwicGF0aCI6Ii80MTE2NzYyMC8zNjgzNjMyOTMtZDI2ZTY2NjQtMmFmMC00NzI5LWEzYjQtMjJkZDJlMzhmNzZiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE3VDAwMzkzNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWFmZTY5NmIxMzMxNzYzNjExMjhiMmM4ZjgwZWRmZGRmOTVjN2I4ZTA3Y2U0Y2E4NzA1ZmYxZmEyYTg1MDg2YjImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.4r73eJDtg6_NOQFQlVfJu3QndUAQ77Hr8g_UIxbIKYk)
After this PR, with a WebGL2 context (default):
![image](https://private-user-images.githubusercontent.com/41167620/368363447-7bb45d3c-bd7f-41b0-b08a-6ddca82bcc94.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk3NTMwNzQsIm5iZiI6MTczOTc1Mjc3NCwicGF0aCI6Ii80MTE2NzYyMC8zNjgzNjM0NDctN2JiNDVkM2MtYmQ3Zi00MWIwLWIwOGEtNmRkY2E4MmJjYzk0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE3VDAwMzkzNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ5MDU0MzlmOTU1MDQ5ODE0MTU2NGViNTI4OTczM2NkMDJjNzQyYjY5YWRiZmZlMDEyYjJhMTg5MjIwZmM2NDEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Pdx6uGkkRrKtrMiGbiKeTyWYZVSOItNJurVnYpcrdck)
After this PR, with a WebGL1 context:
![image](https://private-user-images.githubusercontent.com/41167620/368363386-7916c74f-2a9d-4806-8e25-9a5dc267c14e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk3NTMwNzQsIm5iZiI6MTczOTc1Mjc3NCwicGF0aCI6Ii80MTE2NzYyMC8zNjgzNjMzODYtNzkxNmM3NGYtMmE5ZC00ODA2LThlMjUtOWE1ZGMyNjdjMTRlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE3VDAwMzkzNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgyNjUxYWJmY2FkN2Y0NTE4MDc3N2I1ODk1NDY2ODMyNTQ3YTAyODM5MDQ4YmI2MGE2NDUxMGZiM2YwZGY4MTgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.EtnSBsxZMJefcz6oHAQGGmAWULiSLMXwwJlZM1DoJ8c)
Issue number and link
Partially addresses #10106.
Testing plan
Author checklist
CONTRIBUTORS.md
CHANGES.md
with a short summary of my change