VerticalBlurShader.js 1.8 KB

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