SavePass.js 1.3 KB

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