Skip to content

Commit 6a1ba9c

Browse files
committed
Spotlight shadow bugfix (#5451)
# Objective fix an error in shadow map indexing that occurs when point lights without shadows are used in conjunction with spotlights with shadows ## Solution calculate point_light_count correctly
1 parent d478711 commit 6a1ba9c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

crates/bevy_pbr/src/render/light.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -797,10 +797,14 @@ pub fn prepare_lights(
797797

798798
let point_light_count = point_lights
799799
.iter()
800-
.filter(|light| light.1.shadows_enabled && light.1.spot_light_angles.is_none())
800+
.filter(|light| light.1.spot_light_angles.is_none())
801801
.count();
802802

803-
let point_light_shadow_maps_count = point_light_count.min(max_texture_cubes);
803+
let point_light_shadow_maps_count = point_lights
804+
.iter()
805+
.filter(|light| light.1.shadows_enabled && light.1.spot_light_angles.is_none())
806+
.count()
807+
.min(max_texture_cubes);
804808

805809
let directional_shadow_maps_count = directional_lights
806810
.iter()
@@ -970,7 +974,7 @@ pub fn prepare_lights(
970974
n_directional_lights: directional_lights.iter().len() as u32,
971975
// spotlight shadow maps are stored in the directional light array, starting at directional_shadow_maps_count.
972976
// the spot lights themselves start in the light array at point_light_count. so to go from light
973-
// index to shadow map index, we need to subtract point light shadowmap count and add directional shadowmap count.
977+
// index to shadow map index, we need to subtract point light count and add directional shadowmap count.
974978
spot_light_shadowmap_offset: directional_shadow_maps_count as i32
975979
- point_light_count as i32,
976980
};
@@ -1045,7 +1049,7 @@ pub fn prepare_lights(
10451049
let spot_view_transform = spot_view_matrix.into();
10461050

10471051
let angle = light.spot_light_angles.expect("lights should be sorted so that \
1048-
[point_light_shadow_maps_count..point_light_shadow_maps_count + spot_light_shadow_maps_count] are spot lights").1;
1052+
[point_light_count..point_light_count + spot_light_shadow_maps_count] are spot lights").1;
10491053
let spot_projection = spot_light_projection_matrix(angle);
10501054

10511055
let depth_texture_view =

0 commit comments

Comments
 (0)