VerticalBlurShader.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Two pass Gaussian blur filter (horizontal and vertical blur shaders)
  3. * - see http://www.cake23.de/traveling-wavefronts-lit-up.html
  4. *
  5. * - 9 samples per pass
  6. * - standard deviation 2.7
  7. * - "h" and "v" parameters should be set to "1 / width" and "1 / height"
  8. */
  9. const VerticalBlurShader = {
  10. uniforms: {
  11. 'tDiffuse': { value: null },
  12. 'v': { value: 1.0 / 512.0 }
  13. },
  14. vertexShader: /* glsl */`
  15. varying vec2 vUv;
  16. void main() {
  17. vUv = uv;
  18. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  19. }`,
  20. fragmentShader: /* glsl */`
  21. uniform sampler2D tDiffuse;
  22. uniform float v;
  23. varying vec2 vUv;
  24. void main() {
  25. vec4 sum = vec4( 0.0 );
  26. sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * v ) ) * 0.051;
  27. sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * v ) ) * 0.0918;
  28. sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * v ) ) * 0.12245;
  29. sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * v ) ) * 0.1531;
  30. sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;
  31. sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * v ) ) * 0.1531;
  32. sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * v ) ) * 0.12245;
  33. sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * v ) ) * 0.0918;
  34. sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * v ) ) * 0.051;
  35. gl_FragColor = sum;
  36. }`
  37. };
  38. export { VerticalBlurShader };