Skip to content

Commit b89c3b2

Browse files
committed
many_lights: Tweak the cluster configuration for much better performance
1 parent e6c5096 commit b89c3b2

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

examples/stress_tests/many_lights.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bevy::{
22
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
33
math::{DVec2, DVec3},
4-
pbr::{ExtractedPointLight, GlobalLightMeta},
4+
pbr::{ClusterConfig, ClusterZConfig, ExtractedPointLight, GlobalLightMeta},
55
prelude::*,
66
render::{camera::CameraProjection, primitives::Frustum, RenderApp, RenderStage},
77
};
@@ -70,7 +70,7 @@ fn setup(
7070
}
7171

7272
// camera
73-
match std::env::args().nth(1).as_deref() {
73+
let mut camera = match std::env::args().nth(1).as_deref() {
7474
Some("orthographic") => {
7575
let mut orthographic_camera_bundle = OrthographicCameraBundle::new_3d();
7676
orthographic_camera_bundle.orthographic_projection.scale = 20.0;
@@ -88,6 +88,21 @@ fn setup(
8888
_ => commands.spawn_bundle(PerspectiveCameraBundle::default()),
8989
};
9090

91+
// NOTE: The lights in this example are distributed primarily in x and y across the
92+
// screen. Using only 1 z-slice and letting the x,y slicing be calculated
93+
// automatically produces much better light distribution across the clusters (i.e.
94+
// fewer maximum lights in any one cluster). The consequences of this versus the
95+
// default on an M1 Max means going from ~65fps to ~130fps!!!
96+
camera.insert(ClusterConfig::FixedZ {
97+
total: 4096,
98+
z_slices: 1,
99+
z_config: ClusterZConfig {
100+
first_slice_depth: 5.0,
101+
far_z_mode: bevy::pbr::ClusterFarZMode::MaxLightRange,
102+
},
103+
dynamic_resizing: true,
104+
});
105+
91106
// add one cube, the only one with strong handles
92107
// also serves as a reference point during rotation
93108
commands.spawn_bundle(PbrBundle {

0 commit comments

Comments
 (0)