Fix CSM shadow casters incorrectly culled by camera distance; add cross-cascade blending - #1244
Merged
Merged
Conversation
…ade blending Directional-light shadow casters were culled by camera-depth distance against each cascade's own split, but an object outside a cascade's camera-depth interval can still project a shadow into it (e.g. a low sun casting a long shadow from off-screen). Cull casters against the fitted light-space cascade frustum instead, which is the correctness-preserving test; restore the lost draw-call optimization with a direction-agnostic distance reject measured from each cascade's own world-space bounding sphere instead of the camera. Also: - Cross-fade shadow visibility across the last 10% of each cascade interval instead of hard-switching, avoiding a visible pop as geometry crosses a split. The blend boundary is computed once per frame on the CPU (ShadowSystem.cascadeBlendStart) and uploaded to the shader, rather than independently re-derived on both sides. - Push the shadow-space sample point along the surface normal (normal-offset shadows) instead of only biasing depth, fixing acne from normal-mapped shading normals; guard against a zero-length normal so a degenerate G-buffer normal can't NaN the shadow lookup. - Convert shadow bias and PCF filter radius to world units and back so they stay physically consistent across cascades with different orthographic depth ranges and texel densities.
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.
Summary
a valid caster whenever it sat outside a cascade's camera-depth interval
but still projected a shadow into it (e.g. long shadows from a low sun).
Casters are now culled against the fitted light-space cascade frustum,
which is correctness-preserving. The lost draw-call optimization is
restored via a new distance reject measured from each cascade's own
world-space bounding sphere (direction-agnostic, so it can't reintroduce
the original bug).
now cross-fades between adjacent cascade shadow maps instead of hard-
switching, removing a visible pop at cascade splits. The blend boundary is
computed once per frame on the CPU and uploaded to the shader as data, so
the CPU frustum-widening and GPU cross-fade can't drift out of sync.
normals, with a guard against zero-length normals so a degenerate
G-buffer normal can't produce NaN in the shadow lookup.
back, keeping them physically consistent across cascades with different
orthographic depth ranges and texel densities.
This PR addressed issue #1221
Test plan
swift buildsucceedsbuildkernels.shrebuilds all.metallibtargets cleanlyswift test --filter "ShadowSystemCascade|ShadowSystemMakeUniformsTests|CsmCascadeCountTests|ShadowDistanceCullingTests"— 38/38 pass