Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gather all lights recursively in getVisibleLights() #408

Merged
merged 1 commit into from
Jul 18, 2022
Merged
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: 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