Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Add --assert and committed trap results to the flicker ground-truth probe (#751)

Nguyen Xuan An7de36fce54f4
diff --git a/bench/flicker/probe.mjs b/bench/flicker/probe.mjs
index 42c82e5d..ded6900e 100644
--- a/bench/flicker/probe.mjs
+++ b/bench/flicker/probe.mjs
@@ -3,6 +3,7 @@
// --spots spots.json --configs "reversed=1,nearFit=1;reversed=0,nearFit=0"
// spots.json: [{ "name": "roofs", "eye": [x, y, z], "target": [x, y, z] }]. Without --spots it prints the scene bounds and exits.
// node bench/flicker/probe.mjs --traps --configs "reversed=1;reversed=0" runs every trap scene of traps.js with its own camera.
+// Add --assert to exit with code 1 when any trap shows a swapped pixel with the flush pass on (configs without offset=0).
// Each result also carries `truth`, the ground-truth probe of ground-truth.js: the render compared with a float64 ray cast that
// cannot z-fight. `swapped` is the count that matters (a pixel showing the colour of a face behind the visible one), `tied` the
// pixels where the scene itself names no winner (exact coplanar faces with the flush pass off, `offset=0`), and `wrong` also holds
@@ -10,6 +11,7 @@
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { chromium } from 'playwright';
+import { failingTraps } from './verdict.js';
function argument(name, fallback) {
const index = process.argv.indexOf(`--${name}`);
@@ -55,6 +57,11 @@ async function probeTraps() {
}
}
writeFileSync(path.join(outputFolder, `${prefix}-results.json`), JSON.stringify(results, null, 1));
+ if (process.argv.includes('--assert')) {
+ const failures = failingTraps(results);
+ console.log(failures.length === 0 ? 'assert: no swapped pixels with the flush pass on' : `assert: FAILED ${JSON.stringify(failures)}`);
+ if (failures.length > 0) process.exitCode = 1;
+ }
}
try {
diff --git a/bench/flicker/results/README.md b/bench/flicker/results/README.md
new file mode 100644
index 00000000..eb8eadf4
--- /dev/null
+++ b/bench/flicker/results/README.md
@@ -0,0 +1,6 @@
+# Flicker probe results
+
+`traps-1280x720.json` is the ground-truth output of `node bench/flicker/probe.mjs --traps --viewport 1280x720 --assert` with
+configs `reversed=1;reversed=0;reversed=1,offset=0;reversed=0,offset=0` (reversed-Z float depth and 24-bit depth, flush pass on and
+off). It needs a GPU browser, so it is a local run, not part of CI; rerun it after a change to the flush pass or the depth path.
+`--assert` exits 1 if any trap shows a swapped pixel with the flush pass on.
diff --git a/bench/flicker/results/traps-1280x720.json b/bench/flicker/results/traps-1280x720.json
new file mode 100644
index 00000000..82fa5c92
--- /dev/null
+++ b/bench/flicker/results/traps-1280x720.json
@@ -0,0 +1,398 @@
+[
+ {
+ "trap": "plaque-2m",
+ "configuration": "reversed1",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 0
+ },
+ {
+ "trap": "plaque-20m",
+ "configuration": "reversed1",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 0
+ },
+ {
+ "trap": "plaque-200m",
+ "configuration": "reversed1",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 0
+ },
+ {
+ "trap": "stacked-slabs",
+ "configuration": "reversed1",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 66876
+ },
+ {
+ "trap": "kitbash-duplicates",
+ "configuration": "reversed1",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 0
+ },
+ {
+ "trap": "decal-grazing-2deg",
+ "configuration": "reversed1",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 664
+ },
+ {
+ "trap": "walls-16mm-1km-5deg",
+ "configuration": "reversed1",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 422
+ },
+ {
+ "trap": "panel-15mm-176m",
+ "configuration": "reversed1",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 31064
+ },
+ {
+ "trap": "stack-30-exact",
+ "configuration": "reversed1",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 0
+ },
+ {
+ "trap": "instanced-flush",
+ "configuration": "reversed1",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 13848
+ },
+ {
+ "trap": "plaque-closeup-0.5m",
+ "configuration": "reversed1",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 18365,
+ "contested": 915208
+ },
+ {
+ "trap": "plaque-2m",
+ "configuration": "reversed0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 0
+ },
+ {
+ "trap": "plaque-20m",
+ "configuration": "reversed0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 0
+ },
+ {
+ "trap": "plaque-200m",
+ "configuration": "reversed0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 0
+ },
+ {
+ "trap": "stacked-slabs",
+ "configuration": "reversed0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 66876
+ },
+ {
+ "trap": "kitbash-duplicates",
+ "configuration": "reversed0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 0
+ },
+ {
+ "trap": "decal-grazing-2deg",
+ "configuration": "reversed0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 664
+ },
+ {
+ "trap": "walls-16mm-1km-5deg",
+ "configuration": "reversed0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 422
+ },
+ {
+ "trap": "panel-15mm-176m",
+ "configuration": "reversed0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 31064
+ },
+ {
+ "trap": "stack-30-exact",
+ "configuration": "reversed0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 0
+ },
+ {
+ "trap": "instanced-flush",
+ "configuration": "reversed0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 13848
+ },
+ {
+ "trap": "plaque-closeup-0.5m",
+ "configuration": "reversed0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 18359,
+ "contested": 915208
+ },
+ {
+ "trap": "plaque-2m",
+ "configuration": "reversed1-offset0",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 337656,
+ "wrong": 0,
+ "contested": 337656
+ },
+ {
+ "trap": "plaque-20m",
+ "configuration": "reversed1-offset0",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 3014,
+ "wrong": 0,
+ "contested": 3014
+ },
+ {
+ "trap": "plaque-200m",
+ "configuration": "reversed1-offset0",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 12,
+ "wrong": 0,
+ "contested": 12
+ },
+ {
+ "trap": "stacked-slabs",
+ "configuration": "reversed1-offset0",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 24544,
+ "wrong": 9,
+ "contested": 69431
+ },
+ {
+ "trap": "kitbash-duplicates",
+ "configuration": "reversed1-offset0",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 140238,
+ "wrong": 0,
+ "contested": 140238
+ },
+ {
+ "trap": "decal-grazing-2deg",
+ "configuration": "reversed1-offset0",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 664
+ },
+ {
+ "trap": "walls-16mm-1km-5deg",
+ "configuration": "reversed1-offset0",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 422
+ },
+ {
+ "trap": "panel-15mm-176m",
+ "configuration": "reversed1-offset0",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 31064
+ },
+ {
+ "trap": "stack-30-exact",
+ "configuration": "reversed1-offset0",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 123566,
+ "wrong": 0,
+ "contested": 123566
+ },
+ {
+ "trap": "instanced-flush",
+ "configuration": "reversed1-offset0",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 0,
+ "tied": 6431,
+ "wrong": 0,
+ "contested": 20279
+ },
+ {
+ "trap": "plaque-closeup-0.5m",
+ "configuration": "reversed1-offset0",
+ "depth": "reversed-Z, 32-bit float",
+ "swapped": 389,
+ "tied": 0,
+ "wrong": 18751,
+ "contested": 916408
+ },
+ {
+ "trap": "plaque-2m",
+ "configuration": "reversed0-offset0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 337656,
+ "wrong": 0,
+ "contested": 337656
+ },
+ {
+ "trap": "plaque-20m",
+ "configuration": "reversed0-offset0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 3014,
+ "wrong": 0,
+ "contested": 3014
+ },
+ {
+ "trap": "plaque-200m",
+ "configuration": "reversed0-offset0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 12,
+ "wrong": 0,
+ "contested": 12
+ },
+ {
+ "trap": "stacked-slabs",
+ "configuration": "reversed0-offset0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 24544,
+ "wrong": 22,
+ "contested": 69431
+ },
+ {
+ "trap": "kitbash-duplicates",
+ "configuration": "reversed0-offset0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 140238,
+ "wrong": 0,
+ "contested": 140238
+ },
+ {
+ "trap": "decal-grazing-2deg",
+ "configuration": "reversed0-offset0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 664
+ },
+ {
+ "trap": "walls-16mm-1km-5deg",
+ "configuration": "reversed0-offset0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 422
+ },
+ {
+ "trap": "panel-15mm-176m",
+ "configuration": "reversed0-offset0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 0,
+ "wrong": 0,
+ "contested": 31064
+ },
+ {
+ "trap": "stack-30-exact",
+ "configuration": "reversed0-offset0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 123566,
+ "wrong": 0,
+ "contested": 123566
+ },
+ {
+ "trap": "instanced-flush",
+ "configuration": "reversed0-offset0",
+ "depth": "24-bit, standard",
+ "swapped": 0,
+ "tied": 6431,
+ "wrong": 0,
+ "contested": 20279
+ },
+ {
+ "trap": "plaque-closeup-0.5m",
+ "configuration": "reversed0-offset0",
+ "depth": "24-bit, standard",
+ "swapped": 208405,
+ "tied": 0,
+ "wrong": 226801,
+ "contested": 916408
+ }
+]
diff --git a/bench/flicker/verdict.js b/bench/flicker/verdict.js
new file mode 100644
index 00000000..60ab26a5
--- /dev/null
+++ b/bench/flicker/verdict.js
@@ -0,0 +1,11 @@
+/**
+ * Pass or fail for a probe run. With the flush pass on (the viewer's default, `offset` not 0) no trap may show a pixel with the
+ * colour of a face behind the visible one. Runs with `offset=0` are the "before" numbers and are never judged.
+ * `results` is the list `probe.mjs --traps` writes; the configuration label holds `offset0` when the flush pass was off.
+ */
+export function failingTraps(results) {
+ return results
+ .filter(result => !result.configuration.includes('offset0'))
+ .filter(result => !result.truth || !Number.isFinite(result.truth.swapped) || result.truth.swapped > 0)
+ .map(result => ({ trap: result.trap, configuration: result.configuration, swapped: result.truth ? result.truth.swapped : null }));
+}
diff --git a/tests/flicker-ground-truth.test.js b/tests/flicker-ground-truth.test.js
index a9ad4887..ddcb8cdc 100644
--- a/tests/flicker-ground-truth.test.js
+++ b/tests/flicker-ground-truth.test.js
@@ -170,3 +170,17 @@ test('a one-sided face seen from behind is not hit', () => {
const behind = castPixelOwners(world, { ...CAMERA, eye: [0, 0, -10] }, WIDTH, HEIGHT);
assert.ok(behind.owner.every(owner => owner === NO_TRIANGLE));
});
+
+test('failingTraps flags a swapped pixel with the flush pass on and ignores runs with it off', async () => {
+ const { failingTraps } = await import('../bench/flicker/verdict.js');
+ const results = [
+ { trap: 'plaque-0.5m', configuration: 'reversed1-offset0', truth: { swapped: 389 } },
+ { trap: 'plaque-0.5m', configuration: 'reversed1', truth: { swapped: 0 } },
+ { trap: 'stacked', configuration: 'reversed0', truth: { swapped: 7 } },
+ { trap: 'missing', configuration: 'reversed0' },
+ ];
+ assert.deepEqual(failingTraps(results), [
+ { trap: 'stacked', configuration: 'reversed0', swapped: 7 },
+ { trap: 'missing', configuration: 'reversed0', swapped: null },
+ ]);
+});