Просмотр исходного кода

LightsNode: Introduce `getBuiltinLights` (#33909)

sunag 1 неделя назад
Родитель
Сommit
6ee0a4228d

+ 3 - 12
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;

+ 2 - 2
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;
 

+ 20 - 4
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<Light>} The scene's lights.
+	 */
+	getBuiltinLights() {
+
+		return this._lights;
+
+	}
+
 	/**
 	 * Whether the scene has lights or not.
 	 *

粤ICP备19079148号