Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions crates/bevy_light/src/cascade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,22 @@ fn calculate_cascade(
max.z,
);

// It is critical for `world_to_cascade` to be stable. So rather than forming `cascade_to_world`
// It is critical for `cascade_from_world` to be stable. So rather than forming `world_from_cascade`
// and inverting it, which risks instability due to numerical precision, we directly form
// `world_to_cascade` as the reference material suggests.
let light_to_world_transpose = world_from_light.transpose();
// `cascade_from_world` as the reference material suggests.
let world_from_light_transpose = world_from_light.transpose();
let cascade_from_world = Mat4::from_cols(
light_to_world_transpose.x_axis,
light_to_world_transpose.y_axis,
light_to_world_transpose.z_axis,
world_from_light_transpose.x_axis,
world_from_light_transpose.y_axis,
world_from_light_transpose.z_axis,
(-near_plane_center).extend(1.0),
);
let world_from_cascade = Mat4::from_cols(
world_from_light.x_axis,
world_from_light.y_axis,
world_from_light.z_axis,
world_from_light * near_plane_center.extend(1.0),
);

// Right-handed orthographic projection, centered at `near_plane_center`.
// NOTE: This is different from the reference material, as we use reverse Z.
Expand All @@ -325,7 +331,7 @@ fn calculate_cascade(

let clip_from_world = clip_from_cascade * cascade_from_world;
Cascade {
world_from_cascade: cascade_from_world.inverse(),
world_from_cascade,
clip_from_cascade,
clip_from_world,
texel_size: cascade_texel_size,
Expand Down
Loading