gaussian_blur_horizontal.frag 1.0 KB

12345678910111213141516171819202122232425262728
  1. #extension GL_ARB_texture_rectangle : enable
  2. // Source:
  3. // http://www.gamerendering.com/2008/10/11/gaussian-blur-filter-shader/
  4. uniform sampler2DRect MyTex;
  5. uniform float blur_size; // blur size
  6. void main(void)
  7. {
  8. vec2 pos = (gl_TextureMatrix[0] * gl_TexCoord[0]).st;
  9. vec4 sum = vec4(0.0);
  10. // blur in x (horizontal)
  11. // take nine samples, with the distance size between them
  12. sum += texture2DRect(MyTex, vec2(pos.x - 4.0*blur_size, pos.y)) * 0.05;
  13. sum += texture2DRect(MyTex, vec2(pos.x - 3.0*blur_size, pos.y)) * 0.09;
  14. sum += texture2DRect(MyTex, vec2(pos.x - 2.0*blur_size, pos.y)) * 0.12;
  15. sum += texture2DRect(MyTex, vec2(pos.x - blur_size, pos.y)) * 0.15;
  16. sum += texture2DRect(MyTex, vec2(pos.x, pos.y)) * 0.16;
  17. sum += texture2DRect(MyTex, vec2(pos.x + blur_size, pos.y)) * 0.15;
  18. sum += texture2DRect(MyTex, vec2(pos.x + 2.0*blur_size, pos.y)) * 0.12;
  19. sum += texture2DRect(MyTex, vec2(pos.x + 3.0*blur_size, pos.y)) * 0.09;
  20. sum += texture2DRect(MyTex, vec2(pos.x + 4.0*blur_size, pos.y)) * 0.05;
  21. gl_FragColor = sum;
  22. }