SavePass.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. */
  4. import {
  5. LinearFilter,
  6. RGBFormat,
  7. ShaderMaterial,
  8. UniformsUtils,
  9. WebGLRenderTarget
  10. } from "../../../build/three.module.js";
  11. import { Pass } from "../postprocessing/Pass.js";
  12. import { CopyShader } from "../shaders/CopyShader.js";
  13. var SavePass = function ( renderTarget ) {
  14. Pass.call( this );
  15. if ( CopyShader === undefined )
  16. console.error( "SavePass relies on CopyShader" );
  17. var shader = CopyShader;
  18. this.textureID = "tDiffuse";
  19. this.uniforms = UniformsUtils.clone( shader.uniforms );
  20. this.material = new ShaderMaterial( {
  21. uniforms: this.uniforms,
  22. vertexShader: shader.vertexShader,
  23. fragmentShader: shader.fragmentShader
  24. } );
  25. this.renderTarget = renderTarget;
  26. if ( this.renderTarget === undefined ) {
  27. this.renderTarget = new WebGLRenderTarget( window.innerWidth, window.innerHeight, { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBFormat, stencilBuffer: false } );
  28. this.renderTarget.texture.name = "SavePass.rt";
  29. }
  30. this.needsSwap = false;
  31. this.fsQuad = new Pass.FullScreenQuad( this.material );
  32. };
  33. SavePass.prototype = Object.assign( Object.create( Pass.prototype ), {
  34. constructor: SavePass,
  35. render: function ( renderer, writeBuffer, readBuffer ) {
  36. if ( this.uniforms[ this.textureID ] ) {
  37. this.uniforms[ this.textureID ].value = readBuffer.texture;
  38. }
  39. renderer.setRenderTarget( this.renderTarget );
  40. if ( this.clear ) renderer.clear();
  41. this.fsQuad.render( renderer );
  42. }
  43. } );
  44. export { SavePass };