AfterimageShader.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. console.warn( "THREE.AfterimageShader: 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 HypnosNova / https://www.threejs.org.cn/gallery/
  4. *
  5. * Afterimage shader
  6. * I created this effect inspired by a demo on codepen:
  7. * https://codepen.io/brunoimbrizi/pen/MoRJaN?page=1&
  8. */
  9. THREE.AfterimageShader = {
  10. uniforms: {
  11. "damp": { value: 0.96 },
  12. "tOld": { value: null },
  13. "tNew": { value: null }
  14. },
  15. vertexShader: [
  16. "varying vec2 vUv;",
  17. "void main() {",
  18. " vUv = uv;",
  19. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  20. "}"
  21. ].join( "\n" ),
  22. fragmentShader: [
  23. "uniform float damp;",
  24. "uniform sampler2D tOld;",
  25. "uniform sampler2D tNew;",
  26. "varying vec2 vUv;",
  27. "vec4 when_gt( vec4 x, float y ) {",
  28. " return max( sign( x - y ), 0.0 );",
  29. "}",
  30. "void main() {",
  31. " vec4 texelOld = texture2D( tOld, vUv );",
  32. " vec4 texelNew = texture2D( tNew, vUv );",
  33. " texelOld *= damp * when_gt( texelOld, 0.1 );",
  34. " gl_FragColor = max(texelNew, texelOld);",
  35. "}"
  36. ].join( "\n" )
  37. };