blur.fragment.fx 762 B

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