Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Wire Cycles filter_glossy in KernelParamsV2 and neutral cutout mask

Nguyen Xuan An3f103bf4e491
diff --git a/packages/render-native/FORMAT-v2.md b/packages/render-native/FORMAT-v2.md
index ed00962f..8bf09c59 100644
--- a/packages/render-native/FORMAT-v2.md
+++ b/packages/render-native/FORMAT-v2.md
@@ -87,7 +87,7 @@ Total size: **320 bytes** (`20 × 16 B`), alignment: **16 bytes**.
| `288` | `4` | `4` | `f32` | `film_exposure` | Linear exposure multiplier applied on film accumulation (default `1.0`) |
| `292` | `4` | `4` | `f32` | `background_mis_weight` | `1.0` when environment MIS is active, `0.0` otherwise |
| `296` | `4` | `4` | `u32` | `sobol_table_offset` | Word offset into `texture_texels` for Sobol / blue-noise tables |
-| `300` | `4` | `4` | `u32` | `reserved_u0` | Reserved (`0`) |
+| `300` | `4` | `4` | `f32` | `filter_glossy` | Cycles Filter Glossy (`blur_glossy`) factor (`0.0` = off, default `1.0`) |
| `304` | `16` | `16` | `vec4<u32>` | `reserved_tail` | Reserved (`[0, 0, 0, 0]`) |
---
diff --git a/packages/render-native/index.mjs b/packages/render-native/index.mjs
index a434252c..33b49e11 100644
--- a/packages/render-native/index.mjs
+++ b/packages/render-native/index.mjs
@@ -66,9 +66,17 @@ export function traceNative(input, options = {}) {
}
return addon.traceScene(input, { width, height, samples, maxSeconds, kernel: selectedKernel });
}
- const v2Input = input?.schemaVersion === FORMAT_V2_VERSION
+ let v2Input = input?.schemaVersion === FORMAT_V2_VERSION
? input
: upgradeNativeInputV1ToV2(input, options);
+ const explicitFilterGlossy = options.filterGlossy ?? options.blurGlossy;
+ if (input?.schemaVersion === FORMAT_V2_VERSION && explicitFilterGlossy !== undefined) {
+ const rawFilterGlossy = Number(explicitFilterGlossy);
+ const resolvedFilterGlossy = Number.isFinite(rawFilterGlossy) && rawFilterGlossy > 0 ? rawFilterGlossy : 0.0;
+ const patchedParams = new Uint8Array(v2Input.kernelParams);
+ new DataView(patchedParams.buffer, patchedParams.byteOffset, patchedParams.byteLength).setFloat32(300, resolvedFilterGlossy, true);
+ v2Input = { ...v2Input, kernelParams: patchedParams };
+ }
return addon.traceSceneCycles(v2Input, {
width,
height,
diff --git a/packages/render-native/pack-input-v2.mjs b/packages/render-native/pack-input-v2.mjs
index d26e2382..7fe756f3 100644
--- a/packages/render-native/pack-input-v2.mjs
+++ b/packages/render-native/pack-input-v2.mjs
@@ -1617,10 +1617,13 @@ function packKernelParamsV2({
u32[70] = Math.max(1, Math.round(Number(options.adaptiveMinSamples ?? 16))) >>> 0;
u32[71] = 0;
+ const rawFilterGlossy = Number(options.filterGlossy ?? options.blurGlossy ?? 1.0);
+ const filterGlossy = Number.isFinite(rawFilterGlossy) && rawFilterGlossy > 0 ? rawFilterGlossy : 0.0;
+
f32[72] = Number(options.exposure ?? 1.0);
f32[73] = packedEnvironment.envWidth > 0 && packedEnvironment.envTotalWeight > 0 ? 1.0 : 0.0;
u32[74] = 0;
- u32[75] = 0;
+ f32[75] = filterGlossy;
u32[76] = 0;
u32[77] = 0;
diff --git a/packages/render-native/src/cycles/abi.wgsl b/packages/render-native/src/cycles/abi.wgsl
index 76befe0e..0524b153 100644
--- a/packages/render-native/src/cycles/abi.wgsl
+++ b/packages/render-native/src/cycles/abi.wgsl
@@ -179,7 +179,7 @@ struct KernelParamsV2 {
film_exposure: f32,
background_mis_weight: f32,
sobol_table_offset: u32,
- reserved_u0: u32,
+ filter_glossy: f32,
reserved_tail: vec4<u32>,
}
diff --git a/tests/native-pack-v2.test.js b/tests/native-pack-v2.test.js
index 8c729112..cdd84b3f 100644
--- a/tests/native-pack-v2.test.js
+++ b/tests/native-pack-v2.test.js
@@ -47,15 +47,15 @@ function quadGeometry(z = 0) {
};
}
-function makeCheckerRgba8(width = 4, height = 4, cutoutLeftHalf = false) {
+function makeCheckerRgba8(width = 4, height = 4, cutoutLeftHalf = false, neutralWhite = false) {
const data = new Uint8Array(width * height * 4);
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const idx = (y * width + x) * 4;
const bright = (x + y) % 2 === 0;
- data[idx] = bright ? 240 : 60;
- data[idx + 1] = bright ? 180 : 40;
- data[idx + 2] = bright ? 100 : 20;
+ data[idx] = neutralWhite ? 255 : (bright ? 240 : 60);
+ data[idx + 1] = neutralWhite ? 255 : (bright ? 180 : 40);
+ data[idx + 2] = neutralWhite ? 255 : (bright ? 100 : 20);
data[idx + 3] = cutoutLeftHalf && x < width / 2 ? 0 : 255;
}
}
@@ -449,7 +449,7 @@ test('upgradeNativeInputV1ToV2 preserves textures, lights, subsurface, volume, a
});
test('Cycles v2 host executes multi-BLAS/TLAS ray queries, cutout alpha masking, v1 auto-upgrade, and probeCyclesLobe on GPU', { skip: !findNativeAddon() }, () => {
- const cutoutImage = makeCheckerRgba8(4, 4, true); // left half alpha=0, right half alpha=255
+ const cutoutImage = makeCheckerRgba8(4, 4, true, true); // left half alpha=0, right half opaque neutral white
const sharedQuad = quadGeometry(0);
const camera = createCamera({ eye: [0, 0, 2.4], target: [0, 0, 0], fov: 50 }, 16, 16);