Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Merge origin/main into feat/material-evidence

Nguyen Xuan An1cefc4ee753c
diff --cc CHANGELOG.md
index bdd71e60,8d487c16..933f04b5
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -2,7 -2,8 +2,9 @@@
## Unreleased
+- Score material scenes and Khronos sample assets against their baseline (parts of issues #50 and #51). `brick-flat` is the control for `brick-graph`: the same wall in the graph's average colour with no maps. `npm run reference -- --khronos` draws Khronos sample assets downloaded into gitignored `artifacts/khronos/` and scores them against Cycles reading the same GLB, on the pixels the asset covers (`khronos.json`, `images/khronos-*.jpg`; `baseline.json` is unchanged). The brick bump is not weaker than Blender's: its bright edge is stronger and bump 0 would score better (0.2065 against 0.2269), so no engine change. The assets found two importer faults, fixed in `src/gltf.js`: `KHR_xmp` and `KHR_xmp_json_ld` metadata refused the whole file, and `KHR_materials_variants` is now accepted with a warning. Still open: texture slots in layer extensions (the anisotropy textures matter, both anisotropy assets score worse with the factor than with none) and occlusion on TEXCOORD_1 (`SheenChair`).
+ - Measure what an equal feature set costs against three.js (part of issue #74; no engine change, no speed-up). `bench/runtime` gets the engines `67js-ldr`, `67js-one-sample`, `67js-ldr-one-sample` and `three-one-sample` (run with `--engine`) and a `--cpu-only` flag. Measured: with no MSAA and no HDR target 67js is still 5.2 to 5.7 times three.js on SwiftShader in `large-mesh`, `many-materials` and `instanced-objects` (7.8, 5.3 and 7.8 with the defaults), so the gap is the lit shader and not those two features. On the RTX 3060 `large-mesh` costs 3.6 ms against 0.6 ms and is not explained by HDR, MSAA, the vertex shader or the vertex attributes; on ANGLE Vulkan the ratio is 2.3 instead of 5.8. Skipping zero-intensity fill lights was tried and reverted (inside the noise). The profile is in `bench/runtime/PROFILE.md`.
+ - Add cascaded sun shadows and light linking (part of issue #52; recipes do not reach either, and `lit-interior` was already improved by the light bake, not by this work). `addons/cascaded-shadows`: `new Renderer67(canvas, parts, { shadowCascades: createCascadedShadows({ count: 3 }) })` fits up to four depth maps to slices of the camera's view, with sphere fitting and texel snapping so edges do not crawl; on the new `long-street` reference scene the score against Cycles goes from 0.1555 to 0.1398 for about 0.2 ms more a frame on an RTX 3060 (+25 percent on SwiftShader) when the camera moves. `addons/light-linking`: `applyLightLinks(parts, environment)` limits a light to the parts named in its `affects` list (`environment.keyAffects` for the sun) through a per-part mask in `material.lightMask`; the new `light-linking` reference scene scores 0.0998 against Cycles with the same lists as Blender receiver collections. Both keep their GLSL out of the core bundle (`registerShaderFeatureCode`, new slots `sunVisibility`, `linkSun`, `linkPoint`, `linkSpot` and `linkArea`), and `npm run reference -- --cascades <n>` and `frame-time.mjs <scene> <backend> --cascades` measure them. No earlier reference scene moved.
- Fix the recipe light bake budget, which rejected the demo room at samples 96, bounces 2, texelsPerUnit 3 (11.5 s before the budget) and scaled `standard` there to 16 samples (part of issue #55). The ray work estimate multiplied by every light and so overcounted open scenes by about 4 times. The budget now counts path steps (texels x samples x bounces), which cost about the same per path in a closed 56 part room and in the demo room. A preset scales down to 5 million path steps (the demo room at `standard` keeps about 52 samples, not 16); explicit settings are limited only by a hard bound of 24 million path steps and by the real 20 s limit, which fails the edit with the scene unchanged and names a lower samples and texelsPerUnit to try. A bake on a worker has 90 s instead of 20 s (the page's own thread keeps 20 s), and the preview's 30 s call deadline grows by 90 s for a `scene_create` with a `bake` and a `scene_apply` with `set-bake`. `bake.used` and `bake.reduced` are unchanged; the capability limit `maxRayWork` is now `maxPathWork`.
- Make room in the npm package without adding a dependency (part of issue #36). The archive fell from 802,581 to 695,041 bytes (353,535 free under 1 MiB; the target was 300,000), and every library and MCP install stays as light as before. Two causes: (1) every one of the 80 built files began with the full `LICENSE` and `THIRD-PARTY-NOTICES.md` text, about 4 KB each; they now carry a one-line notice and the complete texts stay once at the package root, about 61,000 bytes saved; (2) the MCP SDK's Node shim pulls in Ajv (the validator for elicitation answers, about 270 KB before minification) that this server never uses, so `build/mcp/server.mjs` now bundles `scripts/mcp-sdk-shims.mjs` instead, which fails with a clear message if elicitation is ever requested: `server.mjs` fell from 677,484 to 484,111 bytes and the archive by about 47,000 bytes. `build/mcp/LICENSES.md` no longer lists the Ajv family because that code is gone, and its unused copies left `licenses/mcp/`. Measured, and not worth doing: `zod/mini` (zod's classic layer is 30 KB of the server before gzip), source maps (none are shipped), standalone core copies (none in the archive), and docs (every packaged page is linked from the README, `llms.txt`, the MCP guide or the skills). `npm run smoke:package` now loads every `exports` entry in a clean consumer. Film and site code were already outside the archive. Separate lazy-loaded packages were not built: the lazy addons together are about 157 KB gzip, so splitting them out could return at most that much, for the cost of a package, a release pipeline and a version matrix each. `archiveBytes` budget 815,000 to 705,500. Module load of the server is no slower (minimum of 25 runs, 217 and 188 ms against 231 and 209 ms).
diff --cc bench/reference/baseline.json
index 0a8257ee,eeb3ff86..cd1abc10
--- a/bench/reference/baseline.json
+++ b/bench/reference/baseline.json
@@@ -2,61 -2,65 +2,69 @@@
"metric": "FLIP (LDR), mean error, lower is better",
"blenderVersion": "5.2.2 LTS",
"seconds": {
+ "brick-flat": {
+ "cycles": 24.4,
+ "eevee": 6.4
+ },
"brick-graph": {
- "cycles": 34.6,
- "eevee": 2.8
+ "cycles": 16.4,
+ "eevee": 8.5
},
"brick-room": {
- "cycles": 230.4,
- "eevee": 1.1
+ "cycles": 29.1,
+ "eevee": 2.2
},
"brushed-film": {
- "cycles": 18.7,
- "eevee": 0.9
+ "cycles": 15.9,
+ "eevee": 2.0
},
"car-paint": {
- "cycles": 27.5,
- "eevee": 0.7
+ "cycles": 13.8,
+ "eevee": 3.4
},
"character": {
- "cycles": 14.9,
- "eevee": 0.7
+ "cycles": 17.6,
+ "eevee": 3.8
},
"fog": {
- "cycles": 475.8,
- "eevee": 2.4
+ "cycles": 40.9,
+ "eevee": 3.9
},
"foliage": {
- "cycles": 159.4,
- "eevee": 1.0
+ "cycles": 28.1,
+ "eevee": 9.9
},
"glass": {
- "cycles": 15.8,
- "eevee": 0.8
+ "cycles": 22.2,
+ "eevee": 16.7
+ },
+ "light-linking": {
+ "cycles": 12.1,
+ "eevee": 4.0
},
"lit-interior": {
- "cycles": 82.6,
- "eevee": 1.4
+ "cycles": 21.8,
+ "eevee": 4.7
+ },
+ "long-street": {
+ "cycles": 12.8,
+ "eevee": 4.8
},
"material-spheres": {
- "cycles": 35.2,
- "eevee": 0.9
+ "cycles": 18.4,
+ "eevee": 4.4
},
"metal": {
- "cycles": 27.8,
- "eevee": 1.6
+ "cycles": 32.5,
+ "eevee": 4.6
},
"outdoor-hdri": {
- "cycles": 52.4,
- "eevee": 0.8
+ "cycles": 9.4,
+ "eevee": 5.0
},
"spot-area": {
- "cycles": 17.4,
- "eevee": 0.8
+ "cycles": 12.0,
+ "eevee": 2.2
}
},
"graphics": {
diff --cc bench/reference/harness.js
index c03d4a1a,6c881484..df4e7743
--- a/bench/reference/harness.js
+++ b/bench/reference/harness.js
@@@ -4,10 -4,9 +4,12 @@@ import { REFERENCE_SCENES, KHRONOS_SCEN
import { skinnedGeometry } from '/src/path-tracer-scene.js';
import { boxProjectedGeometry } from '/src/export-box-uv.js';
import '/src/material-layer-shaders.js';
+ import { createCascadedShadows } from '/src/cascaded-shadows.js';
+ import { applyLightLinks } from '/src/light-linking.js';
+// ?set=khronos draws the Khronos sample assets (npm run reference -- --khronos) instead of the fixed scenes.
+const SCENES = new URLSearchParams(location.search).get('set') === 'khronos' ? KHRONOS_SCENES : REFERENCE_SCENES;
+
function encodeBytes(typedArray) {
const bytes = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength);
let text = '';
@@@ -75,15 -72,19 +77,20 @@@ async function bakeScene(scene, bakeOpt
return { parts: baked.parts, report: baked.report, seconds: (performance.now() - started) / 1000 };
}
- async function renderReferenceScene(id, { describe, ambientOcclusion = 0, ambientOcclusionRadius = 0.5, bake = null, backgroundOnly = false }) {
+ // The 67js renderer for a scene: light linking from the lights' affects lists, and cascaded sun shadows when asked for.
+ function createSceneRenderer(parts, scene, cascades) {
+ return new Renderer67(document.querySelector('canvas'), applyLightLinks(parts, scene.environment), {
+ ground: false, hdr: true, depth: true, samples: 4, pixelRatio: 1, memoryBudgetMiB: 1024, world: true,
+ environment: scene.environment, shadowBounds: scene.shadow, shadowCascades: cascades ? createCascadedShadows({ count: cascades }) : null,
+ });
+ }
+
-async function renderReferenceScene(id, { describe, ambientOcclusion = 0, ambientOcclusionRadius = 0.5, bake = null, cascades = 0 }) {
- const scene = await REFERENCE_SCENES[id]();
++async function renderReferenceScene(id, { describe, ambientOcclusion = 0, ambientOcclusionRadius = 0.5, bake = null, cascades = 0, backgroundOnly = false }) {
+ const scene = await SCENES[id]();
const baked = bake ? await bakeScene(scene, bake) : null;
const canvas = document.querySelector('canvas');
- const renderer = createSceneRenderer(baked ? baked.parts : scene.parts, scene, cascades);
+ // backgroundOnly draws the sky alone, so a score can be limited to the pixels the asset covers.
- const renderer = new Renderer67(canvas, backgroundOnly ? [] : baked ? baked.parts : scene.parts, {
- ground: false, hdr: true, depth: true, samples: 4, pixelRatio: 1, memoryBudgetMiB: 1024, world: true,
- environment: scene.environment, shadowBounds: scene.shadow,
- });
++ const renderer = createSceneRenderer(backgroundOnly ? [] : baked ? baked.parts : scene.parts, scene, cascades);
renderer.resize();
const frame = { ...scene.camera, environment: scene.environment, time: 0, exposure: 1, effects: { ambientOcclusion, ambientOcclusionRadius } };
renderer.render(frame);
diff --cc bench/reference/run.mjs
index adb297d5,3b8bf55b..c07053ab
--- a/bench/reference/run.mjs
+++ b/bench/reference/run.mjs
@@@ -51,7 -50,8 +53,8 @@@ async function renderBackend(backend, s
const page = await browser.newPage({ viewport: { width: WIDTH, height: HEIGHT } });
const errors = [];
page.on('pageerror', error => errors.push(error.message));
+ page.on('console', message => message.text().includes('GL_') && console.log('PAGE', message.text().slice(0, 200)));
- await page.goto(`${serverUrl}/bench/reference/harness.html`, { timeout: PAGE_LOAD_TIMEOUT });
+ await page.goto(`${serverUrl}/bench/reference/harness.html${khronos ? '?set=khronos' : ''}`, { timeout: PAGE_LOAD_TIMEOUT });
await page.waitForFunction(() => window.renderReferenceScene, null, { timeout: PAGE_LOAD_TIMEOUT });
const sceneIds = await page.evaluate(() => window.referenceSceneIds);
for (const id of sceneIds) {
diff --cc tests/reference-baseline.test.js
index 00f241ce,ca81f496..42ce3094
--- a/tests/reference-baseline.test.js
+++ b/tests/reference-baseline.test.js
@@@ -4,7 -4,7 +4,7 @@@ import test from 'node:test'
const REFERENCE_DIRECTORY = new URL('../bench/reference/', import.meta.url);
const baseline = JSON.parse(readFileSync(new URL('baseline.json', REFERENCE_DIRECTORY), 'utf8'));
- const EXPECTED_SCENES = ['brick-flat', 'brick-graph', 'brick-room', 'brushed-film', 'car-paint', 'character', 'fog', 'foliage', 'glass', 'lit-interior', 'material-spheres', 'metal', 'outdoor-hdri', 'spot-area'];
-const EXPECTED_SCENES = ['brick-graph', 'brick-room', 'brushed-film', 'car-paint', 'character', 'fog', 'foliage', 'glass', 'light-linking', 'lit-interior', 'long-street', 'material-spheres', 'metal', 'outdoor-hdri', 'spot-area'];
++const EXPECTED_SCENES = ['brick-flat', 'brick-graph', 'brick-room', 'brushed-film', 'car-paint', 'character', 'fog', 'foliage', 'glass', 'light-linking', 'lit-interior', 'long-street', 'material-spheres', 'metal', 'outdoor-hdri', 'spot-area'];
const EXPECTED_SCORES = ['cpu-vs-cycles', 'cpu-vs-eevee', 'eevee-vs-cycles', 'gpu-vs-cpu', 'gpu-vs-cycles', 'gpu-vs-eevee'];
test('the render baseline scores every scene with every renderer pair', () => {