3D engine that AI agents drive
Measure the foliage leak with the sun separated from the sky (part of #206)
Nguyen Xuan Anbeb81f281678
diff --git a/bench/reference/README.md b/bench/reference/README.mdindex 8da64a25..04a16b4c 100644--- a/bench/reference/README.md+++ b/bench/reference/README.md@@ -712,6 +712,18 @@ The true mask gives a larger leak than the full-light approximation did (11,137- A shadow bias grown on back-facing leaves is not the cause either. `shadowVisibility` floors the cosine at 0.05, which gives a back-lit leaf the largest bias; using `abs(dot)` changed the leak from 13,071 to 13,069, so it was not kept.- Solid quads in the shadow pass (no cutout) leave 5,418 leaking pixels (2,804 away from a lit edge) but 67js then lights 14,991 crown pixels against 19,883 in Cycles, and 10,310 are lit only in Cycles. The truth is between the two: the cutout shadow lets too much sun through, solid cards block too much, and neither a bias nor a threshold sits between them (see the table of the section above). The cause is still open; the lead is how much of a card Cycles blocks for a shadow ray, which needs a Cycles render with the leaf alpha changed to test.+## The foliage leak is mostly not shadow (2026-11-03, part of issue #206)++No engine change came out of this. The "leak" of the section above compared two lights that are not the same thing, so it was re-measured with the sun of 67js separated from everything else. `render-gpu.mjs` has a new `--key <scale>` switch (the sun's intensity); `crown-leak.py` takes the `--ambient 0 --key 0` render as a third argument, subtracts it from the `--ambient 0` render, and applies one threshold (0.02) to both sides. All numbers are on the same 56,921 crown pixels, the GPU render at 960 x 540, with the stored sun-only Cycles array.++- With the sun off and the ambient at 0, 67js still lights 5,068 crown pixels (3,100 of the 13,071 "leaking" ones): sky reflected in the leaf, which Cycles does not have in its sun-only render. Cycles shadowed was also tested below 0.02 and 67js lit above 0.01, which counts a 67js pixel at 0.015 as a leak next to a Cycles pixel at 0.0005.+- Measured fairly, the leak is 7,661 pixels: 5,213 within 2 px of a pixel Cycles lights (silhouette and leaf placement, as before) and 2,448 farther away. The part that is shadow 67js does not cast is already under the 3,000 of the Done-when. The whole count is not, and its silhouette share is not a shadow matter.+- The mean sun on the crown agrees: 0.0304 linear in 67js, 0.0316 in Cycles. What differs is where it goes. In pixels Cycles shadows, 67js carries 463 units of sun energy (Cycles 89); in pixels Cycles lights, 1,265 (Cycles 1,710). The 25 percent of the sun that sits in the wrong place is partly dimmer lit leaves and partly the 2-px edges, not a missing shadow layer.+- Leaf alpha is not the cause, and Cycles does not treat it as a fraction. The Blender leaf is `GREATER_THAN` the cutoff into a Mix with a Transparent BSDF (`render-blender.py`), so Cycles also cuts at 0.5, on the full-size texture. The 67js leaf texture is close to binary: the cutoff of the shadow pass swept from 0.02 to 0.8 moves the leak between 9,053 and 11,429 (old measure, 10,524 at 0.5), and reading the texture at level 0 changed it by 53 pixels. Solid cards in the shadow pass leave 2,474 leaking but only 0.013 of mean sun on the crown, 42 percent of Cycles, so they are over-dark, and the card is larger than the leaf. Hashed or stochastic alpha was not built: it needs partial alpha to average, and there is none.+- A tighter shadow extent (4.5 instead of 9, so a texel of 0.0044 m) took the leak from 10,524 to 9,592 on the old measure. That is small for a scene change and was not kept.++The second Done-when of #206 (fewer than 3,000 sun-lit crown pixels that Cycles shadows) holds for pixels away from a lit leaf (2,448) and not for the whole crown (7,661). The rest of the gap is placement of leaves and their edges, and the lower brightness of lit leaves. #191 should stay open for that.+## Fog valley against EEVEE (2026-11-03, part of issue #165)`fog-valley` scored 0.1967 against EEVEE's 0.1952. Measured by band of rows on the GPU render (FLIP against Cycles): 67js is better than EEVEE in the sky (0.1311 against 0.1608, and 0.0512 against 0.0815 within 40 pixels of the sun, so the glow is not the problem), and worse below the horizon (0.2437 against 0.2317 at rows 230 to 300, 0.2664 against 0.2576 at rows 300 to 400) and in the left third of the frame (0.2866 against 0.2556), where the shadowed face of the near tower and the ground shadow are darker than in Cycles. The fog's in-scatter inside the sun's shadow is the term that lifts them, and it keeps 15 percent of the ambient there, a constant fitted to closed rooms, where the air in shadow sees walls and not sky.diff --git a/bench/reference/crown-leak.py b/bench/reference/crown-leak.pyindex 7ca33c55..fdcd8a42 100644--- a/bench/reference/crown-leak.py+++ b/bench/reference/crown-leak.py@@ -1,6 +1,8 @@# Counts the crown pixels of `foliage` that 67js lights with the sun and Cycles leaves in shadow.-# uv run --no-project --with numpy --with pillow python bench/reference/crown-leak.py <work directory> <67js --ambient 0 png>-# Needs <work directory>/foliage-cycles.npy (full light, to find the crown) and foliage-cycles-world0.npy (sun only, the true+# uv run --no-project --with numpy --with pillow python bench/reference/crown-leak.py <work directory> <67js --ambient 0 png> [<67js --ambient 0 --key 0 png>]+# With the third picture (the same render with the sun off) its light is subtracted from the sun render, so the 67js sun is+# compared with the sun of Cycles alone: the sky's reflection in a leaf is not sun, and Cycles has no sky in its sun-only render.+# Both sides then use one threshold (CYCLES_SHADOWED_BELOW); without it the old, uneven pair of thresholds applies. Needs <work directory>/foliage-cycles.npy (full light, to find the crown) and foliage-cycles-world0.npy (sun only, the true# shadow mask; render it with render-blender.py ... --world-strength 0 foliage). Prints the counts and writes leak.png beside the PNG:# red = leak, grey = lit on both sides, blue = lit only in Cycles, dark grey = the rest of the crown.import sys@@ -44,6 +46,12 @@ def main():cycles_full = tone_map_like_67js(np.load(work_directory / "foliage-cycles.npy"))cycles_sun = tone_map_like_67js(np.load(work_directory / "foliage-cycles-world0.npy"))gpu_sun = np.asarray(Image.open(gpu_path).convert("RGB"), dtype=np.float32) / 255+ gpu_lit_above = GPU_LIT_ABOVE+ gpu_sun_luminance = tone_mapped_luminance(gpu_sun)+ if len(sys.argv) > 3:+ sun_off = np.asarray(Image.open(sys.argv[3]).convert("RGB"), dtype=np.float32) / 255+ gpu_sun_luminance = gpu_sun_luminance - tone_mapped_luminance(sun_off)+ gpu_lit_above = CYCLES_SHADOWED_BELOWred, green, blue = cycles_full[..., 0], cycles_full[..., 1], cycles_full[..., 2]upper_rows = np.zeros(green.shape, bool)@@ -52,7 +60,7 @@ def main():cycles_shadowed = crown & (tone_mapped_luminance(cycles_sun) < CYCLES_SHADOWED_BELOW)cycles_lit = crown & ~cycles_shadowed- gpu_lit = crown & (tone_mapped_luminance(gpu_sun) > GPU_LIT_ABOVE)+ gpu_lit = crown & (gpu_sun_luminance > gpu_lit_above)leak = gpu_lit & cycles_shadowedbeside_lit_leaf = near_any(cycles_lit, SILHOUETTE_REACH)diff --git a/bench/reference/harness.js b/bench/reference/harness.jsindex 73cc44e0..720aa2c7 100644--- a/bench/reference/harness.js+++ b/bench/reference/harness.js@@ -164,11 +164,12 @@ async function probeScene(scene, id, drawnParts, mode) {return { parts: placed.parts, report: placed.report, seconds: (performance.now() - started) / 1000 };}-async function renderReferenceScene(id, { describe, ambientOcclusion = 0, ambientOcclusionRadius = 0.5, bake = null, cascades = 0, backgroundOnly = false, probes = false, ambient = null, fill = null }) {+async function renderReferenceScene(id, { describe, ambientOcclusion = 0, ambientOcclusionRadius = 0.5, bake = null, cascades = 0, backgroundOnly = false, probes = false, ambient = null, fill = null, key = null }) {const scene = await SCENES[id]();// A measurement switch: 0 removes the world's light from every surface, to show how much of a picture comes from it.if (ambient !== null) scene.environment = { ...scene.environment, ambientIntensity: ambient };if (fill !== null) scene.environment = { ...scene.environment, fillIntensity: fill };+ if (key !== null) scene.environment = { ...scene.environment, keyIntensity: key };const baked = bake ? await bakeScene(scene, bake) : null;const probed = probes ? await probeScene(scene, id, baked ? baked.parts : scene.parts, probes) : null;const canvas = document.querySelector('canvas');diff --git a/bench/reference/render-gpu.mjs b/bench/reference/render-gpu.mjsindex 250766a4..da09f6cf 100644--- a/bench/reference/render-gpu.mjs+++ b/bench/reference/render-gpu.mjs@@ -1,5 +1,5 @@// Draws chosen reference scenes with 67js on the GPU only, into a directory of your choice, with measurement switches. No Blender, no scoring.-// node bench/reference/render-gpu.mjs <output directory> <scene id>,<scene id> [--ambient <scale>] [--fill <scale>]+// node bench/reference/render-gpu.mjs <output directory> <scene id>,<scene id> [--ambient <scale>] [--fill <scale>] [--key <scale>]// [--ambient-occlusion <strength>] [--ambient-occlusion-radius <units>]// Files are <output directory>/<scene id>-gpu.png, the names measure-depth.py and score.py read. Used to find what makes shadows light (issue #197).import { mkdir, writeFile } from 'node:fs/promises';@@ -25,6 +25,7 @@ function numberAfter(flag) {const options = {ambient: numberAfter('--ambient'),fill: numberAfter('--fill'),+ key: numberAfter('--key'),ambientOcclusion: numberAfter('--ambient-occlusion') ?? 0,ambientOcclusionRadius: numberAfter('--ambient-occlusion-radius') ?? 0.5,};