VerticalBlurShader.js 1.6 KB

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