VerticalBlurShader.js 1.5 KB

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