未验证 提交 59d9c361 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #15976 from Oletus/fill-quad-scene-helper

Share code for creating a fill quad scene in postprocessing passes
......@@ -117,12 +117,7 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
blending: THREE.NoBlending
} );
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.scene = new THREE.Scene();
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false; // Avoid getting clipped
this.scene.add( this.quad );
this.fsQuad = new THREE.Pass.FullScreenQuad( null );
};
......@@ -146,35 +141,35 @@ THREE.AdaptiveToneMappingPass.prototype = Object.assign( Object.create( THREE.Pa
if ( this.adaptive ) {
//Render the luminance of the current scene into a render target with mipmapping enabled
this.quad.material = this.materialLuminance;
this.fsQuad.material = this.materialLuminance;
this.materialLuminance.uniforms.tDiffuse.value = readBuffer.texture;
renderer.setRenderTarget( this.currentLuminanceRT );
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
//Use the new luminance values, the previous luminance and the frame delta to
//adapt the luminance over time.
this.quad.material = this.materialAdaptiveLum;
this.fsQuad.material = this.materialAdaptiveLum;
this.materialAdaptiveLum.uniforms.delta.value = deltaTime;
this.materialAdaptiveLum.uniforms.lastLum.value = this.previousLuminanceRT.texture;
this.materialAdaptiveLum.uniforms.currentLum.value = this.currentLuminanceRT.texture;
renderer.setRenderTarget( this.luminanceRT );
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
//Copy the new adapted luminance value so that it can be used by the next frame.
this.quad.material = this.materialCopy;
this.fsQuad.material = this.materialCopy;
this.copyUniforms.tDiffuse.value = this.luminanceRT.texture;
renderer.setRenderTarget( this.previousLuminanceRT );
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
}
this.quad.material = this.materialToneMap;
this.fsQuad.material = this.materialToneMap;
this.materialToneMap.uniforms.tDiffuse.value = readBuffer.texture;
if ( this.renderToScreen ) {
renderer.setRenderTarget( null );
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
} else {
......@@ -182,7 +177,7 @@ THREE.AdaptiveToneMappingPass.prototype = Object.assign( Object.create( THREE.Pa
if ( this.clear ) renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
}
......@@ -230,7 +225,7 @@ THREE.AdaptiveToneMappingPass.prototype = Object.assign( Object.create( THREE.Pa
}
//Put something in the adaptive luminance texture so that the scene can render initially
this.quad.material = new THREE.MeshBasicMaterial( { color: 0x777777 } );
this.fsQuad.material = new THREE.MeshBasicMaterial( { color: 0x777777 } );
this.materialLuminance.needsUpdate = true;
this.materialAdaptiveLum.needsUpdate = true;
this.materialToneMap.needsUpdate = true;
......
......@@ -39,23 +39,12 @@ THREE.AfterimagePass = function ( damp ) {
} );
this.sceneComp = new THREE.Scene();
this.scene = new THREE.Scene();
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.camera.position.z = 1;
var geometry = new THREE.PlaneBufferGeometry( 2, 2 );
this.quadComp = new THREE.Mesh( geometry, this.shaderMaterial );
this.sceneComp.add( this.quadComp );
this.compFsQuad = new THREE.Pass.FullScreenQuad( this.shaderMaterial );
var material = new THREE.MeshBasicMaterial( {
map: this.textureComp.texture
} );
var quadScreen = new THREE.Mesh( geometry, material );
this.scene.add( quadScreen );
this.screenFsQuad = new THREE.Pass.FullScreenQuad( material );
};
......@@ -68,18 +57,16 @@ THREE.AfterimagePass.prototype = Object.assign( Object.create( THREE.Pass.protot
this.uniforms[ "tOld" ].value = this.textureOld.texture;
this.uniforms[ "tNew" ].value = readBuffer.texture;
this.quadComp.material = this.shaderMaterial;
renderer.setRenderTarget( this.textureComp );
renderer.render( this.sceneComp, this.camera );
this.compFsQuad.render( renderer );
renderer.setRenderTarget( this.textureOld );
renderer.render( this.scene, this.camera );
this.screenFsQuad.render( renderer );
if ( this.renderToScreen ) {
renderer.setRenderTarget( null );
renderer.render( this.scene, this.camera );
this.screenFsQuad.render( renderer );
} else {
......@@ -87,7 +74,7 @@ THREE.AfterimagePass.prototype = Object.assign( Object.create( THREE.Pass.protot
if ( this.clear ) renderer.clear();
renderer.render( this.scene, this.camera );
this.screenFsQuad.render( renderer );
}
......
......@@ -67,12 +67,7 @@ THREE.BloomPass = function ( strength, kernelSize, sigma, resolution ) {
this.needsSwap = false;
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.scene = new THREE.Scene();
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false; // Avoid getting clipped
this.scene.add( this.quad );
this.fsQuad = new THREE.Pass.FullScreenQuad( null );
};
......@@ -86,14 +81,14 @@ THREE.BloomPass.prototype = Object.assign( Object.create( THREE.Pass.prototype )
// Render quad with blured scene into texture (convolution pass 1)
this.quad.material = this.materialConvolution;
this.fsQuad.material = this.materialConvolution;
this.convolutionUniforms[ "tDiffuse" ].value = readBuffer.texture;
this.convolutionUniforms[ "uImageIncrement" ].value = THREE.BloomPass.blurX;
renderer.setRenderTarget( this.renderTargetX );
renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
// Render quad with blured scene into texture (convolution pass 2)
......@@ -103,11 +98,11 @@ THREE.BloomPass.prototype = Object.assign( Object.create( THREE.Pass.prototype )
renderer.setRenderTarget( this.renderTargetY );
renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
// Render original scene with superimposed blur to texture
this.quad.material = this.materialCopy;
this.fsQuad.material = this.materialCopy;
this.copyUniforms[ "tDiffuse" ].value = this.renderTargetY.texture;
......@@ -115,7 +110,7 @@ THREE.BloomPass.prototype = Object.assign( Object.create( THREE.Pass.prototype )
renderer.setRenderTarget( readBuffer );
if ( this.clear ) renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
}
......
......@@ -66,12 +66,7 @@ THREE.BokehPass = function ( scene, camera, params ) {
this.uniforms = bokehUniforms;
this.needsSwap = false;
this.camera2 = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.scene2 = new THREE.Scene();
this.quad2 = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad2.frustumCulled = false; // Avoid getting clipped
this.scene2.add( this.quad2 );
this.fsQuad = new THREE.Pass.FullScreenQuad( this.materialBokeh );
this.oldClearColor = new THREE.Color();
this.oldClearAlpha = 1;
......@@ -84,8 +79,6 @@ THREE.BokehPass.prototype = Object.assign( Object.create( THREE.Pass.prototype )
render: function ( renderer, writeBuffer, readBuffer, deltaTime, maskActive ) {
this.quad2.material = this.materialBokeh;
// Render depth into texture
this.scene.overrideMaterial = this.materialDepth;
......@@ -110,13 +103,13 @@ THREE.BokehPass.prototype = Object.assign( Object.create( THREE.Pass.prototype )
if ( this.renderToScreen ) {
renderer.setRenderTarget( null );
renderer.render( this.scene2, this.camera2 );
this.fsQuad.render( renderer );
} else {
renderer.setRenderTarget( writeBuffer );
renderer.clear();
renderer.render( this.scene2, this.camera2 );
this.fsQuad.render( renderer );
}
......
......@@ -25,12 +25,7 @@ THREE.DotScreenPass = function ( center, angle, scale ) {
} );
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.scene = new THREE.Scene();
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false; // Avoid getting clipped
this.scene.add( this.quad );
this.fsQuad = new THREE.Pass.FullScreenQuad( this.material );
};
......@@ -43,18 +38,16 @@ THREE.DotScreenPass.prototype = Object.assign( Object.create( THREE.Pass.prototy
this.uniforms[ "tDiffuse" ].value = readBuffer.texture;
this.uniforms[ "tSize" ].value.set( readBuffer.width, readBuffer.height );
this.quad.material = this.material;
if ( this.renderToScreen ) {
renderer.setRenderTarget( null );
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
} else {
renderer.setRenderTarget( writeBuffer );
if ( this.clear ) renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
}
......
......@@ -203,3 +203,45 @@ Object.assign( THREE.Pass.prototype, {
}
} );
// Helper for passes that need to fill the viewport with a single quad.
THREE.Pass.FullScreenQuad = (function() {
var camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
var geometry = new THREE.PlaneBufferGeometry( 2, 2 );
var FullScreenQuad = function ( material ) {
this._mesh = new THREE.Mesh( geometry, material );
};
Object.defineProperty( FullScreenQuad.prototype, 'material', {
get: function () {
return this._mesh.material;
},
set: function ( value ) {
this._mesh.material = value;
}
} );
Object.assign( FullScreenQuad.prototype, {
render: function ( renderer ) {
renderer.render( this._mesh, camera );
}
} );
return FullScreenQuad;
})();
......@@ -26,12 +26,7 @@ THREE.FilmPass = function ( noiseIntensity, scanlinesIntensity, scanlinesCount,
if ( scanlinesIntensity !== undefined ) this.uniforms.sIntensity.value = scanlinesIntensity;
if ( scanlinesCount !== undefined ) this.uniforms.sCount.value = scanlinesCount;
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.scene = new THREE.Scene();
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false; // Avoid getting clipped
this.scene.add( this.quad );
this.fsQuad = new THREE.Pass.FullScreenQuad( this.material );
};
......@@ -44,18 +39,16 @@ THREE.FilmPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ),
this.uniforms[ "tDiffuse" ].value = readBuffer.texture;
this.uniforms[ "time" ].value += deltaTime;
this.quad.material = this.material;
if ( this.renderToScreen ) {
renderer.setRenderTarget( null );
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
} else {
renderer.setRenderTarget( writeBuffer );
if ( this.clear ) renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
}
......
......@@ -23,12 +23,7 @@ THREE.GlitchPass = function ( dt_size ) {
fragmentShader: shader.fragmentShader
} );
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.scene = new THREE.Scene();
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false; // Avoid getting clipped
this.scene.add( this.quad );
this.fsQuad = new THREE.Pass.FullScreenQuad( this.material );
this.goWild = false;
this.curF = 0;
......@@ -73,18 +68,17 @@ THREE.GlitchPass.prototype = Object.assign( Object.create( THREE.Pass.prototype
}
this.curF ++;
this.quad.material = this.material;
if ( this.renderToScreen ) {
renderer.setRenderTarget( null );
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
} else {
renderer.setRenderTarget( writeBuffer );
if ( this.clear ) renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
}
......
......@@ -36,11 +36,7 @@ THREE.HalftonePass = function ( width, height, params ) {
}
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.scene = new THREE.Scene();
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false;
this.scene.add( this.quad );
this.fsQuad = new THREE.Pass.FullScreenQuad( this.material );
};
......@@ -51,18 +47,17 @@ THREE.HalftonePass.prototype = Object.assign( Object.create( THREE.Pass.prototyp
render: function ( renderer, writeBuffer, readBuffer, deltaTime, maskActive ) {
this.material.uniforms[ "tDiffuse" ].value = readBuffer.texture;
this.quad.material = this.material;
if ( this.renderToScreen ) {
renderer.setRenderTarget( null );
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
} else {
renderer.setRenderTarget( writeBuffer );
if ( this.clear ) renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
}
......
......@@ -101,12 +101,7 @@ THREE.OutlinePass = function ( resolution, scene, camera, selectedObjects ) {
this.oldClearColor = new THREE.Color();
this.oldClearAlpha = 1;
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.scene = new THREE.Scene();
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false; // Avoid getting clipped
this.scene.add( this.quad );
this.fsQuad = new THREE.Pass.FullScreenQuad( null );
this.tempPulseColor1 = new THREE.Color();
this.tempPulseColor2 = new THREE.Color();
......@@ -302,11 +297,11 @@ THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype
this.renderScene.background = currentBackground;
// 2. Downsample to Half resolution
this.quad.material = this.materialCopy;
this.fsQuad.material = this.materialCopy;
this.copyUniforms[ "tDiffuse" ].value = this.renderTargetMaskBuffer.texture;
renderer.setRenderTarget( this.renderTargetMaskDownSampleBuffer );
renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
this.tempPulseColor1.copy( this.visibleEdgeColor );
this.tempPulseColor2.copy( this.hiddenEdgeColor );
......@@ -320,44 +315,44 @@ THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype
}
// 3. Apply Edge Detection Pass
this.quad.material = this.edgeDetectionMaterial;
this.fsQuad.material = this.edgeDetectionMaterial;
this.edgeDetectionMaterial.uniforms[ "maskTexture" ].value = this.renderTargetMaskDownSampleBuffer.texture;
this.edgeDetectionMaterial.uniforms[ "texSize" ].value = new THREE.Vector2( this.renderTargetMaskDownSampleBuffer.width, this.renderTargetMaskDownSampleBuffer.height );
this.edgeDetectionMaterial.uniforms[ "visibleEdgeColor" ].value = this.tempPulseColor1;
this.edgeDetectionMaterial.uniforms[ "hiddenEdgeColor" ].value = this.tempPulseColor2;
renderer.setRenderTarget( this.renderTargetEdgeBuffer1 );
renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
// 4. Apply Blur on Half res
this.quad.material = this.separableBlurMaterial1;
this.fsQuad.material = this.separableBlurMaterial1;
this.separableBlurMaterial1.uniforms[ "colorTexture" ].value = this.renderTargetEdgeBuffer1.texture;
this.separableBlurMaterial1.uniforms[ "direction" ].value = THREE.OutlinePass.BlurDirectionX;
this.separableBlurMaterial1.uniforms[ "kernelRadius" ].value = this.edgeThickness;
renderer.setRenderTarget( this.renderTargetBlurBuffer1 );
renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
this.separableBlurMaterial1.uniforms[ "colorTexture" ].value = this.renderTargetBlurBuffer1.texture;
this.separableBlurMaterial1.uniforms[ "direction" ].value = THREE.OutlinePass.BlurDirectionY;
renderer.setRenderTarget( this.renderTargetEdgeBuffer1 );
renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
// Apply Blur on quarter res
this.quad.material = this.separableBlurMaterial2;
this.fsQuad.material = this.separableBlurMaterial2;
this.separableBlurMaterial2.uniforms[ "colorTexture" ].value = this.renderTargetEdgeBuffer1.texture;
this.separableBlurMaterial2.uniforms[ "direction" ].value = THREE.OutlinePass.BlurDirectionX;
renderer.setRenderTarget( this.renderTargetBlurBuffer2 );
renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
this.separableBlurMaterial2.uniforms[ "colorTexture" ].value = this.renderTargetBlurBuffer2.texture;
this.separableBlurMaterial2.uniforms[ "direction" ].value = THREE.OutlinePass.BlurDirectionY;
renderer.setRenderTarget( this.renderTargetEdgeBuffer2 );
renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
// Blend it additively over the input texture
this.quad.material = this.overlayMaterial;
this.fsQuad.material = this.overlayMaterial;
this.overlayMaterial.uniforms[ "maskTexture" ].value = this.renderTargetMaskBuffer.texture;
this.overlayMaterial.uniforms[ "edgeTexture1" ].value = this.renderTargetEdgeBuffer1.texture;
this.overlayMaterial.uniforms[ "edgeTexture2" ].value = this.renderTargetEdgeBuffer2.texture;
......@@ -370,7 +365,7 @@ THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype
if ( maskActive ) renderer.context.enable( renderer.context.STENCIL_TEST );
renderer.setRenderTarget( readBuffer );
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
renderer.setClearColor( this.oldClearColor, this.oldClearAlpha );
renderer.autoClear = oldAutoClear;
......@@ -379,10 +374,10 @@ THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype
if ( this.renderToScreen ) {
this.quad.material = this.materialCopy;
this.fsQuad.material = this.materialCopy;
this.copyUniforms[ "tDiffuse" ].value = readBuffer.texture;
renderer.setRenderTarget( null );
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
}
......
......@@ -160,10 +160,7 @@ THREE.SAOPass = function ( scene, camera, depthTexture, useNormals, resolution )
blending: THREE.NoBlending
} );
this.quadCamera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.quadScene = new THREE.Scene();
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quadScene.add( this.quad );
this.fsQuad = new THREE.Pass.FullScreenQuad( null );
};
......@@ -331,8 +328,8 @@ THREE.SAOPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ),
}
this.quad.material = passMaterial;
renderer.render( this.quadScene, this.quadCamera );
this.fsQuad.material = passMaterial;
this.fsQuad.render( renderer );
// restore original state
renderer.autoClear = originalAutoClear;
......
......@@ -109,12 +109,7 @@ THREE.SMAAPass = function ( width, height ) {
this.needsSwap = false;
this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
this.scene = new THREE.Scene();
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false; // Avoid getting clipped
this.scene.add( this.quad );
this.fsQuad = new THREE.Pass.FullScreenQuad( null );
};
......@@ -128,36 +123,36 @@ THREE.SMAAPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ),
this.uniformsEdges[ "tDiffuse" ].value = readBuffer.texture;
this.quad.material = this.materialEdges;
this.fsQuad.material = this.materialEdges;
renderer.setRenderTarget( this.edgesRT );
if ( this.clear ) renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
// pass 2
this.quad.material = this.materialWeights;
this.fsQuad.material = this.materialWeights;
renderer.setRenderTarget( this.weightsRT );
if ( this.clear ) renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
// pass 3
this.uniformsBlend[ "tColor" ].value = readBuffer.texture;
this.quad.material = this.materialBlend;
this.fsQuad.material = this.materialBlend;
if ( this.renderToScreen ) {
renderer.setRenderTarget( null );
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
} else {
renderer.setRenderTarget( writeBuffer );
if ( this.clear ) renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
}
......
......@@ -40,11 +40,7 @@ THREE.SSAARenderPass = function ( scene, camera, clearColor, clearAlpha ) {
depthWrite: false
} );
this.camera2 = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.scene2 = new THREE.Scene();
this.quad2 = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), this.copyMaterial );
this.quad2.frustumCulled = false; // Avoid getting clipped
this.scene2.add( this.quad2 );
this.fsQuad = new THREE.Pass.FullScreenQuad( this.copyMaterial );
};
......@@ -133,7 +129,7 @@ THREE.SSAARenderPass.prototype = Object.assign( Object.create( THREE.Pass.protot
}
renderer.render( this.scene2, this.camera2 );
this.fsQuad.render( renderer );
}
......
......@@ -134,14 +134,7 @@ THREE.SSAOPass = function ( scene, camera, width, height ) {
blendEquationAlpha: THREE.AddEquation
} );
//
this.quadCamera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.quadScene = new THREE.Scene();
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quadScene.add( this.quad );
//
this.fsQuad = new THREE.Pass.FullScreenQuad( null );
this.originalClearColor = new THREE.Color();
......@@ -276,8 +269,8 @@ THREE.SSAOPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ),
}
this.quad.material = passMaterial;
renderer.render( this.quadScene, this.quadCamera );
this.fsQuad.material = passMaterial;
this.fsQuad.render( renderer );
// restore original state
renderer.autoClear = originalAutoClear;
......
......@@ -34,12 +34,7 @@ THREE.SavePass = function ( renderTarget ) {
this.needsSwap = false;
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.scene = new THREE.Scene();
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false; // Avoid getting clipped
this.scene.add( this.quad );
this.fsQuad = new THREE.Pass.FullScreenQuad( this.material );
};
......@@ -55,11 +50,9 @@ THREE.SavePass.prototype = Object.assign( Object.create( THREE.Pass.prototype ),
}
this.quad.material = this.material;
renderer.setRenderTarget( this.renderTarget );
if ( this.clear ) renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
}
......
......@@ -29,13 +29,7 @@ THREE.ShaderPass = function ( shader, textureID ) {
}
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.scene = new THREE.Scene();
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false; // Avoid getting clipped
this.scene.add( this.quad );
this.fsQuad = new THREE.Pass.FullScreenQuad( this.material );
};
THREE.ShaderPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
......@@ -50,19 +44,19 @@ THREE.ShaderPass.prototype = Object.assign( Object.create( THREE.Pass.prototype
}
this.quad.material = this.material;
this.fsQuad.material = this.material;
if ( this.renderToScreen ) {
renderer.setRenderTarget( null );
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
} else {
renderer.setRenderTarget( writeBuffer );
// TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600
if ( this.clear ) renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
}
......
......@@ -99,7 +99,7 @@ THREE.TAARenderPass.prototype = Object.assign( Object.create( THREE.SSAARenderPa
renderer.setRenderTarget( this.sampleRenderTarget );
if ( this.accumulateIndex === 0 ) renderer.clear();
renderer.render( this.scene2, this.camera2 );
this.fsQuad.render( renderer );
this.accumulateIndex ++;
......@@ -119,7 +119,7 @@ THREE.TAARenderPass.prototype = Object.assign( Object.create( THREE.SSAARenderPa
this.copyUniforms[ "tDiffuse" ].value = this.sampleRenderTarget.texture;
renderer.setRenderTarget( writeBuffer );
renderer.clear();
renderer.render( this.scene2, this.camera2 );
this.fsQuad.render( renderer );
}
......@@ -129,7 +129,7 @@ THREE.TAARenderPass.prototype = Object.assign( Object.create( THREE.SSAARenderPa
this.copyUniforms[ "tDiffuse" ].value = this.holdRenderTarget.texture;
renderer.setRenderTarget( writeBuffer );
if ( accumulationWeight === 0 ) renderer.clear();
renderer.render( this.scene2, this.camera2 );
this.fsQuad.render( renderer );
}
......
......@@ -28,12 +28,7 @@ THREE.TexturePass = function ( map, opacity ) {
this.needsSwap = false;
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.scene = new THREE.Scene();
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false; // Avoid getting clipped
this.scene.add( this.quad );
this.fsQuad = new THREE.Pass.FullScreenQuad( null );
};
......@@ -46,7 +41,7 @@ THREE.TexturePass.prototype = Object.assign( Object.create( THREE.Pass.prototype
var oldAutoClear = renderer.autoClear;
renderer.autoClear = false;
this.quad.material = this.material;
this.fsQuad.material = this.material;
this.uniforms[ "opacity" ].value = this.opacity;
this.uniforms[ "tDiffuse" ].value = this.map;
......@@ -54,7 +49,7 @@ THREE.TexturePass.prototype = Object.assign( Object.create( THREE.Pass.prototype
renderer.setRenderTarget( this.renderToScreen ? null : readBuffer );
if ( this.clear ) renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
renderer.autoClear = oldAutoClear;
}
......
......@@ -131,14 +131,9 @@ THREE.UnrealBloomPass = function ( resolution, strength, radius, threshold ) {
this.oldClearColor = new THREE.Color();
this.oldClearAlpha = 1;
this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.scene = new THREE.Scene();
this.basic = new THREE.MeshBasicMaterial();
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.quad.frustumCulled = false; // Avoid getting clipped
this.scene.add( this.quad );
this.fsQuad = new THREE.Pass.FullScreenQuad( null );
};
......@@ -200,12 +195,12 @@ THREE.UnrealBloomPass.prototype = Object.assign( Object.create( THREE.Pass.proto
if ( this.renderToScreen ) {
this.quad.material = this.basic;
this.fsQuad.material = this.basic;
this.basic.map = readBuffer.texture;
renderer.setRenderTarget( null );
renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
}
......@@ -213,11 +208,11 @@ THREE.UnrealBloomPass.prototype = Object.assign( Object.create( THREE.Pass.proto
this.highPassUniforms[ "tDiffuse" ].value = readBuffer.texture;
this.highPassUniforms[ "luminosityThreshold" ].value = this.threshold;
this.quad.material = this.materialHighPassFilter;
this.fsQuad.material = this.materialHighPassFilter;
renderer.setRenderTarget( this.renderTargetBright );
renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
// 2. Blur All the mips progressively
......@@ -225,19 +220,19 @@ THREE.UnrealBloomPass.prototype = Object.assign( Object.create( THREE.Pass.proto
for ( var i = 0; i < this.nMips; i ++ ) {
this.quad.material = this.separableBlurMaterials[ i ];
this.fsQuad.material = this.separableBlurMaterials[ i ];
this.separableBlurMaterials[ i ].uniforms[ "colorTexture" ].value = inputRenderTarget.texture;
this.separableBlurMaterials[ i ].uniforms[ "direction" ].value = THREE.UnrealBloomPass.BlurDirectionX;
renderer.setRenderTarget( this.renderTargetsHorizontal[ i ] );
renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
this.separableBlurMaterials[ i ].uniforms[ "colorTexture" ].value = this.renderTargetsHorizontal[ i ].texture;
this.separableBlurMaterials[ i ].uniforms[ "direction" ].value = THREE.UnrealBloomPass.BlurDirectionY;
renderer.setRenderTarget( this.renderTargetsVertical[ i ] );
renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
inputRenderTarget = this.renderTargetsVertical[ i ];
......@@ -245,18 +240,18 @@ THREE.UnrealBloomPass.prototype = Object.assign( Object.create( THREE.Pass.proto
// Composite All the mips
this.quad.material = this.compositeMaterial;
this.fsQuad.material = this.compositeMaterial;
this.compositeMaterial.uniforms[ "bloomStrength" ].value = this.strength;
this.compositeMaterial.uniforms[ "bloomRadius" ].value = this.radius;
this.compositeMaterial.uniforms[ "bloomTintColors" ].value = this.bloomTintColors;
renderer.setRenderTarget( this.renderTargetsHorizontal[ 0 ] );
renderer.clear();
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
// Blend it additively over the input texture
this.quad.material = this.materialCopy;
this.fsQuad.material = this.materialCopy;
this.copyUniforms[ "tDiffuse" ].value = this.renderTargetsHorizontal[ 0 ].texture;
if ( maskActive ) renderer.context.enable( renderer.context.STENCIL_TEST );
......@@ -265,12 +260,12 @@ THREE.UnrealBloomPass.prototype = Object.assign( Object.create( THREE.Pass.proto
if ( this.renderToScreen ) {
renderer.setRenderTarget( null );
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
} else {
renderer.setRenderTarget( readBuffer );
renderer.render( this.scene, this.camera );
this.fsQuad.render( renderer );
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册