Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Trace light linking in the path tracer (part of #215)

Nguyen Xuan An3596e90138a1
diff --git a/bench/reference/README.md b/bench/reference/README.md
index f58a6d03..cc8e3060 100644
--- a/bench/reference/README.md
+++ b/bench/reference/README.md
@@ -32,7 +32,7 @@ All of them are against the Blender 5.2.2 renders taken on 2026-11-03 with the s
| `fog-valley` | 0.1855 | 0.1952 | 0.1443 | | |
| `foliage` | 0.1023 | 0.0888 | 0.0853 | | 0.1753 |
| `glass` | 0.1034 | 0.1009 | 0.0996 | | 0.1406 |
-| `light-linking` | 0.0998 | 0.1558 | 0.1122 | | 0.6241 |
+| `light-linking` | 0.0998 | 0.1558 | 0.1122 | | 0.0213 |
| `lit-interior` | 0.5055 | 0.5159 | 0.0923 | 0.1399 | 0.2167 |
| `long-street` | 0.1407 | 0.0976 | 0.1252 | | 0.1818 |
| `material-spheres` | 0.1293 | 0.1053 | 0.0756 | | 0.1383 |
@@ -536,7 +536,7 @@ The tracer is worse than the rasterizer on `outdoor-hdri` and `character`: in th
Path tracer, second pass (issue #129, 2026-11-01): 64 samples at most, `noiseThreshold` 0.03, four threads, 960 by 540; seconds are wall time and include scene setup. The scores are in "Scores now".
-`light-linking` scores 0.6241 because the tracer does not trace light linking (every light lights every part).
+`light-linking` scores 0.0213 against Cycles, ahead of the rasterizer (0.0998): the tracer honours light linking, so a light adds nothing at a part it skips.
Before and after on four scenes, 64 samples: every sample drawn without the box-projection and shadow-ray changes (the state of `main`), then the defaults of this change. `brick-graph` 0.1370 then 0.1373, `brick-room` 0.2794 then 0.2743 (seconds 121.2 then 126.7, the box-projected walls now read their projected UVs), `character` 0.1116 then 0.1120, `outdoor-hdri` 0.1014 then 0.1016. `brick-graph` is a UV-mapped wall, so it already drew its bump and nothing in this change touches it: against the 0.1538 of the table above (32 samples) it improved, against the same tracer at 64 samples it did not move (0.0003 worse, inside the noise). `brick-room` is the scene with box-projected materials; its normal and roughness maps used to be ignored.
diff --git a/bench/reference/harness.js b/bench/reference/harness.js
index a1ac6eea..aa0523bc 100644
--- a/bench/reference/harness.js
+++ b/bench/reference/harness.js
@@ -227,7 +227,7 @@ window.measureReferenceFrameTime = measureReferenceFrameTime;
async function renderReferencePathTraced(id, options) {
const scene = await REFERENCE_SCENES[id]();
const { renderPathTracedImage } = await import('/src/path-tracer.js');
- const result = await renderPathTracedImage({ parts: scene.parts, environment: scene.environment, camera: scene.camera }, options);
+ const result = await renderPathTracedImage({ parts: applyLightLinks(scene.parts, scene.environment), environment: scene.environment, camera: scene.camera }, options);
const canvas = document.createElement('canvas');
canvas.width = result.width;
canvas.height = result.height;
diff --git a/bench/reference/path-tracer.json b/bench/reference/path-tracer.json
index ef064782..36bec2d6 100644
--- a/bench/reference/path-tracer.json
+++ b/bench/reference/path-tracer.json
@@ -3,42 +3,42 @@
"scores": {
"brick-flat": {
"pathtracer-vs-cycles": 0.0246,
- "seconds": 28.2,
+ "seconds": 24.1,
"samples": 64,
"averageSamples": 64,
"ignored": []
},
"brick-graph": {
"pathtracer-vs-cycles": 0.0805,
- "seconds": 24.3,
+ "seconds": 23.9,
"samples": 64,
"averageSamples": 64,
"ignored": []
},
"brick-room": {
"pathtracer-vs-cycles": 0.2587,
- "seconds": 98.1,
+ "seconds": 98.5,
"samples": 64,
"averageSamples": 64,
"ignored": []
},
"brushed-film": {
"pathtracer-vs-cycles": 0.0599,
- "seconds": 36.1,
+ "seconds": 35.9,
"samples": 64,
"averageSamples": 64,
"ignored": []
},
"car-paint": {
"pathtracer-vs-cycles": 0.0324,
- "seconds": 35.8,
+ "seconds": 36.4,
"samples": 64,
"averageSamples": 64,
"ignored": []
},
"character": {
"pathtracer-vs-cycles": 0.0287,
- "seconds": 28.1,
+ "seconds": 29,
"samples": 64,
"averageSamples": 64,
"ignored": [
@@ -47,7 +47,7 @@
},
"fog": {
"pathtracer-vs-cycles": 0.5333,
- "seconds": 24,
+ "seconds": 24.1,
"samples": 64,
"averageSamples": 64,
"ignored": [
@@ -56,7 +56,7 @@
},
"foliage": {
"pathtracer-vs-cycles": 0.1001,
- "seconds": 61.5,
+ "seconds": 63.4,
"samples": 64,
"averageSamples": 64,
"ignored": [
@@ -65,35 +65,35 @@
},
"glass": {
"pathtracer-vs-cycles": 0.0385,
- "seconds": 30.7,
+ "seconds": 31.9,
"samples": 64,
"averageSamples": 64,
"ignored": []
},
"light-linking": {
- "pathtracer-vs-cycles": 0.6518,
- "seconds": 35.2,
+ "pathtracer-vs-cycles": 0.0213,
+ "seconds": 29.2,
"samples": 64,
"averageSamples": 64,
"ignored": []
},
"lit-interior": {
"pathtracer-vs-cycles": 0.0769,
- "seconds": 78.5,
+ "seconds": 78.3,
"samples": 64,
"averageSamples": 64,
"ignored": []
},
"long-street": {
"pathtracer-vs-cycles": 0.0291,
- "seconds": 40.9,
+ "seconds": 43.9,
"samples": 64,
"averageSamples": 64,
"ignored": []
},
"material-spheres": {
"pathtracer-vs-cycles": 0.0449,
- "seconds": 45.1,
+ "seconds": 45.6,
"samples": 64,
"averageSamples": 64,
"ignored": []
@@ -107,14 +107,14 @@
},
"outdoor-hdri": {
"pathtracer-vs-cycles": 0.0226,
- "seconds": 19.5,
+ "seconds": 19.6,
"samples": 64,
"averageSamples": 64,
"ignored": []
},
"spot-area": {
"pathtracer-vs-cycles": 0.0261,
- "seconds": 26.4,
+ "seconds": 26.9,
"samples": 64,
"averageSamples": 64,
"ignored": []
diff --git a/changes/issue-215-path-tracer-linking.md b/changes/issue-215-path-tracer-linking.md
new file mode 100644
index 00000000..7749d260
--- /dev/null
+++ b/changes/issue-215-path-tracer-linking.md
@@ -0,0 +1 @@
+- The path tracer now honours light linking (part of issue #215). A light with `affects`, and the sun with `environment.keyAffects`, adds nothing at a part it skips, as direct light and at every bounce, and still casts shadows for the others; it reads the same per-part `material.lightMask` as the renderer and the light bake. `report.ignored` no longer lists linking. The `light-linking` scene against Cycles goes from 0.6518 to 0.0213 (the rasterizer scores 0.0998); scenes without links draw the same pixels as before, and the reference harness now passes its path-traced scenes through `applyLightLinks`.
diff --git a/docs/parity.md b/docs/parity.md
index c747233e..e45b4afd 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -191,7 +191,7 @@ To move to a new Blender release, run `node scripts/parity-manual-snapshot.mjs`.
| Rendering > Render Engines > Workbench | out of scope | A viewport engine for working by hand. | | |
| Rendering > Cameras | partial | Perspective, orthographic views, focal length, animated paths, depth of field from depth and camera motion blur, both repeatable per frame. Object motion blur and bokeh shapes are missing. | [camera-path](../tests/camera-path.test.js), [camera](../tests/camera.test.js), [render-passes](../tests/render-passes.test.js) | #54 |
| Rendering > Lights > Light Objects | partial | One directional light with a shadow, 8 point lights, 8 spot lights and 4 rectangular area lights. Point and spot lights can cast shadows from one 24-tile atlas (a point light takes 6 tiles, a spot light 1). Area lights use a representative point and cast no shadow. The directional shadow is a single map, or up to four cascades through `addons/cascaded-shadows` (`shadowCascades` on the renderer and `environment.shadowCascades` in recipes, three by themselves when `shadow.extent` is above 40): scene `long-street` scores 0.1555 against Cycles with one map and 0.1398 with three cascades, for about 0.2 ms more a frame on an RTX 3060 when the camera moves. | [lighting](../tests/lighting.test.js), [cascades](../tests/cascaded-shadows.test.js), `npm run reference` scenes `spot-area` and `long-street` | #52 |
-| Rendering > Lights > Light Linking | partial | `addons/light-linking`: a light's `affects` list (and `environment.keyAffects` for the sun) limits it to the named parts through `applyLightLinks`, as a Blender receiver collection does; the shader skips a light whose bit in the part's mask is clear. Linking changes what a light adds, not what it shadows. The path tracer and the light bake ignore it, recipes do not reach it (`lightLinking: false` in `scene_capabilities`) and there is no blocker list. Scene `light-linking` scores 0.0998 against Cycles. | [light-linking](../tests/light-linking.test.js), `npm run reference` scene `light-linking` | #52 |
+| Rendering > Lights > Light Linking | partial | `addons/light-linking`: a light's `affects` list (and `environment.keyAffects` for the sun) limits it to the named parts through `applyLightLinks`, as a Blender receiver collection does; the shader skips a light whose bit in the part's mask is clear. Linking changes what a light adds, not what it shadows. The path tracer and the light bake honour it, recipes do not reach it (`lightLinking: false` in `scene_capabilities`) and there is no blocker list. Scene `light-linking` scores 0.0998 against Cycles. | [light-linking](../tests/light-linking.test.js), `npm run reference` scene `light-linking` | #52 |
| Rendering > Lights > World Environment | partial | Recipes pick a named setup (`daylight`, `overcast`, `sunset`, `studio`) that carries a procedural environment map, with opt-in screen-space ambient occlusion. Code can load any HDRI; recipes reach only the named maps, with no URLs or files. No reflections between objects yet. The MCP preview adds an automatic floor with a contact shadow (`environment.ground: false` removes it). Cold-run reference-free score for sitting on a surface, summed over six tasks and 0 to 3 each: 0 before, 6 with the floor and 7 after a lone flat object (a gear) stopped being read as a floor; the front and side cameras see it edge-on, so only the three-quarter view shows it. A blind pairwise Sonnet judge (`default-judge.mjs`, six cold recipes, two cameras, 18 calls) prefers the floor to none 18 of 18 (p 0.0000076) and the darker floor now used (0.22) to the first one (0.6) 18 of 18; its control, one image against itself, picks the first 17 of 18. | [environment](../tests/environment.test.js), [default look](../tests/default-look.test.js) | #53 |
| Rendering > Materials > Components | partial | Surfaces with PBR factors and five maps, a clear coat, transmission with thickness, attenuation and IOR, sheen, and specular weight and tint. Anisotropic highlights and a thin-film iridescence layer, as in the glTF extensions, are compiled in only when a part uses them. There is no subsurface scattering, volume material or displacement. | [texture-set](../tests/texture-set.test.js), [material-layers](../tests/material-layers.test.js) | #50, #51 |
| Rendering > Materials > Assignment | done | A node names one material. | [agent-scene](../tests/agent-scene.test.js) | |
diff --git a/docs/path-tracer.md b/docs/path-tracer.md
index c5c1dddc..951c3456 100644
--- a/docs/path-tracer.md
+++ b/docs/path-tracer.md
@@ -18,7 +18,7 @@ From an agent, submit an `image` render job with `settings.renderer` (see [rende
Unidirectional path tracing against the triangle BVH that the [light bake](light-bake.md) uses, with next-event estimation and the environment map drawn by importance, then a wavelet denoiser. The first hit of every path samples every light. Later hits draw one light at random and divide by its chance, so the average is the same and a scene with eleven lights costs one shadow ray per bounce instead of eleven.
- Surfaces: diffuse, GGX specular with metals, clear coat, glass (`transmission`, `ior`, rough glass), emission, image maps (`map`, with `alphaMode: "mask"` cutouts, `normalMap` with `normalScale`, and `metallicRoughnessMap`, whose green channel scales roughness and blue scales metallic as in the rasterizer; box-projected materials read all of them through the UVs of their projection, the same ones the glTF export writes) and vertex colour. Skinned parts are drawn at their current pose.
-- Lights: the sun (`keyColor`, `lightDirection`, as a 1 degree disk), point lights with a radius, spot lights with a soft cone, rectangular area lights, and the environment map with its rotation. All of them cast soft shadows, whatever their `castShadow` says, as in Cycles.
+- Lights: the sun (`keyColor`, `lightDirection`, as a 1 degree disk), point lights with a radius, spot lights with a soft cone, rectangular area lights, and the environment map with its rotation. All of them cast soft shadows, whatever their `castShadow` says, as in Cycles. Light linking is honoured: a light with `affects` (or the sun with `environment.keyAffects`) adds nothing at a part it skips, as a direct light or as a bounce source, and still shadows the other lights.
- Light that bounces between surfaces, and the sky seen in mirrors and through glass.
## What it does not draw
diff --git a/src/light-link-bits.js b/src/light-link-bits.js
new file mode 100644
index 00000000..cc6025bd
--- /dev/null
+++ b/src/light-link-bits.js
@@ -0,0 +1,6 @@
+// Which bit of a part's `material.lightMask` belongs to which light, in the order of the environment lists. Kept apart
+// from the shader code in light-linking.js so the path tracer can read the masks without pulling in the shaders.
+export const SUN_BIT = 0;
+export const POINT_FIRST_BIT = 1;
+export const SPOT_FIRST_BIT = 9;
+export const AREA_FIRST_BIT = 17;
diff --git a/src/light-linking.js b/src/light-linking.js
index e48423f8..58ae8def 100644
--- a/src/light-linking.js
+++ b/src/light-linking.js
@@ -1,18 +1,16 @@
import { registerShaderFeatureCode } from './shaders.js';
import { ALL_LIGHTS_MASK } from './material-layers.js';
+import { SUN_BIT, POINT_FIRST_BIT, SPOT_FIRST_BIT, AREA_FIRST_BIT } from './light-link-bits.js';
// Light linking: a light can be limited to the parts it lights, as Blender's receiver collection does. A part carries
// a bit mask in `material.lightMask`; the shader skips a light whose bit is clear. The code lives here, not in the
// renderer, so a scene without linking never downloads it and its shader has no mask test.
// Bit 0 is the sun (the key light), bits 1 to 8 the point lights, 9 to 16 the spot lights and 17 to 20 the area lights,
// in the order of the environment lists. Linking changes what a light adds, not what it shadows: a part that a light
-// does not reach still blocks that light for the others. The path tracer ignores linking and says so in its report; the light bake honours it.
+// does not reach still blocks that light for the others. The path tracer and the light bake honour it too.
// The GLSL has no comments, because comments ship to every page.
-export const SUN_BIT = 0;
-export const POINT_FIRST_BIT = 1;
-export const SPOT_FIRST_BIT = 9;
-export const AREA_FIRST_BIT = 17;
+export { SUN_BIT, POINT_FIRST_BIT, SPOT_FIRST_BIT, AREA_FIRST_BIT };
registerShaderFeatureCode('lightLinking', {
declarations: `uniform int lightLinkMask;
diff --git a/src/path-tracer-scene.js b/src/path-tracer-scene.js
index 2313f96b..7d6b615f 100644
--- a/src/path-tracer-scene.js
+++ b/src/path-tracer-scene.js
@@ -1,5 +1,6 @@
import { buildTriangleBvh } from './triangle-bvh.js';
import { createTracer } from './ray-query.js';
+import { SUN_BIT, POINT_FIRST_BIT, SPOT_FIRST_BIT, AREA_FIRST_BIT } from './light-link-bits.js';
import { boxProjectedGeometry, columnLengths } from './export-box-uv.js';
// The scene a path trace reads: every part flattened into one world-space triangle soup with per-vertex normals, UVs
@@ -78,6 +79,9 @@ function resolveTexture(descriptor) {
};
}
+// A part without a mask is lit by every light.
+const ALL_LIGHTS = -1;
+
function resolveMaterial(material) {
const emissionColor = material.emissiveColor ?? material.color;
const emissionStrength = material.emission ?? 0;
@@ -94,6 +98,7 @@ function resolveMaterial(material) {
normalTexture: resolveTexture(material.normalMap),
normalScale: material.normalScale ?? [1, 1],
surfaceTexture: resolveTexture(material.metallicRoughnessMap),
+ lightMask: material.lightMask ?? ALL_LIGHTS,
alphaCutoff: material.alphaMode === 'mask' ? material.alphaCutoff ?? 0.5 : 0,
};
}
@@ -195,20 +200,20 @@ function resolveLights(environment) {
const lightCount = (environment.pointLights?.length ?? 0) + (environment.spotLights?.length ?? 0) + (environment.areaLights?.length ?? 0);
if (lightCount > MAX_TRACE_LIGHTS) throw new RangeError(`A path trace takes at most ${MAX_TRACE_LIGHTS} point, spot and area lights.`);
return {
- sun: sunPower > 0 ? { direction: normalized(environment.lightDirection ?? [0, 1, 0]), color: environment.keyColor } : null,
- points: (environment.pointLights ?? []).map(light => ({ position: light.position, color: light.color, intensity: light.intensity, radius: light.radius ?? 0, range: light.range ?? 0 })),
- spots: (environment.spotLights ?? []).map(light => ({
- position: light.position, color: light.color, intensity: light.intensity, radius: light.radius ?? 0, range: light.range ?? 0,
+ sun: sunPower > 0 ? { bit: SUN_BIT, direction: normalized(environment.lightDirection ?? [0, 1, 0]), color: environment.keyColor } : null,
+ points: (environment.pointLights ?? []).map((light, index) => ({ bit: POINT_FIRST_BIT + index, position: light.position, color: light.color, intensity: light.intensity, radius: light.radius ?? 0, range: light.range ?? 0 })),
+ spots: (environment.spotLights ?? []).map((light, index) => ({
+ bit: SPOT_FIRST_BIT + index, position: light.position, color: light.color, intensity: light.intensity, radius: light.radius ?? 0, range: light.range ?? 0,
direction: normalized(light.direction),
cosineHalfAngle: Math.cos(light.angle),
blend: (1 - Math.cos(light.angle)) * (light.penumbra ?? 0),
})),
- areas: (environment.areaLights ?? []).map(light => {
+ areas: (environment.areaLights ?? []).map((light, index) => {
const normal = normalized(light.direction);
const guide = normalized(light.up ?? [0, 1, 0]);
const across = normalized([guide[1] * normal[2] - guide[2] * normal[1], guide[2] * normal[0] - guide[0] * normal[2], guide[0] * normal[1] - guide[1] * normal[0]]);
const along = [normal[1] * across[2] - normal[2] * across[1], normal[2] * across[0] - normal[0] * across[2], normal[0] * across[1] - normal[1] * across[0]];
- return { position: light.position, color: light.color, intensity: light.intensity, width: light.width, height: light.height, normal, across, along };
+ return { bit: AREA_FIRST_BIT + index, position: light.position, color: light.color, intensity: light.intensity, width: light.width, height: light.height, normal, across, along };
}),
};
}
diff --git a/src/path-tracer.js b/src/path-tracer.js
index 5bc5dd1a..a262ddc4 100644
--- a/src/path-tracer.js
+++ b/src/path-tracer.js
@@ -427,7 +427,11 @@ function createPathTracer(scene, options) {
let selectionProbability = 1;
const fullWeight = () => 1 / selectionProbability;
+ // A light skips a part whose mask has its bit clear, at every bounce, so it is no bounce source there either.
+ const reaches = light => (hit.material.lightMask >> light.bit & 1) === 1;
+
function sampleSun(depth, normal) {
+ if (!reaches(lights.sun)) return;
const cosineTheta = 1 - random.next() * (1 - sunCosineMax);
const sineTheta = Math.sqrt(Math.max(0, 1 - cosineTheta * cosineTheta));
const phi = 2 * Math.PI * random.next();
@@ -462,6 +466,7 @@ function createPathTracer(scene, options) {
const jitter = new Float64Array(3);
function samplePointLight(depth, normal, light) {
+ if (!reaches(light)) return;
randomOnSphere(light.radius, jitter);
const { distance, distanceSquared } = aimAt(light.position[0] + jitter[0], light.position[1] + jitter[1], light.position[2] + jitter[2]);
if (distance < 1e-6) return;
@@ -471,6 +476,7 @@ function createPathTracer(scene, options) {
}
function sampleSpotLight(depth, normal, light) {
+ if (!reaches(light)) return;
randomOnSphere(light.radius, jitter);
const { distance, distanceSquared } = aimAt(light.position[0] + jitter[0], light.position[1] + jitter[1], light.position[2] + jitter[2]);
if (distance < 1e-6) return;
@@ -484,6 +490,7 @@ function createPathTracer(scene, options) {
}
function sampleAreaLight(depth, normal, light) {
+ if (!reaches(light)) return;
const across = (random.next() - 0.5) * light.width;
const along = (random.next() - 0.5) * light.height;
const pointX = light.position[0] + light.across[0] * across + light.along[0] * along;
@@ -675,7 +682,6 @@ export function describeIgnoredFeatures(parts, environment) {
for (const field of IGNORED_MAP_FIELDS) if (material[field]) notes.add(`${field} is ignored.`);
if (material.tag && material.tag !== 'surface') notes.add(`${material.tag} materials are traced as plain surfaces.`);
if (material.alphaMode === 'blend') notes.add('Blended transparency is traced as opaque.');
- if (material.lightMask !== undefined) notes.add('Light linking (affects) is not traced: every light lights every part.');
}
return [...notes];
}
diff --git a/tests/path-tracer-light-linking.test.js b/tests/path-tracer-light-linking.test.js
new file mode 100644
index 00000000..538dafab
--- /dev/null
+++ b/tests/path-tracer-light-linking.test.js
@@ -0,0 +1,99 @@
+import assert from 'node:assert/strict';
+import { createHash } from 'node:crypto';
+import test from 'node:test';
+
+import { box, sphere } from '../src/geometry.js';
+import { createEnvironmentMap } from '../src/environment.js';
+import { SUN_BIT, POINT_FIRST_BIT } from '../src/light-link-bits.js';
+import { describeIgnoredFeatures, renderPathTracedImage } from '../src/path-tracer.js';
+
+function placed(translation, scale) {
+ return new Float32Array([scale[0], 0, 0, 0, 0, scale[1], 0, 0, 0, 0, scale[2], 0, translation[0], translation[1], translation[2], 1]);
+}
+
+function surface(color, extra = {}) {
+ return { tag: 'surface', metallic: 0, roughness: 0.5, emission: 0, color, ...extra };
+}
+
+const EVERY_BIT = 0x1fffff;
+const without = (...bits) => bits.reduce((mask, bit) => mask & ~(1 << bit), EVERY_BIT);
+
+// A scene with no linking at all. Its pixels were hashed on the code before the path tracer read light masks, so a
+// change that shifts an unlinked scene shows up here.
+function unlinkedScene(extraMaterial = {}) {
+ return {
+ parts: [
+ { name: 'floor', geometry: box(0, 1), matrix: placed([0, -0.05, 0], [40, 0.1, 40]), material: surface([0.5, 0.5, 0.5], { roughness: 1, ...extraMaterial }) },
+ { name: 'ball', geometry: sphere(24, 16), matrix: placed([0, 0.6, 0], [0.6, 0.6, 0.6]), material: surface([0.8, 0.3, 0.2], { metallic: 0.5, clearcoat: 0.5, ...extraMaterial }) },
+ ],
+ environment: {
+ keyColor: [3, 3, 3],
+ lightDirection: [0, 1, 0],
+ pointLights: [{ position: [0, 2, 1], color: [1, 1, 1], intensity: 4, radius: 0.1 }],
+ map: createEnvironmentMap({ width: 8, height: 4, data: new Float32Array(8 * 4 * 3).fill(0.4) }),
+ },
+ camera: { eye: [0, 2, 5], target: [0, 0.5, 0], up: [0, 1, 0], fov: 40 },
+ };
+}
+
+const SMALL = { width: 32, height: 24, samples: 4, bounces: 3, threads: 1 };
+
+test('a scene without links keeps the pixels it had before linking was traced', async () => {
+ const image = await renderPathTracedImage(unlinkedScene(), SMALL);
+ assert.equal(createHash('sha256').update(image.rgba).digest('hex'), '796f20c1155f33e4b9e235b02a95a965a99251b360c1062b18384e0c8b5693fc');
+});
+
+test('a mask that lets every light through gives the pixels of no mask', async () => {
+ const plain = await renderPathTracedImage(unlinkedScene(), SMALL);
+ const masked = await renderPathTracedImage(unlinkedScene({ lightMask: EVERY_BIT }), SMALL);
+ assert.deepEqual(masked.rgba, plain.rgba);
+});
+
+// Two floors far apart, so light bounced from one never reaches the other. The camera looks straight down at one.
+function twoFloors(rightMask, environment) {
+ const floor = (name, x, extra) => ({ name, geometry: box(0, 1), matrix: placed([x, -0.05, 0], [10, 0.1, 10]), material: surface([0.5, 0.5, 0.5], { roughness: 1, ...extra }) });
+ return { parts: [floor('left', -100, {}), floor('right', 100, { lightMask: rightMask })], environment };
+}
+
+async function centreOf(parts, environment, x) {
+ const camera = { eye: [x, 3, 0], target: [x, 0, 0], up: [0, 0, -1], fov: 40 };
+ const { linear } = await renderPathTracedImage({ parts, environment, camera }, { width: 16, height: 16, samples: 16, bounces: 2, denoise: false, threads: 1 });
+ const centre = (8 * 16 + 8) * 3;
+ return linear[centre] + linear[centre + 1] + linear[centre + 2];
+}
+
+test('the sun adds nothing at a part whose mask skips it', async () => {
+ const environment = { keyColor: [3, 3, 3], lightDirection: [0, 1, 0] };
+ const { parts } = twoFloors(without(SUN_BIT), environment);
+ assert.ok(await centreOf(parts, environment, -100) > 0.1);
+ assert.equal(await centreOf(parts, environment, 100), 0);
+});
+
+test('a point light adds nothing at a part whose mask skips it, and the other light still does', async () => {
+ const environment = {
+ pointLights: [
+ { position: [100, 2, 0], color: [1, 1, 1], intensity: 6, radius: 0 },
+ { position: [100, 3, 0], color: [1, 1, 1], intensity: 6, radius: 0 },
+ ],
+ };
+ const both = await centreOf(twoFloors(EVERY_BIT, environment).parts, environment, 100);
+ const onlySecond = await centreOf(twoFloors(without(POINT_FIRST_BIT), environment).parts, environment, 100);
+ const neither = await centreOf(twoFloors(without(POINT_FIRST_BIT, POINT_FIRST_BIT + 1), environment).parts, environment, 100);
+ assert.ok(both > onlySecond, `both ${both}, one skipped ${onlySecond}`);
+ assert.ok(onlySecond > 0.05);
+ assert.equal(neither, 0);
+});
+
+test('a spot light and an area light honour their bits too', async () => {
+ const environment = {
+ spotLights: [{ position: [100, 3, 0], direction: [0, -1, 0], angle: 1, color: [1, 1, 1], intensity: 8 }],
+ areaLights: [{ position: [100, 3, 0], direction: [0, -1, 0], width: 1, height: 1, color: [1, 1, 1], intensity: 8 }],
+ };
+ assert.ok(await centreOf(twoFloors(EVERY_BIT, environment).parts, environment, 100) > 0.05);
+ assert.equal(await centreOf(twoFloors(without(9, 17), environment).parts, environment, 100), 0);
+});
+
+test('the path tracer no longer names light linking as ignored', () => {
+ const parts = twoFloors(without(SUN_BIT), {}).parts;
+ assert.ok(!describeIgnoredFeatures(parts, {}).some(note => /linking/i.test(note)));
+});
diff --git a/tests/recipe-cascades-linking.test.js b/tests/recipe-cascades-linking.test.js
index d1fa27a1..5de92688 100644
--- a/tests/recipe-cascades-linking.test.js
+++ b/tests/recipe-cascades-linking.test.js
@@ -106,11 +106,9 @@ test('scene_capabilities says recipes reach linking and cascades', () => {
assert.deepEqual([...AGENT_SCENE_CAPABILITIES.shadowCascades.counts], [0, 1, 2, 3, 4]);
});
-test('the path tracer names linking as not traced', async () => {
+test('the path tracer traces linking, so its report does not list it', async () => {
const scene = await sceneFrom(sceneRecipe({ keyAffects: ['left'] }));
- assert.ok(describeIgnoredFeatures(scene.parts, {}).some(note => /Light linking/.test(note)));
- const plain = await sceneFrom(sceneRecipe());
- assert.ok(!describeIgnoredFeatures(plain.parts, {}).some(note => /Light linking/.test(note)));
+ assert.ok(!describeIgnoredFeatures(scene.parts, {}).some(note => /Light linking/.test(note)));
});
function bakeRoom() {