From 4c4a6c4506dac24014d3bc7c677c71a3bed02022 Mon Sep 17 00:00:00 2001 From: Brian Reavis Date: Thu, 1 Aug 2024 12:29:18 -0700 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20prepare=20lights=20(and=20shado?= =?UTF-8?q?w=20map=20textures)=20for=202D=20cameras=20(#14574)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective When running the Metal debugger I noticed that 2D cameras have shadow map textures from `bevy_pbr` built for them. For a 2560x1440 2D camera, this PR saves about 40mb of texture memory. ![image](https://github.com/user-attachments/assets/925e9392-2721-41bb-83e9-25c84fd563cd) ![image](https://github.com/user-attachments/assets/0cc3c0a9-cbf7-431c-b444-952c28d4e9d0) ## Solution - Added `With` filter to the appropriate view queries. ## Testing - This is a trivial fix (the examples still work) --- crates/bevy_pbr/src/cluster/mod.rs | 5 +++-- crates/bevy_pbr/src/render/light.rs | 17 ++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/bevy_pbr/src/cluster/mod.rs b/crates/bevy_pbr/src/cluster/mod.rs index a0d628474d..fe913a1d19 100644 --- a/crates/bevy_pbr/src/cluster/mod.rs +++ b/crates/bevy_pbr/src/cluster/mod.rs @@ -2,10 +2,11 @@ use std::num::NonZeroU64; +use bevy_core_pipeline::core_3d::Camera3d; use bevy_ecs::{ component::Component, entity::{Entity, EntityHashMap}, - query::Without, + query::{With, Without}, reflect::ReflectComponent, system::{Commands, Query, Res, Resource}, world::{FromWorld, World}, @@ -348,7 +349,7 @@ impl Clusters { pub fn add_clusters( mut commands: Commands, - cameras: Query<(Entity, Option<&ClusterConfig>, &Camera), Without>, + cameras: Query<(Entity, Option<&ClusterConfig>, &Camera), (Without, With)>, ) { for (entity, config, camera) in &cameras { if !camera.is_active { diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 11e3f2dcfd..9ecf1b3616 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -1,6 +1,6 @@ use bevy_asset::UntypedAssetId; use bevy_color::ColorToComponents; -use bevy_core_pipeline::core_3d::CORE_3D_DEPTH_FORMAT; +use bevy_core_pipeline::core_3d::{Camera3d, CORE_3D_DEPTH_FORMAT}; use bevy_ecs::entity::EntityHashSet; use bevy_ecs::prelude::*; use bevy_ecs::{entity::EntityHashMap, system::lifetimeless::Read}; @@ -515,12 +515,15 @@ pub fn prepare_lights( render_queue: Res, mut global_light_meta: ResMut, mut light_meta: ResMut, - views: Query<( - Entity, - &ExtractedView, - &ExtractedClusterConfig, - Option<&RenderLayers>, - )>, + views: Query< + ( + Entity, + &ExtractedView, + &ExtractedClusterConfig, + Option<&RenderLayers>, + ), + With, + >, ambient_light: Res, point_light_shadow_map: Res, directional_light_shadow_map: Res,