From d7b06a93565620a5d56c331c4fea404ccd700ac8 Mon Sep 17 00:00:00 2001 From: oguzeroglu Date: Tue, 31 Jul 2018 11:45:32 +0300 Subject: [PATCH] UnrealBloomPass memory optimization --- examples/js/postprocessing/UnrealBloomPass.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/js/postprocessing/UnrealBloomPass.js b/examples/js/postprocessing/UnrealBloomPass.js index af815c24be..cb3cf54abe 100644 --- a/examples/js/postprocessing/UnrealBloomPass.js +++ b/examples/js/postprocessing/UnrealBloomPass.js @@ -1,6 +1,6 @@ /** * @author spidersharma / http://eduperiment.com/ - * + * * Inspired from Unreal Engine * https://docs.unrealengine.com/latest/INT/Engine/Rendering/PostProcessEffects/Bloom/ */ @@ -13,6 +13,9 @@ THREE.UnrealBloomPass = function ( resolution, strength, radius, threshold ) { this.threshold = threshold; this.resolution = ( resolution !== undefined ) ? new THREE.Vector2( resolution.x, resolution.y ) : new THREE.Vector2( 256, 256 ); + // create color only once here, reuse it later inside the render function + this.reusableColor = new THREE.Color( 0, 0, 0 ); + // render targets var pars = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBAFormat }; this.renderTargetsHorizontal = []; @@ -189,7 +192,7 @@ THREE.UnrealBloomPass.prototype = Object.assign( Object.create( THREE.Pass.proto var oldAutoClear = renderer.autoClear; renderer.autoClear = false; - renderer.setClearColor( new THREE.Color( 0, 0, 0 ), 0 ); + renderer.setClearColor( this.reusableColor, 0 ); if ( maskActive ) renderer.context.disable( renderer.context.STENCIL_TEST ); -- GitLab