|
@@ -33,6 +33,8 @@ THREE.BokehPass = function ( scene, camera, params ) {
|
|
|
// depth material
|
|
|
|
|
|
this.materialDepth = new THREE.MeshDepthMaterial();
|
|
|
+ this.materialDepth.depthPacking = THREE.RGBADepthPacking;
|
|
|
+ this.materialDepth.blending = THREE.NoBlending;
|
|
|
|
|
|
// bokeh material
|
|
|
|
|
@@ -51,8 +53,11 @@ THREE.BokehPass = function ( scene, camera, params ) {
|
|
|
bokehUniforms[ "aspect" ].value = aspect;
|
|
|
bokehUniforms[ "aperture" ].value = aperture;
|
|
|
bokehUniforms[ "maxblur" ].value = maxblur;
|
|
|
+ bokehUniforms[ "nearClip" ].value = camera.near;
|
|
|
+ bokehUniforms[ "farClip" ].value = camera.far;
|
|
|
|
|
|
this.materialBokeh = new THREE.ShaderMaterial( {
|
|
|
+ defines: bokehShader.defines,
|
|
|
uniforms: bokehUniforms,
|
|
|
vertexShader: bokehShader.vertexShader,
|
|
|
fragmentShader: bokehShader.fragmentShader
|
|
@@ -68,6 +73,9 @@ THREE.BokehPass = function ( scene, camera, params ) {
|
|
|
this.quad2.frustumCulled = false; // Avoid getting clipped
|
|
|
this.scene2.add( this.quad2 );
|
|
|
|
|
|
+ this.oldClearColor = new THREE.Color();
|
|
|
+ this.oldClearAlpha = 1;
|
|
|
+
|
|
|
};
|
|
|
|
|
|
THREE.BokehPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
|
|
@@ -82,11 +90,20 @@ THREE.BokehPass.prototype = Object.assign( Object.create( THREE.Pass.prototype )
|
|
|
|
|
|
this.scene.overrideMaterial = this.materialDepth;
|
|
|
|
|
|
+ this.oldClearColor.copy( renderer.getClearColor() );
|
|
|
+ this.oldClearAlpha = renderer.getClearAlpha();
|
|
|
+ var oldAutoClear = renderer.autoClear;
|
|
|
+ renderer.autoClear = false;
|
|
|
+
|
|
|
+ renderer.setClearColor( 0xffffff );
|
|
|
+ renderer.setClearAlpha( 1.0 );
|
|
|
renderer.render( this.scene, this.camera, this.renderTargetDepth, true );
|
|
|
|
|
|
// Render bokeh composite
|
|
|
|
|
|
this.uniforms[ "tColor" ].value = readBuffer.texture;
|
|
|
+ this.uniforms[ "nearClip" ].value = this.camera.near;
|
|
|
+ this.uniforms[ "farClip" ].value = this.camera.far;
|
|
|
|
|
|
if ( this.renderToScreen ) {
|
|
|
|
|
@@ -99,7 +116,10 @@ THREE.BokehPass.prototype = Object.assign( Object.create( THREE.Pass.prototype )
|
|
|
}
|
|
|
|
|
|
this.scene.overrideMaterial = null;
|
|
|
-
|
|
|
+ renderer.setClearColor( this.oldClearColor );
|
|
|
+ renderer.setClearAlpha( this.oldClearAlpha );
|
|
|
+ renderer.autoClear = this.oldAutoClear;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
} );
|