TriangleBlurShader.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. console.warn( "THREE.TriangleBlurShader: 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. * Triangle blur shader
  6. * based on glfx.js triangle blur shader
  7. * https://github.com/evanw/glfx.js
  8. *
  9. * A basic blur filter, which convolves the image with a
  10. * pyramid filter. The pyramid filter is separable and is applied as two
  11. * perpendicular triangle filters.
  12. */
  13. THREE.TriangleBlurShader = {
  14. uniforms: {
  15. "texture": { value: null },
  16. "delta": { value: new THREE.Vector2( 1, 1 ) }
  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. "#include <common>",
  27. "#define ITERATIONS 10.0",
  28. "uniform sampler2D texture;",
  29. "uniform vec2 delta;",
  30. "varying vec2 vUv;",
  31. "void main() {",
  32. " vec4 color = vec4( 0.0 );",
  33. " float total = 0.0;",
  34. // randomize the lookup values to hide the fixed number of samples
  35. " float offset = rand( vUv );",
  36. " for ( float t = -ITERATIONS; t <= ITERATIONS; t ++ ) {",
  37. " float percent = ( t + offset - 0.5 ) / ITERATIONS;",
  38. " float weight = 1.0 - abs( percent );",
  39. " color += texture2D( texture, vUv + delta * percent ) * weight;",
  40. " total += weight;",
  41. " }",
  42. " gl_FragColor = color / total;",
  43. "}"
  44. ].join( "\n" )
  45. };