@@ -390,6 +390,14 @@ impl Clusters {
390
390
// NOTE: Maximum 4096 clusters due to uniform buffer size constraints
391
391
debug_assert ! ( self . dimensions. x * self . dimensions. y * self . dimensions. z <= 4096 ) ;
392
392
}
393
+ fn clear ( & mut self ) {
394
+ self . tile_size = UVec2 :: ONE ;
395
+ self . dimensions = UVec3 :: ONE ;
396
+ self . near = 0.0 ;
397
+ self . far = 0.0 ;
398
+ self . aabbs . clear ( ) ;
399
+ self . lights . clear ( ) ;
400
+ }
393
401
}
394
402
395
403
fn clip_to_view ( inverse_projection : Mat4 , clip : Vec4 ) -> Vec4 {
@@ -787,22 +795,22 @@ pub(crate) fn assign_lights_to_clusters(
787
795
for ( view_entity, camera_transform, camera, frustum, config, clusters, mut visible_lights) in
788
796
views. iter_mut ( )
789
797
{
798
+ let clusters = clusters. into_inner ( ) ;
799
+
790
800
if matches ! ( config, ClusterConfig :: None ) && visible_lights. is_some ( ) {
791
801
commands. entity ( view_entity) . remove :: < VisiblePointLights > ( ) ;
802
+ clusters. clear ( ) ;
792
803
continue ;
793
804
}
794
805
795
- let clusters = clusters. into_inner ( ) ;
796
806
let screen_size =
797
807
if let Some ( screen_size) = camera. target . get_physical_size ( & windows, & images) {
798
808
screen_size
799
809
} else {
810
+ clusters. clear ( ) ;
800
811
continue ;
801
812
} ;
802
813
803
- clusters. aabbs . clear ( ) ;
804
- clusters. lights . clear ( ) ;
805
-
806
814
let mut requested_cluster_dimensions = config. dimensions_for_screen_size ( screen_size) ;
807
815
808
816
let view_transform = camera_transform. compute_matrix ( ) ;
@@ -931,6 +939,7 @@ pub(crate) fn assign_lights_to_clusters(
931
939
// so that we can calculate the cluster index in the fragment shader!
932
940
// I (Rob Swain) choose to scan along rows of tiles in x,y, and for each tile then scan
933
941
// along z
942
+ clusters. aabbs . clear ( ) ;
934
943
for y in 0 ..clusters. dimensions . y {
935
944
for x in 0 ..clusters. dimensions . x {
936
945
for z in 0 ..clusters. dimensions . z {
0 commit comments