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
+19
View File
@@ -131,6 +131,7 @@ export function defaultLocalLayer(kind: LocalMaskKind, index: number): LocalLaye
linear: { x1: 0.5, y1: 0.2, x2: 0.5, y2: 0.8 },
radial: { cx: 0.5, cy: 0.5, rx: 0.25, ry: 0.3 },
range: { enabled: false, lumaMin: 0, lumaMax: 100, hue: 30, hueRange: 180, satMin: 0 },
curve: identityCurve(),
adjust: defaultLocalAdjust(),
};
}
@@ -269,6 +270,23 @@ function rasterMask(input: unknown): RasterMask | undefined {
return { data: raw.data, width, height };
}
/**
* Per-mask curve points. Masks saved before the field existed have none, and
* they must come back as the identity rather than leaving the shader LUT row
* undefined.
*/
function localCurve(input: unknown): CurvePoint[] {
if (!Array.isArray(input)) return identityCurve();
const points: CurvePoint[] = [];
for (const raw of input.slice(0, 16)) {
if (!raw || typeof raw !== 'object') continue;
const point = raw as Partial<CurvePoint>;
points.push({ x: clamp01(num(point.x, 0, 0, 1)), y: clamp01(num(point.y, 0, 0, 1)) });
}
points.sort((a, b) => a.x - b.x);
return points.length >= 2 ? points : identityCurve();
}
function localLayers(input: unknown): LocalLayer[] {
if (!Array.isArray(input)) return [];
const out: LocalLayer[] = [];
@@ -311,6 +329,7 @@ function localLayers(input: unknown): LocalLayer[] {
hueRange: num(range.hueRange, 180, 0, 180),
satMin: num(range.satMin, 0, 0, 100),
},
curve: localCurve(layer.curve),
adjust: {
exposure: num(adjust.exposure, 0, -4, 4),
contrast: num(adjust.contrast, 0, -100, 100),