Skip to content

Fix SpotLight3D light_projector doesn't render when shadow_enabled is false - #1326

Open
Shakai-Dev wants to merge 2 commits into
Redot-Engine:masterfrom
Shakai-Dev:121615-fix
Open

Fix SpotLight3D light_projector doesn't render when shadow_enabled is false#1326
Shakai-Dev wants to merge 2 commits into
Redot-Engine:masterfrom
Shakai-Dev:121615-fix

Conversation

@Shakai-Dev

@Shakai-Dev Shakai-Dev commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

The Problem

When shadow_enabled is set to false on a SpotLight3D, LightStorage::update_light_buffers previously skipped calculating light_data.shadow_matrix altogether. However, the spotlight shader relies on shadow_matrix to calculate projector UVs whenever a light_projector texture is assigned but since shadow_matrix was never written when shadows were disabled, the shader read garbage/uninitialized matrix data, resulting in broken projector UVs, black output or visual glitches from stale memory.

The Solution

This PR adds a fallback check inside LightStorage::update_light_buffers for when shadows are disabled (has_shadow is false). If a spotlight has a valid projector texture assigned (has_projector is true), the matrix is now calculated manually using the spotlight's parameters (spot_angle, radius, light_transform) & stored into light_data.shadow_matrix.

Before After
Before View After View

Summary by CodeRabbit

  • Bug Fixes
    • Improved spotlight projector rendering when shadows are disabled.
    • Projected lighting now uses the correct spotlight camera and perspective calculations.
    • Shadow processing is more accurately restricted to lights eligible for shadow rendering.

@Shakai-Dev
Shakai-Dev requested review from a team July 25, 2026 16:41
@Shakai-Dev Shakai-Dev self-assigned this Jul 25, 2026
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 8ee3b9da-c139-4aec-9729-e54954d7031e

📥 Commits

Reviewing files that changed from the base of the PR and between 63d5ffe and 34f0226.

📒 Files selected for processing (1)
  • servers/rendering/renderer_rd/storage_rd/light_storage.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • servers/rendering/renderer_rd/storage_rd/light_storage.cpp

Walkthrough

LightStorage::update_light_buffers() refines shadow-state handling and adds projector-derived shadow matrix generation for spot lights when shadows are not rendered.

Changes

Light projector shadow handling

Layer / File(s) Summary
Shadow eligibility and projector matrix update
servers/rendering/renderer_rd/storage_rd/light_storage.cpp
Shadow eligibility is consolidated into derived flags, while eligible spot-light projectors now generate and store a bias- and depth-corrected perspective shadow matrix when shadow rendering is disabled.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the change: it fixes SpotLight3D projector rendering when shadows are disabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@servers/rendering/renderer_rd/storage_rd/light_storage.cpp`:
- Around line 1035-1051: Replace the invalid RSE::LIGHT_SPOT reference in the
projector/shadow matrix branch with RS::LIGHT_SPOT, matching the
rendering-server enum used throughout the surrounding function.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0de94a42-a16f-4bcf-8558-2d96b1e29618

📥 Commits

Reviewing files that changed from the base of the PR and between 9fe4edb and 63d5ffe.

📒 Files selected for processing (1)
  • servers/rendering/renderer_rd/storage_rd/light_storage.cpp

Comment thread servers/rendering/renderer_rd/storage_rd/light_storage.cpp
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Open

Development

Successfully merging this pull request may close these issues.

1 participant