diff --git a/scripts/render-check.mjs b/scripts/render-check.mjs index 78cecfb..0f0eb07 100644 --- a/scripts/render-check.mjs +++ b/scripts/render-check.mjs @@ -296,6 +296,13 @@ try { 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); + // The develop view tints the baked mask instead of redrawing the stroke, so + // the overlay has to follow the same coverage: strong in the core, a real + // gradient at the rim, and nothing at all outside the brush circle. + renderer.render(brushEdits(80), { width: w, height: h, maskView: 0 }); + const tintCore = pixelAt(0.25, 0.2); + const tintRim = pixelAt(0.25, 0.2 + dabRadiusY * 0.75); + const tintOutside = pixelAt(0.25, 0.2 + dabRadiusY * 1.15); pre.textContent = 'RESULT ' + JSON.stringify({ clipPixels, @@ -328,6 +335,13 @@ try { dabSoft, dabRimSoft, dabOutsideSoft, + tintCore, + tintRim, + tintOutside, + // Orange tint: blue is the channel the overlay pushes up, so it ranks the + // 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, // A hard dab covers the core, and even an 80 % feather stops at the rim. dabCoreDarkened: dabHard[0] < 140, dabSoftCoreDarkened: dabSoft[0] < 140, @@ -554,18 +568,26 @@ async function main() { ` outsideHard=${JSON.stringify(result.dabOutsideHard)} soft=${JSON.stringify(result.dabSoft)}` + ` rimSoft=${JSON.stringify(result.dabRimSoft)} outsideSoft=${JSON.stringify(result.dabOutsideSoft)}`, ); + console.log( + `render check: mask overlay core=${JSON.stringify(result.tintCore)}` + + ` rim=${JSON.stringify(result.tintRim)} outside=${JSON.stringify(result.tintOutside)}`, + ); if ( !result.dabCoreDarkened || !result.dabSoftCoreDarkened || !result.dabRimSmooth || !result.dabBoundedHard || - !result.dabBoundedSoft + !result.dabBoundedSoft || + !result.tintFollowsMask || + !result.tintBounded ) { 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)}).`, + `outsideSoft=${JSON.stringify(result.dabOutsideSoft)}, ` + + `tint=${JSON.stringify(result.tintCore)}/${JSON.stringify(result.tintRim)}/` + + `${JSON.stringify(result.tintOutside)}).`, ); return 1; } diff --git a/src/components/Develop.tsx b/src/components/Develop.tsx index 4d59c92..04b12d2 100644 --- a/src/components/Develop.tsx +++ b/src/components/Develop.tsx @@ -597,6 +597,14 @@ export default function Develop({ : view, ); + // The mask overlay is the baked mask itself, so it can only be shown when a + // local layer is selected. The histogram ignores it: a tinted chart is not + // a measurement of the photo. + const maskView = + showOriginal || !localMode + ? -1 + : (edits.local ?? []).findIndex((layer) => layer.id === localSelected); + try { renderer.setImage(bitmap, hdrSource); // "Show original" must show the untouched source, not the cleaned proxy. @@ -606,7 +614,7 @@ export default function Develop({ height: pxH, cropPreview: cropMode, // The histogram describes the whole photo, so it is only refreshed at fit. - histogram: !cropMode && !showOriginal && zoomFactor <= 1.0001, + histogram: !cropMode && !showOriginal && zoomFactor <= 1.0001 && maskView < 0, view: zoomFactor <= 1.0001 ? undefined : view, // Holding the grain still keeps the noise from crawling while a crop // handle moves; the new crop-relative scale applies on release. @@ -618,6 +626,7 @@ export default function Develop({ clipping: clipping ?? undefined, lens: showOriginal ? null : lensCorrection, lensSplit: lensSplit && !showOriginal ? lensSplitAt : undefined, + maskView, }); histRef.current = renderer.histogram; setHistVersion((v) => v + 1); @@ -639,6 +648,8 @@ export default function Develop({ lensCorrection, lensSplit, lensSplitAt, + localMode, + localSelected, // Loading or clearing a printer profile changes the finish pass, and the // cube lives outside the edit record, so the redraw is keyed on it here. proofProfile, @@ -2210,36 +2221,37 @@ export default function Develop({ /** Brush diameter in canvas pixels, for the stroke preview. */ const diameterPx = (r: number) => (r * 2 * bitmap.width * canvasW) / (frame.w * view.w); const feather = Math.max(0, Math.min(1, activeComponent.feather / 100)); - const strokes = localDraft - ? [...activeComponent.brush.strokes, localDraft] - : activeComponent.brush.strokes; + // Committed strokes are not redrawn here: the shader tints the + // baked mask, which is the real feathered shape. Only the stroke + // in progress is drawn, as a preview of what will be baked. + const draft = localDraft && localDraft.points.length ? localDraft : null; return ( {activeComponent.kind === 'brush' && - strokes.map((stroke, i) => { - if (!stroke.points.length) return null; - const points = stroke.points.map(marker).map((p) => `${p.x},${p.y}`).join(' '); - const width = Math.max(1, diameterPx(stroke.size)); + (() => { + if (!draft) return null; + const points = draft.points.map(marker).map((p) => `${p.x},${p.y}`).join(' '); + const width = Math.max(1, diameterPx(draft.size)); const core = Math.max(1, width * (1 - feather)); return ( - + {core < width - 0.5 && ( )} ); - })} + })()} {activeComponent.kind === 'radial' && (() => { const c = marker({ x: activeComponent.radial.cx, y: activeComponent.radial.cy }); const edge = marker({ diff --git a/src/gl/renderer.ts b/src/gl/renderer.ts index 2ac4728..1afffb8 100644 --- a/src/gl/renderer.ts +++ b/src/gl/renderer.ts @@ -77,6 +77,8 @@ uniform vec2 u_healSize[24]; uniform sampler2D u_masks; // layers 1-4 uniform sampler2D u_masks2; // layers 5-8 uniform int u_localCount; +// Local mask overlay: index of the layer tinted over the picture, -1 = off. +uniform float u_maskView; uniform vec4 u_localAdj[8]; // exposure, contrast, temp, tint uniform vec4 u_localAdj2[8]; // saturation, highlights, shadows, unused uniform vec4 u_localAdj3[8]; // whites, blacks, vibrance, hue degrees @@ -566,6 +568,18 @@ void main(){ } } + // Mask overlay: tint the baked shape, not a redrawn brush band. Reading the + // same source uv the adjustments use keeps the preview on the picture through + // crops, straightening, zoom and lens correction, and it shows the feather + // exactly as the mask stores it. + if (u_maskView >= 0.0 && u_localCount > 0) { + int mv = int(u_maskView + 0.5); + int mk = mv < 4 ? mv : mv - 4; + vec4 mtex = mv < 4 ? texture(u_masks, uv) : texture(u_masks2, uv); + float cov = mk == 0 ? mtex.r : mk == 1 ? mtex.g : mk == 2 ? mtex.b : mtex.a; + srgb = mix(srgb, vec3(0.98, 0.72, 0.35), clamp(cov, 0.0, 1.0) * 0.5); + } + outColor = vec4(clamp(srgb, 0.0, 1.0), 1.0); }`; @@ -1792,6 +1806,7 @@ export class Renderer { bounds: { w: number; h: number }, upscale: boolean, srcLod = 0, + maskView = -1, ) { const g = this.grade; this.gl.useProgram(g.program); @@ -1878,6 +1893,8 @@ export class Renderer { g.tex('u_masks2', this.maskTex2, 7); g.tex('u_localCurves', curveTex, 8); g.i('u_localCount', localCount); + // Only tint a layer that this edit actually has; -1 leaves the picture alone. + g.f('u_maskView', maskView >= 0 && maskView < localCount ? maskView : -1); for (let i = 0; i < localCount; i++) { const layer = edits.local[i]; g.v4i('u_localAdj', i, layer.adjust.exposure, layer.adjust.contrast, layer.adjust.temp, layer.adjust.tint); @@ -1920,6 +1937,7 @@ export class Renderer { // shows the Optics split. const split = this.lensSplit; this.lensSplit = -1; + // No mask overlay here: the eyedropper must read the photo, not the tint. this.bindGrade(edits, crop, valid, bounds, !!opts.upscale); this.lensSplit = split; this.grade.f('u_pick', 1); @@ -1961,6 +1979,8 @@ export class Renderer { clipPreview?: boolean; /** paint blown highlights or crushed shadows outside the range */ clipping?: 'highlights' | 'shadows'; + /** tint this local layer's baked mask over the picture; -1 or omitted = off */ + maskView?: number; /** return the finished image as linear-space floats instead of drawing the canvas */ floatOut?: boolean; }, @@ -2005,7 +2025,7 @@ export class Renderer { const cropPxW = Math.max(1, bounds.w * crop.w); const cropPxH = Math.max(1, bounds.h * crop.h); const srcLod = Math.max(0, Math.log2(Math.max(cropPxW / w, cropPxH / h))); - this.bindGrade(edits, crop, valid, bounds, !!opts.upscale, srcLod); + this.bindGrade(edits, crop, valid, bounds, !!opts.upscale, srcLod, opts.maskView ?? -1); this.drawQuad(); // Passes 2-3: small blur (detail) and large blur (clarity) from the graded image