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 linearization #4360

Merged
merged 5 commits into from
Jun 23, 2022
Merged

Fix depth linearization #4360

merged 5 commits into from
Jun 23, 2022

Conversation

GSterbrant
Copy link
Contributor

Fixes #3411

Linearization of the depth buffer was done incorrectly, however it produced coherently variant results with a perspective projection, but not with an orthogonal one. That resulted in post effects linearizing depth producing incorrect results, such as the SSAO:

Screenshot 2022-06-22 at 16 23 51
effect.

With this PR, the results are more correct:

Screenshot 2022-06-22 at 16 53 48

@willeastcott
Copy link
Contributor

willeastcott commented Jun 22, 2022

Cool, great to see this fixed. As an aside, I'm wondering whether the chessboard @mvaligursky added would be a much better scene to show off post effects (particularly bokeh). (I'm not suggesting this should be addressed in this PR though!).

Copy link
Contributor

@mvaligursky mvaligursky left a comment

Choose a reason for hiding this comment

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

nice one!

Actually, orthographic projection already stores the depth linearly, so all we need to do is to scale it back so it's between near and far plane.

As for perspective projection, since the depth is already in normalized space [0, 1], there should be no need to move it back to NDC coordinates since we don't want the depth in -1, 1 when we output.

One unfortunate effect is that we are more or less forced to branch on a uniform since the shader has no awareness of the type of projection being used.
@GSterbrant GSterbrant merged commit c175011 into main Jun 23, 2022
@GSterbrant GSterbrant deleted the gsterbrant_linearize_depth_fix branch June 23, 2022 11:18
@GSterbrant GSterbrant self-assigned this Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SSAO post effect not working with Orthographic camera mode
3 participants