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 regression in SSS with reverse-z #99220

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

Flarkk
Copy link
Contributor

@Flarkk Flarkk commented Nov 14, 2024

This PR fixes how the Subsurface Scattering shader fetches depth from the now reverse-z buffer.
It seems like SSS was missed in the original reverse-z implementation #88328.

The change is very subtle, so I had to set the depth scale to 1.0 in the settings to make it obvious in the screenshots below (rendering/environment/subsurface_scattering/subsurface_scattering_depth_scale).

Note that the depth value is not used in orthographic mode, hence no difference.

I also took this opportunity to rewrite the depth reconstruction code in a less convoluted way. It should allow easier maintenance in the future.

4.2.1 (before reverse-z) 4.3 (after reverse-z) With this PR
Perspective Capture d’écran du 2024-11-14 10-13-32 Capture d’écran du 2024-11-14 10-16-48 Capture d’écran du 2024-11-14 10-14-37
Orthographic Capture d’écran du 2024-11-14 10-22-15 Capture d’écran du 2024-11-14 10-22-15 Capture d’écran du 2024-11-14 10-20-51

@Flarkk Flarkk requested a review from a team as a code owner November 14, 2024 10:04
@AThousandShips AThousandShips added this to the 4.4 milestone Nov 14, 2024
@akien-mga
Copy link
Member

akien-mga commented Nov 14, 2024

Welcome and thanks for contributing!

Could you amend the commit message to remove the "This reverts commit dd74865f0e6d860932f6c084bceb92ab6d6c6103." line?
This seems to be something that was specific to your work branch, this commit doesn't exist upstream and this is not a revert commit.

@Flarkk
Copy link
Contributor Author

Flarkk commented Nov 14, 2024

Thanks @akien-mga !
Done. Indeed I cherry-picked this fix from another local branch I'm working on and overlooked the commit message. Sorry for this !

@Calinou Calinou added topic:3d cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release labels Nov 14, 2024
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

I would simplify this and just do the same change we did for every other shader that reconstructs depth. You can fix this issue with some very minor shader changes. Take a look at servers/rendering/renderer_rd/shaders/effects/bokeh_dof.glsl for example, it was modified in the reverse z PR

Overall, I prefer that all the screen space effects use the same code so that we can fix them all at the same time when they need to be fixed.

@Flarkk
Copy link
Contributor Author

Flarkk commented Nov 24, 2024

Makes sense to have same code everywhere.

I would then suggest to move instead to the depth reconstruction code of this PR, for all other effects.

The reason is it doesn't depend on any camera value extraction method (get_zfar(), is_orthogonal(), etc...) which can break under certain conditions (typically when zfar is much bigger than znear, the projection matrix becomes infinite and it's not possible to retrieve zfar anymore).

This is related to the work I'm carrying out on supporting a wider range of zfar / znear values to untap the potential of reverse-z in single precision.

What I can propose to separate the concerns is twofold :

  • simplify this PR as you suggested
  • open a separate PR to change the depth reconstruction code in all screen space effects. I almost completed this work locally and can push something quite soon

How does it sound ?

@clayjohn
Copy link
Member

What I can propose to separate the concerns is twofold :

  • simplify this PR as you suggested
  • open a separate PR to change the depth reconstruction code in all screen space effects. I almost completed this work locally and can push something quite soon

How does it sound ?

That sounds great!

@Flarkk
Copy link
Contributor Author

Flarkk commented Nov 26, 2024

Completed this PR simplification

@Flarkk Flarkk requested a review from clayjohn November 26, 2024 11:39
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Looks great!

@Flarkk
Copy link
Contributor Author

Flarkk commented Nov 27, 2024

The separate PR to change the depth reconstruction code in all effects is here : #99755

@Repiteo Repiteo merged commit c58ae91 into godotengine:master Nov 27, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Nov 27, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release topic:rendering topic:3d
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants