You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.4 KiB
80 lines
1.4 KiB
6 months ago
|
import {
|
||
|
HalfFloatType,
|
||
|
NoBlending,
|
||
|
ShaderMaterial,
|
||
|
UniformsUtils,
|
||
|
WebGLRenderTarget
|
||
|
} from 'three';
|
||
|
import { Pass, FullScreenQuad } from './Pass.js';
|
||
|
import { CopyShader } from '../shaders/CopyShader.js';
|
||
|
|
||
|
class SavePass extends Pass {
|
||
|
|
||
|
constructor( renderTarget ) {
|
||
|
|
||
|
super();
|
||
|
|
||
|
const shader = CopyShader;
|
||
|
|
||
|
this.textureID = 'tDiffuse';
|
||
|
|
||
|
this.uniforms = UniformsUtils.clone( shader.uniforms );
|
||
|
|
||
|
this.material = new ShaderMaterial( {
|
||
|
|
||
|
uniforms: this.uniforms,
|
||
|
vertexShader: shader.vertexShader,
|
||
|
fragmentShader: shader.fragmentShader,
|
||
|
blending: NoBlending
|
||
|
|
||
|
} );
|
||
|
|
||
|
this.renderTarget = renderTarget;
|
||
|
|
||
|
if ( this.renderTarget === undefined ) {
|
||
|
|
||
|
this.renderTarget = new WebGLRenderTarget( 1, 1, { type: HalfFloatType } ); // will be resized later
|
||
|
this.renderTarget.texture.name = 'SavePass.rt';
|
||
|
|
||
|
}
|
||
|
|
||
|
this.needsSwap = false;
|
||
|
|
||
|
this.fsQuad = new FullScreenQuad( this.material );
|
||
|
|
||
|
}
|
||
|
|
||
|
render( renderer, writeBuffer, readBuffer/*, deltaTime, maskActive */ ) {
|
||
|
|
||
|
if ( this.uniforms[ this.textureID ] ) {
|
||
|
|
||
|
this.uniforms[ this.textureID ].value = readBuffer.texture;
|
||
|
|
||
|
}
|
||
|
|
||
|
renderer.setRenderTarget( this.renderTarget );
|
||
|
if ( this.clear ) renderer.clear();
|
||
|
this.fsQuad.render( renderer );
|
||
|
|
||
|
}
|
||
|
|
||
|
setSize( width, height ) {
|
||
|
|
||
|
this.renderTarget.setSize( width, height );
|
||
|
|
||
|
}
|
||
|
|
||
|
dispose() {
|
||
|
|
||
|
this.renderTarget.dispose();
|
||
|
|
||
|
this.material.dispose();
|
||
|
|
||
|
this.fsQuad.dispose();
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
export { SavePass };
|