Skip to content

Commit b4483db

Browse files
committed
perf: only recalculate frusta of changed lights (#4086)
## Objective Currently, all directional and point lights have their viewing frusta recalculated every frame, even if they have not moved or been disabled/enabled. ## Solution The relevant systems now make use of change detection to only update those lights whose viewing frusta may have changed.
1 parent fb02b84 commit b4483db

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

crates/bevy_pbr/src/light.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -702,12 +702,15 @@ pub(crate) fn assign_lights_to_clusters(
702702
}
703703

704704
pub fn update_directional_light_frusta(
705-
mut views: Query<(
706-
&GlobalTransform,
707-
&DirectionalLight,
708-
&mut Frustum,
709-
&Visibility,
710-
)>,
705+
mut views: Query<
706+
(
707+
&GlobalTransform,
708+
&DirectionalLight,
709+
&mut Frustum,
710+
&Visibility,
711+
),
712+
Or<(Changed<GlobalTransform>, Changed<DirectionalLight>)>,
713+
>,
711714
) {
712715
for (transform, directional_light, mut frustum, visibility) in views.iter_mut() {
713716
// The frustum is used for culling meshes to the light for shadow mapping
@@ -731,7 +734,10 @@ pub fn update_directional_light_frusta(
731734
// NOTE: Run this after assign_lights_to_clusters!
732735
pub fn update_point_light_frusta(
733736
global_lights: Res<VisiblePointLights>,
734-
mut views: Query<(Entity, &GlobalTransform, &PointLight, &mut CubemapFrusta)>,
737+
mut views: Query<
738+
(Entity, &GlobalTransform, &PointLight, &mut CubemapFrusta),
739+
Or<(Changed<GlobalTransform>, Changed<PointLight>)>,
740+
>,
735741
) {
736742
let projection =
737743
Mat4::perspective_infinite_reverse_rh(std::f32::consts::FRAC_PI_2, 1.0, POINT_LIGHT_NEAR_Z);

0 commit comments

Comments
 (0)