blurshadowV.comp 939 B

12345678910111213141516171819202122232425262728293031323334
  1. uniform sampler2D source;
  2. uniform layout(r32f) restrict writeonly image2D dest;
  3. uniform vec2 pixel;
  4. uniform float weights[7];
  5. // Gaussian separated blur with radius 6.
  6. layout (local_size_x = 8, local_size_y = 8) in;
  7. shared float local_src[8][8 + 2 * 6];
  8. void main()
  9. {
  10. int x = int(gl_LocalInvocationID.x), y = int(gl_LocalInvocationID.y);
  11. ivec2 iuv = ivec2(gl_GlobalInvocationID.x, gl_GlobalInvocationID.y);
  12. vec2 uv_m = (iuv - ivec2(0, 6)) * pixel;
  13. vec2 uv = iuv * pixel;
  14. vec2 uv_p = (iuv + ivec2(0, 6)) * pixel;
  15. local_src[x][y] = texture(source, uv_m).x;
  16. local_src[x][y + 6] = texture(source, uv).x;
  17. local_src[x][y + 12] = texture(source, uv_p).x;
  18. barrier();
  19. float sum = local_src[x][y + 6] * weights[0];
  20. for (int i = 1; i < 6; i++) {
  21. sum += local_src[x][6 + y - i] * weights[i];
  22. sum += local_src[x][6 + y + i] * weights[i];
  23. }
  24. imageStore(dest, iuv, vec4(sum));
  25. }