Skip to content

Commit 244687a

Browse files
committed
Dynamic light clusters (#3968)
# Objective provide some customisation for default cluster setup avoid "cluster index lists is full" in all cases (using a strategy outlined by @superdump) ## Solution Add ClusterConfig enum (which can be inserted into a view at any time) to allow specifying cluster setup with variants: - None (do not do any light assignment - for views which do not require light info, e.g. minimaps etc) - Single (one cluster) - XYZ (explicit cluster counts in each dimension) - FixedZ (most similar to current - specify Z-slices and total, then x and y counts are dynamically determined to give approximately square clusters based on current aspect ratio) Defaults to FixedZ { total: 4096, z: 24 } which is similar to the current setup. Per frame, estimate the number of indices that would be required for the current config and decrease the cluster counts / increase the cluster sizes in the x and y dimensions if the index list would be too small. notes: - I didn't put ClusterConfig in the camera bundles to avoid introducing a dependency from bevy_render to bevy_pbr. the ClusterConfig enum comes with a pbr-centric impl block so i didn't want to move that into bevy_render either. - ~Might want to add None variant to cluster config for views that don't care about lights?~ - Not well tested for orthographic - ~there's a cluster_muck branch on my repo which includes some diagnostics / a modified lighting example which may be useful for tyre-kicking~ (outdated, i will bring it up to date if required) anecdotal timings: FPS on the lighting demo is negligibly better (~5%), maybe due to a small optimisation constraining the light aabb to be in front of the camera FPS on the lighting demo with 100 extra lights added is ~33% faster, and also renders correctly as the cluster index count is no longer exceeded
1 parent a188bab commit 244687a

File tree

3 files changed

+451
-146
lines changed

3 files changed

+451
-146
lines changed

crates/bevy_pbr/src/lib.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,11 @@ impl Plugin for PbrPlugin {
8282
.exclusive_system()
8383
.label(SimulationLightSystems::AddClusters),
8484
)
85-
.add_system_to_stage(
86-
CoreStage::PostUpdate,
87-
// NOTE: Must come after add_clusters!
88-
update_clusters
89-
.label(SimulationLightSystems::UpdateClusters)
90-
.after(TransformSystem::TransformPropagate),
91-
)
9285
.add_system_to_stage(
9386
CoreStage::PostUpdate,
9487
assign_lights_to_clusters
9588
.label(SimulationLightSystems::AssignLightsToClusters)
96-
.after(TransformSystem::TransformPropagate)
97-
.after(SimulationLightSystems::UpdateClusters),
89+
.after(TransformSystem::TransformPropagate),
9890
)
9991
.add_system_to_stage(
10092
CoreStage::PostUpdate,

0 commit comments

Comments
 (0)