gaussian_blur_vertical.frag 1.1 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; // the texture with the scene you want to blur
  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 y (vertical)
  11. // take nine samples, with the distance blur_size between them
  12. sum += texture2DRect(MyTex, vec2(pos.x, pos.y - 4.0*blur_size)) * 0.05;
  13. sum += texture2DRect(MyTex, vec2(pos.x, pos.y - 3.0*blur_size)) * 0.09;
  14. sum += texture2DRect(MyTex, vec2(pos.x, pos.y - 2.0*blur_size)) * 0.12;
  15. sum += texture2DRect(MyTex, vec2(pos.x, pos.y - blur_size)) * 0.15;
  16. sum += texture2DRect(MyTex, vec2(pos.x, pos.y)) * 0.16;
  17. sum += texture2DRect(MyTex, vec2(pos.x, pos.y + blur_size)) * 0.15;
  18. sum += texture2DRect(MyTex, vec2(pos.x, pos.y + 2.0*blur_size)) * 0.12;
  19. sum += texture2DRect(MyTex, vec2(pos.x, pos.y + 3.0*blur_size)) * 0.09;
  20. sum += texture2DRect(MyTex, vec2(pos.x, pos.y + 4.0*blur_size)) * 0.05;
  21. gl_FragColor = sum;
  22. }