2
0

TriangleBlurShader.js 1.6 KB

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