Give every mask its own tone curve.

Local masks could only shift tone globally, so a burnt sky or a backlit face had
to fight the frame-wide sliders. Each mask now carries an RGB point curve,
applied to the masked pixels before the mask blend. All eight curves ride in one
256×8 LUT texture, so the grade shader needs a single extra sampler rather than
eight. Masks saved before this exist migrate to an identity curve, so old edits
keep their look; the render check fails if the curve stops reaching the grade,
and a unit test pins the LUT's identity, per-row isolation and monotonicity.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
2026-11-28 15:42:24 +00:00
parent 00e6fee9bd
commit acf582251f
6 changed files with 159 additions and 2 deletions
+31 -1
View File
@@ -96,7 +96,7 @@ const PAGE_HTML = `<!doctype html>
<script type="module">
import { parsePreview16 } from '/src/lib/preview16.ts';
import { Renderer } from '/src/gl/renderer.ts';
import { defaultEdits } from '/src/lib/edits.ts';
import { defaultEdits, defaultLocalLayer } from '/src/lib/edits.ts';
const pre = document.getElementById('out');
const half = (bits) => {
const s = bits >> 15 ? -1 : 1;
@@ -225,6 +225,20 @@ try {
renderer.render(shadowEdits, { width: w, height: h, clipping: 'shadows' });
const shadowDarkPixel = sampleBand(2);
// Per-mask curve: a radial covering the whole frame, first with an identity
// curve and then with one that halves the output. The mask must leave the
// frame alone with the identity curve and darken it with the real one.
const maskLayer = defaultLocalLayer('radial', 0);
maskLayer.feather = 0;
maskLayer.radial = { cx: 0.5, cy: 0.5, rx: 1.2, ry: 1.2 };
const maskedEdits = defaultEdits();
maskedEdits.local = [{ ...maskLayer, curve: [{ x: 0, y: 0 }, { x: 1, y: 1 }] }];
renderer.render(maskedEdits, { width: w, height: h });
const maskIdentityPixel = sampleBand(2);
maskedEdits.local = [{ ...maskLayer, curve: [{ x: 0, y: 0 }, { x: 1, y: 0.4 }] }];
renderer.render(maskedEdits, { width: w, height: h });
const maskCurvePixel = sampleBand(2);
pre.textContent = 'RESULT ' + JSON.stringify({
clipPixels,
clipRed: near(clipPixels[0], RED_MARK),
@@ -243,6 +257,10 @@ try {
shadowCyan: near(shadowPixels[3], [26, 217, 255]),
shadowFollowsExposure: near(shadowDarkPixel, [255, 255, 255]),
shadowDarkPixel,
maskIdentityPixel,
maskCurvePixel,
maskIdentityFlat: near(maskIdentityPixel, [61, 71, 89]),
maskCurveDarkens: maskCurvePixel[0] < maskIdentityPixel[0] * 0.75,
flagHonouredForBitmap: !same(proxyTop, proxyNoFlipTop),
proxyTop: +proxyTop.toFixed(4),
sidecarTop: +sideTop.toFixed(4),
@@ -397,6 +415,10 @@ async function main() {
` cyan=${JSON.stringify(result.shadowPixels[3])}` +
` | at -9EV the clean band is ${JSON.stringify(result.shadowDarkPixel)}`,
);
console.log(
`render check: mask curve identity=${JSON.stringify(result.maskIdentityPixel)}` +
` darkened=${JSON.stringify(result.maskCurvePixel)}`,
);
if (!result.matchTop || !result.matchBottom) {
console.error(
result.reversed
@@ -420,6 +442,14 @@ async function main() {
);
return 1;
}
if (!result.maskIdentityFlat || !result.maskCurveDarkens) {
console.error(
'render check FAILED: the per-mask curve is not reaching the grade ' +
`(identity=${JSON.stringify(result.maskIdentityPixel)}, ` +
`curve=${JSON.stringify(result.maskCurvePixel)}).`,
);
return 1;
}
if (!result.shadowFollowsExposure) {
console.error(
'render check FAILED: the shadow clipping overlay does not follow Exposure; ' +