TexturePass.js 1.2 KB

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