Draw brush masks with a soft dab inside the brush circle.

Feathering blurred a copy of the stroke and unioned it with the hard
stroke, so coverage stayed at full strength across the whole stroke and
then continued as a halo past the brush outline. The adjustment visibly
spilled outside the brush circle and its rim read as a step rather than a
falloff.

Each stroke is now stamped with a dab that is solid out to 1 - feather of
its radius and fades to nothing at the rim, so the mask follows the brush
circle and softens smoothly at any size. The render gate measures the
dab's core, its rim and the area just outside the circle.
This commit is contained in:
2026-11-28 16:47:49 +00:00
parent 5c2903eeef
commit 69a327cd45
2 changed files with 101 additions and 26 deletions
+57
View File
@@ -271,6 +271,32 @@ try {
renderer.render(groupEdits, { width: w, height: h });
const maskGroupIntersectPixel = sampleBand(2);
// Brush masks are source-space and feather softens the rim inside the brush
// circle. The dab below has a radius of 0.08 of the frame width, so it spans
// 0.12 of the frame height; nothing outside that may be touched, even at a
// high feather, and the rim itself must be a gradient rather than a step.
const pixelAt = (fx, fy) => {
const px = new Uint8Array(4);
const py = h - 1 - Math.min(h - 1, Math.floor(fy * h));
viewGl.readPixels(Math.min(w - 1, Math.floor(fx * w)), py, 1, 1, viewGl.RGBA, viewGl.UNSIGNED_BYTE, px);
return [px[0], px[1], px[2]];
};
const dabRadiusY = 0.08 * (w / h);
const brushEdits = (feather) => {
const layer = defaultLocalLayer('brush', 0);
const shape = layer.components[0];
shape.feather = feather;
shape.brush.strokes = [{ points: [{ x: 0.25, y: 0.2 }], size: 0.08, erase: false }];
return { ...defaultEdits(), local: [{ ...layer, curve: darkCurve }] };
};
renderer.render(brushEdits(0), { width: w, height: h });
const dabHard = pixelAt(0.25, 0.2);
const dabOutsideHard = pixelAt(0.25, 0.2 + dabRadiusY * 1.15);
renderer.render(brushEdits(80), { width: w, height: h });
const dabSoft = pixelAt(0.25, 0.2);
const dabRimSoft = pixelAt(0.25, 0.2 + dabRadiusY * 0.75);
const dabOutsideSoft = pixelAt(0.25, 0.2 + dabRadiusY * 1.15);
pre.textContent = 'RESULT ' + JSON.stringify({
clipPixels,
clipRed: near(clipPixels[0], RED_MARK),
@@ -297,6 +323,17 @@ try {
maskGroupSubtractCleared: near(maskGroupSubtractPixel, maskIdentityPixel),
maskGroupIntersectPixel,
maskGroupIntersectDarkens: maskGroupIntersectPixel[0] < maskIdentityPixel[0] * 0.75,
dabHard,
dabOutsideHard,
dabSoft,
dabRimSoft,
dabOutsideSoft,
// A hard dab covers the core, and even an 80 % feather stops at the rim.
dabCoreDarkened: dabHard[0] < 140,
dabSoftCoreDarkened: dabSoft[0] < 140,
dabRimSmooth: dabRimSoft[0] > 140 && dabRimSoft[0] < 240,
dabBoundedHard: dabOutsideHard[0] > 240,
dabBoundedSoft: dabOutsideSoft[0] > 240,
flagHonouredForBitmap: !same(proxyTop, proxyNoFlipTop),
proxyTop: +proxyTop.toFixed(4),
sidecarTop: +sideTop.toFixed(4),
@@ -512,6 +549,26 @@ async function main() {
);
return 1;
}
console.log(
`render check: brush dab hard=${JSON.stringify(result.dabHard)}` +
` outsideHard=${JSON.stringify(result.dabOutsideHard)} soft=${JSON.stringify(result.dabSoft)}` +
` rimSoft=${JSON.stringify(result.dabRimSoft)} outsideSoft=${JSON.stringify(result.dabOutsideSoft)}`,
);
if (
!result.dabCoreDarkened ||
!result.dabSoftCoreDarkened ||
!result.dabRimSmooth ||
!result.dabBoundedHard ||
!result.dabBoundedSoft
) {
console.error(
'render check FAILED: the brush mask does not follow the brush circle ' +
`(hard=${JSON.stringify(result.dabHard)}, rim=${JSON.stringify(result.dabRimSoft)}, ` +
`outsideHard=${JSON.stringify(result.dabOutsideHard)}, ` +
`outsideSoft=${JSON.stringify(result.dabOutsideSoft)}).`,
);
return 1;
}
console.log(
'render check PASSED: proxy and sidecar share a row order and the clipping overlay names the channels.',
);