From 125fbb05d312abf3f2f5d152d5368d30ddb49ff3 Mon Sep 17 00:00:00 2001 From: Eero Lehtinen Date: Mon, 19 May 2025 22:42:09 +0300 Subject: [PATCH] Fix spot light shadow glitches (#19273) # Objective Spot light shadows are still broken after fixing point lights in #19265 ## Solution Fix spot lights in the same way, just using the spot light specific visible entities component. I also changed the query to be directly in the render world instead of being extracted to be more accurate. ## Testing Tested with the same code but changing `PointLight` to `SpotLight`. --- crates/bevy_pbr/src/render/light.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index dfc7f679f3..f57ba9adf3 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -221,7 +221,17 @@ pub fn extract_lights( point_light_shadow_map: Extract>, directional_light_shadow_map: Extract>, global_visible_clusterable: Extract>, - cubemap_visible_entities: Extract>>, + previous_point_lights: Query< + Entity, + ( + With, + With, + ), + >, + previous_spot_lights: Query< + Entity, + (With, With), + >, point_lights: Extract< Query<( Entity, @@ -278,14 +288,20 @@ pub fn extract_lights( commands.insert_resource(directional_light_shadow_map.clone()); } - // Clear previous visible entities for all cubemapped lights as they might not be in the + // Clear previous visible entities for all point/spot lights as they might not be in the // `global_visible_clusterable` list anymore. commands.try_insert_batch( - cubemap_visible_entities + previous_point_lights .iter() .map(|render_entity| (render_entity, RenderCubemapVisibleEntities::default())) .collect::>(), ); + commands.try_insert_batch( + previous_spot_lights + .iter() + .map(|render_entity| (render_entity, RenderVisibleMeshEntities::default())) + .collect::>(), + ); // This is the point light shadow map texel size for one face of the cube as a distance of 1.0 // world unit from the light.