VerticalBlurShader.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. console.warn( "THREE.VerticalBlurShader: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/index.html#manual/en/introduction/Import-via-modules." );
  2. /**
  3. * @author zz85 / http://www.lab4games.net/zz85/blog
  4. *
  5. * Two pass Gaussian blur filter (horizontal and vertical blur shaders)
  6. * - described in http://www.gamerendering.com/2008/10/11/gaussian-blur-filter-shader/
  7. * and used in http://www.cake23.de/traveling-wavefronts-lit-up.html
  8. *
  9. * - 9 samples per pass
  10. * - standard deviation 2.7
  11. * - "h" and "v" parameters should be set to "1 / width" and "1 / height"
  12. */
  13. THREE.VerticalBlurShader = {
  14. uniforms: {
  15. "tDiffuse": { value: null },
  16. "v": { value: 1.0 / 512.0 }
  17. },
  18. vertexShader: [
  19. "varying vec2 vUv;",
  20. "void main() {",
  21. " vUv = uv;",
  22. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  23. "}"
  24. ].join( "\n" ),
  25. fragmentShader: [
  26. "uniform sampler2D tDiffuse;",
  27. "uniform float v;",
  28. "varying vec2 vUv;",
  29. "void main() {",
  30. " vec4 sum = vec4( 0.0 );",
  31. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * v ) ) * 0.051;",
  32. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * v ) ) * 0.0918;",
  33. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * v ) ) * 0.12245;",
  34. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * v ) ) * 0.1531;",
  35. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;",
  36. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * v ) ) * 0.1531;",
  37. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * v ) ) * 0.12245;",
  38. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * v ) ) * 0.0918;",
  39. " sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * v ) ) * 0.051;",
  40. " gl_FragColor = sum;",
  41. "}"
  42. ].join( "\n" )
  43. };