TexturePass.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. */
  4. import {
  5. ShaderMaterial,
  6. UniformsUtils
  7. } from "../../../build/three.module.js";
  8. import { Pass } from "../postprocessing/Pass.js";
  9. import { CopyShader } from "../shaders/CopyShader.js";
  10. var TexturePass = function ( map, opacity ) {
  11. Pass.call( this );
  12. if ( CopyShader === undefined )
  13. console.error( "TexturePass relies on CopyShader" );
  14. var shader = CopyShader;
  15. this.map = map;
  16. this.opacity = ( opacity !== undefined ) ? opacity : 1.0;
  17. this.uniforms = UniformsUtils.clone( shader.uniforms );
  18. this.material = new ShaderMaterial( {
  19. uniforms: this.uniforms,
  20. vertexShader: shader.vertexShader,
  21. fragmentShader: shader.fragmentShader,
  22. depthTest: false,
  23. depthWrite: false
  24. } );
  25. this.needsSwap = false;
  26. this.fsQuad = new Pass.FullScreenQuad( null );
  27. };
  28. TexturePass.prototype = Object.assign( Object.create( Pass.prototype ), {
  29. constructor: TexturePass,
  30. render: function ( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) {
  31. var oldAutoClear = renderer.autoClear;
  32. renderer.autoClear = false;
  33. this.fsQuad.material = this.material;
  34. this.uniforms[ "opacity" ].value = this.opacity;
  35. this.uniforms[ "tDiffuse" ].value = this.map;
  36. this.material.transparent = ( this.opacity < 1.0 );
  37. renderer.setRenderTarget( this.renderToScreen ? null : readBuffer );
  38. if ( this.clear ) renderer.clear();
  39. this.fsQuad.render( renderer );
  40. renderer.autoClear = oldAutoClear;
  41. }
  42. } );
  43. export { TexturePass };