blur.fragment.fx 772 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifdef GL_ES
  2. precision highp float;
  3. #endif
  4. // Samplers
  5. varying vec2 vUV;
  6. uniform sampler2D textureSampler;
  7. // Parameters
  8. uniform vec2 screenSize;
  9. uniform vec2 direction;
  10. uniform float blurWidth;
  11. void main(void)
  12. {
  13. float weights[7];
  14. weights[0] = 0.05;
  15. weights[1] = 0.1;
  16. weights[2] = 0.2;
  17. weights[3] = 0.3;
  18. weights[4] = 0.2;
  19. weights[5] = 0.1;
  20. weights[6] = 0.05;
  21. vec2 texelSize = vec2(1.0 / screenSize.x, 1.0 / screenSize.y);
  22. vec2 texelStep = texelSize * direction * blurWidth;
  23. vec2 start = vUV - 3.0 * texelStep;
  24. vec4 baseColor = vec4(0., 0., 0., 0.);
  25. vec2 texelOffset = vec2(0., 0.);
  26. for (int i = 0; i < 7; i++)
  27. {
  28. baseColor += texture2D(textureSampler, start + texelOffset) * weights[i];
  29. texelOffset += texelStep;
  30. }
  31. gl_FragColor = baseColor;
  32. }