SavePass.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {
  2. LinearFilter,
  3. RGBFormat,
  4. ShaderMaterial,
  5. UniformsUtils,
  6. WebGLRenderTarget
  7. } from '../../../build/three.module.js';
  8. import { Pass, FullScreenQuad } from './Pass.js';
  9. import { CopyShader } from '../shaders/CopyShader.js';
  10. class SavePass extends Pass {
  11. constructor( renderTarget ) {
  12. super();
  13. if ( CopyShader === undefined ) console.error( 'THREE.SavePass relies on CopyShader' );
  14. const shader = CopyShader;
  15. this.textureID = 'tDiffuse';
  16. this.uniforms = UniformsUtils.clone( shader.uniforms );
  17. this.material = new ShaderMaterial( {
  18. uniforms: this.uniforms,
  19. vertexShader: shader.vertexShader,
  20. fragmentShader: shader.fragmentShader
  21. } );
  22. this.renderTarget = renderTarget;
  23. if ( this.renderTarget === undefined ) {
  24. this.renderTarget = new WebGLRenderTarget( window.innerWidth, window.innerHeight, { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBFormat } );
  25. this.renderTarget.texture.name = 'SavePass.rt';
  26. }
  27. this.needsSwap = false;
  28. this.fsQuad = new FullScreenQuad( this.material );
  29. }
  30. render( renderer, writeBuffer, readBuffer/*, deltaTime, maskActive */ ) {
  31. if ( this.uniforms[ this.textureID ] ) {
  32. this.uniforms[ this.textureID ].value = readBuffer.texture;
  33. }
  34. renderer.setRenderTarget( this.renderTarget );
  35. if ( this.clear ) renderer.clear();
  36. this.fsQuad.render( renderer );
  37. }
  38. }
  39. export { SavePass };