[Draft/RFC] Add angular ray bias to ContactShadows to fix steep slope artifacts - #25355
Open
Affinator wants to merge 1 commit into
Open
[Draft/RFC] Add angular ray bias to ContactShadows to fix steep slope artifacts #25355Affinator wants to merge 1 commit into
Affinator wants to merge 1 commit into
Conversation
…surface normal on steep surfaces (prevents self occlusion)
Contributor
|
Welcome, new contributor! Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨ |
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.
Full disclosure: This PR description has been generated with AI. The code was written by hand.
Objective
Solution
The shader now dynamically bends the contact shadow ray away from the surface (towards the normal) by up to
ray_bias_degrees. The geometric approach is as follows:NdotL).NdotL < 0.25), the bias applies fully. As the angle becomes more direct (NdotLapproaches0.45), the bias smoothly fades to zero via asmoothstepcurve.theta(in radians) by multiplyingray_bias_degreesby this fade factor and converting to rad.Tthat points directly away from the surface.thetausinglight_dir * cos(theta) + T * sin(theta).While we experimented with more classical shadow normal biases (like shifting the ray's origin or target), they introduced other forms of artifacts. This angular ray bending solution clears the depth buffer's staircase artifacts and creates very believable contact shadows, which are only slightly "physically wrong" in these specific grazing angle ranges.
Added an early-exit optimization: We now immediately exit and return no shadow if the surface is facing away from the light (
NdotL < 0.0), since the surface is self-occluding by definition and handled by macro shadow maps. This is not necessary to fix the artifacts, but since we now have this information available, this seems to be a sensible optimization.Visual Proof
ray_bias_degrees = 0.0)ray_bias_degrees = 6.5)|


|
|
Changelog
ray_bias_degreestoContactShadowsand its corresponding uniform/WESL types to control angular ray bending at grazing angles.@if(SIXTEEN_BYTE_ALIGNMENT) _padding: f32in theContactShadowsSettingsWESL struct, as the addition ofray_bias_degreesnaturally aligns the struct to 16 bytes.Migration Guide
ContactShadowshas a newray_bias_degreesfield. If you were manually constructingContactShadowswithout..default(), you will need to addray_bias_degrees(e.g.6.5or lower depending on your scene) to your struct instantiation.