Don’t prepare lights (and shadow map textures) for 2D cameras (#14574)

# 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<Camera3d>` filter to the appropriate view queries.

## Testing

- This is a trivial fix (the examples still work)
This commit is contained in:
Brian Reavis 2024-08-01 12:29:18 -07:00 committed by GitHub
parent 0c7df881e7
commit 4c4a6c4506
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 9 deletions

View file

@ -2,10 +2,11 @@
use std::num::NonZeroU64; use std::num::NonZeroU64;
use bevy_core_pipeline::core_3d::Camera3d;
use bevy_ecs::{ use bevy_ecs::{
component::Component, component::Component,
entity::{Entity, EntityHashMap}, entity::{Entity, EntityHashMap},
query::Without, query::{With, Without},
reflect::ReflectComponent, reflect::ReflectComponent,
system::{Commands, Query, Res, Resource}, system::{Commands, Query, Res, Resource},
world::{FromWorld, World}, world::{FromWorld, World},
@ -348,7 +349,7 @@ impl Clusters {
pub fn add_clusters( pub fn add_clusters(
mut commands: Commands, mut commands: Commands,
cameras: Query<(Entity, Option<&ClusterConfig>, &Camera), Without<Clusters>>, cameras: Query<(Entity, Option<&ClusterConfig>, &Camera), (Without<Clusters>, With<Camera3d>)>,
) { ) {
for (entity, config, camera) in &cameras { for (entity, config, camera) in &cameras {
if !camera.is_active { if !camera.is_active {

View file

@ -1,6 +1,6 @@
use bevy_asset::UntypedAssetId; use bevy_asset::UntypedAssetId;
use bevy_color::ColorToComponents; 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::entity::EntityHashSet;
use bevy_ecs::prelude::*; use bevy_ecs::prelude::*;
use bevy_ecs::{entity::EntityHashMap, system::lifetimeless::Read}; use bevy_ecs::{entity::EntityHashMap, system::lifetimeless::Read};
@ -515,12 +515,15 @@ pub fn prepare_lights(
render_queue: Res<RenderQueue>, render_queue: Res<RenderQueue>,
mut global_light_meta: ResMut<GlobalClusterableObjectMeta>, mut global_light_meta: ResMut<GlobalClusterableObjectMeta>,
mut light_meta: ResMut<LightMeta>, mut light_meta: ResMut<LightMeta>,
views: Query<( views: Query<
Entity, (
&ExtractedView, Entity,
&ExtractedClusterConfig, &ExtractedView,
Option<&RenderLayers>, &ExtractedClusterConfig,
)>, Option<&RenderLayers>,
),
With<Camera3d>,
>,
ambient_light: Res<AmbientLight>, ambient_light: Res<AmbientLight>,
point_light_shadow_map: Res<PointLightShadowMap>, point_light_shadow_map: Res<PointLightShadowMap>,
directional_light_shadow_map: Res<DirectionalLightShadowMap>, directional_light_shadow_map: Res<DirectionalLightShadowMap>,