From 5322adc76103f79af0d1b309946b793f0c9fa667 Mon Sep 17 00:00:00 2001 From: Tentone Date: Wed, 30 Aug 2017 22:39:34 +0100 Subject: [PATCH] Unreal bloom render to screen --- examples/js/postprocessing/UnrealBloomPass.js | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/examples/js/postprocessing/UnrealBloomPass.js b/examples/js/postprocessing/UnrealBloomPass.js index 456cd9cdb6..ea5efa8021 100644 --- a/examples/js/postprocessing/UnrealBloomPass.js +++ b/examples/js/postprocessing/UnrealBloomPass.js @@ -131,6 +131,8 @@ THREE.UnrealBloomPass = function ( resolution, strength, radius, threshold ) { 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 ); @@ -191,11 +193,24 @@ THREE.UnrealBloomPass.prototype = Object.assign( Object.create( THREE.Pass.proto if ( maskActive ) renderer.context.disable( renderer.context.STENCIL_TEST ); + // Render input to screen + + if( this.renderToScreen ) { + + this.quad.material = this.basic; + this.basic.map = readBuffer.texture; + + renderer.render( this.scene, this.camera, undefined, true ); + + } + + // 1. Extract Bright Areas this.highPassUniforms[ "tDiffuse" ].value = readBuffer.texture; this.highPassUniforms[ "luminosityThreshold" ].value = this.threshold; - this.quad.material = this.materialHighPassFilter; + this.quad.material = this.materialHighPassFilter; + renderer.render( this.scene, this.camera, this.renderTargetBright, true ); // 2. Blur All the mips progressively @@ -228,6 +243,7 @@ THREE.UnrealBloomPass.prototype = Object.assign( Object.create( THREE.Pass.proto this.compositeMaterial.uniforms[ "bloomStrength" ].value = this.strength; this.compositeMaterial.uniforms[ "bloomRadius" ].value = this.radius; this.compositeMaterial.uniforms[ "bloomTintColors" ].value = this.bloomTintColors; + renderer.render( this.scene, this.camera, this.renderTargetsHorizontal[ 0 ], true ); // Blend it additively over the input texture @@ -237,7 +253,18 @@ THREE.UnrealBloomPass.prototype = Object.assign( Object.create( THREE.Pass.proto if ( maskActive ) renderer.context.enable( renderer.context.STENCIL_TEST ); - renderer.render( this.scene, this.camera, readBuffer, false ); + + if( this.renderToScreen ) { + + renderer.render( this.scene, this.camera, undefined, false ); + + } else { + + renderer.render( this.scene, this.camera, readBuffer, false ); + + } + + // Restore renderer settings renderer.setClearColor( this.oldClearColor, this.oldClearAlpha ); renderer.autoClear = oldAutoClear; -- GitLab