Skip to content

Commit

Permalink
Merge pull request #408 from KhronosGroup/fix/recursive_light_instant…
Browse files Browse the repository at this point in the history
…iation

Gather all lights recursively in `getVisibleLights()`
  • Loading branch information
UX3D-kanzler authored Jul 18, 2022
2 parents 563ab27 + c61c3ac commit 00d88be
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions source/Renderer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class gltfRenderer
this.viewMatrix = currentCamera.getViewMatrix(state.gltf);
this.currentCameraPosition = currentCamera.getPosition(state.gltf);

this.visibleLights = this.getVisibleLights(state.gltf, scene);
this.visibleLights = this.getVisibleLights(state.gltf, scene.nodes);
if (this.visibleLights.length === 0 && !state.renderingParameters.useIBL &&
state.renderingParameters.useDirectionalLightsWithDisabledIBL)
{
Expand Down Expand Up @@ -586,18 +586,25 @@ class gltfRenderer
}

/// Compute a list of lights instantiated by one or more nodes as a list of node-light tuples.
getVisibleLights(gltf, scene)
getVisibleLights(gltf, nodes)
{
const nodeLights = [];
for (const nodeIndex of scene.nodes) {
let nodeLights = [];

for (const nodeIndex of nodes) {
const node = gltf.nodes[nodeIndex];

if (node.children !== undefined) {
nodeLights = nodeLights.concat(this.getVisibleLights(gltf, node.children))
}

const lightIndex = node.extensions?.KHR_lights_punctual?.light;
if (lightIndex === undefined) {
continue;
}
const light = gltf.lights[lightIndex];
nodeLights.push([node, light]);
}

return nodeLights;
}

Expand Down

0 comments on commit 00d88be

Please sign in to comment.