Skip to content

Commit

Permalink
Don’t prepare lights (and shadow map textures) for 2D cameras (#14574)
Browse files Browse the repository at this point in the history
# 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)
  • Loading branch information
brianreavis authored Aug 1, 2024
1 parent 0c7df88 commit 4c4a6c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
5 changes: 3 additions & 2 deletions crates/bevy_pbr/src/cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -348,7 +349,7 @@ impl Clusters {

pub fn add_clusters(
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 {
if !camera.is_active {
Expand Down
17 changes: 10 additions & 7 deletions crates/bevy_pbr/src/render/light.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -515,12 +515,15 @@ pub fn prepare_lights(
render_queue: Res<RenderQueue>,
mut global_light_meta: ResMut<GlobalClusterableObjectMeta>,
mut light_meta: ResMut<LightMeta>,
views: Query<(
Entity,
&ExtractedView,
&ExtractedClusterConfig,
Option<&RenderLayers>,
)>,
views: Query<
(
Entity,
&ExtractedView,
&ExtractedClusterConfig,
Option<&RenderLayers>,
),
With<Camera3d>,
>,
ambient_light: Res<AmbientLight>,
point_light_shadow_map: Res<PointLightShadowMap>,
directional_light_shadow_map: Res<DirectionalLightShadowMap>,
Expand Down

0 comments on commit 4c4a6c4

Please sign in to comment.