Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Compare denoised Cook with denoised Cycles at low sample counts (#897)

Nguyen Xuan An2bf2f4ee7dff
diff --git a/bench/cycles-parity/make-denoised-comparison-figure.py b/bench/cycles-parity/make-denoised-comparison-figure.py
new file mode 100644
index 00000000..c4d18dc8
--- /dev/null
+++ b/bench/cycles-parity/make-denoised-comparison-figure.py
@@ -0,0 +1,122 @@
+"""Builds the denoised comparison picture of docs/cook-denoised-comparison.jpg.
+
+Top row: Cook raw, Cook + OIDN, Cycles + OIDN and the Cycles 4096 spp reference of one scene at one sample count.
+Bottom row: the same four images cropped on one region and enlarged 2x with nearest-neighbour pixels (not smoothed).
+Each label carries the relMSE and the total seconds (sampling plus denoise) of that image.
+
+ uv run --no-project --with numpy --with pillow python bench/cycles-parity/make-denoised-comparison-figure.py \
+ --rows rows.json --images <folder with the *.half.npy files> --reference <scene>-cycles-4096-seed1.npy \
+ --scene many-lights-500 --samples 64 --crop-x 600 --crop-y 60 --output docs/cook-denoised-comparison.jpg
+"""
+import argparse
+import importlib.util
+import json
+import os
+import statistics
+import sys
+
+import numpy
+from PIL import Image, ImageDraw, ImageFont
+
+PANEL_WIDTH = 480
+PANEL_HEIGHT = 270
+LABEL_HEIGHT = 44
+CROP_WIDTH = PANEL_WIDTH // 2
+CROP_HEIGHT = PANEL_HEIGHT // 2
+VARIANTS = [
+ ("cook-raw", "Cook raw"),
+ ("cook-oidn-cuda", "Cook + OIDN"),
+ ("cycles-oidn", "Cycles + OIDN"),
+]
+
+
+def load_settle_function():
+ """The summary script owns how Cycles' denoise seconds are derived; the picture labels must use the same numbers."""
+ summary_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "summarize-denoised-comparison.py")
+ specification = importlib.util.spec_from_file_location("summarize_denoised_comparison", summary_path)
+ module = importlib.util.module_from_spec(specification)
+ specification.loader.exec_module(module)
+ return module.settle_cycles_denoise_seconds
+
+
+def srgb_of(linear, exposure):
+ scaled = numpy.clip(linear * exposure, 0.0, 1.0)
+ return numpy.where(scaled <= 0.0031308, scaled * 12.92, 1.055 * numpy.power(scaled, 1 / 2.4) - 0.055)
+
+
+def exposure_for(reference):
+ luminance = reference[..., 0] * 0.2126 + reference[..., 1] * 0.7152 + reference[..., 2] * 0.0722
+ return 0.4 / max(float(luminance.mean()), 1e-4)
+
+
+def to_picture(linear, exposure):
+ return Image.fromarray((srgb_of(linear.astype(numpy.float64), exposure) * 255 + 0.5).astype(numpy.uint8))
+
+
+def median_total_seconds(rows, variant, scene, samples):
+ totals = [row["samplingSeconds"] + row["denoiseSeconds"] for row in rows
+ if row.get("variant") == variant and row.get("scene") == scene and row.get("samples") == samples and "relMse" in row]
+ return statistics.median(totals)
+
+
+def round_one_relative_mse(rows, variant, scene, samples):
+ for row in rows:
+ if row.get("variant") == variant and row.get("scene") == scene and row.get("samples") == samples and row.get("round") == 1 and "relMse" in row:
+ return row["relMse"]
+ raise SystemExit(f"No round 1 row for {variant} {scene} {samples} spp.")
+
+
+def draw_label(canvas, left, top, title, detail):
+ draw = ImageDraw.Draw(canvas)
+ title_font = ImageFont.load_default(size=15)
+ detail_font = ImageFont.load_default(size=13)
+ draw.text((left + 8, top + 4), title, fill=(235, 235, 235), font=title_font)
+ draw.text((left + 8, top + 24), detail, fill=(170, 170, 170), font=detail_font)
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--rows", required=True)
+ parser.add_argument("--images", required=True)
+ parser.add_argument("--reference", required=True)
+ parser.add_argument("--scene", default="many-lights-500")
+ parser.add_argument("--samples", type=int, default=64)
+ parser.add_argument("--crop-x", type=int, required=True, help="left edge of the crop in full-resolution pixels")
+ parser.add_argument("--crop-y", type=int, required=True, help="top edge of the crop in full-resolution pixels")
+ parser.add_argument("--output", required=True)
+ parser.add_argument("--quality", type=int, default=82)
+ arguments = parser.parse_args()
+ sys.stdout.reconfigure(encoding="utf-8", errors="replace")
+
+ with open(arguments.rows, encoding="utf-8") as handle:
+ rows = load_settle_function()(json.load(handle))
+ reference = numpy.load(arguments.reference)[..., :3].astype(numpy.float64)
+ exposure = exposure_for(reference)
+
+ panels = []
+ for variant, title in VARIANTS:
+ path = f"{arguments.images}/{variant}-{arguments.scene}-s{arguments.samples}-r1.half.npy"
+ image = numpy.load(path)[..., :3]
+ relative_mse = round_one_relative_mse(rows, variant, arguments.scene, arguments.samples)
+ seconds = median_total_seconds(rows, variant, arguments.scene, arguments.samples)
+ panels.append((title, f"relMSE {relative_mse:.4f} {seconds:.1f} s", to_picture(image, exposure)))
+ panels.append(("Cycles 4096 spp", "reference", to_picture(reference, exposure)))
+
+ width = PANEL_WIDTH * len(panels)
+ height = (PANEL_HEIGHT + LABEL_HEIGHT) * 2
+ canvas = Image.new("RGB", (width, height), (24, 24, 24))
+ crop_box = (arguments.crop_x, arguments.crop_y, arguments.crop_x + CROP_WIDTH, arguments.crop_y + CROP_HEIGHT)
+ for column, (title, detail, picture) in enumerate(panels):
+ left = column * PANEL_WIDTH
+ whole = picture.resize((PANEL_WIDTH, PANEL_HEIGHT), Image.BOX)
+ canvas.paste(whole, (left, LABEL_HEIGHT))
+ draw_label(canvas, left, 0, title, detail)
+ enlarged = picture.crop(crop_box).resize((PANEL_WIDTH, PANEL_HEIGHT), Image.NEAREST)
+ canvas.paste(enlarged, (left, PANEL_HEIGHT + LABEL_HEIGHT * 2))
+ draw_label(canvas, left, PANEL_HEIGHT + LABEL_HEIGHT, f"{title}, crop 2x", f"{CROP_WIDTH}x{CROP_HEIGHT} px at {arguments.crop_x},{arguments.crop_y}")
+ canvas.save(arguments.output, "JPEG", quality=arguments.quality, optimize=True, subsampling=0)
+ print(f"wrote {arguments.output}")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/bench/cycles-parity/render-cycles.py b/bench/cycles-parity/render-cycles.py
index 8bd3c8ef..9e38ee60 100644
--- a/bench/cycles-parity/render-cycles.py
+++ b/bench/cycles-parity/render-cycles.py
@@ -54,7 +54,7 @@ def parse_cli_arguments():
raise ValueError("Pass script arguments after '--': <sceneJsonPath> <outputPrefix> [options].")
argument_list = sys.argv[sys.argv.index("--") + 1:]
if len(argument_list) < 2 or argument_list[0].startswith("--") or argument_list[1].startswith("--"):
- raise ValueError("Usage: blender -b --factory-startup --python bench/cycles-parity/render-cycles.py -- <sceneJsonPath> <outputPrefix> [--samples 256] [--bounces 8] [--transparent-bounces 8] [--seed 1] [--width 960] [--height 540] [--filter-type box|gaussian|blackman-harris] [--filter-width 1.0] [--keep-exr] [--part-ids] [--grey-diffuse] [--z-depth] [--depth-samples 64]")
+ raise ValueError("Usage: blender -b --factory-startup --python bench/cycles-parity/render-cycles.py -- <sceneJsonPath> <outputPrefix> [--samples 256] [--bounces 8] [--transparent-bounces 8] [--seed 1] [--width 960] [--height 540] [--filter-type box|gaussian|blackman-harris] [--filter-width 1.0] [--keep-exr] [--part-ids] [--grey-diffuse] [--z-depth] [--depth-samples 64] [--denoise none|oidn-gpu|oidn-cpu]")
return {
"scene_json_path": os.path.abspath(argument_list[0]),
"output_prefix": os.path.abspath(argument_list[1]),
@@ -75,6 +75,7 @@ def parse_cli_arguments():
"grey_diffuse": "--grey-diffuse" in argument_list,
"z_depth": "--z-depth" in argument_list,
"depth_samples": int(read_flag_value(argument_list, "--depth-samples", str(DEFAULT_DEPTH_SAMPLES))),
+ "denoise": read_flag_value(argument_list, "--denoise", "none"),
}
@@ -445,6 +446,25 @@ def configure_linear_exr_output(scene, width, height):
scene.view_settings.look = "None"
+def configure_cycles_denoising(scene, mode):
+ """Off by default. "oidn-gpu" and "oidn-cpu" run Cycles' own Open Image Denoise with albedo and normal passes.
+
+ Blender's default denoiser for final renders is Open Image Denoise (the other choice is OptiX), with the
+ albedo and normal passes, the accurate prefilter and, when a GPU renders, GPU denoising. This sets those
+ values explicitly so the comparison does not depend on a default.
+ """
+ if mode == "none":
+ scene.cycles.use_denoising = False
+ return
+ if mode not in ("oidn-gpu", "oidn-cpu"):
+ raise ValueError(f"--denoise must be none, oidn-gpu or oidn-cpu, got {mode!r}.")
+ scene.cycles.use_denoising = True
+ scene.cycles.denoiser = "OPENIMAGEDENOISE"
+ scene.cycles.denoising_input_passes = "RGB_ALBEDO_NORMAL"
+ scene.cycles.denoising_prefilter = "ACCURATE"
+ scene.cycles.denoising_use_gpu = mode == "oidn-gpu"
+
+
def configure_cycles_parity(scene, options):
scene.render.engine = "CYCLES"
preferences = bpy.context.preferences.addons["cycles"].preferences
@@ -460,7 +480,7 @@ def configure_cycles_parity(scene, options):
scene.cycles.device = "GPU"
scene.cycles.samples = options["samples"]
scene.cycles.seed = options["seed"]
- scene.cycles.use_denoising = False
+ configure_cycles_denoising(scene, options["denoise"])
scene.cycles.use_adaptive_sampling = False
scene.cycles.pixel_filter_type = PIXEL_FILTER_TYPES[options["filter_type"]]
scene.cycles.filter_width = options["filter_width"]
@@ -604,6 +624,7 @@ def execute_timed_cycles_render(scene, exr_path):
"render_call_seconds": render_call_seconds,
"cycles_sync_seconds": cycles_sync_seconds,
"sampling_seconds": sampling_seconds,
+ "after_last_sample_seconds": max(0.0, render_call_seconds - (last_sample_seconds or render_call_seconds)),
"peak_stats_megabytes": peak_stats_megabytes,
"stats_event_count": len(stats_events),
"last_stats_text": stats_events[-1][1] if stats_events else "",
@@ -692,6 +713,9 @@ def main():
"cyclesSyncSeconds": round(timing["cycles_sync_seconds"], 6),
"setupSeconds": round(setup_seconds, 6),
"samplingSeconds": round(timing["sampling_seconds"], 6),
+ "secondsAfterLastSample": round(timing["after_last_sample_seconds"], 6),
+ "denoiseMode": options["denoise"],
+ "denoiser": scene.cycles.denoiser if scene.cycles.use_denoising else None,
"renderCallSeconds": round(timing["render_call_seconds"], 6),
"totalTraceSeconds": round(total_trace_seconds, 6),
"cyclesPeakMemoryMegabytes": round(timing["peak_stats_megabytes"], 2),
diff --git a/bench/cycles-parity/summarize-denoised-comparison.py b/bench/cycles-parity/summarize-denoised-comparison.py
new file mode 100644
index 00000000..1e13f952
--- /dev/null
+++ b/bench/cycles-parity/summarize-denoised-comparison.py
@@ -0,0 +1,111 @@
+"""Turns the rows of the denoised comparison run into a Markdown table and the equal-time reading.
+
+ uv run --no-project python bench/cycles-parity/summarize-denoised-comparison.py <rows.json>
+
+One row per scene, sample count and variant: median sampling seconds, median denoise seconds, total, relMSE (epsilon 0.01) and
+mean ratio (medians over rounds; the images are the same in every round, only the timing moves), and FLIP (LDR) from round 1.
+The equal-time lines pick, per scene, the cheapest sample count of each renderer's best denoised variant that reaches a
+given total-seconds budget and compare the relMSE at that budget by linear interpolation in log-log.
+"""
+import json
+import math
+import statistics
+import sys
+
+VARIANT_ORDER = ["cook-raw", "cook-atrous", "cook-oidn-cuda", "cook-oidn-cpu", "cycles-raw", "cycles-oidn"]
+
+
+def median_of(values):
+ values = [value for value in values if value is not None]
+ return statistics.median(values) if values else None
+
+
+def settle_cycles_denoise_seconds(rows):
+ """Cycles denoises inside its render call, so there is no separate timer. The denoise seconds of a denoised render are
+ the time it spends from the first sample to the end of the call, minus the same time of the raw render of the same
+ rung and round; its sampling seconds are those of that raw render."""
+ raw_rows = {(row["scene"], row["samples"], row["round"]): row for row in rows if row.get("variant") == "cycles-raw" and "relMse" in row}
+ settled = []
+ for row in rows:
+ if row.get("variant") == "cycles-oidn" and "relMse" in row:
+ raw = raw_rows[(row["scene"], row["samples"], row["round"])]
+ render_seconds = row["samplingSeconds"] + row["secondsAfterLastSample"]
+ raw_render_seconds = raw["samplingSeconds"] + raw["secondsAfterLastSample"]
+ row = {**row, "samplingSeconds": raw["samplingSeconds"], "denoiseSeconds": max(0.0, render_seconds - raw_render_seconds)}
+ settled.append(row)
+ return settled
+
+
+def build_table(rows):
+ rows = settle_cycles_denoise_seconds(rows)
+ groups = {}
+ for row in rows:
+ if "relMse" not in row:
+ continue
+ key = (row["scene"], row["samples"], row["variant"])
+ groups.setdefault(key, []).append(row)
+ table = {}
+ for key, group in groups.items():
+ table[key] = {
+ "sampling": median_of([row["samplingSeconds"] for row in group]),
+ "denoise": median_of([row["denoiseSeconds"] for row in group]),
+ "relMse": median_of([row["relMse"] for row in group]),
+ "meanRatio": median_of([row["meanRatio"] for row in group]),
+ "flip": median_of([row.get("flip") for row in group]),
+ "rounds": len(group),
+ }
+ table[key]["total"] = table[key]["sampling"] + table[key]["denoise"]
+ return table
+
+
+def interpolate_error_at(points, seconds):
+ """relMSE at a total-seconds budget, log-log between the two nearest measured rungs; None outside the measured range."""
+ ordered = sorted(points)
+ for (low_seconds, low_error), (high_seconds, high_error) in zip(ordered, ordered[1:]):
+ if low_seconds <= seconds <= high_seconds:
+ fraction = (math.log(seconds) - math.log(low_seconds)) / (math.log(high_seconds) - math.log(low_seconds))
+ return math.exp(math.log(low_error) + fraction * (math.log(high_error) - math.log(low_error)))
+ return None
+
+
+def main():
+ sys.stdout.reconfigure(encoding="utf-8", errors="replace")
+ with open(sys.argv[1], encoding="utf-8") as handle:
+ rows = json.load(handle)
+ table = build_table(rows)
+ scenes = sorted({key[0] for key in table})
+ print("| scene | spp | variant | sampling s | denoise s | total s | relMSE | FLIP | mean ratio |")
+ print("| --- | ---: | --- | ---: | ---: | ---: | ---: | ---: | ---: |")
+ for scene in scenes:
+ for samples in sorted({key[1] for key in table if key[0] == scene}):
+ for variant in VARIANT_ORDER:
+ entry = table.get((scene, samples, variant))
+ if not entry:
+ continue
+ flip = "" if entry["flip"] is None else f"{entry['flip']:.3f}"
+ print(f"| {scene} | {samples} | {variant} | {entry['sampling']:.2f} | {entry['denoise']:.2f} | {entry['total']:.2f} | "
+ f"{entry['relMse']:.3g} | {flip} | {entry['meanRatio']:.3f} |")
+ print()
+ print("Equal total seconds (relMSE interpolated log-log between measured rungs):")
+ for scene in scenes:
+ curves = {}
+ for variant in VARIANT_ORDER:
+ points = [(table[key]["total"], table[key]["relMse"]) for key in table if key[0] == scene and key[2] == variant]
+ if len(points) >= 2:
+ curves[variant] = points
+ for budget_variant, other_variant in (("cook-oidn-cuda", "cycles-oidn"), ("cook-atrous", "cycles-oidn"), ("cook-raw", "cycles-raw")):
+ if budget_variant not in curves or other_variant not in curves:
+ continue
+ low = max(min(seconds for seconds, _ in curves[budget_variant]), min(seconds for seconds, _ in curves[other_variant]))
+ high = min(max(seconds for seconds, _ in curves[budget_variant]), max(seconds for seconds, _ in curves[other_variant]))
+ if low >= high:
+ print(f"- {scene}: {budget_variant} and {other_variant} share no total-seconds range.")
+ continue
+ budget = math.sqrt(low * high)
+ first = interpolate_error_at(curves[budget_variant], budget)
+ second = interpolate_error_at(curves[other_variant], budget)
+ print(f"- {scene} at {budget:.1f} s: {budget_variant} relMSE {first:.3g}, {other_variant} relMSE {second:.3g} (ratio {first / second:.2f})")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/bench/cycles-parity/trace-native.mjs b/bench/cycles-parity/trace-native.mjs
index 457390f8..4d10230a 100644
--- a/bench/cycles-parity/trace-native.mjs
+++ b/bench/cycles-parity/trace-native.mjs
@@ -11,6 +11,7 @@ import { writeFloat32Npy } from './npy.mjs';
import { reconstructTraceSceneSource } from './scene-bridge.mjs';
import { denoiseRadiance } from '../../src/path-tracer-denoise.js';
import { applyGreyDiffuseOverride } from './grey-diffuse-override.mjs';
+import { denoiseWithOidn } from '../../packages/denoise-oidn/index.mjs';
const SUPPORTED_KERNELS = new Set(['legacy', 'cycles']);
const SUPPORTED_FILTERS = new Set(['box', 'gaussian', 'blackman-harris']);
@@ -84,6 +85,17 @@ function parseDenoiseOption(argumentList) {
return parseChoiceOption(argumentList, '--denoise', ['none', 'wavelet', 'atrous'], 'none');
}
+function parseOidnDevicesOption(argumentList) {
+ const requested = String(readFlagValue(argumentList, '--oidn-devices', ''));
+ const devices = requested === '' ? [] : requested.split(',');
+ for (const device of devices) {
+ if (!['cpu', 'cuda', 'default'].includes(device)) {
+ throw new RangeError(`Option --oidn-devices takes a comma list of cpu, cuda or default, got "${device}".`);
+ }
+ }
+ return devices;
+}
+
function parseLightSamplingOption(argumentList) {
const lightSampling = String(readFlagValue(argumentList, '--light-sampling', 'auto'));
if (!['auto', 'tree', 'uniform'].includes(lightSampling)) {
@@ -102,7 +114,7 @@ function parseLightSamplingOption(argumentList) {
function parseTraceArguments(argumentList) {
if (argumentList.length < 2 || argumentList[0].startsWith('--') || argumentList[1].startsWith('--')) {
- throw new RangeError('Usage: node bench/cycles-parity/trace-native.mjs <sceneJsonPath> <outputPrefix> [--kernel legacy|cycles] [--samples 256] [--bounces 8] [--transparent-bounces 8] [--seed 1] [--width 960] [--height 540] [--sampler white|sobol-burley] [--light-sampling auto|tree|uniform] [--path-regeneration] [--env-compensation 0..1] [--filter-type box|gaussian|blackman-harris] [--filter-width 1.0] [--clamp-direct 0] [--clamp-indirect 0] [--firefly-clamp 1e9] [--noise-threshold 0] [--denoise none|wavelet|atrous] [--grey-diffuse] [--write-depth]');
+ throw new RangeError('Usage: node bench/cycles-parity/trace-native.mjs <sceneJsonPath> <outputPrefix> [--kernel legacy|cycles] [--samples 256] [--bounces 8] [--transparent-bounces 8] [--seed 1] [--width 960] [--height 540] [--sampler white|sobol-burley] [--light-sampling auto|tree|uniform] [--path-regeneration] [--env-compensation 0..1] [--filter-type box|gaussian|blackman-harris] [--filter-width 1.0] [--clamp-direct 0] [--clamp-indirect 0] [--firefly-clamp 1e9] [--noise-threshold 0] [--denoise none|wavelet|atrous] [--oidn-devices cpu,cuda] [--grey-diffuse] [--write-depth]');
}
return {
sceneJsonPath: resolve(argumentList[0]),
@@ -131,6 +143,7 @@ function parseTraceArguments(argumentList) {
fireflyClamp: parseNumberOption(argumentList, '--firefly-clamp', 1e9, 0),
noiseThreshold: parseNumberOption(argumentList, '--noise-threshold', 0, 0),
denoise: parseDenoiseOption(argumentList),
+ oidnDevices: parseOidnDevicesOption(argumentList),
samplesPerDispatch: argumentList.includes('--samples-per-dispatch')
? parseIntegerOption(argumentList, '--samples-per-dispatch', 16, 1)
: undefined,
@@ -193,6 +206,38 @@ function applyWavelet(traced, linearRgb, width, height) {
return { image: result, seconds, replacedPixels };
}
+/**
+ * Comparison runs only: runs the OIDN addon (packages/denoise-oidn, the official oidnDenoise tool through PFM files) on the
+ * traced colour with the kernel's first-hit albedo and normal guides, once per device, and writes each result to
+ * <prefix>.oidn-<device>.npy. The seconds are a second, warm call as the addon is built (PFM write, tool start, weights
+ * load, filter, PFM read); the first call is reported apart.
+ */
+async function runOidnComparison(traced, linearRgb, options, outputPrefix) {
+ const albedo = traced.albedo;
+ const normal = new Float32Array(traced.normal);
+ normalizeNormals(normal);
+ const results = {};
+ for (const device of options.oidnDevices) {
+ const callOidn = () => denoiseWithOidn({ width: options.width, height: options.height, color: linearRgb, albedo, normal, device });
+ try {
+ const firstStarted = performance.now();
+ await callOidn();
+ const firstSeconds = (performance.now() - firstStarted) / 1000;
+ const started = performance.now();
+ const denoised = await callOidn();
+ results[device] = {
+ seconds: Number(((performance.now() - started) / 1000).toFixed(6)),
+ firstCallSeconds: Number(firstSeconds.toFixed(6)),
+ };
+ await writeFloat32Npy(`${outputPrefix}.oidn-${device}.npy`, denoised, [options.height, options.width, 3]);
+ } catch (error) {
+ // One failing device (for example CUDA missing in a container) must not lose the other variants of this trace.
+ results[device] = { error: String(error.message).slice(0, 600) };
+ }
+ }
+ return results;
+}
+
async function runCli() {
setPriority(0, constants.priority.PRIORITY_BELOW_NORMAL);
const options = parseTraceArguments(process.argv.slice(2));
@@ -246,6 +291,7 @@ async function runCli() {
if (unfilteredNpyPath) {
await writeFloat32Npy(unfilteredNpyPath, unfilteredRgb, [options.height, options.width, 3]);
}
+ const oidnTrial = options.oidnDevices.length > 0 ? await runOidnComparison(traced, unfilteredRgb, options, options.outputPrefix) : null;
const setupSeconds = sceneBuildSeconds + traced.setupSeconds + traced.compileSeconds + traced.uploadSeconds + traced.accelerationBuildSeconds;
// The depth buffer is the mean first-hit distance ALONG THE RAY (unit direction), 0 where the ray missed; Cycles' Z is
// the distance along the view axis. compare-depth.py converts. Cook's film averages over all samples, misses included.
@@ -289,6 +335,7 @@ async function runCli() {
denoiseGpuSeconds: Number((traced.denoiseGpuSeconds ?? 0).toFixed(6)),
denoiseCompileSeconds: Number((traced.denoiseCompileSeconds ?? 0).toFixed(6)),
denoiseNonFinitePixelsReplaced: wavelet ? wavelet.replacedPixels : 0,
+ oidnTrial,
triangleCount: nativeInput.triangleCount,
adapter: traced.adapter,
backend: traced.backend,
diff --git a/docs/cook-denoised-comparison.jpg b/docs/cook-denoised-comparison.jpg
new file mode 100644
index 00000000..bdf0f9b6
Binary files /dev/null and b/docs/cook-denoised-comparison.jpg differ
diff --git a/docs/cycles-parity.md b/docs/cycles-parity.md
index 1ede5ed4..5ed4280e 100644
--- a/docs/cycles-parity.md
+++ b/docs/cycles-parity.md
@@ -605,6 +605,143 @@ The all-steps time is 8 to 9 ms on an NVIDIA A10 (section above) and 13 to 14 ms
![lit-interior and many-lights-500 at 64 spp: Cook unfiltered, Cook with the a-trous filter, Cycles 4096 spp](cook-atrous-comparison.jpg)
+## Denoised Cook against denoised Cycles (#897)
+
+The raw 64 spp images are noisy; the question here is how the finished image compares. Cook (`--kernel cycles`, defaults: no path regeneration, no environment compensation) is compared with Blender Cycles 5.3.0 OptiX, both raw and denoised, on four scenes at 16, 64 and 256 spp. `[measured]`
+
+**Setup.** One Modal container on an NVIDIA A10 (driver 610.57, card pinned), `960 x 540`, 8 bounces, seed 3 for both renderers (the references are Cycles 4096 spp seed 1), two rounds, medians of the two rounds. Modal preempted the first container once and restarted the function with the same input; the numbers come from the complete restarted run (144 rows, none failed). The variants:
+
+- **Cook raw**, **Cook + a-trous** (`denoise: 'atrous'`, the GPU filter of the section above) and **Cook + OIDN**: one trace gives all three images from the same samples. OIDN 2.5.1 runs through `packages/denoise-oidn` (`oidnDenoise`, HDR mode, quality high) on the kernel's first-hit albedo and normal buffers, on the CUDA device; the CPU device is listed too. The denoise seconds are a warm second call and include what the addon does around the filter (PFM files written and read, process start, weights load).
+- **Cycles raw** and **Cycles + OIDN**: two renders per rung with the same seed. The denoised one sets `denoiser = OPENIMAGEDENOISE`, albedo and normal passes, prefilter accurate and GPU denoising explicitly, so the result does not depend on which denoiser is the default (which one it is on 5.3 was not checked). Cycles denoises inside its render call, so its denoise seconds are the time from first sample to end of call of the denoised render minus the same time of the raw render of that rung and round; its sampling seconds are those of the raw render. Every Cycles + OIDN row ran the GPU denoiser.
+- Error is relMSE (epsilon 0.01) and mean ratio against the Cycles 4096 spp seed 1 reference; FLIP is the LDR mean from round 1 (sRGB, exposure set from the reference). Total seconds are sampling plus denoise, scene build and shader compile excluded.
+
+| scene | spp | variant | sampling s | denoise s | total s | relMSE | FLIP | mean ratio |
+| --- | ---: | --- | ---: | ---: | ---: | ---: | ---: | ---: |
+| glass | 16 | cook-raw | 0.27 | 0.00 | 0.27 | 0.00424 | 0.030 | 0.999 |
+| glass | 16 | cook-atrous | 0.27 | 0.01 | 0.28 | 0.000754 | 0.023 | 0.995 |
+| glass | 16 | cook-oidn-cuda | 0.27 | 0.65 | 0.92 | 0.000275 | 0.022 | 0.995 |
+| glass | 16 | cook-oidn-cpu | 0.27 | 0.61 | 0.88 | 0.000273 | 0.021 | 0.995 |
+| glass | 16 | cycles-raw | 0.11 | 0.00 | 0.11 | 0.0117 | 0.045 | 1.000 |
+| glass | 16 | cycles-oidn | 0.11 | 0.07 | 0.18 | 0.000216 | 0.019 | 0.998 |
+| glass | 64 | cook-raw | 0.48 | 0.00 | 0.48 | 0.000962 | 0.018 | 0.998 |
+| glass | 64 | cook-atrous | 0.48 | 0.01 | 0.49 | 0.000398 | 0.018 | 0.996 |
+| glass | 64 | cook-oidn-cuda | 0.48 | 0.72 | 1.20 | 0.000168 | 0.019 | 0.996 |
+| glass | 64 | cook-oidn-cpu | 0.48 | 0.53 | 1.01 | 0.000165 | 0.018 | 0.996 |
+| glass | 64 | cycles-raw | 0.39 | 0.00 | 0.39 | 0.0025 | 0.024 | 0.999 |
+| glass | 64 | cycles-oidn | 0.39 | 0.08 | 0.47 | 0.000119 | 0.016 | 1.000 |
+| glass | 256 | cook-raw | 1.89 | 0.00 | 1.89 | 0.000265 | 0.013 | 0.999 |
+| glass | 256 | cook-atrous | 1.89 | 0.01 | 1.89 | 0.000231 | 0.015 | 0.997 |
+| glass | 256 | cook-oidn-cuda | 1.89 | 0.35 | 2.23 | 0.000117 | 0.017 | 0.998 |
+| glass | 256 | cook-oidn-cpu | 1.89 | 0.23 | 2.11 | 0.000114 | 0.016 | 0.998 |
+| glass | 256 | cycles-raw | 1.50 | 0.00 | 1.50 | 0.000532 | 0.014 | 1.000 |
+| glass | 256 | cycles-oidn | 1.50 | 0.12 | 1.62 | 9.71e-05 | 0.014 | 1.000 |
+| lit-interior | 16 | cook-raw | 0.34 | 0.00 | 0.34 | 0.0653 | 0.142 | 1.003 |
+| lit-interior | 16 | cook-atrous | 0.34 | 0.01 | 0.35 | 0.00157 | 0.095 | 0.975 |
+| lit-interior | 16 | cook-oidn-cuda | 0.34 | 0.72 | 1.05 | 0.000319 | 0.040 | 0.997 |
+| lit-interior | 16 | cook-oidn-cpu | 0.34 | 0.23 | 0.57 | 0.000319 | 0.040 | 0.997 |
+| lit-interior | 16 | cycles-raw | 0.24 | 0.00 | 0.24 | 0.0702 | 0.152 | 1.000 |
+| lit-interior | 16 | cycles-oidn | 0.24 | 0.10 | 0.34 | 0.000294 | 0.042 | 0.998 |
+| lit-interior | 64 | cook-raw | 0.77 | 0.00 | 0.77 | 0.0128 | 0.076 | 1.003 |
+| lit-interior | 64 | cook-atrous | 0.77 | 0.01 | 0.78 | 0.000421 | 0.037 | 0.997 |
+| lit-interior | 64 | cook-oidn-cuda | 0.77 | 0.35 | 1.12 | 0.000219 | 0.028 | 1.002 |
+| lit-interior | 64 | cook-oidn-cpu | 0.77 | 0.22 | 0.99 | 0.000218 | 0.028 | 1.002 |
+| lit-interior | 64 | cycles-raw | 0.86 | 0.00 | 0.86 | 0.0148 | 0.082 | 1.000 |
+| lit-interior | 64 | cycles-oidn | 0.86 | 0.11 | 0.97 | 0.000207 | 0.028 | 0.998 |
+| lit-interior | 256 | cook-raw | 3.12 | 0.00 | 3.12 | 0.00274 | 0.040 | 1.003 |
+| lit-interior | 256 | cook-atrous | 3.12 | 0.01 | 3.13 | 0.000232 | 0.023 | 1.002 |
+| lit-interior | 256 | cook-oidn-cuda | 3.12 | 0.46 | 3.58 | 0.000184 | 0.023 | 1.002 |
+| lit-interior | 256 | cook-oidn-cpu | 3.12 | 0.33 | 3.45 | 0.000182 | 0.022 | 1.002 |
+| lit-interior | 256 | cycles-raw | 3.44 | 0.00 | 3.44 | 0.0031 | 0.043 | 1.000 |
+| lit-interior | 256 | cycles-oidn | 3.44 | 0.13 | 3.58 | 0.000171 | 0.021 | 1.000 |
+| many-lights-500 | 16 | cook-raw | 0.91 | 0.00 | 0.91 | 0.128 | 0.176 | 1.001 |
+| many-lights-500 | 16 | cook-atrous | 0.91 | 0.01 | 0.92 | 0.00225 | 0.084 | 0.971 |
+| many-lights-500 | 16 | cook-oidn-cuda | 0.91 | 0.36 | 1.28 | 0.000741 | 0.047 | 0.997 |
+| many-lights-500 | 16 | cook-oidn-cpu | 0.91 | 0.22 | 1.14 | 0.000743 | 0.047 | 0.997 |
+| many-lights-500 | 16 | cycles-raw | 0.78 | 0.00 | 0.78 | 0.117 | 0.177 | 1.000 |
+| many-lights-500 | 16 | cycles-oidn | 0.78 | 0.07 | 0.85 | 0.000622 | 0.044 | 1.000 |
+| many-lights-500 | 64 | cook-raw | 3.14 | 0.00 | 3.14 | 0.0306 | 0.105 | 1.001 |
+| many-lights-500 | 64 | cook-atrous | 3.14 | 0.01 | 3.15 | 0.0009 | 0.044 | 0.991 |
+| many-lights-500 | 64 | cook-oidn-cuda | 3.14 | 0.36 | 3.50 | 0.000559 | 0.034 | 1.000 |
+| many-lights-500 | 64 | cook-oidn-cpu | 3.14 | 0.22 | 3.36 | 0.000559 | 0.034 | 1.000 |
+| many-lights-500 | 64 | cycles-raw | 2.99 | 0.00 | 2.99 | 0.0279 | 0.101 | 1.000 |
+| many-lights-500 | 64 | cycles-oidn | 2.99 | 0.08 | 3.08 | 0.000503 | 0.032 | 1.000 |
+| many-lights-500 | 256 | cook-raw | 12.31 | 0.00 | 12.31 | 0.00763 | 0.058 | 1.001 |
+| many-lights-500 | 256 | cook-atrous | 12.31 | 0.01 | 12.32 | 0.000568 | 0.029 | 0.998 |
+| many-lights-500 | 256 | cook-oidn-cuda | 12.31 | 0.37 | 12.68 | 0.00048 | 0.027 | 1.001 |
+| many-lights-500 | 256 | cook-oidn-cpu | 12.31 | 0.22 | 12.53 | 0.00048 | 0.027 | 1.002 |
+| many-lights-500 | 256 | cycles-raw | 11.86 | 0.00 | 11.86 | 0.00698 | 0.055 | 1.000 |
+| many-lights-500 | 256 | cycles-oidn | 11.86 | 0.13 | 11.98 | 0.000453 | 0.025 | 1.000 |
+| outdoor-hdri | 16 | cook-raw | 0.17 | 0.00 | 0.17 | 0.00117 | 0.016 | 1.000 |
+| outdoor-hdri | 16 | cook-atrous | 0.17 | 0.01 | 0.18 | 5.02e-05 | 0.011 | 1.000 |
+| outdoor-hdri | 16 | cook-oidn-cuda | 0.17 | 0.37 | 0.53 | 4.66e-05 | 0.016 | 0.999 |
+| outdoor-hdri | 16 | cook-oidn-cpu | 0.17 | 0.22 | 0.39 | 4.41e-05 | 0.015 | 0.999 |
+| outdoor-hdri | 16 | cycles-raw | 0.07 | 0.00 | 0.07 | 0.00591 | 0.029 | 1.000 |
+| outdoor-hdri | 16 | cycles-oidn | 0.07 | 0.07 | 0.14 | 3.96e-05 | 0.015 | 1.000 |
+| outdoor-hdri | 64 | cook-raw | 0.15 | 0.00 | 0.15 | 0.000198 | 0.010 | 1.000 |
+| outdoor-hdri | 64 | cook-atrous | 0.15 | 0.01 | 0.16 | 2.11e-05 | 0.009 | 1.000 |
+| outdoor-hdri | 64 | cook-oidn-cuda | 0.15 | 0.36 | 0.51 | 2.35e-05 | 0.013 | 0.999 |
+| outdoor-hdri | 64 | cook-oidn-cpu | 0.15 | 0.22 | 0.38 | 2.13e-05 | 0.012 | 0.999 |
+| outdoor-hdri | 64 | cycles-raw | 0.24 | 0.00 | 0.24 | 0.00118 | 0.015 | 1.000 |
+| outdoor-hdri | 64 | cycles-oidn | 0.24 | 0.09 | 0.32 | 2.19e-05 | 0.014 | 1.000 |
+| outdoor-hdri | 256 | cook-raw | 0.58 | 0.00 | 0.58 | 5.05e-05 | 0.008 | 1.000 |
+| outdoor-hdri | 256 | cook-atrous | 0.58 | 0.01 | 0.58 | 1.02e-05 | 0.008 | 1.000 |
+| outdoor-hdri | 256 | cook-oidn-cuda | 0.58 | 0.40 | 0.97 | 1.37e-05 | 0.012 | 0.999 |
+| outdoor-hdri | 256 | cook-oidn-cpu | 0.58 | 0.22 | 0.80 | 1.19e-05 | 0.011 | 1.000 |
+| outdoor-hdri | 256 | cycles-raw | 0.89 | 0.00 | 0.89 | 0.000169 | 0.009 | 1.000 |
+| outdoor-hdri | 256 | cycles-oidn | 0.89 | 0.10 | 0.99 | 1.29e-05 | 0.013 | 1.000 |
+
+The picture is `many-lights-500` at 64 spp. Top row: Cook raw, Cook + OIDN, Cycles + OIDN, Cycles 4096 spp. Bottom row: the same images cropped at 240 x 135 pixels around a door edge, a box and a sphere, enlarged 2x with nearest-neighbour pixels. Labels give relMSE and total seconds.
+
+![many-lights-500 at 64 spp: Cook raw, Cook + OIDN, Cycles + OIDN, Cycles 4096 spp, with a 2x crop](cook-denoised-comparison.jpg)
+
+**Where Cook's denoised image is better or cheaper.**
+
+- Raw Cook is the cheaper estimate at defaults on `lit-interior` at 256 spp (3.12 s against 3.44 s) and on `outdoor-hdri` (0.58 s against 0.89 s at 256 spp); at equal total seconds its raw relMSE is 0.33 to 0.76 times that of raw Cycles on `glass`, `lit-interior` and `outdoor-hdri`.
+- The a-trous filter costs 0.01 s against 0.07 to 0.13 s for Cycles' OIDN and 0.35 to 0.7 s for the OIDN addon call, and it brings relMSE down by about 30 times at 64 spp on `lit-interior` and `many-lights-500`.
+- Where the image is smooth, Cook + OIDN and Cycles + OIDN are the same: on `many-lights-500` at 64 spp, in the flattest 70 percent of pixels (lowest reference gradient), relMSE is 0.00046 against 0.00043 and the mean ratio 1.0006 against 0.9991. FLIP at 64 spp is 0.034 against 0.032 (`many-lights-500`), 0.028 against 0.028 (`lit-interior`), 0.019 against 0.016 (`glass`), 0.013 against 0.014 (`outdoor-hdri`).
+
+**Where Cook's denoised image is worse.**
+
+- Edges: on `many-lights-500` at 64 spp, in the 5 percent of pixels with the highest reference gradient, Cook + OIDN has relMSE 0.00153 against 0.00114 for Cycles + OIDN (34 percent higher), Cook + a-trous 0.00253 (2.2 times). One image, one seed; the cause (guide buffers, filter settings) was not investigated.
+- Mean shift: the a-trous filter darkens the image, mean ratio 0.971 to 0.975 at 16 spp and 0.991 to 0.997 at 64 spp on `lit-interior` and `many-lights-500` (the flat region of `many-lights-500` at 64 spp reads 0.9896). Cook + OIDN stays within 0.3 percent of the reference mean on `lit-interior` and `many-lights-500` (0.997 to 1.002) and reads 0.5 percent low on `glass` (0.995 to 0.998); Cycles + OIDN within 0.2 percent (0.998 to 1.000).
+- Cost of the OIDN step: 0.35 to 0.72 s through the addon (CUDA device; 0.22 to 0.61 s on the CPU device) against 0.07 to 0.13 s inside Cycles. The addon starts the `oidnDenoise` tool and moves the images through files, which Cycles does not; the difference is the integration, not the filter.
+- Texture detail was not measured: none of the four scenes carries an image texture. The reference noise floor (relMSE between two 4096 spp seeds, table above) is 0.000832 for `many-lights-500`, 0.00026 for `lit-interior` and 0.000058 for `glass`, so denoised relMSE values near or below those numbers cannot rank two denoisers; FLIP separates them better, and it shows them close.
+- Cook raw at defaults samples slower than Cycles on `glass` (1.89 s against 1.50 s at 256 spp) and `many-lights-500` (12.31 s against 11.86 s); `--path-regeneration` cuts that by 0.67 to 0.72 on three scenes (section above) but was not part of this run.
+
+**Equal total seconds** (relMSE interpolated log-log between the measured rungs at the budget named; the ratio is Cook over Cycles, above 1 means Cycles has the lower error):
+
+Cook + OIDN against Cycles + OIDN:
+
+- glass at 1.2 s: cook-oidn-cuda relMSE 0.000166, cycles-oidn relMSE 0.000102 (ratio 1.63)
+- lit-interior at 1.9 s: cook-oidn-cuda relMSE 0.000201, cycles-oidn relMSE 0.000187 (ratio 1.08)
+- many-lights-500 at 3.9 s: cook-oidn-cuda relMSE 0.000552, cycles-oidn relMSE 0.000494 (ratio 1.12)
+- outdoor-hdri at 0.7 s: cook-oidn-cuda relMSE 2.63e-05, cycles-oidn relMSE 1.51e-05 (ratio 1.74)
+
+Cook + a-trous against Cycles + OIDN:
+
+- glass at 0.7 s: cook-atrous relMSE 0.000351, cycles-oidn relMSE 0.000113 (ratio 3.12)
+- lit-interior at 1.0 s: cook-atrous relMSE 0.000372, cycles-oidn relMSE 0.000205 (ratio 1.81)
+- many-lights-500 at 3.3 s: cook-atrous relMSE 0.000884, cycles-oidn relMSE 0.0005 (ratio 1.77)
+- outdoor-hdri at 0.3 s: cook-atrous relMSE 2.4e-05, cycles-oidn relMSE 2.25e-05 (ratio 1.07)
+
+Cook raw against Cycles raw:
+
+- glass at 0.6 s: cook-raw relMSE 0.000738, cycles-raw relMSE 0.00143 (ratio 0.52)
+- lit-interior at 1.0 s: cook-raw relMSE 0.00932, cycles-raw relMSE 0.0122 (ratio 0.76)
+- many-lights-500 at 3.3 s: cook-raw relMSE 0.0292, cycles-raw relMSE 0.0254 (ratio 1.15)
+- outdoor-hdri at 0.3 s: cook-raw relMSE 0.000275, cycles-raw relMSE 0.000838 (ratio 0.33)
+
+For the same total seconds, the finished image of Cycles + OIDN has the lower error than Cook + OIDN on all four scenes (1.08 to 1.74 times), with a larger lead over Cook + a-trous (1.07 to 3.12 times at the budgets above). The OIDN gap is mostly the 0.3 s of the addon call: Cook samples as fast or faster on two of the four scenes at defaults, so a denoise step as cheap as Cycles' would close part of it. Both gaps sit where relMSE is near the reference noise floor, so read them with the FLIP column. Raw, Cook is ahead at equal seconds on three scenes and behind on `many-lights-500` (1.15).
+
+Commands (the Modal pipeline stays outside the repository; each step is a script in `bench/cycles-parity/`):
+
+```sh
+node bench/cycles-parity/trace-native.mjs <scene.json> <prefix> --kernel cycles --samples 64 --seed 3 --bounces 8 --denoise atrous --oidn-devices cuda,cpu
+blender -b --factory-startup --python bench/cycles-parity/render-cycles.py -- <scene.json> <prefix> --samples 64 --bounces 8 --seed 3 --denoise oidn-gpu
+uv run --no-project python bench/cycles-parity/summarize-denoised-comparison.py <rows.json>
+uv run --no-project --with numpy --with pillow python bench/cycles-parity/make-denoised-comparison-figure.py --rows <rows.json> --images <folder> --reference <reference.npy> --crop-x 300 --crop-y 255 --output docs/cook-denoised-comparison.jpg
+```
+
## Depth and grey-diffuse comparison (#896, slice C1a)
The Done-when item of #896 for the Classroom scene asks for two checks against Cycles with every material overridden to grey diffuse: the image-match gates and a depth pass that agrees on 99.9 percent of pixels. This slice adds the harness for both and proves it on two existing scenes; the Classroom scene itself is a later slice. Only `bench/`, `tests/` and this guide change.