gaussian6v.frag 652 B

12345678910111213141516171819202122232425262728293031
  1. uniform sampler2D tex;
  2. uniform vec2 pixel;
  3. uniform float sigma;
  4. // Gaussian separated blur with radius 6.
  5. out vec4 FragColor;
  6. void main()
  7. {
  8. vec2 uv = gl_FragCoord.xy * pixel;
  9. float X = uv.x;
  10. float Y = uv.y;
  11. float g0, g1, g2;
  12. g0 = 1.0 / (sqrt(2.0 * 3.14) * sigma);
  13. g1 = exp(-0.5 / (sigma * sigma));
  14. g2 = g1 * g1;
  15. vec4 sum = texture(tex, vec2(X, Y)) * g0;
  16. g0 *= g1;
  17. g1 *= g2;
  18. for (int i = 1; i < 6; i++) {
  19. sum += texture(tex, vec2(X, Y - float(i) * pixel.y)) * g0;
  20. sum += texture(tex, vec2(X, Y + float(i) * pixel.y)) * g0;
  21. g0 *= g1;
  22. g1 *= g2;
  23. }
  24. FragColor = sum;
  25. }