GTAO test - #1090
Draft
chrisj wants to merge 20 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Corrected GTAO
The corrected implementation in shaders.ts explicitly evaluates GTAO in view-space slices.
1. Reconstruct the surface point
The depth buffer stores
1 - gl_FragCoord.z, so the shader reverses that and reconstructs view-space position:2. Decode the view-space normal
Normals are packed from$[-1,1]$ into $[0,1]$ :
A zero-RGB packed value is reserved as the no-AO sentinel. Background, annotations, skeletons, highlighted meshes, and other excluded fragments therefore return full visibility immediately.
3. Determine the sampling radius
uRadiusis a fraction of viewport height. It controls both:The projection matrix converts the viewport fraction into a view-space radius:
For perspective projection,$w_{\mathrm{clip}}$ varies with distance. For orthographic projection it is constant.
4. Rotate the sampling pattern
A pixel-dependent hash rotates the four sampling slices:
This prevents persistent axis-aligned artifacts. Another hash jitters the sample positions along each slice.
Only a half-circle of directions is needed because every slice is sampled on both its positive and negative sides.
5. Construct a view-space slice
For each screen-space direction, the shader reconstructs a nearby point at the same depth to obtain a view-space tangent:
The slice is the plane containing:
For perspective projection:
For orthographic projection:
6. Project the normal into the slice
Only the component of the surface normal lying in the current slice contributes to that slice’s integral:
The shader records both:
The length weights the slice’s contribution. A slice nearly perpendicular to the surface normal contributes little.
The signed angle between the projected normal and the view direction is
normalAngle.7. Find the two horizon angles
An unobstructed normal-oriented hemisphere spans:
These are the initial negative and positive horizon limits.
As samples are examined, each side’s horizon moves inward when geometry blocks part of the visible arc:
Nearby samples have more influence. The distance falloff is:
Rather than multiplying a slope by this falloff, the corrected version interpolates the sample horizon toward the unobstructed hemisphere boundary. A sample at the radius therefore contributes no occlusion.
The minimum accepted sample distance is also relative to the view-space radius, instead of using one fixed world-space threshold.
8. Integrate the visible arc
Once the two horizons are known,
integrateArcanalytically integrates visibility relative to the projected normal:The positive and mirrored negative arcs are combined:
This is the key difference from the old implementation. The shader now measures the angular area of the visible normal-oriented hemisphere, rather than using the largest sample-normal dot product as a proxy.
Each slice contributes:
The final result is the average visibility over all four slices:
Behavioral Difference
Consider a tilted but perfectly flat plane.
In the previous version, samples along that plane can have positive dot products with the normal because of projection, discretization, or slice orientation. The maximum-dot heuristic may interpret this as occlusion and darken the plane.
In the corrected version, the normal is first projected into each slice. The plane’s horizons coincide with the boundaries of its normal-oriented hemisphere, so the integrated visible arc remains approximately complete:
For a crevice or pit, nearby geometry moves both horizons inward. The visible angular interval shrinks, producing a lower AO value.