ColorCopyShorteningComputeShaderSource.comp
1 #version 450 core 2 3 layout (std140, binding = 0) uniform ratio_in 4 { 5 int ratio; 6 }; 7 8 layout (set = 2, binding = 0) uniform usampler2D src; 9 layout (set = 3, binding = 0) writeonly uniform uimage2D dst; 10 11 layout (local_size_x = 32, local_size_y = 32, local_size_z = 1) in; 12 13 void main() 14 { 15 uvec2 coords = gl_GlobalInvocationID.xy; 16 ivec2 textureSz = textureSize(src, 0); 17 18 if (int(coords.x) >= textureSz.x || int(coords.y) >= textureSz.y) 19 { 20 return; 21 } 22 23 uint coordsShifted = coords.x << ratio; 24 25 uvec2 dstCoords0 = uvec2(coordsShifted, coords.y); 26 uvec2 dstCoords1 = uvec2(coordsShifted + 1, coords.y); 27 uvec2 dstCoords2 = uvec2(coordsShifted + 2, coords.y); 28 uvec2 dstCoords3 = uvec2(coordsShifted + 3, coords.y); 29 30 uvec4 rgba = texelFetch(src, ivec2(coords), 0); 31 32 imageStore(dst, ivec2(dstCoords0), rgba.rrrr); 33 imageStore(dst, ivec2(dstCoords1), rgba.gggg); 34 imageStore(dst, ivec2(dstCoords2), rgba.bbbb); 35 imageStore(dst, ivec2(dstCoords3), rgba.aaaa); 36 }