Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Score AgX against Blender 5.2.2: ramp error table and three reference scenes (#282)

Nguyen Xuan An0fb6c2a04851
diff --git a/bench/reference/README.md b/bench/reference/README.md
index 65bc616e..6fb5bf19 100644
--- a/bench/reference/README.md
+++ b/bench/reference/README.md
@@ -58,6 +58,29 @@ The mean of the 23 baseline scenes is 0.1746 for 67js and 0.1986 for EEVEE. The
Dated notes below, kept where they explain a decision. Numbers in them are from the date they name, and those before 2026-11-01 use the sky with two suns.
+## AgX and Khronos PBR Neutral against Blender 5.2.2 (2026-11-03, part of issue #282)
+
+`environment.viewTransform: 'agx' | 'neutral'` (#319) against Blender's AgX and Khronos PBR Neutral view transforms.
+
+Colour ramp (`scripts/blender-view-transform-golden.py`, rerun on 5.2.2: the output matches the committed `tests/fixtures/blender/view-transform-golden.json` byte for byte). 27 patches: 15 greys from 0 to 16 and 12 colours up to 5.0. Each is an emissive plane; the error is |67js - Blender| per channel in sRGB-encoded display units (0 to 1; 0.01 is 2.6 of 255 steps). `tests/view-transform.test.js` fails above the threshold.
+
+| Transform | Threshold (max) | Max error | Mean error | Max per channel R, G, B | Within |
+| --- | --- | --- | --- | --- | --- |
+| `neutral` | 0.010 | 0.0079 | 0.0013 | 0.0079, 0.0052, 0.0079 | yes |
+| `agx` | 0.090 | 0.0885 | 0.0252 | 0.0714, 0.0756, 0.0885 | yes, but loose |
+
+`agx` is within its threshold only because the threshold was set at the measured error. 67js uses the Filament/three.js polynomial for the AgX contrast, and Blender 5.2.2 is darker in the mid-tones: grey 0.18 maps to 0.461 in Blender and 0.501 in 67js (0.09 gives 0.320 against 0.374, 0.03 gives 0.165 against 0.198); the worst patch is the saturated red 0.8, 0.1, 0.05. `neutral` follows Blender to within 2 steps of 255 (the Khronos formula is the same). Closing the `agx` gap needs Blender's own contrast curve; no change was made to `src/` here.
+
+Scenes: `npm run reference -- --view-transform agx --scene <id>,<id>` draws 67js with `viewTransform: 'agx'`, renders Cycles with the AgX view transform (same samples, denoising and scene description as the suite; 8-bit sRGB PNG, so both sides are quantised), and scores them with FLIP. Blender's sRGB picture is decoded and encoded with the 2.2 power 67js uses, so the score measures the curve and the lighting, not the transfer function. The standard column is the suite's own score (Cycles with the `Raw` transform, then the ACES fit on both sides, `baseline.json`).
+
+| Scene | 67js `agx` against Cycles AgX | Standard (ACES fit both sides) | Change |
+| --- | --- | --- | --- |
+| `outdoor-hdri` | 0.0997 | 0.0462 | +0.0535 |
+| `material-spheres` | 0.1467 | 0.1293 | +0.0174 |
+| `character` | 0.1238 | 0.0799 | +0.0439 |
+
+AgX scores worse than the standard row on all three. The mid-tone gap measured on the ramp (67js `agx` is brighter than Blender's) is the likely cause (inferred, not isolated by an experiment). The scores are in `view-transform.json`; Cycles ran on OptiX as in the suite, 67js on the RTX 3060.
+
## One sun (2026-11-01)
The HDRI holds its own sun: 6 of its 524,288 pixels carry 48.1 percent of the sky light, at 48 degrees of elevation. Most scenes also add a sun light. Cycles and EEVEE therefore drew two shadows of each object, and 67js drew one because its environment casts no shadow. `scenes.js` and `render-blender.py` now cap the image at radiance 16 on both sides, which removes the sun and its halo and keeps the clouds. The sky keeps 49.2 percent of its light. A scene with a sky now has only its own sun light.
diff --git a/bench/reference/harness.js b/bench/reference/harness.js
index 9366e12e..8ec3bdeb 100644
--- a/bench/reference/harness.js
+++ b/bench/reference/harness.js
@@ -5,6 +5,7 @@ import { GRAND_SCENES } from './grand-scenes.js';
import { skinnedGeometry } from '/src/path-tracer-scene.js';
import { boxProjectedGeometry } from '/src/export-box-uv.js';
import '/src/material-layer-shaders.js';
+import '/src/view-transform-shader.js';
import { skyOpenness } from '/src/closed-room.js';
import { fogSkyVisibility } from '/src/fog-sky-visibility.js';
import { createCascadedShadows } from '/src/cascaded-shadows.js';
@@ -173,8 +174,10 @@ 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, key = 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, viewTransform = null }) {
const scene = await SCENES[id]();
+ // A view transform (agx, neutral) replaces the ACES fit in the shaders, as environment.viewTransform does in a recipe.
+ if (viewTransform) scene.environment = { ...scene.environment, viewTransform };
// 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 };
diff --git a/bench/reference/render-blender.py b/bench/reference/render-blender.py
index 57db7cde..4e66733a 100644
--- a/bench/reference/render-blender.py
+++ b/bench/reference/render-blender.py
@@ -4,6 +4,7 @@
# (0 leaves the sun and the point lights), into <id>-cycles-world<scale>.npy. The EEVEE render and the timings are left alone.
# ... -- <work directory> --sun-strength <scale> [scene ids] the same for the sun: Cycles only, the sun times <scale> (0 leaves the world and
# the point lights), into <id>-cycles-sun<scale>.npy. Both switches together write <id>-cycles-world<a>-sun<b>.npy.
+# ... -- <work directory> --view-transform <AgX|Khronos PBR Neutral|...> [scene ids] Cycles only, with that Blender view transform, into <id>-cycles-<name>.png (16-bit sRGB).
# ... -- <work directory> --max-bounces <n> [--floor-color <v>] [scene ids] Cycles only, with at most n light bounces (0 is direct light only)
# and/or the part named "floor" painted a grey of v (0 is black), into <id>-cycles-bounces<n>-floor<v>.npy. They show how much light the ground bounces.
# Light units were measured on a white plane: sun strength equals irradiance, a point or spot light has 4 pi watts for each
@@ -863,6 +864,19 @@ def render_to_numpy(scene, work_directory, name):
return seconds
+def render_with_view_transform(scene, work_directory, name, view_transform):
+ """Cycles with a Blender view transform (for example AgX) applied, saved as an 8-bit sRGB PNG, like the 67js picture: the picture a Blender user gets."""
+ scene.view_settings.view_transform = view_transform
+ scene.display_settings.display_device = "sRGB"
+ scene.render.image_settings.file_format = "PNG"
+ scene.render.image_settings.color_depth = "8"
+ scene.render.image_settings.color_mode = "RGB"
+ scene.render.filepath = os.path.join(work_directory, f"{name}.png")
+ started = time.perf_counter()
+ bpy.ops.render.render(write_still=True)
+ return time.perf_counter() - started
+
+
def import_glb(root, glb_file):
"""A Khronos sample asset goes through Blender's own glTF importer, so Cycles shades the file as its authors meant."""
bpy.ops.import_scene.gltf(filepath=os.path.join(root, glb_file))
@@ -942,6 +956,11 @@ def main():
flag_index = arguments.index("--floor-color")
floor_grey = float(arguments[flag_index + 1])
del arguments[flag_index:flag_index + 2]
+ view_transform = None
+ if "--view-transform" in arguments:
+ flag_index = arguments.index("--view-transform")
+ view_transform = arguments[flag_index + 1]
+ del arguments[flag_index:flag_index + 2]
only = set(arguments[1:])
root = os.getcwd()
timings = {}
@@ -953,6 +972,11 @@ def main():
with open(os.path.join(scene_directory, file_name), encoding="utf-8") as file:
description = json.load(file)
scene = build_scene(description, root)
+ if view_transform is not None:
+ configure_cycles(scene)
+ seconds = render_with_view_transform(scene, work_directory, f"{scene_id}-cycles-{view_transform.lower().replace(' ', '-')}", view_transform)
+ print(f"RENDERED {scene_id} as cycles with {view_transform}: {seconds:.1f} s")
+ continue
if world_scale is not None or sun_scale is not None or bounces is not None or floor_grey is not None:
suffix = ""
if bounces is not None:
diff --git a/bench/reference/run.mjs b/bench/reference/run.mjs
index 3871a0f2..5273ae3f 100644
--- a/bench/reference/run.mjs
+++ b/bench/reference/run.mjs
@@ -25,7 +25,14 @@ const cloth = process.argv.includes('--cloth');
// --grand draws the options for the grand scenes (grand-scenes.js, issue #168) and scores them into grand.json.
const grand = process.argv.includes('--grand');
const sceneSet = khronos ? 'khronos' : cloth ? 'cloth' : grand ? 'grand' : null;
-const WORK_DIRECTORY = resolve(sceneSet ? `artifacts/reference-${sceneSet}` : 'artifacts/reference');
+// --view-transform <agx|neutral> draws the scenes with that environment.viewTransform and renders Cycles with the matching Blender view
+// transform (AgX, Khronos PBR Neutral), then scores the pair with view-transform-score.py into view-transform.json (issue #282).
+// Use it with --scene <id>,<id>; the work directory is separate and baseline.json stays as it is.
+const viewTransformFlag = process.argv.indexOf('--view-transform');
+const viewTransform = viewTransformFlag >= 0 ? process.argv[viewTransformFlag + 1] : null;
+const BLENDER_VIEW_TRANSFORMS = { agx: 'AgX', neutral: 'Khronos PBR Neutral' };
+if (viewTransform && !BLENDER_VIEW_TRANSFORMS[viewTransform]) throw new Error(`--view-transform must be one of ${Object.keys(BLENDER_VIEW_TRANSFORMS).join(', ')}.`);
+const WORK_DIRECTORY = resolve(viewTransform ? `artifacts/reference-view-${viewTransform}` : sceneSet ? `artifacts/reference-${sceneSet}` : 'artifacts/reference');
const OUTPUT_DIRECTORY = resolve('bench/reference');
const CHROME = process.env.CHROME_PATH ?? 'C:/Program Files/Google/Chrome/Application/chrome.exe';
const BLENDER = process.env.BLENDER_PATH ?? 'C:/Program Files/Blender Foundation/Blender 5.2/blender.exe';
@@ -91,7 +98,7 @@ const bakeScoreRun = bakedSceneIds !== null && !sceneSet && !pathTracerFlag;
const bakeVariantFlags = ['--sky-only', '--bake-preset', '--probes', '--ambient', '--ambient-occlusion', '--cascades', '--no-object-probes', '--object-probes', '--no-water', '--ssr-water', '--no-ground-bounce'];
const bakeScoreIsBaseline = bakeScoreRun && argumentsGiven.includes('--update-baseline') && !bakeVariantFlags.some(flag => argumentsGiven.includes(flag));
const onlyScenes = sceneIdsGiven ?? (bakeScoreRun ? bakedSceneIds : null);
-const skipCpu = skipCpuFlag || bakeScoreRun;
+const skipCpu = skipCpuFlag || bakeScoreRun || Boolean(viewTransform);
async function renderBackend(backend, serverUrl, graphics) {
const browser = await chromium.launch({ executablePath: CHROME, headless: true, args: BACKEND_ARGUMENTS[backend] });
@@ -119,7 +126,7 @@ async function renderBackend(backend, serverUrl, graphics) {
const objectProbesThisScene = !argumentsGiven.includes('--no-object-probes') && (objectProbeSceneIds === null || objectProbeSceneIds.includes(id));
const probes = probesThisScene || (objectProbesThisScene ? 'objects' : false);
const bake = bakesThisScene ? { ...skyOnlyOptions, ...(bakePreset ? { preset: bakePreset } : {}) } : null;
- const result = await page.evaluate(([sceneId, shouldDescribe, ambientOcclusion, ambientOcclusionRadius, bakeOptions, cascadeCount, withProbes, ambientScale]) => window.renderReferenceScene(sceneId, { describe: shouldDescribe, ambientOcclusion, ambientOcclusionRadius, bake: bakeOptions, cascades: cascadeCount, probes: withProbes, ambient: ambientScale }), [id, describe, ambientOcclusion, ambientOcclusionRadius, bake, cascades, probes, ambient]);
+ const result = await page.evaluate(([sceneId, shouldDescribe, ambientOcclusion, ambientOcclusionRadius, bakeOptions, cascadeCount, withProbes, ambientScale, selectedViewTransform]) => window.renderReferenceScene(sceneId, { describe: shouldDescribe, ambientOcclusion, ambientOcclusionRadius, bake: bakeOptions, cascades: cascadeCount, probes: withProbes, ambient: ambientScale, viewTransform: selectedViewTransform }), [id, describe, ambientOcclusion, ambientOcclusionRadius, bake, cascades, probes, ambient, viewTransform]);
if (result.glError !== 0) throw new Error(`${id} on ${backend} gave WebGL error ${result.glError}.`);
graphics[backend] = result.graphics;
await writeFile(`${WORK_DIRECTORY}/${id}-${backend}.png`, Buffer.from(result.image, 'base64'));
@@ -195,10 +202,18 @@ if (!scoreOnly && !pathTracerFlag) {
await writeFile(`${WORK_DIRECTORY}/graphics.json`, JSON.stringify(graphics, null, 1));
if (!skipBlender) {
const sceneArguments = onlyScenes ?? [];
- runChecked(BLENDER, ['-b', '--factory-startup', '--python', 'bench/reference/render-blender.py', '--', WORK_DIRECTORY, ...sceneArguments]);
+ const viewTransformArguments = viewTransform ? ['--view-transform', BLENDER_VIEW_TRANSFORMS[viewTransform]] : [];
+ runChecked(BLENDER, ['-b', '--factory-startup', '-t', '6', '--python', 'bench/reference/render-blender.py', '--', WORK_DIRECTORY, ...viewTransformArguments, ...sceneArguments]);
}
}
+if (viewTransform) {
+ runChecked('uv', [
+ 'run', '--no-project', '--python', '3.12', '--with', 'flip-evaluator', '--with', 'pillow', '--with', 'numpy',
+ 'python', '-I', 'bench/reference/view-transform-score.py', WORK_DIRECTORY, OUTPUT_DIRECTORY, viewTransform, ...(onlyScenes ?? []),
+ ]);
+}
+
if ((!onlyScenes && !skipCpu) || pathTracerFlag || bakeScoreRun) {
runChecked('uv', [
'run', '--no-project', '--python', '3.12', '--with', 'flip-evaluator', '--with', 'pillow', '--with', 'numpy',
diff --git a/bench/reference/view-transform-score.py b/bench/reference/view-transform-score.py
new file mode 100644
index 00000000..bcf25977
--- /dev/null
+++ b/bench/reference/view-transform-score.py
@@ -0,0 +1,47 @@
+# Scores 67js drawn with environment.viewTransform against Cycles rendered with the matching Blender view transform (issue #282).
+# uv run --no-project --python 3.12 --with flip-evaluator --with pillow --with numpy python -I bench/reference/view-transform-score.py <work directory> <output directory> <agx|neutral> [scene ids]
+# Blender writes its picture in the sRGB transfer curve, and 67js encodes with a power of 1 / 2.2 (src/post.js). The Blender picture is decoded
+# to display-linear and encoded with the 2.2 power, so both sides meet in one display space as score.py does for the plain suite; the
+# difference left is the tone curve and the lighting. Writes view-transform.json in the output directory.
+import json
+import sys
+from pathlib import Path
+
+import flip_evaluator
+import numpy as np
+from PIL import Image
+
+GAMMA = 2.2
+
+
+def load_png(path):
+ return np.asarray(Image.open(path).convert("RGB"), dtype=np.float32) / 255
+
+
+def srgb_to_display(encoded):
+ linear = np.where(encoded <= 0.04045, encoded / 12.92, ((encoded + 0.055) / 1.055) ** 2.4)
+ return np.round(np.clip(linear, 0, 1) ** (1 / GAMMA) * 255).astype(np.float32) / 255
+
+
+def flip_score(reference, test):
+ _, mean_error, _ = flip_evaluator.evaluate(reference.astype(np.float32), test.astype(np.float32), "LDR", inputsRGB=True)
+ return round(float(mean_error), 4)
+
+
+def main():
+ work_directory = Path(sys.argv[1])
+ output_directory = Path(sys.argv[2])
+ name = sys.argv[3]
+ blender_suffix = {"agx": "agx", "neutral": "khronos-pbr-neutral"}[name]
+ scene_ids = sys.argv[4:] or sorted(path.name.removesuffix(f"-cycles-{blender_suffix}.png") for path in work_directory.glob(f"*-cycles-{blender_suffix}.png"))
+ scores = {}
+ for scene_id in scene_ids:
+ cycles = srgb_to_display(load_png(work_directory / f"{scene_id}-cycles-{blender_suffix}.png"))
+ mine = load_png(work_directory / f"{scene_id}-gpu.png")
+ scores[scene_id] = flip_score(cycles, mine)
+ print(f"{scene_id}: 67js {name} against Cycles {name}: {scores[scene_id]}")
+ result = {"metric": "FLIP (LDR), mean error, lower is better", "viewTransform": name, "scores": scores}
+ (output_directory / "view-transform.json").write_text(json.dumps(result, indent=1) + "\n", encoding="utf-8")
+
+
+main()
diff --git a/bench/reference/view-transform.json b/bench/reference/view-transform.json
new file mode 100644
index 00000000..4f8cad6a
--- /dev/null
+++ b/bench/reference/view-transform.json
@@ -0,0 +1,9 @@
+{
+ "metric": "FLIP (LDR), mean error, lower is better",
+ "viewTransform": "agx",
+ "scores": {
+ "outdoor-hdri": 0.0997,
+ "material-spheres": 0.1467,
+ "character": 0.1238
+ }
+}
diff --git a/changes/282-blender.md b/changes/282-blender.md
new file mode 100644
index 00000000..6174b029
--- /dev/null
+++ b/changes/282-blender.md
@@ -0,0 +1 @@
+- Score the view transforms against Blender 5.2.2 (issue #282): `npm run reference -- --view-transform agx --scene <id>,<id>` draws 67js with `viewTransform` and Cycles with Blender's AgX, and scores them into `bench/reference/view-transform.json`. The colour ramp shows `neutral` within 0.0079 of Blender (mean 0.0013) and `agx` within 0.0885 (mean 0.0252); the README has the table and the scene scores.