提交 9406f2cd 编写于 作者: B Ben Houston (Clara.io) 提交者: Mr.doob

fix buggy prototype usage in Pass derived classes. (#8916)

* fix buggy prototype usage in Pass derived classes.

* remove constructors as suggested by @mrdoob

* fix MaskPass's prototype.
上级 63def1e9
......@@ -125,9 +125,7 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
THREE.AdaptiveToneMappingPass.prototype = Object.create( THREE.Pass.prototype );
THREE.AdaptiveToneMappingPass.prototype = {
constructor: THREE.AdaptiveToneMappingPass,
Object.assign( THREE.AdaptiveToneMappingPass.prototype, {
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
......@@ -317,4 +315,4 @@ THREE.AdaptiveToneMappingPass.prototype = {
}
};
} );
......@@ -75,9 +75,7 @@ THREE.BloomPass = function ( strength, kernelSize, sigma, resolution ) {
THREE.BloomPass.prototype = Object.create( THREE.Pass.prototype );
THREE.BloomPass.prototype = {
constructor: THREE.BloomPass,
Object.assign( THREE.BloomPass.prototype, {
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
......@@ -112,7 +110,7 @@ THREE.BloomPass.prototype = {
}
};
} );
THREE.BloomPass.blurX = new THREE.Vector2( 0.001953125, 0.0 );
THREE.BloomPass.blurY = new THREE.Vector2( 0.0, 0.001953125 );
......@@ -39,7 +39,7 @@ THREE.BokehPass = function ( scene, camera, params ) {
console.error( "THREE.BokehPass relies on THREE.BokehShader" );
}
var bokehShader = THREE.BokehShader;
var bokehUniforms = THREE.UniformsUtils.clone( bokehShader.uniforms );
......@@ -69,9 +69,7 @@ THREE.BokehPass = function ( scene, camera, params ) {
THREE.BokehPass.prototype = Object.create( THREE.Pass.prototype );
THREE.BokehPass.prototype = {
constructor: THREE.BokehPass,
Object.assign( THREE.BokehPass.prototype, {
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
......@@ -101,4 +99,4 @@ THREE.BokehPass.prototype = {
}
};
} );
......@@ -12,9 +12,7 @@ THREE.ClearPass = function () {
THREE.ClearPass.prototype = Object.create( THREE.Pass.prototype );
THREE.ClearPass.prototype = {
constructor: THREE.ClearPass,
Object.assign( THREE.ClearPass.prototype, {
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
......@@ -23,4 +21,4 @@ THREE.ClearPass.prototype = {
}
};
} );
......@@ -35,9 +35,7 @@ THREE.DotScreenPass = function ( center, angle, scale ) {
THREE.DotScreenPass.prototype = Object.create( THREE.Pass.prototype );
THREE.DotScreenPass.prototype = {
constructor: THREE.DotScreenPass,
Object.assign( THREE.DotScreenPass.prototype, {
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
......@@ -58,4 +56,4 @@ THREE.DotScreenPass.prototype = {
}
};
} );
......@@ -36,9 +36,7 @@ THREE.FilmPass = function ( noiseIntensity, scanlinesIntensity, scanlinesCount,
THREE.FilmPass.prototype = Object.create( THREE.Pass.prototype );
THREE.FilmPass.prototype = {
constructor: THREE.FilmPass,
Object.assign( THREE.FilmPass.prototype, {
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
......@@ -59,4 +57,4 @@ THREE.FilmPass.prototype = {
}
};
} );
......@@ -37,9 +37,7 @@ THREE.GlitchPass = function ( dt_size ) {
THREE.GlitchPass.prototype = Object.create( THREE.Pass.prototype );
THREE.GlitchPass.prototype = {
constructor: THREE.GlitchPass,
Object.assign( THREE.GlitchPass.prototype, {
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
......@@ -114,4 +112,4 @@ THREE.GlitchPass.prototype = {
}
};
} );
......@@ -54,9 +54,7 @@ THREE.ManualMSAARenderPass = function ( scene, camera, params ) {
THREE.ManualMSAARenderPass.prototype = Object.create( THREE.Pass.prototype );
THREE.ManualMSAARenderPass.prototype = {
constructor: THREE.ManualMSAARenderPass,
Object.assign( THREE.ManualMSAARenderPass.prototype, {
dispose: function() {
......@@ -69,10 +67,9 @@ THREE.ManualMSAARenderPass.prototype = {
},
setSize: function ( width, height ) {
if ( this.sampleRenderTarget ) { this.sampleRenderTarget.setSize( width, height ); }
if ( this.sampleRenderTarget ) this.sampleRenderTarget.setSize( width, height );
},
......@@ -116,7 +113,7 @@ THREE.ManualMSAARenderPass.prototype = {
}
};
} );
// These jitter vectors are specified in integers because it is easier.
// I am assuming a [-8,8) integer grid, but it needs to be mapped onto [-0.5,0.5)
......
......@@ -18,9 +18,7 @@ THREE.MaskPass = function ( scene, camera ) {
THREE.MaskPass.prototype = Object.create( THREE.Pass.prototype );
THREE.MaskPass.prototype = {
constructor: THREE.MaskPass,
Object.assign( THREE.MaskPass.prototype, {
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
......@@ -75,7 +73,7 @@ THREE.MaskPass.prototype = {
}
};
} );
THREE.ClearMaskPass = function () {
......@@ -88,9 +86,7 @@ THREE.ClearMaskPass = function () {
THREE.ClearMaskPass.prototype = Object.create( THREE.Pass.prototype );
THREE.ClearMaskPass.prototype = {
constructor: THREE.ClearMaskPass,
Object.assign( THREE.ClearMaskPass.prototype, {
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
......@@ -98,4 +94,4 @@ THREE.ClearMaskPass.prototype = {
}
};
} );
......@@ -24,9 +24,7 @@ THREE.RenderPass = function ( scene, camera, overrideMaterial, clearColor, clear
THREE.RenderPass.prototype = Object.create( THREE.Pass.prototype );
THREE.RenderPass.prototype = {
constructor: THREE.RenderPass,
Object.assign( THREE.RenderPass.prototype, {
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
......@@ -53,4 +51,4 @@ THREE.RenderPass.prototype = {
}
};
} );
......@@ -106,9 +106,7 @@ THREE.SMAAPass = function ( width, height ) {
THREE.SMAAPass.prototype = Object.create( THREE.Pass.prototype );
THREE.SMAAPass.prototype = {
constructor: THREE.SMAAPass,
Object.assign( THREE.SMAAPass.prototype, {
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
......@@ -163,4 +161,4 @@ THREE.SMAAPass.prototype = {
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEIAAAAhCAAAAABIXyLAAAAAOElEQVRIx2NgGAWjYBSMglEwEICREYRgFBZBqDCSLA2MGPUIVQETE9iNUAqLR5gIeoQKRgwXjwAAGn4AtaFeYLEAAAAASUVORK5CYII=';
}
};
} );
......@@ -44,9 +44,7 @@ THREE.SavePass = function ( renderTarget ) {
THREE.SavePass.prototype = Object.create( THREE.Pass.prototype );
THREE.SavePass.prototype = {
constructor: THREE.SavePass,
Object.assign( THREE.SavePass.prototype, {
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
......@@ -62,4 +60,4 @@ THREE.SavePass.prototype = {
}
};
} );
......@@ -40,9 +40,7 @@ THREE.ShaderPass = function( shader, textureID ) {
THREE.ShaderPass.prototype = Object.create( THREE.Pass.prototype );
THREE.ShaderPass.prototype = {
constructor: THREE.ShaderPass,
Object.assign( THREE.ShaderPass.prototype, {
render: function( renderer, writeBuffer, readBuffer, delta, maskActive ) {
......@@ -66,4 +64,4 @@ THREE.ShaderPass.prototype = {
}
};
} );
......@@ -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;
}
}
});
......@@ -36,9 +36,7 @@ THREE.TexturePass = function ( texture, opacity ) {
THREE.TexturePass.prototype = Object.create( THREE.Pass.prototype );
THREE.TexturePass.prototype = {
constructor: THREE.TexturePass,
Object.assign( THREE.TexturePass.prototype, {
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
......@@ -48,4 +46,4 @@ THREE.TexturePass.prototype = {
}
};
} );
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册