From 9d1a10273c38b87c7e0c6b7ccceaff76b789509d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9l=C3=A8ne=20Amanita?= <134181069+Selene-Amanita@users.noreply.github.com> Date: Thu, 10 Aug 2023 01:06:27 +0100 Subject: [PATCH] Update `Camera`'s `Frustum` only when its `GlobalTransform` or `CameraProjection` changed (#9092) # Objective Update a camera's frustum only when needed. - Maybe a performance gain from not having to compute frusta when not needed, at the cost of change detection (?) - Making "fighting" with `update_frusta` less tedious, see https://github.com/bevyengine/bevy/issues/9077 and https://discord.com/channels/691052431525675048/743663924229963868/1127566087966433322 ## Solution Add change detection filter for `GlobalTransform` or `T: CameraProjection` in `update_frusta`, since those are the cases when the frustum needs to be updated. ## Note I don't think a migration guide and changelog are needed, but I'm not 100% sure, I could put something like "if you're fighting against `update_frusta`, you can do it only when there is a change to `GlobalTransform` or `CameraProjection` now", what do you think? It's not really a breaking change with a normal use case. --- crates/bevy_render/src/view/visibility/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/bevy_render/src/view/visibility/mod.rs b/crates/bevy_render/src/view/visibility/mod.rs index 5938fe2f95b69..33f8627978494 100644 --- a/crates/bevy_render/src/view/visibility/mod.rs +++ b/crates/bevy_render/src/view/visibility/mod.rs @@ -268,7 +268,10 @@ pub fn calculate_bounds( } pub fn update_frusta( - mut views: Query<(&GlobalTransform, &T, &mut Frustum)>, + mut views: Query< + (&GlobalTransform, &T, &mut Frustum), + Or<(Changed, Changed)>, + >, ) { for (transform, projection, mut frustum) in &mut views { let view_projection =