Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Name the fresnel emission gap on the GPU path tracers and make the graph outputs map prototype-free (Part of #860)

Nguyen Xuan An1539d98732ea
diff --git a/docs/agent-scene.md b/docs/agent-scene.md
index e232238e..84f1e011 100644
--- a/docs/agent-scene.md
+++ b/docs/agent-scene.md
@@ -194,7 +194,7 @@ Placement and pattern nodes:
- `coord` (`"generated"`, `"object"` or `"world"`) is a vector for `at`. `generated` is the unit tile, `object` and `world` are metres across the tile (texture u and v times the pattern `size`). A baked texture is projected onto the mesh, so it knows only the two axes of that projection and the third is 0; `object` and `world` are the same because box mapping reads the placed, scaled position.
- `mapping` (`vector`, default `{ "coord": "generated" }`; `scale` a number or `[x, y, z]`; `rotate` radians around Z; `offset` `[x, y, z]`) scales, turns and moves a vector, as Blender's Mapping node does. Feed it to `at`.
-These make a material work on a mesh without UVs: box mapping (the default) projects the baked graph along the object axes, so a brick wall or a noise pattern needs no unwrap. `vertex_color` on a mesh already multiplies the baked colour. Not in graphs yet: ambient occlusion, bevel and curvature masks, fresnel and a vertex group node (they need per-vertex or per-pixel data that a bake from `u` and `v` alone does not have).
+These make a material work on a mesh without UVs: box mapping (the default) projects the baked graph along the object axes, so a brick wall or a noise pattern needs no unwrap. `vertex_color` on a mesh already multiplies the baked colour. Not in graphs yet: ambient occlusion, bevel and curvature masks, fresnel anywhere but as an emission factor, and a vertex group node (they need per-vertex or per-pixel data that a bake from `u` and `v` alone does not have).
Limits, checked while the recipe is read: at most 64 nodes in all outputs, depth 12 (the field expression limits), at most 8 ramp
stops, `resolution` of 256, 512 or 1024, and a work budget of 30 million units, where a plain node costs 1, a `noise` octave 3
diff --git a/src/material-graph.js b/src/material-graph.js
index c51b9caf..47ba8d70 100644
--- a/src/material-graph.js
+++ b/src/material-graph.js
@@ -657,7 +657,7 @@ export function compileMaterialGraph(graph, { size = 1, images } = {}) {
const names = Object.keys(graph);
if (names.length === 0) throw graphError(`graph needs at least one output: ${MATERIAL_GRAPH_OUTPUTS.join(', ')}.`);
const state = { nodeCount: 0, cost: 0, size, images };
- const outputs = {};
+ const outputs = Object.create(null);
let emissionFresnel;
for (const name of names) {
let node = graph[name];
diff --git a/src/path-tracer-capabilities.js b/src/path-tracer-capabilities.js
index b8fcf9ca..8f4a1cf1 100644
--- a/src/path-tracer-capabilities.js
+++ b/src/path-tracer-capabilities.js
@@ -18,7 +18,7 @@ export const OIDN_DEFAULT_SAMPLES = 16;
export const PATH_TRACER_CAPABILITIES = Object.freeze({
setting: 'settings.renderer { type: "pathTracer", backend ("cpu" default | "gpu" | "native"), samples, bounces, denoise (true | false | "wavelet" | "oidn" | "none"), seed, maxSeconds, noiseThreshold }; image, stills and video jobs, no passes. backend gpu needs a runtime on the GPU backend; backend native uses hardware ray queries through the optional @codepawlhq/67js-render-native package and falls back to gpu (cpu on a cpu runtime) with metrics.pathTracer.backendNote when the package, its binary or a Vulkan ray query adapter is missing; it traces volume fog, subsurface and noiseThreshold; the report names backend, gpuCompileSeconds and gpuKernelCompiles (1 for a whole film). Past maxSeconds on one frame the job fails.',
noiseThreshold: 'Default 0 draws every sample. Above 0 a pixel stops once its standard error relative to its mean is under the value, checked from 16 samples on: faster and noisier, and it cost quality on spot-area (score 0.0658 at 0, 0.0900 at 0.03). docs/path-tracer.md has the table.',
- traces: 'emissive maps and strength; volume fog as a uniform medium (density, colour, anisotropy, box; noise, drift and ambient are not used); the material subsurface block as a bounded random walk on the cpu and gpu backends (at most 32 scattering events, mean free path radius times scale in metres), and a card with nothing behind it as thin translucency.',
- skips: 'occlusion maps, liquids, anisotropy, iridescence, sheen, caustics, depth of field, bloom; metrics.pathTracer.ignored in the job result lists what the scene asked for.',
+ traces: 'emissive maps and strength (a graph fresnel emission factor on the cpu backend only); volume fog as a uniform medium (density, colour, anisotropy, box; noise, drift and ambient are not used); the material subsurface block as a bounded random walk on the cpu and gpu backends (at most 32 scattering events, mean free path radius times scale in metres), and a card with nothing behind it as thin translucency.',
+ skips: 'the graph fresnel emission factor on the gpu backends (flat emission), occlusion maps, liquids, anisotropy, iridescence, sheen, caustics, depth of field, bloom; metrics.pathTracer.ignored in the job result lists what the scene asked for.',
limits: PATH_TRACER_JOB_LIMITS,
});
diff --git a/src/path-tracer.js b/src/path-tracer.js
index 0ce732b5..50396905 100644
--- a/src/path-tracer.js
+++ b/src/path-tracer.js
@@ -970,7 +970,7 @@ export function toneMapToRgba8(linear, width, height, { viewTransform = 'aces',
}
/** Names what this scene asks for that the path tracer does not draw, so a result never claims more than it traced. */
-export function describeIgnoredFeatures(parts, environment) {
+export function describeIgnoredFeatures(parts, environment, backend = 'cpu') {
const notes = new Set();
const fog = environment?.volumeFog;
if (fog?.density > 0 && (fog.noiseAmount ?? 0.5) > 0) notes.add('volumeFog is traced as a uniform medium: noiseAmount, noiseScale and drift are ignored.');
@@ -982,6 +982,7 @@ export function describeIgnoredFeatures(parts, environment) {
if (material.tag && material.tag !== 'surface') notes.add(`${material.tag} materials are traced as plain surfaces.`);
if (material.alphaMode === 'blend') notes.add(hasGraphOpacity(material) ? 'A graph opacity output is traced as a cutout at 0.5.' : 'Blended transparency is traced as opaque.');
if (material.layerMaps?.clearcoatTexture || material.transmissionMap) notes.add('Graph clearcoat and transmission masks are read by the CPU tracer; the GPU tracers use the factors.');
+ if (material.emissionFresnel > 0 && backend !== 'cpu') notes.add('emission fresnel is ignored by the GPU path tracers; the cpu backend applies it.');
for (const [name, isUsed] of IGNORED_LAYERS) if (isUsed(material)) notes.add(`${name} is ignored.`);
}
return [...notes];
@@ -1193,7 +1194,7 @@ export async function renderPathTracedImage({ parts, environment = {}, camera },
backend: options.backend, ...(gpuName ? { gpu: gpuName, gpuCompileSeconds, gpuKernelCompiles } : {}),
averageSamples: totalSamples(samplesTaken) / pixelCount, noiseThreshold: options.noiseThreshold,
triangles: scene.indices.length / 3, tracedSeconds, seconds: (performance.now() - started) / 1000,
- ignored: describeIgnoredFeatures(parts, environment),
+ ignored: describeIgnoredFeatures(parts, environment, options.backend),
},
};
}
diff --git a/tests/material-graph-mixing.test.js b/tests/material-graph-mixing.test.js
index c200b537..e21f7eaa 100644
--- a/tests/material-graph-mixing.test.js
+++ b/tests/material-graph-mixing.test.js
@@ -107,6 +107,16 @@ test('opacity blends the material, and the tracer cuts it out and says what it i
assert.ok(notes.some(note => /clearcoat and transmission masks are read by the CPU tracer/.test(note)));
});
+test('describeIgnoredFeatures names a fresnel emission factor on the GPU backends only', () => {
+ const parts = [{ material: { emission: 1, emissionFresnel: 1.5 } }];
+ const fresnelNote = /emission fresnel is ignored by the GPU path tracers/;
+ assert.ok(!describeIgnoredFeatures(parts, {}).some(note => fresnelNote.test(note)));
+ assert.ok(!describeIgnoredFeatures(parts, {}, 'cpu').some(note => fresnelNote.test(note)));
+ assert.ok(describeIgnoredFeatures(parts, {}, 'gpu').some(note => fresnelNote.test(note)));
+ assert.ok(describeIgnoredFeatures(parts, {}, 'webgpu').some(note => fresnelNote.test(note)));
+ assert.ok(!describeIgnoredFeatures([{ material: { emission: 1 } }], {}, 'gpu').some(note => fresnelNote.test(note)));
+});
+
test('scene_capabilities lists the new outputs and mixing nodes', () => {
const { outputs, operators, nodes } = AGENT_SCENE_CAPABILITIES.materialGraph;
for (const name of ['opacity', 'clearcoat', 'transmission']) assert.ok(outputs.includes(name), name);