Simplify depth reprojection code #99755
Open
+135
−210
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR rewrites ndc-to-view space depth reprojection code in all effects and environment shaders : GI, SSS, SSR, SSIL, SSAO, SS downsampler, Bokeh, Copy effects and Cubemap to DP
The new code typically looks like this :
It replaces old reprojection code which typically looks like that :
There are some slight variations depending on whether the shader expects negative or positive depth, and whether the ndc depth is reversed.
Benefits
1. The new code doesn't depend on camera attributes anymore, which avoids issues under certain circumstances.
Camera attributes are typically retrieved from the projection matrix (with
Projection::is_orthogonal()
,Projection::get_z_far()
, ...) then passed to the shaders.The above functions can break under certain circumstances.
Typically when zfar is much bigger than znear, the perspective matrix that derives from it is infinite, then it becomes mathematically impossible to retrieve zfar back.
This change is part of the groundwork I'm carrying out to support wider ranges of zfar / znear ratios in single precision (today limited to ~1e6, typically zfar = 10km with znear = 0.01) which is important in open worlds and space games.
2. It prepares the support of custom projection matrices where it cannot be determined whether the projection is orthographic (for example with blended perspective and orthographic projections)
Non-regression tests
Test project : reprojection.zip
There shouldn't be any visual change after this PR
except for SSS, which is broken in master (see #99220 - this PR fixes it too). The screen captures for SSS below are made with 4.2.[edit : #99220 was merged]Visual reference before this PR (all visuals do match after the PR - see test project) :