Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions examples/jsm/tsl/lighting/ClusteredLightsNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class ClusteredLightsNode extends LightsNode {

this.materialLights = [];
this.clusteredLights = [];
this._allLights = [];

this.maxLights = maxLights;
this.tileSize = tileSize;
Expand Down Expand Up @@ -206,8 +205,6 @@ class ClusteredLightsNode extends LightsNode {

setLights( lights ) {

this._allLights = lights;

const { clusteredLights, materialLights } = this;

let materialIndex = 0;
Expand All @@ -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;

}

Expand Down Expand Up @@ -598,12 +595,6 @@ class ClusteredLightsNode extends LightsNode {

}

get hasLights() {

return super.hasLights || this.clusteredLights.length > 0;

}

}

export default ClusteredLightsNode;
Expand Down
4 changes: 2 additions & 2 deletions src/materials/nodes/manager/NodeMaterialObserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -701,7 +701,7 @@ class NodeMaterialObserver {
}

cached.renderId = renderId;
this.getLightsData( lightsNode.getLights(), cached.lightsData );
this.getLightsData( lightsNode.getBuiltinLights(), cached.lightsData );

return cached.lightsData;

Expand Down
24 changes: 20 additions & 4 deletions src/nodes/lighting/LightsNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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.
*
Expand Down