Guest User

Untitled

a guest
Oct 20th, 2025
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #version 460 core
  2.  
  3. layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
  4.  
  5. struct ActiveClusters {
  6. uint clusterActive;
  7. };
  8.  
  9. layout (std430, binding = 7) buffer clusterActive{
  10. ActiveClusters clusteractive[ ];
  11. };
  12.  
  13. uniform uint tileSizeInPx; // How many pixels a rectangular cluster takes in x and y
  14. uniform uvec3 numClusters; // The fixed number of clusters in x y and z axes
  15. uniform float zNear;
  16. uniform float zFar;
  17. uniform vec2 screenDimensions;
  18.  
  19. uniform sampler2D depthtext;
  20.  
  21. float LinearizeDepth(float depth);
  22. void markActiveClusters(vec2 pixelID, float z);
  23. uint getClusterIndex(vec3 pixelCoord);
  24. uint getDepthSlice(float depth);
  25.  
  26. void main() {
  27. ivec3 groupId = ivec3(gl_WorkGroupID);
  28. ivec3 localId = ivec3(gl_LocalInvocationID);
  29. ivec3 globalId = ivec3(gl_GlobalInvocationID);
  30. ivec3 coords = groupId * ivec3(gl_WorkGroupSize) + localId;
  31. ivec2 pixelCoord = ivec2(coords.xy);
  32.  
  33.  
  34. ivec2 ScreenCord = pixelCoord.xy / ivec2(screenDimensions.xy);
  35.  
  36. float z = LinearizeDepth(texture(depthtext, ScreenCord).r / zFar);
  37.  
  38. uint clusterID = getClusterIndex(vec3(pixelCoord.xy, z));
  39. clusteractive[clusterID].clusterActive == 1;
  40. }
  41.  
  42.  
  43. void markActiveClusters(vec2 pixelID, float z){
  44. uint clusterID = getClusterIndex(vec3(pixelID.xy, z));
  45. clusteractive[clusterID].clusterActive == 1;
  46.  
  47. }
  48.  
  49. uint getDepthSlice(float depth){
  50. float part1 = numClusters.z / log(zFar / zNear);
  51. float part2 = -(numClusters.z * log(zNear)) / log(zFar / zNear);
  52. uint clusterZvalue = uint(max(log(depth) * part1 + part2, 0.0f));
  53.  
  54. return clusterZvalue;
  55. }
  56. uint getClusterIndex(vec3 pixelCoord){
  57. uint clusterZVal = getDepthSlice(pixelCoord.z);
  58. uvec3 clusters = uvec3( uvec2( pixelCoord.xy / tileSizeInPx), clusterZVal);
  59. uint clusterIndex = clusters.x +
  60. numClusters.x * clusters.y +
  61. (numClusters.x * numClusters.y) * clusters.z;
  62. return clusterIndex;
  63. }
  64.  
  65. float LinearizeDepth(float depth)
  66. {
  67. float z = depth * 2.0 - 1.0; // Back to NDC
  68. return (2.0 * zNear * zFar) / (zFar + zNear - z * (zFar - zNear));
  69. }
  70.  
  71.  
Advertisement
Add Comment
Please, Sign In to add comment