GaussianBlurGeneric.frag.glsl 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (C) 2009-2017, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. // Weights and offsets generated by GaussialBlur.h from Intel
  6. //
  7. // Switches: VPASS or HPASS, COL_RGBA or COL_RGB or COL_R
  8. // Also must define TEXTURE_SIZE and KERNEL_SIZE
  9. #include "shaders/GaussianBlurCommon.glsl"
  10. // Preprocessor switches sanity checks
  11. #if !defined(VPASS) && !defined(HPASS)
  12. #error See file
  13. #endif
  14. #if !(defined(COL_RGBA) || defined(COL_RGB) || defined(COL_R))
  15. #error See file
  16. #endif
  17. #if !defined(TEXTURE_SIZE)
  18. #error See file
  19. #endif
  20. layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_tex; ///< Input FAI
  21. layout(location = 0) in vec2 in_uv;
  22. // Determine color type
  23. #if defined(COL_RGBA)
  24. #define COL_TYPE vec4
  25. #elif defined(COL_RGB)
  26. #define COL_TYPE vec3
  27. #elif defined(COL_R)
  28. #define COL_TYPE float
  29. #endif
  30. // Determine tex fetch
  31. #if defined(COL_RGBA)
  32. #define TEX_FETCH rgba
  33. #elif defined(COL_RGB)
  34. #define TEX_FETCH rgb
  35. #elif defined(COL_R)
  36. #define TEX_FETCH r
  37. #endif
  38. // Output
  39. layout(location = 0) out COL_TYPE out_color;
  40. void main()
  41. {
  42. #if defined(VPASS)
  43. const vec2 TEXEL_SIZE = vec2(0.0, 1.0 / TEXTURE_SIZE.y);
  44. #else
  45. const vec2 TEXEL_SIZE = vec2(1.0 / TEXTURE_SIZE.x, 0.0);
  46. #endif
  47. out_color = COL_TYPE(0.0);
  48. for(uint i = 0u; i < STEP_COUNT; ++i)
  49. {
  50. vec2 texCoordOffset = OFFSETS[i] * TEXEL_SIZE;
  51. COL_TYPE col =
  52. texture(u_tex, in_uv + texCoordOffset).TEX_FETCH + texture(u_tex, in_uv - texCoordOffset).TEX_FETCH;
  53. out_color += WEIGHTS[i] * col;
  54. }
  55. }