Skip to content

Commit 207ebde

Browse files
committed
Always update clusters and remove per-frame allocations (#4169)
* Refactor assign_lights_to_clusters to always clear + update clusters, even if the screen size isn't available yet / is zero. This fixes #4167. We still avoid the "expensive" per-light work when the screen size isn't available yet. I also consolidated some logic to eliminate some redundancies. * Removed _a ton_ of (potentially very large) per-frame reallocations * Removed `Res<VisiblePointLights>` (a vec) in favor of `Res<GlobalVisiblePointLights>` (a hashmap). We were allocating a new hashmap every frame, the collecting it into a vec every frame, then in another system _re-generating the hashmap_. It is always used like a hashmap, might as well embrace that. We now reuse the same hashmap every frame and dont use any intermediate collections. * We were re-allocating Clusters aabb and light vectors every frame by re-constructing Clusters every frame. We now re-use the existing collections. * Reuse per-camera VisiblePointLight vecs when possible instead of allocating them every frame. We now only insert VisiblePointLights if the component doesn't exist yet.
1 parent b1c3e98 commit 207ebde

File tree

3 files changed

+207
-230
lines changed

3 files changed

+207
-230
lines changed

crates/bevy_pbr/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ impl Plugin for PbrPlugin {
7171
.add_plugin(MeshRenderPlugin)
7272
.add_plugin(MaterialPlugin::<StandardMaterial>::default())
7373
.init_resource::<AmbientLight>()
74+
.init_resource::<GlobalVisiblePointLights>()
7475
.init_resource::<DirectionalLightShadowMap>()
7576
.init_resource::<PointLightShadowMap>()
76-
.init_resource::<VisiblePointLights>()
7777
.add_system_to_stage(
7878
CoreStage::PostUpdate,
7979
// NOTE: Clusters need to have been added before update_clusters is run so

0 commit comments

Comments
 (0)