Make the mask tint a view toggle and mask local detail in source space

The mask overlay was always painted while the mask tool was open, at a fixed
strength; it is now a persisted view toggle (O or the Mask button) with its own
strength slider, so the photo underneath stays readable. The mask HUD also
gains + and - so a brush can erase and a shape can subtract without leaving the
canvas.

Local texture, clarity, dehaze and sharpen sampled the baked masks at the view
coordinate in the finish pass, so their coverage slid off the subject under a
crop or zoom. The grade pass now writes each pixel's source coordinate to a
second render target and the finish pass reads the masks through it, which also
follows straightening and lens correction.

The render gate checks the tint and a local dehaze amount through a quarter
frame crop and a synthetic lens warp, plus the tint strength and toggle.
This commit is contained in:
2026-11-28 17:39:31 +00:00
parent 46dcc231a7
commit fb43ca8e99
4 changed files with 297 additions and 27 deletions
+130
View File
@@ -304,6 +304,81 @@ try {
const tintRim = pixelAt(0.25, 0.2 + dabRadiusY * 0.75);
const tintOutside = pixelAt(0.25, 0.2 + dabRadiusY * 1.15);
// Source-space alignment. Masks are baked over the whole source, so a crop
// that keeps a dab in frame but moves it on screen must move its tint and
// its local detail with it: source (0.6, 0.4) inside a quarter-frame crop
// lands at screen (0.4, 0.6), and nothing may be tinted at (0.6, 0.4).
const cropRect = {
x: 0.5,
y: 0.25,
w: 0.25,
h: 0.25,
angle: 0,
quarter: 0,
aspect: 'original',
flipH: false,
flipV: false,
};
const dabEdits = (at, size, adjust) => {
const layer = defaultLocalLayer('brush', 0);
const shape = layer.components[0];
shape.feather = 0;
shape.brush.strokes = [{ points: [at], size, erase: false }];
return {
...defaultEdits(),
local: [{ ...layer, adjust: { ...layer.adjust, ...(adjust || {}) } }],
};
};
const cropped = { ...defaultEdits(), crop: cropRect };
renderer.render(cropped, { width: w, height: h });
const cropRef = pixelAt(0.4, 0.6);
const cropRefOff = pixelAt(0.6, 0.4);
const cropDab = dabEdits({ x: 0.6, y: 0.4 }, 0.02);
cropDab.crop = cropRect;
renderer.render(cropDab, { width: w, height: h, maskView: 0 });
const cropTintOn = pixelAt(0.4, 0.6);
const cropTintOff = pixelAt(0.6, 0.4);
// Same crop and dab, but as a local detail amount instead of a tint: the
// finish pass has to read the mask through the same source coordinate.
const cropDetail = dabEdits({ x: 0.6, y: 0.4 }, 0.02, { dehaze: 100 });
cropDetail.crop = cropRect;
renderer.render(cropDetail, { width: w, height: h });
const cropDetailOn = pixelAt(0.4, 0.6);
const cropDetailOff = pixelAt(0.6, 0.4);
// Tint strength and toggle: full strength must read stronger than the default
// half, and no maskView at all must leave the photo untouched.
renderer.render(brushEdits(80), { width: w, height: h, maskView: 0, maskStrength: 1 });
const tintFull = pixelAt(0.25, 0.2);
renderer.render(brushEdits(80), { width: w, height: h });
const tintOffPixel = pixelAt(0.25, 0.2);
// Lens warp: a geometry map that magnifies the centre by 1.6 puts the dab at
// source (0.7, 0.45) at screen (0.625, 0.469); its source uv must be clear.
const lensN = 33;
const lensData = new Float32Array(lensN * lensN * 4);
for (let ly = 0; ly < lensN; ly++) {
for (let lx = 0; lx < lensN; lx++) {
const i = (ly * lensN + lx) * 4;
lensData[i] = 0.5 + ((lx + 0.5) / lensN - 0.5) * 1.6;
lensData[i + 1] = 0.5 + ((ly + 0.5) / lensN - 0.5) * 1.6;
lensData[i + 2] = 0;
lensData[i + 3] = 1;
}
}
const lensWarp = {
key: 'render-check-warp',
scale: 1,
geometry: { data: lensData, width: lensN, height: lensN },
};
renderer.render(defaultEdits(), { width: w, height: h, lens: lensWarp });
const lensRef = pixelAt(0.625, 0.469);
const lensRefOff = pixelAt(0.7, 0.469);
const lensDab = dabEdits({ x: 0.7, y: 0.45 }, 0.04);
renderer.render(lensDab, { width: w, height: h, lens: lensWarp, maskView: 0 });
const lensTintOn = pixelAt(0.625, 0.469);
const lensTintOff = pixelAt(0.7, 0.469);
pre.textContent = 'RESULT ' + JSON.stringify({
clipPixels,
clipRed: near(clipPixels[0], RED_MARK),
@@ -342,6 +417,28 @@ try {
// coverage without depending on how dark the adjustment left the pixels.
tintFollowsMask: tintCore[2] > tintRim[2] && tintRim[2] > tintOutside[2] + 5,
tintBounded: Math.abs(tintOutside[2] - dabOutsideSoft[2]) <= 1,
cropRef,
cropRefOff,
cropTintOn,
cropTintOff,
cropDetailOn,
cropDetailOff,
lensRef,
lensRefOff,
lensTintOn,
lensTintOff,
tintFull,
tintOffPixel,
// The tint pushes red up hard on the dark mid band, so red ranks coverage.
cropTintAligned: cropTintOn[0] > cropRef[0] + 40,
cropTintBounded: Math.abs(cropTintOff[0] - cropRefOff[0]) <= 2,
// Local dehaze lifts the blue of that band, so blue marks where it landed.
cropDetailAligned: cropDetailOn[2] > cropDetailOff[2] + 10,
cropDetailBounded: Math.abs(cropDetailOff[2] - cropRefOff[2]) <= 3,
lensTintAligned: lensTintOn[0] > lensRef[0] + 40,
lensTintBounded: Math.abs(lensTintOff[0] - lensRefOff[0]) <= 2,
tintStrengthWorks: tintFull[2] > tintCore[2] + 8,
tintOffMatches: Math.abs(tintOffPixel[2] - dabSoft[2]) <= 1,
// A hard dab covers the core, and even an 80 % feather stops at the rim.
dabCoreDarkened: dabHard[0] < 140,
dabSoftCoreDarkened: dabSoft[0] < 140,
@@ -572,6 +669,39 @@ async function main() {
`render check: mask overlay core=${JSON.stringify(result.tintCore)}` +
` rim=${JSON.stringify(result.tintRim)} outside=${JSON.stringify(result.tintOutside)}`,
);
console.log(
`render check: crop mask tint on=${JSON.stringify(result.cropTintOn)}` +
` off=${JSON.stringify(result.cropTintOff)} ref=${JSON.stringify(result.cropRef)}` +
` | local detail on=${JSON.stringify(result.cropDetailOn)}` +
` off=${JSON.stringify(result.cropDetailOff)}`,
);
console.log(
`render check: lens mask tint on=${JSON.stringify(result.lensTintOn)}` +
` off=${JSON.stringify(result.lensTintOff)} ref=${JSON.stringify(result.lensRef)}` +
` | tint strength full=${JSON.stringify(result.tintFull)}` +
` half=${JSON.stringify(result.tintCore)}`,
);
if (
!result.cropTintAligned ||
!result.cropTintBounded ||
!result.cropDetailAligned ||
!result.cropDetailBounded ||
!result.lensTintAligned ||
!result.lensTintBounded ||
!result.tintStrengthWorks ||
!result.tintOffMatches
) {
console.error(
'render check FAILED: the local mask does not stay on its source pixels ' +
'through a crop or a lens warp ' +
`(crop tint ${JSON.stringify(result.cropTintOn)}/${JSON.stringify(result.cropTintOff)}` +
` vs ${JSON.stringify(result.cropRef)}, detail ` +
`${JSON.stringify(result.cropDetailOn)}/${JSON.stringify(result.cropDetailOff)}` +
`, lens tint ${JSON.stringify(result.lensTintOn)}/${JSON.stringify(result.lensTintOff)}` +
` vs ${JSON.stringify(result.lensRef)}).`,
);
return 1;
}
if (
!result.dabCoreDarkened ||
!result.dabSoftCoreDarkened ||