TexturePass.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {
  2. ShaderMaterial,
  3. UniformsUtils
  4. } from 'three';
  5. import { Pass, FullScreenQuad } from './Pass.js';
  6. import { CopyShader } from '../shaders/CopyShader.js';
  7. class TexturePass extends Pass {
  8. constructor( map, opacity ) {
  9. super();
  10. if ( CopyShader === undefined ) console.error( 'THREE.TexturePass relies on CopyShader' );
  11. const shader = CopyShader;
  12. this.map = map;
  13. this.opacity = ( opacity !== undefined ) ? opacity : 1.0;
  14. this.uniforms = UniformsUtils.clone( shader.uniforms );
  15. this.material = new ShaderMaterial( {
  16. uniforms: this.uniforms,
  17. vertexShader: shader.vertexShader,
  18. fragmentShader: shader.fragmentShader,
  19. depthTest: false,
  20. depthWrite: false
  21. } );
  22. this.needsSwap = false;
  23. this.fsQuad = new FullScreenQuad( null );
  24. }
  25. render( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) {
  26. const oldAutoClear = renderer.autoClear;
  27. renderer.autoClear = false;
  28. this.fsQuad.material = this.material;
  29. this.uniforms[ 'opacity' ].value = this.opacity;
  30. this.uniforms[ 'tDiffuse' ].value = this.map;
  31. this.material.transparent = ( this.opacity < 1.0 );
  32. renderer.setRenderTarget( this.renderToScreen ? null : readBuffer );
  33. if ( this.clear ) renderer.clear();
  34. this.fsQuad.render( renderer );
  35. renderer.autoClear = oldAutoClear;
  36. }
  37. }
  38. export { TexturePass };