Skip to content

Keep the sign of the spectral weight so dispersion fringes match Cycles (#50) - #53

Merged
anxuanng merged 1 commit into
mainfrom
50-dispersion-saturation
Nov 16, 2026
Merged

anxuanng merged 1 commit into
mainfrom
50-dispersion-saturation

Conversation

@anxuanng

Copy link
Copy Markdown
Contributor

Closes #50

Spectral colours lie outside the sRGB gamut, so the linear sRGB weight of one wavelength has negative lobes. Cook clamped the weight at zero, then clamped every sample again before the film, which dropped the lobes and pulled the fringes toward white. Cycles keeps them signed (its raw output has negative pixels). Now the weight keeps its sign and is divided by its signed mean over 400 to 700 nm, and a scene with dispersion accumulates negative channels. A scene without dispersion compiles the old sanitising.

Evidence

RTX 3060, 256 spp, Cook against Cycles 5.3 on the same scenes (tools/dispersion-parity*).

scene mean ratio R, G, B fringe colour Cook / Cycles ratio
prism-view before 0.991, 1.001, 1.000 0.309 / 0.463 0.67
prism-view after 0.998, 1.000, 0.998 0.438 / 0.463 0.94
gem before 1.094, 0.908, 0.980 0.760 / 0.841 0.90
gem after 1.039, 0.954, 0.919 0.967 / 0.841 1.15
gem, 1024 spp after 1.001, 0.996, 0.936 0.880 / 0.853 1.03

The gem at 256 spp is noisy (mean 0.014, a few bright pixels): at 1024 spp both renderers agree within 4 percent on fringe colour and the red to blue spread is -12.4 against -12.9 px. Other things tried on the prism view: widening the range to 380-780 nm changes nothing (0.668); signed weights with the per-sample clamp kept raise the fringe to 0.81 but the mean to 1.06 (gem red 1.43).

Cook on the left, Cycles on the right (before, then after):

prism before
prism after
gem before
gem after

Dispersion 0 is bit-identical: sha256 of the 256 spp raw render before and after is 40c14f86823b0468 for prism-view and 631b2734795f42e5 for gem (first 16 hex digits, same for both builds).

The image can now hold small negative values at the most saturated fringes (3 percent of the pixels in the Cycles prism-view render do too); the README says so, and an encoder clamps them.

How I checked it

  • node tools/dispersion-parity.mjs, tools/dispersion-parity-cycles.py (Blender 5.3) and tools/dispersion-parity-compare.py on prism-view and gem, before and after.
  • node --test: 182 pass. node tools/run-cargo-tests.mjs: 137 and 23 pass. Two kernel-text tests fail on a Windows checkout with CRLF line endings, with or without this change, and pass with LF.
  • New tests: the kernel weight is the signed mean-one weight, a blue wavelength has a negative green lobe, and the sanitising keeps a negative channel only behind SCENE_HAS_DISPERSION.
  • release-guard prints clean.

…es' saturation (#50)

The weight of a hero wavelength was its linear sRGB clamped at zero, and every sample was clamped again when it reached the film.
Spectral colours lie outside the sRGB gamut, so the negative lobes were dropped and the fringes drifted toward white (0.67x of
Cycles on the prism view). The weight now keeps its sign and is divided by the signed mean, and a dispersive scene accumulates
negative channels like Cycles does. A scene without dispersion compiles the old sanitising and renders bit for bit as before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dispersion fringes are less saturated than Cycles (0.67x on the prism view)

1 participant