Skip to content

fixed spotlight shadow issue due to incorrect basis reconstruction#24238

Open
JeroenHoogers wants to merge 2 commits into
bevyengine:mainfrom
JeroenHoogers:fix-spotlight-volumetric-fog-shadows
Open

fixed spotlight shadow issue due to incorrect basis reconstruction#24238
JeroenHoogers wants to merge 2 commits into
bevyengine:mainfrom
JeroenHoogers:fix-spotlight-volumetric-fog-shadows

Conversation

@JeroenHoogers
Copy link
Copy Markdown
Contributor

Objective

Fixes #24232

Solution

The basis vector construction code in the shader was no longer in sync with the rust code. I updated the shader to match the rust code:

pub fn orthonormalize(z_basis: Dir3) -> Mat3 {
let sign = 1f32.copysign(z_basis.z);
let a = -1.0 / (sign + z_basis.z);
let b = z_basis.x * z_basis.y * a;
let x_basis = Vec3::new(
1.0 + sign * z_basis.x * z_basis.x * a,
sign * b,
-sign * z_basis.x,
);
let y_basis = Vec3::new(b, sign + z_basis.y * z_basis.y * a, -z_basis.y);
Mat3::from_cols(x_basis, y_basis, z_basis.into())
}

Testing

Run the example code posted in #24232

Showcase

Before:
screenshot-2026-05-10_17-43-50

After:

screenshot-2026-05-10_23-34-33

@JeroenHoogers JeroenHoogers changed the title fixed spotlight shadow issue due to incorrect matrix reconstruction fixed spotlight shadow issue due to incorrect basis reconstruction May 10, 2026
// the construction of the up and right vectors needs to precisely mirror the code
// in render/light.rs:spot_light_view_matrix
// in light/spot_light.rs:orthonormalize
var sign = -1.0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

might be a dumb question, but is there a reason why this can't delegate to orthonormalize in bevy_render::maths? to reduce on the number of places that this logic should be kept in sync. that function also has a reference to spot_light.rs as well

https://github.com/bevyengine/bevy/blob/main/crates/bevy_render/src/maths.wgsl#L72-L87

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great suggestion, thank you! I was not aware of this function's existence. Definitely looks like a cleaner solution to just call this instead.

@kfc35 kfc35 added A-Rendering Drawing game state to the screen D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 10, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering May 10, 2026
@kfc35 kfc35 added the C-Bug An unexpected or incorrect behavior label May 10, 2026
@kfc35 kfc35 added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 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 S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

Spotlight shadows inside volumetric fog incorrect

3 participants