From 6ee0a4228d78ecb4200d6494ceabd3413541d68a Mon Sep 17 00:00:00 2001 From: sunag Date: Tue, 30 Jun 2026 12:36:03 -0300 Subject: [PATCH] LightsNode: Introduce `getBuiltinLights` (#33909) --- .../jsm/tsl/lighting/ClusteredLightsNode.js | 15 +++--------- .../nodes/manager/NodeMaterialObserver.js | 4 ++-- src/nodes/lighting/LightsNode.js | 24 +++++++++++++++---- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/examples/jsm/tsl/lighting/ClusteredLightsNode.js b/examples/jsm/tsl/lighting/ClusteredLightsNode.js index 65c281c1bd93b7..d30c9163aa74cc 100644 --- a/examples/jsm/tsl/lighting/ClusteredLightsNode.js +++ b/examples/jsm/tsl/lighting/ClusteredLightsNode.js @@ -44,7 +44,6 @@ class ClusteredLightsNode extends LightsNode { this.materialLights = []; this.clusteredLights = []; - this._allLights = []; this.maxLights = maxLights; this.tileSize = tileSize; @@ -206,8 +205,6 @@ class ClusteredLightsNode extends LightsNode { setLights( lights ) { - this._allLights = lights; - const { clusteredLights, materialLights } = this; let materialIndex = 0; @@ -230,13 +227,13 @@ class ClusteredLightsNode extends LightsNode { materialLights.length = materialIndex; clusteredLights.length = clusteredIndex; - return super.setLights( materialLights ); + return super.setLights( lights ); } - getLights() { + getBuiltinLights() { - return this._allLights; + return this.materialLights; } @@ -598,12 +595,6 @@ class ClusteredLightsNode extends LightsNode { } - get hasLights() { - - return super.hasLights || this.clusteredLights.length > 0; - - } - } export default ClusteredLightsNode; diff --git a/src/materials/nodes/manager/NodeMaterialObserver.js b/src/materials/nodes/manager/NodeMaterialObserver.js index 1f4c2546c937c7..a48680fe0c5610 100644 --- a/src/materials/nodes/manager/NodeMaterialObserver.js +++ b/src/materials/nodes/manager/NodeMaterialObserver.js @@ -222,7 +222,7 @@ class NodeMaterialObserver { data.environmentIntensity = environmentIntensity; data.environmentRotation = environmentRotation.clone(); - data.lights = this.getLightsData( renderObject.lightsNode.getLights(), [] ); + data.lights = this.getLightsData( renderObject.lightsNode.getBuiltinLights(), [] ); this.renderObjects.set( renderObject, data ); @@ -701,7 +701,7 @@ class NodeMaterialObserver { } cached.renderId = renderId; - this.getLightsData( lightsNode.getLights(), cached.lightsData ); + this.getLightsData( lightsNode.getBuiltinLights(), cached.lightsData ); return cached.lightsData; diff --git a/src/nodes/lighting/LightsNode.js b/src/nodes/lighting/LightsNode.js index f20784d45c38df..9a1dabe607894f 100644 --- a/src/nodes/lighting/LightsNode.js +++ b/src/nodes/lighting/LightsNode.js @@ -146,11 +146,11 @@ class LightsNode extends Node { */ customCacheKey() { - const lights = this._lights; + const builtinLights = this.getBuiltinLights(); - for ( let i = 0; i < lights.length; i ++ ) { + for ( let i = 0; i < builtinLights.length; i ++ ) { - const light = lights[ i ]; + const light = builtinLights[ i ]; _hashData.push( light.id ); _hashData.push( light.castShadow ? 1 : 0 ); @@ -241,7 +241,9 @@ class LightsNode extends Node { const previousLightNodes = nodeData.lightNodes || null; const materialLightings = builder.context.materialLightings; - const lights = sortLights( [ ...materialLightings, ...this._lights ] ); + const builtinLights = this.getBuiltinLights(); + + const lights = sortLights( [ ...materialLightings, ...builtinLights ] ); const nodeLibrary = builder.renderer.library; for ( const light of lights ) { @@ -458,6 +460,20 @@ class LightsNode extends Node { } + /** + * Returns an array of the scene's lights. + * + * The light variations are shader-dependent; + * if this array changes, the shader needs to be recreated. + * + * @return {Array} The scene's lights. + */ + getBuiltinLights() { + + return this._lights; + + } + /** * Whether the scene has lights or not. *