SavePass.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. */
  4. THREE.SavePass = function ( renderTarget ) {
  5. THREE.Pass.call( this );
  6. if ( THREE.CopyShader === undefined )
  7. console.error( "THREE.SavePass relies on THREE.CopyShader" );
  8. var shader = THREE.CopyShader;
  9. this.textureID = "tDiffuse";
  10. this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
  11. this.material = new THREE.ShaderMaterial( {
  12. uniforms: this.uniforms,
  13. vertexShader: shader.vertexShader,
  14. fragmentShader: shader.fragmentShader
  15. } );
  16. this.renderTarget = renderTarget;
  17. if ( this.renderTarget === undefined ) {
  18. this.renderTargetParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false };
  19. this.renderTarget = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, this.renderTargetParameters );
  20. }
  21. this.needsSwap = false;
  22. this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  23. this.scene = new THREE.Scene();
  24. this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
  25. this.quad.frustumCulled = false; // Avoid getting clipped
  26. this.scene.add( this.quad );
  27. };
  28. THREE.SavePass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
  29. constructor: THREE.SavePass,
  30. render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  31. if ( this.uniforms[ this.textureID ] ) {
  32. this.uniforms[ this.textureID ].value = readBuffer.texture;
  33. }
  34. this.quad.material = this.material;
  35. renderer.render( this.scene, this.camera, this.renderTarget, this.clear );
  36. }
  37. } );