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:
@@ -304,6 +304,81 @@ try {
|
|||||||
const tintRim = pixelAt(0.25, 0.2 + dabRadiusY * 0.75);
|
const tintRim = pixelAt(0.25, 0.2 + dabRadiusY * 0.75);
|
||||||
const tintOutside = pixelAt(0.25, 0.2 + dabRadiusY * 1.15);
|
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({
|
pre.textContent = 'RESULT ' + JSON.stringify({
|
||||||
clipPixels,
|
clipPixels,
|
||||||
clipRed: near(clipPixels[0], RED_MARK),
|
clipRed: near(clipPixels[0], RED_MARK),
|
||||||
@@ -342,6 +417,28 @@ try {
|
|||||||
// coverage without depending on how dark the adjustment left the pixels.
|
// coverage without depending on how dark the adjustment left the pixels.
|
||||||
tintFollowsMask: tintCore[2] > tintRim[2] && tintRim[2] > tintOutside[2] + 5,
|
tintFollowsMask: tintCore[2] > tintRim[2] && tintRim[2] > tintOutside[2] + 5,
|
||||||
tintBounded: Math.abs(tintOutside[2] - dabOutsideSoft[2]) <= 1,
|
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.
|
// A hard dab covers the core, and even an 80 % feather stops at the rim.
|
||||||
dabCoreDarkened: dabHard[0] < 140,
|
dabCoreDarkened: dabHard[0] < 140,
|
||||||
dabSoftCoreDarkened: dabSoft[0] < 140,
|
dabSoftCoreDarkened: dabSoft[0] < 140,
|
||||||
@@ -572,6 +669,39 @@ async function main() {
|
|||||||
`render check: mask overlay core=${JSON.stringify(result.tintCore)}` +
|
`render check: mask overlay core=${JSON.stringify(result.tintCore)}` +
|
||||||
` rim=${JSON.stringify(result.tintRim)} outside=${JSON.stringify(result.tintOutside)}`,
|
` 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 (
|
if (
|
||||||
!result.dabCoreDarkened ||
|
!result.dabCoreDarkened ||
|
||||||
!result.dabSoftCoreDarkened ||
|
!result.dabSoftCoreDarkened ||
|
||||||
|
|||||||
@@ -267,6 +267,12 @@ export default function Develop({
|
|||||||
const [localBrush, setLocalBrush] = useState(72);
|
const [localBrush, setLocalBrush] = useState(72);
|
||||||
const [localHover, setLocalHover] = useState<{ x: number; y: number } | null>(null);
|
const [localHover, setLocalHover] = useState<{ x: number; y: number } | null>(null);
|
||||||
const [localDraft, setLocalDraft] = useState<LocalStroke | null>(null);
|
const [localDraft, setLocalDraft] = useState<LocalStroke | null>(null);
|
||||||
|
// The mask tint is a view aid, not an edit: it has its own toggle (O) and
|
||||||
|
// strength, and both are display preferences rather than catalog data.
|
||||||
|
const [maskOverlay, setMaskOverlay] = usePersistentState('develop.maskOverlay', true);
|
||||||
|
const [maskStrength, setMaskStrength] = usePersistentState('develop.maskStrength', 50);
|
||||||
|
// How the next mask gesture combines with the group: paint or erase.
|
||||||
|
const [localErase, setLocalErase] = useState(false);
|
||||||
const [lensCorrection, setLensCorrection] = useState<LensCorrection | null>(null);
|
const [lensCorrection, setLensCorrection] = useState<LensCorrection | null>(null);
|
||||||
const [lensSplit, setLensSplit] = useState(false);
|
const [lensSplit, setLensSplit] = useState(false);
|
||||||
const [lensSplitAt, setLensSplitAt] = useState(0.5);
|
const [lensSplitAt, setLensSplitAt] = useState(0.5);
|
||||||
@@ -597,11 +603,12 @@ export default function Develop({
|
|||||||
: view,
|
: view,
|
||||||
);
|
);
|
||||||
|
|
||||||
// The mask overlay is the baked mask itself, so it can only be shown when a
|
// The mask overlay is the baked mask itself, and it is a view toggle: off
|
||||||
// local layer is selected. The histogram ignores it: a tinted chart is not
|
// while holding \\ (before/after), while the mask tool is closed, or when
|
||||||
// a measurement of the photo.
|
// the user hides it. The histogram ignores it: a tinted chart is not a
|
||||||
|
// measurement of the photo.
|
||||||
const maskView =
|
const maskView =
|
||||||
showOriginal || !localMode
|
showOriginal || !localMode || !maskOverlay
|
||||||
? -1
|
? -1
|
||||||
: (edits.local ?? []).findIndex((layer) => layer.id === localSelected);
|
: (edits.local ?? []).findIndex((layer) => layer.id === localSelected);
|
||||||
|
|
||||||
@@ -627,6 +634,7 @@ export default function Develop({
|
|||||||
lens: showOriginal ? null : lensCorrection,
|
lens: showOriginal ? null : lensCorrection,
|
||||||
lensSplit: lensSplit && !showOriginal ? lensSplitAt : undefined,
|
lensSplit: lensSplit && !showOriginal ? lensSplitAt : undefined,
|
||||||
maskView,
|
maskView,
|
||||||
|
maskStrength: maskStrength / 100,
|
||||||
});
|
});
|
||||||
histRef.current = renderer.histogram;
|
histRef.current = renderer.histogram;
|
||||||
setHistVersion((v) => v + 1);
|
setHistVersion((v) => v + 1);
|
||||||
@@ -650,6 +658,8 @@ export default function Develop({
|
|||||||
lensSplitAt,
|
lensSplitAt,
|
||||||
localMode,
|
localMode,
|
||||||
localSelected,
|
localSelected,
|
||||||
|
maskOverlay,
|
||||||
|
maskStrength,
|
||||||
// Loading or clearing a printer profile changes the finish pass, and the
|
// 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.
|
// cube lives outside the edit record, so the redraw is keyed on it here.
|
||||||
proofProfile,
|
proofProfile,
|
||||||
@@ -1246,7 +1256,11 @@ export default function Develop({
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.currentTarget.setPointerCapture(e.pointerId);
|
e.currentTarget.setPointerCapture(e.pointerId);
|
||||||
if (activeComponent.kind === 'brush') {
|
if (activeComponent.kind === 'brush') {
|
||||||
const stroke: LocalStroke = { points: [p], size: localRadius(), erase: e.altKey };
|
const stroke: LocalStroke = {
|
||||||
|
points: [p],
|
||||||
|
size: localRadius(),
|
||||||
|
erase: e.altKey || localErase,
|
||||||
|
};
|
||||||
localDrag.current = { layerId: activeLocal.id, componentId: activeComponent.id, mode: 'brush', stroke };
|
localDrag.current = { layerId: activeLocal.id, componentId: activeComponent.id, mode: 'brush', stroke };
|
||||||
setLocalDraft(stroke);
|
setLocalDraft(stroke);
|
||||||
return;
|
return;
|
||||||
@@ -1381,9 +1395,16 @@ export default function Develop({
|
|||||||
setLocalComponentSelected(null);
|
setLocalComponentSelected(null);
|
||||||
setLocalMode(false);
|
setLocalMode(false);
|
||||||
setLocalDraft(null);
|
setLocalDraft(null);
|
||||||
|
setLocalErase(false);
|
||||||
localDrag.current = null;
|
localDrag.current = null;
|
||||||
}, [photo.id]);
|
}, [photo.id]);
|
||||||
|
|
||||||
|
// Leaving the mask tool drops the erase mode, so the next visit starts by
|
||||||
|
// painting rather than cutting holes into the mask.
|
||||||
|
useEffect(() => {
|
||||||
|
if (!localMode) setLocalErase(false);
|
||||||
|
}, [localMode]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!(edits.local ?? []).some((layer) => layer.id === localSelected)) {
|
if (!(edits.local ?? []).some((layer) => layer.id === localSelected)) {
|
||||||
setLocalSelected(null);
|
setLocalSelected(null);
|
||||||
@@ -1529,6 +1550,13 @@ export default function Develop({
|
|||||||
toggleLocalMode();
|
toggleLocalMode();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
} else if (e.key.toLowerCase() === 'o' && !e.metaKey && !e.ctrlKey && !e.altKey) {
|
||||||
|
// The mask tint is a view, so it can be hidden while painting or
|
||||||
|
// checking the photo underneath without leaving the mask tool.
|
||||||
|
if (localMode) {
|
||||||
|
setMaskOverlay((v) => !v);
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
} else if (e.key === 'Enter' && cropMode) {
|
} else if (e.key === 'Enter' && cropMode) {
|
||||||
setCropMode(false);
|
setCropMode(false);
|
||||||
} else if (e.key === 'Escape') {
|
} else if (e.key === 'Escape') {
|
||||||
@@ -2382,6 +2410,42 @@ export default function Develop({
|
|||||||
<span className="heal-read">{Math.round(activeComponent.feather)}%</span>
|
<span className="heal-read">{Math.round(activeComponent.feather)}%</span>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
<button
|
||||||
|
className={`heal-act ${(activeComponent.kind === 'brush' ? !localErase : activeComponent.mode !== 'subtract') ? 'on' : ''}`}
|
||||||
|
onClick={() => {
|
||||||
|
if (activeComponent.kind === 'brush') {
|
||||||
|
setLocalErase(false);
|
||||||
|
} else if (activeComponent.mode === 'subtract') {
|
||||||
|
patchComponent(activeLocal.id, activeComponent.id, { mode: 'add' }, 'Shape add');
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
title="Add to the mask (+)"
|
||||||
|
>
|
||||||
|
+
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={`heal-act ${(activeComponent.kind === 'brush' ? localErase : activeComponent.mode === 'subtract') ? 'on' : ''}`}
|
||||||
|
onClick={() => {
|
||||||
|
if (activeComponent.kind === 'brush') {
|
||||||
|
setLocalErase(true);
|
||||||
|
} else {
|
||||||
|
patchComponent(activeLocal.id, activeComponent.id, { mode: 'subtract' }, 'Shape subtract');
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={
|
||||||
|
activeComponent.kind !== 'brush' &&
|
||||||
|
activeLocal.components[0]?.id === activeComponent.id
|
||||||
|
}
|
||||||
|
title={
|
||||||
|
activeComponent.kind === 'brush'
|
||||||
|
? 'Erase from the mask (−)'
|
||||||
|
: activeLocal.components[0]?.id === activeComponent.id
|
||||||
|
? 'The first shape starts the mask, so it always adds'
|
||||||
|
: 'Subtract this shape from the mask (−)'
|
||||||
|
}
|
||||||
|
>
|
||||||
|
−
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
className="heal-act"
|
className="heal-act"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -2411,12 +2475,35 @@ export default function Develop({
|
|||||||
>
|
>
|
||||||
Clear
|
Clear
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
className={`heal-act ${maskOverlay ? 'on' : ''}`}
|
||||||
|
onClick={() => setMaskOverlay((v) => !v)}
|
||||||
|
title="Show or hide the mask tint (O)"
|
||||||
|
>
|
||||||
|
Mask
|
||||||
|
</button>
|
||||||
|
{maskOverlay && (
|
||||||
|
<>
|
||||||
|
<label className="heal-field">
|
||||||
|
Tint
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min={10}
|
||||||
|
max={100}
|
||||||
|
step={1}
|
||||||
|
value={maskStrength}
|
||||||
|
onChange={(e) => setMaskStrength(Number(e.target.value))}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<span className="heal-read">{Math.round(maskStrength)}%</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<button className="heal-act on" onClick={() => setLocalMode(false)}>
|
<button className="heal-act on" onClick={() => setLocalMode(false)}>
|
||||||
Done
|
Done
|
||||||
</button>
|
</button>
|
||||||
<span className="heal-tip">
|
<span className="heal-tip">
|
||||||
{activeComponent.kind === 'brush'
|
{activeComponent.kind === 'brush'
|
||||||
? 'Paint the mask · Alt paints an erase stroke · wheel sizes the brush'
|
? 'Paint the mask · − erases · Alt erases one stroke · wheel sizes the brush'
|
||||||
: activeComponent.kind === 'radial'
|
: activeComponent.kind === 'radial'
|
||||||
? 'Drag the centre or the edge handle · wheel zooms'
|
? 'Drag the centre or the edge handle · wheel zooms'
|
||||||
: 'Drag either end of the gradient'}
|
: 'Drag either end of the gradient'}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ const GROUPS: { title: string; rows: [string, string][] }[] = [
|
|||||||
['C', 'Crop & straighten'],
|
['C', 'Crop & straighten'],
|
||||||
['Q', 'Spot healing brush'],
|
['Q', 'Spot healing brush'],
|
||||||
['M', 'Edit the selected local mask'],
|
['M', 'Edit the selected local mask'],
|
||||||
|
['O', 'Show or hide the mask tint'],
|
||||||
['Enter', 'Apply the crop'],
|
['Enter', 'Apply the crop'],
|
||||||
['\\ (hold)', 'Before / after'],
|
['\\ (hold)', 'Before / after'],
|
||||||
['1 – 5', 'Star rating'],
|
['1 – 5', 'Star rating'],
|
||||||
|
|||||||
+64
-12
@@ -18,7 +18,11 @@ void main(){
|
|||||||
const GRADE_FRAG = `#version 300 es
|
const GRADE_FRAG = `#version 300 es
|
||||||
precision highp float;
|
precision highp float;
|
||||||
in vec2 v_uv;
|
in vec2 v_uv;
|
||||||
out vec4 outColor;
|
layout(location = 0) out vec4 outColor;
|
||||||
|
// Source coordinate that produced this pixel, written alongside the picture so
|
||||||
|
// later passes can read the source-space masks at the right place. Alpha is 1
|
||||||
|
// when the pixel is inside the cropped image and 0 on the letterbox.
|
||||||
|
layout(location = 1) out vec4 outMap;
|
||||||
|
|
||||||
uniform sampler2D u_src;
|
uniform sampler2D u_src;
|
||||||
uniform sampler2D u_curve;
|
uniform sampler2D u_curve;
|
||||||
@@ -79,6 +83,8 @@ uniform sampler2D u_masks2; // layers 5-8
|
|||||||
uniform int u_localCount;
|
uniform int u_localCount;
|
||||||
// Local mask overlay: index of the layer tinted over the picture, -1 = off.
|
// Local mask overlay: index of the layer tinted over the picture, -1 = off.
|
||||||
uniform float u_maskView;
|
uniform float u_maskView;
|
||||||
|
// Opacity of that tint, 0-1.
|
||||||
|
uniform float u_maskStrength;
|
||||||
uniform vec4 u_localAdj[8]; // exposure, contrast, temp, tint
|
uniform vec4 u_localAdj[8]; // exposure, contrast, temp, tint
|
||||||
uniform vec4 u_localAdj2[8]; // saturation, highlights, shadows, unused
|
uniform vec4 u_localAdj2[8]; // saturation, highlights, shadows, unused
|
||||||
uniform vec4 u_localAdj3[8]; // whites, blacks, vibrance, hue degrees
|
uniform vec4 u_localAdj3[8]; // whites, blacks, vibrance, hue degrees
|
||||||
@@ -280,6 +286,7 @@ vec2 warpGeometry(vec2 s){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
|
outMap = vec4(0.0);
|
||||||
// The eyedropper renders one pixel at an arbitrary point, so the mapping below
|
// The eyedropper renders one pixel at an arbitrary point, so the mapping below
|
||||||
// takes its coordinate from the uniform instead of the fragment position.
|
// takes its coordinate from the uniform instead of the fragment position.
|
||||||
vec2 outUv = u_pick > 0.5 ? u_pickUv : v_uv;
|
vec2 outUv = u_pick > 0.5 ? u_pickUv : v_uv;
|
||||||
@@ -322,6 +329,9 @@ void main(){
|
|||||||
: lensQ;
|
: lensQ;
|
||||||
}
|
}
|
||||||
vec2 uv = lensCoord;
|
vec2 uv = lensCoord;
|
||||||
|
// Hand the source coordinate to the passes that need source-space data (the
|
||||||
|
// local detail masks) instead of making them repeat this warp.
|
||||||
|
outMap = vec4(uv, 0.0, 1.0);
|
||||||
vec3 src;
|
vec3 src;
|
||||||
if (showLens && (u_lensFlags & 2) != 0) {
|
if (showLens && (u_lensFlags & 2) != 0) {
|
||||||
vec4 t = lensSample(u_lensTca, u_lensTcaSize, lensCoord);
|
vec4 t = lensSample(u_lensTca, u_lensTcaSize, lensCoord);
|
||||||
@@ -577,7 +587,11 @@ void main(){
|
|||||||
int mk = mv < 4 ? mv : mv - 4;
|
int mk = mv < 4 ? mv : mv - 4;
|
||||||
vec4 mtex = mv < 4 ? texture(u_masks, uv) : texture(u_masks2, uv);
|
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;
|
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);
|
srgb = mix(
|
||||||
|
srgb,
|
||||||
|
vec3(0.98, 0.72, 0.35),
|
||||||
|
clamp(cov, 0.0, 1.0) * clamp(u_maskStrength, 0.0, 1.0)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
outColor = vec4(clamp(srgb, 0.0, 1.0), 1.0);
|
outColor = vec4(clamp(srgb, 0.0, 1.0), 1.0);
|
||||||
@@ -609,6 +623,8 @@ uniform sampler2D u_blurBig;
|
|||||||
// grade pass. Amounts are added to the global sliders per pixel.
|
// grade pass. Amounts are added to the global sliders per pixel.
|
||||||
uniform sampler2D u_masks;
|
uniform sampler2D u_masks;
|
||||||
uniform sampler2D u_masks2;
|
uniform sampler2D u_masks2;
|
||||||
|
// Source coordinate of this output pixel, from the grade pass.
|
||||||
|
uniform sampler2D u_maskUv;
|
||||||
uniform int u_localCount;
|
uniform int u_localCount;
|
||||||
uniform vec4 u_localDetail[8]; // texture, clarity, dehaze, sharpen
|
uniform vec4 u_localDetail[8]; // texture, clarity, dehaze, sharpen
|
||||||
uniform vec4 u_localModes[8]; // x = add / subtract / intersect
|
uniform vec4 u_localModes[8]; // x = add / subtract / intersect
|
||||||
@@ -693,9 +709,14 @@ void main(){
|
|||||||
float localClarity = 0.0;
|
float localClarity = 0.0;
|
||||||
float localDehaze = 0.0;
|
float localDehaze = 0.0;
|
||||||
float localSharpen = 0.0;
|
float localSharpen = 0.0;
|
||||||
if (u_localCount > 0) {
|
// The masks are baked in source space, so read them through the source
|
||||||
vec4 maskA = texture(u_masks, v_uv);
|
// coordinate the grade pass wrote for this pixel: crop, straightening, zoom
|
||||||
vec4 maskB = texture(u_masks2, v_uv);
|
// and lens correction all move the mask along with the picture.
|
||||||
|
vec4 maskMap = texture(u_maskUv, v_uv);
|
||||||
|
if (u_localCount > 0 && maskMap.a > 0.5) {
|
||||||
|
vec2 maskUv = maskMap.rg;
|
||||||
|
vec4 maskA = texture(u_masks, maskUv);
|
||||||
|
vec4 maskB = texture(u_masks2, maskUv);
|
||||||
float prevMask = 1.0;
|
float prevMask = 1.0;
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
if (i >= u_localCount) break;
|
if (i >= u_localCount) break;
|
||||||
@@ -938,6 +959,8 @@ interface Target {
|
|||||||
h: number;
|
h: number;
|
||||||
/** Half-float pixels keep subtle gradients from banding between passes. */
|
/** Half-float pixels keep subtle gradients from banding between passes. */
|
||||||
float: boolean;
|
float: boolean;
|
||||||
|
/** Second colour attachment, e.g. the source-coordinate map of the grade. */
|
||||||
|
aux?: WebGLTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeHistogram(): Histogram {
|
function makeHistogram(): Histogram {
|
||||||
@@ -1656,12 +1679,13 @@ export class Renderer {
|
|||||||
this.proofLutOn = 1;
|
this.proofLutOn = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private makeTarget(w: number, h: number, float = this.floatTargets): Target {
|
private makeTarget(w: number, h: number, float = this.floatTargets, aux = false): Target {
|
||||||
const gl = this.gl;
|
const gl = this.gl;
|
||||||
const tex = gl.createTexture();
|
const tex = gl.createTexture();
|
||||||
const fbo = gl.createFramebuffer();
|
const fbo = gl.createFramebuffer();
|
||||||
if (!tex || !fbo) throw new Error('Unable to allocate render target');
|
if (!tex || !fbo) throw new Error('Unable to allocate render target');
|
||||||
gl.bindTexture(gl.TEXTURE_2D, tex);
|
const alloc = (texture: WebGLTexture) => {
|
||||||
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||||
if (float) {
|
if (float) {
|
||||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA16F, w, h, 0, gl.RGBA, gl.HALF_FLOAT, null);
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA16F, w, h, 0, gl.RGBA, gl.HALF_FLOAT, null);
|
||||||
} else {
|
} else {
|
||||||
@@ -1671,21 +1695,32 @@ export class Renderer {
|
|||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
||||||
|
};
|
||||||
|
alloc(tex);
|
||||||
|
const auxTex = aux ? gl.createTexture() : null;
|
||||||
|
if (aux && !auxTex) throw new Error('Unable to allocate render target');
|
||||||
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
|
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
|
||||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
|
||||||
|
if (auxTex) {
|
||||||
|
alloc(auxTex);
|
||||||
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT1, gl.TEXTURE_2D, auxTex, 0);
|
||||||
|
gl.drawBuffers([gl.COLOR_ATTACHMENT0, gl.COLOR_ATTACHMENT1]);
|
||||||
|
}
|
||||||
if (float && gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE) {
|
if (float && gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE) {
|
||||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||||
gl.deleteTexture(tex);
|
gl.deleteTexture(tex);
|
||||||
|
if (auxTex) gl.deleteTexture(auxTex);
|
||||||
gl.deleteFramebuffer(fbo);
|
gl.deleteFramebuffer(fbo);
|
||||||
throw new Error('Half-float render targets are unavailable');
|
throw new Error('Half-float render targets are unavailable');
|
||||||
}
|
}
|
||||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||||
return { tex, fbo, w, h, float };
|
return { tex, fbo, w, h, float, aux: auxTex ?? undefined };
|
||||||
}
|
}
|
||||||
|
|
||||||
private freeTarget(target?: Target) {
|
private freeTarget(target?: Target) {
|
||||||
if (!target) return;
|
if (!target) return;
|
||||||
this.gl.deleteTexture(target.tex);
|
this.gl.deleteTexture(target.tex);
|
||||||
|
if (target.aux) this.gl.deleteTexture(target.aux);
|
||||||
this.gl.deleteFramebuffer(target.fbo);
|
this.gl.deleteFramebuffer(target.fbo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1708,13 +1743,14 @@ export class Renderer {
|
|||||||
for (const useFloat of modes) {
|
for (const useFloat of modes) {
|
||||||
const made: Target[] = [];
|
const made: Target[] = [];
|
||||||
try {
|
try {
|
||||||
const mk = (mw: number, mh: number) => {
|
const mk = (mw: number, mh: number, extra = false) => {
|
||||||
const target = this.makeTarget(mw, mh, useFloat);
|
const target = this.makeTarget(mw, mh, useFloat, extra);
|
||||||
made.push(target);
|
made.push(target);
|
||||||
return target;
|
return target;
|
||||||
};
|
};
|
||||||
this.targets = {
|
this.targets = {
|
||||||
graded: mk(w, h),
|
// The grade also writes the source-coordinate map for the finish pass.
|
||||||
|
graded: mk(w, h, true),
|
||||||
smallA: mk(sw, sh),
|
smallA: mk(sw, sh),
|
||||||
smallB: mk(sw, sh),
|
smallB: mk(sw, sh),
|
||||||
bigA: mk(bw, bh),
|
bigA: mk(bw, bh),
|
||||||
@@ -1807,6 +1843,7 @@ export class Renderer {
|
|||||||
upscale: boolean,
|
upscale: boolean,
|
||||||
srcLod = 0,
|
srcLod = 0,
|
||||||
maskView = -1,
|
maskView = -1,
|
||||||
|
maskStrength = 0.5,
|
||||||
) {
|
) {
|
||||||
const g = this.grade;
|
const g = this.grade;
|
||||||
this.gl.useProgram(g.program);
|
this.gl.useProgram(g.program);
|
||||||
@@ -1895,6 +1932,7 @@ export class Renderer {
|
|||||||
g.i('u_localCount', localCount);
|
g.i('u_localCount', localCount);
|
||||||
// Only tint a layer that this edit actually has; -1 leaves the picture alone.
|
// Only tint a layer that this edit actually has; -1 leaves the picture alone.
|
||||||
g.f('u_maskView', maskView >= 0 && maskView < localCount ? maskView : -1);
|
g.f('u_maskView', maskView >= 0 && maskView < localCount ? maskView : -1);
|
||||||
|
g.f('u_maskStrength', clamp01(maskStrength));
|
||||||
for (let i = 0; i < localCount; i++) {
|
for (let i = 0; i < localCount; i++) {
|
||||||
const layer = edits.local[i];
|
const layer = edits.local[i];
|
||||||
g.v4i('u_localAdj', i, layer.adjust.exposure, layer.adjust.contrast, layer.adjust.temp, layer.adjust.tint);
|
g.v4i('u_localAdj', i, layer.adjust.exposure, layer.adjust.contrast, layer.adjust.temp, layer.adjust.tint);
|
||||||
@@ -1981,6 +2019,8 @@ export class Renderer {
|
|||||||
clipping?: 'highlights' | 'shadows';
|
clipping?: 'highlights' | 'shadows';
|
||||||
/** tint this local layer's baked mask over the picture; -1 or omitted = off */
|
/** tint this local layer's baked mask over the picture; -1 or omitted = off */
|
||||||
maskView?: number;
|
maskView?: number;
|
||||||
|
/** opacity of the mask tint, 0-1 (default 0.5) */
|
||||||
|
maskStrength?: number;
|
||||||
/** return the finished image as linear-space floats instead of drawing the canvas */
|
/** return the finished image as linear-space floats instead of drawing the canvas */
|
||||||
floatOut?: boolean;
|
floatOut?: boolean;
|
||||||
},
|
},
|
||||||
@@ -2025,7 +2065,16 @@ export class Renderer {
|
|||||||
const cropPxW = Math.max(1, bounds.w * crop.w);
|
const cropPxW = Math.max(1, bounds.w * crop.w);
|
||||||
const cropPxH = Math.max(1, bounds.h * crop.h);
|
const cropPxH = Math.max(1, bounds.h * crop.h);
|
||||||
const srcLod = Math.max(0, Math.log2(Math.max(cropPxW / w, cropPxH / h)));
|
const srcLod = Math.max(0, Math.log2(Math.max(cropPxW / w, cropPxH / h)));
|
||||||
this.bindGrade(edits, crop, valid, bounds, !!opts.upscale, srcLod, opts.maskView ?? -1);
|
this.bindGrade(
|
||||||
|
edits,
|
||||||
|
crop,
|
||||||
|
valid,
|
||||||
|
bounds,
|
||||||
|
!!opts.upscale,
|
||||||
|
srcLod,
|
||||||
|
opts.maskView ?? -1,
|
||||||
|
opts.maskStrength ?? 0.5,
|
||||||
|
);
|
||||||
this.drawQuad();
|
this.drawQuad();
|
||||||
|
|
||||||
// Passes 2-3: small blur (detail) and large blur (clarity) from the graded image
|
// Passes 2-3: small blur (detail) and large blur (clarity) from the graded image
|
||||||
@@ -2109,6 +2158,9 @@ export class Renderer {
|
|||||||
this.finish.f('u_detailScale', detailScale);
|
this.finish.f('u_detailScale', detailScale);
|
||||||
this.finish.tex('u_masks', this.maskTex, 3);
|
this.finish.tex('u_masks', this.maskTex, 3);
|
||||||
this.finish.tex('u_masks2', this.maskTex2, 4);
|
this.finish.tex('u_masks2', this.maskTex2, 4);
|
||||||
|
// Source coordinate per pixel, written by the grade pass. The masks are
|
||||||
|
// source-space, so local detail reads them through this instead of v_uv.
|
||||||
|
if (t.graded!.aux) this.finish.tex('u_maskUv', t.graded!.aux, 5);
|
||||||
const innerLayers = (edits.local ?? []).slice(0, MAX_LOCAL_LAYERS);
|
const innerLayers = (edits.local ?? []).slice(0, MAX_LOCAL_LAYERS);
|
||||||
this.finish.i('u_localCount', innerLayers.length);
|
this.finish.i('u_localCount', innerLayers.length);
|
||||||
for (let i = 0; i < innerLayers.length; i++) {
|
for (let i = 0; i < innerLayers.length; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user