|
@@ -26,96 +26,98 @@ THREE.TAARenderPass = function ( scene, camera, params ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
-THREE.TAARenderPass.prototype = Object.create( THREE.ManualMSAARenderPass.prototype );
|
|
|
-THREE.TAARenderPass.prototype.constructor = THREE.TAARenderPass;
|
|
|
THREE.TAARenderPass.JitterVectors = THREE.ManualMSAARenderPass.JitterVectors;
|
|
|
|
|
|
-THREE.TAARenderPass.prototype.render = function ( renderer, writeBuffer, readBuffer, delta ) {
|
|
|
+THREE.TAARenderPass.prototype = Object.create( THREE.ManualMSAARenderPass.prototype );
|
|
|
+Object.assign( THREE.TAARenderPass.prototype, {
|
|
|
|
|
|
- if( ! this.accumulate ) {
|
|
|
+ render: function ( renderer, writeBuffer, readBuffer, delta ) {
|
|
|
|
|
|
- THREE.ManualMSAARenderPass.prototype.render.call( this, renderer, writeBuffer, readBuffer, delta );
|
|
|
+ if( ! this.accumulate ) {
|
|
|
|
|
|
- this.accumulateIndex = -1;
|
|
|
- return;
|
|
|
+ THREE.ManualMSAARenderPass.prototype.render.call( this, renderer, writeBuffer, readBuffer, delta );
|
|
|
|
|
|
- }
|
|
|
+ this.accumulateIndex = -1;
|
|
|
+ return;
|
|
|
|
|
|
- var jitterOffsets = THREE.TAARenderPass.JitterVectors[ 5 ];
|
|
|
+ }
|
|
|
|
|
|
- var camera = ( this.camera || this.scene.camera );
|
|
|
+ var jitterOffsets = THREE.TAARenderPass.JitterVectors[ 5 ];
|
|
|
|
|
|
- if ( ! this.sampleRenderTarget ) {
|
|
|
+ var camera = ( this.camera || this.scene.camera );
|
|
|
|
|
|
- this.sampleRenderTarget = new THREE.WebGLRenderTarget( readBuffer.width, readBuffer.height, this.params );
|
|
|
+ if ( ! this.sampleRenderTarget ) {
|
|
|
|
|
|
- }
|
|
|
+ this.sampleRenderTarget = new THREE.WebGLRenderTarget( readBuffer.width, readBuffer.height, this.params );
|
|
|
|
|
|
- if ( ! this.holdRenderTarget ) {
|
|
|
+ }
|
|
|
|
|
|
- this.holdRenderTarget = new THREE.WebGLRenderTarget( readBuffer.width, readBuffer.height, this.params );
|
|
|
+ if ( ! this.holdRenderTarget ) {
|
|
|
|
|
|
- }
|
|
|
+ this.holdRenderTarget = new THREE.WebGLRenderTarget( readBuffer.width, readBuffer.height, this.params );
|
|
|
|
|
|
- if( this.accumulate && this.accumulateIndex === -1 ) {
|
|
|
+ }
|
|
|
|
|
|
- THREE.ManualMSAARenderPass.prototype.render.call( this, renderer, this.holdRenderTarget, readBuffer, delta );
|
|
|
+ if( this.accumulate && this.accumulateIndex === -1 ) {
|
|
|
|
|
|
- this.accumulateIndex = 0;
|
|
|
+ THREE.ManualMSAARenderPass.prototype.render.call( this, renderer, this.holdRenderTarget, readBuffer, delta );
|
|
|
|
|
|
- }
|
|
|
+ this.accumulateIndex = 0;
|
|
|
|
|
|
- var autoClear = renderer.autoClear;
|
|
|
- renderer.autoClear = false;
|
|
|
+ }
|
|
|
|
|
|
- var sampleWeight = 1.0 / ( jitterOffsets.length );
|
|
|
+ var autoClear = renderer.autoClear;
|
|
|
+ renderer.autoClear = false;
|
|
|
|
|
|
- if( this.accumulateIndex >= 0 && this.accumulateIndex < jitterOffsets.length ) {
|
|
|
+ var sampleWeight = 1.0 / ( jitterOffsets.length );
|
|
|
|
|
|
- this.compositeUniforms[ "scale" ].value = sampleWeight;
|
|
|
- this.compositeUniforms[ "tForeground" ].value = writeBuffer.texture;
|
|
|
+ if( this.accumulateIndex >= 0 && this.accumulateIndex < jitterOffsets.length ) {
|
|
|
|
|
|
- // render the scene multiple times, each slightly jitter offset from the last and accumulate the results.
|
|
|
- var numSamplesPerFrame = Math.pow( 2, this.sampleLevel );
|
|
|
- for ( var i = 0; i < numSamplesPerFrame; i ++ ) {
|
|
|
+ this.compositeUniforms[ "scale" ].value = sampleWeight;
|
|
|
+ this.compositeUniforms[ "tForeground" ].value = writeBuffer.texture;
|
|
|
|
|
|
- var j = this.accumulateIndex;
|
|
|
- // only jitters perspective cameras. TODO: add support for jittering orthogonal cameras
|
|
|
- var jitterOffset = jitterOffsets[j];
|
|
|
- if ( camera.setViewOffset ) {
|
|
|
- camera.setViewOffset( readBuffer.width, readBuffer.height,
|
|
|
- jitterOffset[ 0 ] * 0.0625, jitterOffset[ 1 ] * 0.0625, // 0.0625 = 1 / 16
|
|
|
- readBuffer.width, readBuffer.height );
|
|
|
- }
|
|
|
+ // render the scene multiple times, each slightly jitter offset from the last and accumulate the results.
|
|
|
+ var numSamplesPerFrame = Math.pow( 2, this.sampleLevel );
|
|
|
+ for ( var i = 0; i < numSamplesPerFrame; i ++ ) {
|
|
|
|
|
|
- renderer.render( this.scene, this.camera, writeBuffer, true );
|
|
|
+ var j = this.accumulateIndex;
|
|
|
+ // only jitters perspective cameras. TODO: add support for jittering orthogonal cameras
|
|
|
+ var jitterOffset = jitterOffsets[j];
|
|
|
+ if ( camera.setViewOffset ) {
|
|
|
+ camera.setViewOffset( readBuffer.width, readBuffer.height,
|
|
|
+ jitterOffset[ 0 ] * 0.0625, jitterOffset[ 1 ] * 0.0625, // 0.0625 = 1 / 16
|
|
|
+ readBuffer.width, readBuffer.height );
|
|
|
+ }
|
|
|
|
|
|
- renderer.render( this.scene2, this.camera2, this.sampleRenderTarget, ( this.accumulateIndex === 0 ) );
|
|
|
+ renderer.render( this.scene, this.camera, writeBuffer, true );
|
|
|
|
|
|
- this.accumulateIndex ++;
|
|
|
- if( this.accumulateIndex >= jitterOffsets.length ) break;
|
|
|
- }
|
|
|
+ renderer.render( this.scene2, this.camera2, this.sampleRenderTarget, ( this.accumulateIndex === 0 ) );
|
|
|
|
|
|
- // reset jitter to nothing. TODO: add support for orthogonal cameras
|
|
|
- if ( camera.setViewOffset ) camera.setViewOffset( undefined, undefined, undefined, undefined, undefined, undefined );
|
|
|
+ this.accumulateIndex ++;
|
|
|
+ if( this.accumulateIndex >= jitterOffsets.length ) break;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ // reset jitter to nothing. TODO: add support for orthogonal cameras
|
|
|
+ if ( camera.setViewOffset ) camera.setViewOffset( undefined, undefined, undefined, undefined, undefined, undefined );
|
|
|
|
|
|
- var accumulationWeight = this.accumulateIndex * sampleWeight;
|
|
|
+ }
|
|
|
|
|
|
- if( accumulationWeight > 0 ) {
|
|
|
- this.compositeUniforms[ "scale" ].value = 1.0;
|
|
|
- this.compositeUniforms[ "tForeground" ].value = this.sampleRenderTarget.texture;
|
|
|
- renderer.render( this.scene2, this.camera2, writeBuffer, true );
|
|
|
- }
|
|
|
+ var accumulationWeight = this.accumulateIndex * sampleWeight;
|
|
|
|
|
|
- if( accumulationWeight < 1.0 ) {
|
|
|
- this.compositeUniforms[ "scale" ].value = 1.0 - accumulationWeight;
|
|
|
- this.compositeUniforms[ "tForeground" ].value = this.holdRenderTarget.texture;
|
|
|
- renderer.render( this.scene2, this.camera2, writeBuffer, ( accumulationWeight === 0 ) );
|
|
|
- }
|
|
|
+ if( accumulationWeight > 0 ) {
|
|
|
+ this.compositeUniforms[ "scale" ].value = 1.0;
|
|
|
+ this.compositeUniforms[ "tForeground" ].value = this.sampleRenderTarget.texture;
|
|
|
+ renderer.render( this.scene2, this.camera2, writeBuffer, true );
|
|
|
+ }
|
|
|
|
|
|
- renderer.autoClear = autoClear;
|
|
|
+ if( accumulationWeight < 1.0 ) {
|
|
|
+ this.compositeUniforms[ "scale" ].value = 1.0 - accumulationWeight;
|
|
|
+ this.compositeUniforms[ "tForeground" ].value = this.holdRenderTarget.texture;
|
|
|
+ renderer.render( this.scene2, this.camera2, writeBuffer, ( accumulationWeight === 0 ) );
|
|
|
+ }
|
|
|
|
|
|
+ renderer.autoClear = autoClear;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
-}
|
|
|
+});
|