Skip to content

Fix spot light degenerate outer angle - #25368

Open
Saratii wants to merge 4 commits into
bevyengine:mainfrom
Saratii:fix-spot-light-degenerate-outer-angle
Open

Fix spot light degenerate outer angle#25368
Saratii wants to merge 4 commits into
bevyengine:mainfrom
Saratii:fix-spot-light-degenerate-outer-angle

Conversation

@Saratii

@Saratii Saratii commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Objective

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.
  • Old clamp 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.
  • Exactly PI / 2.0f32(PI / 2.0) rounds above true π/2, so tan is -2.3e7 and 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), and clamped_angles(), which clamps both angles, keeps inner <= 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! in extract_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

  • Unit test: clamped angles stay in range and keep the projection finite for 0.0, -1.0, NaN, PI / 2.0, 100.0.
  • Behaves correctly in minimal reproduction at both pi/2 and 0.
Recording.2026-08-11.153411.mp4

@alice-i-cecile alice-i-cecile added this to the 0.19.2 milestone Aug 11, 2026
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 11, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering Aug 11, 2026
@alice-i-cecile alice-i-cecile modified the milestones: 0.19.2, 0.20 Aug 11, 2026
@alice-i-cecile alice-i-cecile added M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

spotlight produces garbage artifacts when outer angle and inner angle are set to zero and shadowmaps enabled

2 participants