mirror of
https://github.com/bevyengine/bevy
synced 2024-11-21 20:23:28 +00:00
Fix directional light shadow frustum culling near clip plane to infinity (#12342)
# Objective - Fix slightly wrong logic from #11442 - Directional lights should not have a near clip plane ## Solution - Push near clip out to infinity, so that the frustum normal is still available if its needed for whatever reason in shader - also opportunistically nabs a typo
This commit is contained in:
parent
f9e70abcac
commit
13d37c534f
2 changed files with 9 additions and 4 deletions
|
@ -589,7 +589,7 @@ fn calculate_cascade(
|
|||
|
||||
// It is critical for `world_to_cascade` to be stable. So rather than forming `cascade_to_world`
|
||||
// and inverting it, which risks instability due to numerical precision, we directly form
|
||||
// `world_to_cascde` as the reference material suggests.
|
||||
// `world_to_cascade` as the reference material suggests.
|
||||
let light_to_world_transpose = light_to_world.transpose();
|
||||
let world_to_cascade = Mat4::from_cols(
|
||||
light_to_world_transpose.x_axis,
|
||||
|
|
|
@ -5,7 +5,7 @@ use bevy_math::{Mat4, UVec3, UVec4, Vec2, Vec3, Vec3Swizzles, Vec4, Vec4Swizzles
|
|||
use bevy_render::{
|
||||
camera::Camera,
|
||||
mesh::Mesh,
|
||||
primitives::{CascadesFrusta, CubemapFrusta, Frustum},
|
||||
primitives::{CascadesFrusta, CubemapFrusta, Frustum, HalfSpace},
|
||||
render_asset::RenderAssets,
|
||||
render_graph::{Node, NodeRunError, RenderGraphContext},
|
||||
render_phase::*,
|
||||
|
@ -1144,7 +1144,7 @@ pub fn prepare_lights(
|
|||
.unwrap()
|
||||
.iter()
|
||||
.take(MAX_CASCADES_PER_LIGHT);
|
||||
for (cascade_index, ((cascade, frusta), bound)) in cascades
|
||||
for (cascade_index, ((cascade, frustum), bound)) in cascades
|
||||
.zip(frusta)
|
||||
.zip(&light.cascade_shadow_config.bounds)
|
||||
.enumerate()
|
||||
|
@ -1171,6 +1171,11 @@ pub fn prepare_lights(
|
|||
});
|
||||
directional_depth_texture_array_index += 1;
|
||||
|
||||
let mut frustum = *frustum;
|
||||
// Push the near clip plane out to infinity for directional lights
|
||||
frustum.half_spaces[4] =
|
||||
HalfSpace::new(frustum.half_spaces[4].normal().extend(f32::INFINITY));
|
||||
|
||||
let view_light_entity = commands
|
||||
.spawn((
|
||||
ShadowView {
|
||||
|
@ -1191,7 +1196,7 @@ pub fn prepare_lights(
|
|||
hdr: false,
|
||||
color_grading: Default::default(),
|
||||
},
|
||||
*frusta,
|
||||
frustum,
|
||||
RenderPhase::<Shadow>::default(),
|
||||
LightEntity::Directional {
|
||||
light_entity,
|
||||
|
|
Loading…
Reference in a new issue