Skip to content

Commit 1791494

Browse files
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`.
1 parent 70e6a90 commit 1791494

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

crates/bevy_pbr/src/render/light.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,17 @@ pub fn extract_lights(
221221
point_light_shadow_map: Extract<Res<PointLightShadowMap>>,
222222
directional_light_shadow_map: Extract<Res<DirectionalLightShadowMap>>,
223223
global_visible_clusterable: Extract<Res<GlobalVisibleClusterableObjects>>,
224-
cubemap_visible_entities: Extract<Query<RenderEntity, With<CubemapVisibleEntities>>>,
224+
previous_point_lights: Query<
225+
Entity,
226+
(
227+
With<RenderCubemapVisibleEntities>,
228+
With<ExtractedPointLight>,
229+
),
230+
>,
231+
previous_spot_lights: Query<
232+
Entity,
233+
(With<RenderVisibleMeshEntities>, With<ExtractedPointLight>),
234+
>,
225235
point_lights: Extract<
226236
Query<(
227237
Entity,
@@ -278,14 +288,20 @@ pub fn extract_lights(
278288
commands.insert_resource(directional_light_shadow_map.clone());
279289
}
280290

281-
// Clear previous visible entities for all cubemapped lights as they might not be in the
291+
// Clear previous visible entities for all point/spot lights as they might not be in the
282292
// `global_visible_clusterable` list anymore.
283293
commands.try_insert_batch(
284-
cubemap_visible_entities
294+
previous_point_lights
285295
.iter()
286296
.map(|render_entity| (render_entity, RenderCubemapVisibleEntities::default()))
287297
.collect::<Vec<_>>(),
288298
);
299+
commands.try_insert_batch(
300+
previous_spot_lights
301+
.iter()
302+
.map(|render_entity| (render_entity, RenderVisibleMeshEntities::default()))
303+
.collect::<Vec<_>>(),
304+
);
289305

290306
// This is the point light shadow map texel size for one face of the cube as a distance of 1.0
291307
// world unit from the light.

0 commit comments

Comments
 (0)