No Description

gaussblur.frag 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. layout (binding = 1) uniform sampler2D samplerColor;
  5. layout (binding = 0) uniform UBO
  6. {
  7. float blurScale;
  8. float blurStrength;
  9. } ubo;
  10. layout (constant_id = 0) const int blurdirection = 0;
  11. layout (location = 0) in vec2 inUV;
  12. layout (location = 0) out vec4 outFragColor;
  13. void main()
  14. {
  15. float weight[5];
  16. weight[0] = 0.227027;
  17. weight[1] = 0.1945946;
  18. weight[2] = 0.1216216;
  19. weight[3] = 0.054054;
  20. weight[4] = 0.016216;
  21. vec2 tex_offset = 1.0 / textureSize(samplerColor, 0) * ubo.blurScale; // gets size of single texel
  22. vec3 result = texture(samplerColor, inUV).rgb * weight[0]; // current fragment's contribution
  23. for(int i = 1; i < 5; ++i)
  24. {
  25. if (blurdirection == 1)
  26. {
  27. // H
  28. result += texture(samplerColor, inUV + vec2(tex_offset.x * i, 0.0)).rgb * weight[i] * ubo.blurStrength;
  29. result += texture(samplerColor, inUV - vec2(tex_offset.x * i, 0.0)).rgb * weight[i] * ubo.blurStrength;
  30. }
  31. else
  32. {
  33. // V
  34. result += texture(samplerColor, inUV + vec2(0.0, tex_offset.y * i)).rgb * weight[i] * ubo.blurStrength;
  35. result += texture(samplerColor, inUV - vec2(0.0, tex_offset.y * i)).rgb * weight[i] * ubo.blurStrength;
  36. }
  37. }
  38. outFragColor = vec4(result, 1.0);
  39. }