DownscaleBlur.glsl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Shaders/Common.glsl>
  7. layout(set = 0, binding = 0) uniform sampler u_linearAnyClampSampler;
  8. layout(set = 0, binding = 1) uniform texture2D u_tex;
  9. #if defined(ANKI_COMPUTE_SHADER)
  10. const UVec2 WORKGROUP_SIZE = UVec2(16, 16);
  11. layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_size_z = 1) in;
  12. // Push constants hold the size of the output image
  13. layout(push_constant, row_major, std430) uniform pc_
  14. {
  15. UVec2 u_fbSize;
  16. UVec2 u_padding;
  17. };
  18. Vec2 in_uv = (Vec2(gl_GlobalInvocationID.xy) + 0.5) / Vec2(u_fbSize);
  19. layout(set = 0, binding = 2) writeonly uniform image2D out_img;
  20. Vec3 out_color;
  21. #else
  22. layout(location = 0) in Vec2 in_uv;
  23. layout(location = 0) out Vec3 out_color;
  24. #endif
  25. void main()
  26. {
  27. #if defined(ANKI_COMPUTE_SHADER)
  28. if(gl_GlobalInvocationID.x >= u_fbSize.x || gl_GlobalInvocationID.y >= u_fbSize.y)
  29. {
  30. // Skip pixels outside the viewport
  31. return;
  32. }
  33. #endif
  34. out_color = textureLod(u_tex, u_linearAnyClampSampler, in_uv, 0.0).rgb;
  35. out_color += textureLodOffset(sampler2D(u_tex, u_linearAnyClampSampler), in_uv, 0.0, IVec2(+1, +1)).rgb;
  36. out_color += textureLodOffset(sampler2D(u_tex, u_linearAnyClampSampler), in_uv, 0.0, IVec2(-1, -1)).rgb;
  37. out_color += textureLodOffset(sampler2D(u_tex, u_linearAnyClampSampler), in_uv, 0.0, IVec2(+1, -1)).rgb;
  38. out_color += textureLodOffset(sampler2D(u_tex, u_linearAnyClampSampler), in_uv, 0.0, IVec2(-1, +1)).rgb;
  39. out_color *= (1.0 / 5.0);
  40. #if defined(ANKI_COMPUTE_SHADER)
  41. imageStore(out_img, IVec2(gl_GlobalInvocationID.xy), Vec4(out_color, 0.0));
  42. #endif
  43. }