From 688c07ae5cd51f73717c5bcd77bf6ce035c68c4a Mon Sep 17 00:00:00 2001 From: Renaud Rohlinger Date: Tue, 24 Sep 2024 10:57:27 +0900 Subject: [PATCH 1/2] WebGPURenderer: Reuse LightNode when available --- src/nodes/lighting/LightsNode.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/nodes/lighting/LightsNode.js b/src/nodes/lighting/LightsNode.js index 3f98dfc653eea8..2dc4341e5ac88e 100644 --- a/src/nodes/lighting/LightsNode.js +++ b/src/nodes/lighting/LightsNode.js @@ -23,6 +23,8 @@ const getLightNodeById = ( id, lightNodes ) => { }; +const _lightsNodeRef = /*@__PURE__*/ new WeakMap(); + class LightsNode extends Node { static get type() { @@ -45,8 +47,6 @@ class LightsNode extends Node { this._lightNodes = null; this._lightNodesHash = null; - this.global = true; - } getHash( builder ) { @@ -119,7 +119,20 @@ class LightsNode extends Node { } - lightNodes.push( nodeObject( new lightNodeClass( light ) ) ); + let lightNode = null; + + if ( ! _lightsNodeRef.has( light ) ) { + + lightNode = new lightNodeClass( light ); + _lightsNodeRef.set( light, lightNode ); + + } else { + + lightNode = _lightsNodeRef.get( light ); + + } + + lightNodes.push( lightNode ); } From 4236a81aa1739dce14a27267031c50d1c3d3e474 Mon Sep 17 00:00:00 2001 From: Renaud Rohlinger Date: Tue, 24 Sep 2024 10:58:35 +0900 Subject: [PATCH 2/2] cleanup --- src/nodes/lighting/LightsNode.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/nodes/lighting/LightsNode.js b/src/nodes/lighting/LightsNode.js index 2dc4341e5ac88e..5e62be4c4f6862 100644 --- a/src/nodes/lighting/LightsNode.js +++ b/src/nodes/lighting/LightsNode.js @@ -47,6 +47,8 @@ class LightsNode extends Node { this._lightNodes = null; this._lightNodesHash = null; + this.global = true; + } getHash( builder ) {