Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 460 core
- layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
- struct ActiveClusters {
- uint clusterActive;
- };
- layout (std430, binding = 7) buffer clusterActive{
- ActiveClusters clusteractive[ ];
- };
- uniform uint tileSizeInPx; // How many pixels a rectangular cluster takes in x and y
- uniform uvec3 numClusters; // The fixed number of clusters in x y and z axes
- uniform float zNear;
- uniform float zFar;
- uniform vec2 screenDimensions;
- uniform sampler2D depthtext;
- float LinearizeDepth(float depth);
- void markActiveClusters(vec2 pixelID, float z);
- uint getClusterIndex(vec3 pixelCoord);
- uint getDepthSlice(float depth);
- void main() {
- ivec3 groupId = ivec3(gl_WorkGroupID);
- ivec3 localId = ivec3(gl_LocalInvocationID);
- ivec3 globalId = ivec3(gl_GlobalInvocationID);
- ivec3 coords = groupId * ivec3(gl_WorkGroupSize) + localId;
- ivec2 pixelCoord = ivec2(coords.xy);
- ivec2 ScreenCord = pixelCoord.xy / ivec2(screenDimensions.xy);
- float z = LinearizeDepth(texture(depthtext, ScreenCord).r / zFar);
- uint clusterID = getClusterIndex(vec3(pixelCoord.xy, z));
- clusteractive[clusterID].clusterActive == 1;
- }
- void markActiveClusters(vec2 pixelID, float z){
- uint clusterID = getClusterIndex(vec3(pixelID.xy, z));
- clusteractive[clusterID].clusterActive == 1;
- }
- uint getDepthSlice(float depth){
- float part1 = numClusters.z / log(zFar / zNear);
- float part2 = -(numClusters.z * log(zNear)) / log(zFar / zNear);
- uint clusterZvalue = uint(max(log(depth) * part1 + part2, 0.0f));
- return clusterZvalue;
- }
- uint getClusterIndex(vec3 pixelCoord){
- uint clusterZVal = getDepthSlice(pixelCoord.z);
- uvec3 clusters = uvec3( uvec2( pixelCoord.xy / tileSizeInPx), clusterZVal);
- uint clusterIndex = clusters.x +
- numClusters.x * clusters.y +
- (numClusters.x * numClusters.y) * clusters.z;
- return clusterIndex;
- }
- float LinearizeDepth(float depth)
- {
- float z = depth * 2.0 - 1.0; // Back to NDC
- return (2.0 * zNear * zFar) / (zFar + zNear - z * (zFar - zNear));
- }
Advertisement
Add Comment
Please, Sign In to add comment