@@ -49,20 +49,25 @@ fn lineIntersectionToZPlane(a: vec3f, b: vec3f, distance: f32) -> vec3f {
4949
5050
5151@compute
52- @workgroup_size (1 , 1 , 1 )
53- fn getClusterBounds (@builtin (global_invocation_id ) globalIdx : vec3u ) {
52+ @workgroup_size (${ clusterLightsWorkgroupX }, ${ clusterLightsWorkgroupY }, ${ clusterLightsWorkgroupZ } )
53+ fn getClusterBounds (@builtin (global_invocation_id ) globalIdx : vec3u ){
5454 let numClustersX = clusterSet . numClustersX ;
5555 let numClustersY = clusterSet . numClustersY ;
5656 let numClustersZ = clusterSet . numClustersZ ;
5757 let numClusters = numClustersX * numClustersY * numClustersZ ;
5858
59- let clusterID = globalIdx . x + (globalIdx . y * numClustersX ) + (globalIdx . z * (numClustersX * numClustersY ));
59+ let clusterX = globalIdx . x ;
60+ let clusterY = globalIdx . y ;
61+ let clusterZ = globalIdx . z ;
6062
61- if (clusterID >= numClusters )
63+ if ( ( clusterX >= numClustersX ) || ( clusterY > = numClustersY ) || ( clusterZ > = numClustersZ ) )
6264 {
6365 return ;
6466 }
6567
68+ let clusterID = (clusterX ) + (clusterY * numClustersX ) + (clusterZ * (numClustersX * numClustersY ));
69+
70+
6671 let uniformSliceLength : f32 = ${sliceLength };
6772 var minZ : f32 = - uniformSliceLength * f32 (globalIdx . z );
6873 var maxZ : f32 = - uniformSliceLength * f32 (globalIdx . z + 1 );
@@ -87,14 +92,14 @@ fn getClusterBounds(@builtin(global_invocation_id) globalIdx: vec3u) {
8792 var clusterLightArrayIdx : u32 = 0 ;
8893 let maxLightsPerCluster : u32 = ${maxLightsPerCluster };
8994
90- for (var lightIdx = 0u ; lightIdx < lightSet . numLights ; lightIdx ++ ) {
95+ for (var lightIdx = 0u ; lightIdx < lightSet . numLights && clusterLightArrayIdx < maxLightsPerCluster ; lightIdx ++ ) {
9196 let light = lightSet . lights [lightIdx ];
9297
9398 // Need to transform lightZ to the view Z to match the cluster's Z sapce
9499 var viewLightPos : vec4f = cameraUniforms . viewMat * vec4f (light . pos , 1f );
95100
96101 var isIntersected : bool = testAABBSphereIntersection (minPointAABB , maxPointAABB , viewLightPos . xyz , ${lightRadius });
97- if (isIntersected && clusterLightArrayIdx < maxLightsPerCluster )
102+ if (isIntersected )
98103 {
99104 // Is there a way to use references for this assignment?
100105 clusterSet . clusters [clusterID ]. lightIndices [clusterLightArrayIdx ] = lightIdx ;
0 commit comments