Fix spot light degenerate outer angle - #25368
Open
Saratii wants to merge 4 commits into
Open
Conversation
…ot-light-degenerate-outer-angle
…ot-light-degenerate-outer-angle
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.
Objective
SpotLightwithouter_angleof0.0renders garbage whenshadow_maps_enabledis set, and aSpotLightwithouter_angleat or nearPI / 2.0disappears entirely, even though it logs that it is being clamped.Solution
tan(outer_angle)is the scale of the cone's perspective projection, and both ends of the old range broke it:0.0→ scale 0, so the shadow map projection and the shader's shadow lookup divide by zero.PI / 2.0 - 1e-4→ scale ~10000, collapsing the cone into a few texels at the shadow map centre, so the nearest occluder shadows everything.PI / 2.0→f32(PI / 2.0)rounds above true π/2, sotanis-2.3e7and the projection inverts.Adds
SpotLight::MIN_OUTER_ANGLE(1e-3),MAX_OUTER_ANGLE(1.5 rad, ~85.9°, still ~1 shadow texel per degree at 2048), andclamped_angles(), which clamps both angles, keepsinner <= outer, and maps NaN to the minimum. Cluster assignment and the shadow map frustum used the raw angle before, so they disagreed with what the shadow map was rendered with.Drops the
warn_once!inextract_lights: it fired once per process and named a clamp target that didn't work. Clamping is silent;clamped_angles()reports what's rendered. The warning was also logically inconsistent if the spotlight goes from invalid to valid to invalid again.Testing
0.0,-1.0,NaN,PI / 2.0,100.0.Recording.2026-08-11.153411.mp4