Skip to content
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6d29e03
LR-BEHAV-RENDER-FIDELITY: process V8, Whites and the tone curves meas…
smi-leonivkovic Nov 10, 2026
b16fd0c
LR-BEHAV-RENDER-FIDELITY: doc comments for the V8 curve stage, Gap 3 …
smi-leonivkovic Nov 11, 2026
6cb4e5b
Merge remote-tracking branch 'origin/main' into lr-v8-tone
smi-leonivkovic Nov 11, 2026
815ebe6
LR-BEHAV-RENDER-FIDELITY: what's new names process 9 (#523)
smi-leonivkovic Nov 11, 2026
fc55dde
LR-BEHAV-RENDER-FIDELITY: review fixes: neutral-render claims, Whites…
smi-leonivkovic Nov 11, 2026
5154467
LR-BEHAV-RENDER-FIDELITY: review fixes: measured curve tables only at…
smi-leonivkovic Nov 11, 2026
b1f6a66
LR-EDIT-LIGHT-CURVE-PARAM: the parametric graph draws and drags the c…
smi-leonivkovic Nov 11, 2026
0bbd0fc
LR-BEHAV-RENDER-FIDELITY: review fixes: the chart tool refuses render…
smi-leonivkovic Nov 11, 2026
b0e9b29
Merge branch 'lr-v8-tone' into lr-v9-curve-graph
smi-leonivkovic Nov 11, 2026
6f565fe
LR-EDIT-LIGHT-CURVE-PARAM: review fixes: a graph drag searches the cu…
smi-leonivkovic Nov 11, 2026
a8b4d7e
LR-BEHAV-RENDER-FIDELITY: review fixes: the measured tables are read …
smi-leonivkovic Nov 11, 2026
0b26397
Merge branch 'lr-v8-tone' into lr-v9-curve-graph
smi-leonivkovic Nov 11, 2026
8bec5c5
LR-EDIT-LIGHT-CURVE-PARAM: review fixes: doc comments on the graph's …
smi-leonivkovic Nov 11, 2026
3437e59
Merge remote-tracking branch 'origin/main' into lr-v8-tone
smi-leonivkovic Nov 14, 2026
5ba1722
Merge branch 'lr-v8-tone' into lr-v9-curve-graph
smi-leonivkovic Nov 14, 2026
14909c4
curve_stage: say in apply's doc that values above white are added bac…
smi-leonivkovic Nov 18, 2026
f54fd34
LR-EDIT-LIGHT-CURVE-PARAM: the parametric graph's fix from #4126 land…
smi-leonivkovic Nov 20, 2026
03de271
Merge origin/main into lr-v8-tone
smi-leonivkovic Nov 20, 2026
789c1a0
LR-BEHAV-RENDER-FIDELITY: Whites and the parametric regions are a fit…
smi-leonivkovic Nov 24, 2026
7c0e8ea
Merge main into lr-v8-tone (#523)
smi-leonivkovic Dec 2, 2026
be29de8
Merge remote-tracking branch 'origin/main' into lr-v8-tone
smi-leonivkovic Dec 3, 2026
1f53475
test(curve): the drag test allows the framework's drag threshold, not…
smi-leonivkovic Dec 3, 2026
ff7529a
Merge main into lr-v8-tone: the series moves to process V18 (#523)
smi-leonivkovic Dec 3, 2026
a85845d
test(proraw): V18's curve stage leaves Whites to the ProRAW chain; V1…
smi-leonivkovic Dec 3, 2026
2722f97
fix(curve_stage): Refine Saturation restores the colour after Whites …
smi-leonivkovic Dec 3, 2026
5a58233
fix(curve_input): under V18 sample where the curve stage reads (#523)
smi-leonivkovic Dec 3, 2026
de0c5a8
fix(tools): the tone charts' manifest carries the tool's prefix and f…
smi-leonivkovic Dec 3, 2026
023c93c
test(gpu): the curve-input prefix test names V17, where the sample is…
smi-leonivkovic Dec 3, 2026
a8872ab
fix(curve_input): on ProRAW the sample's curve stage leaves Whites to…
smi-leonivkovic Dec 3, 2026
587ed53
docs: V17's Apple ProRAW uses its chain's fitted Whites, not V2 White…
smi-leonivkovic Dec 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions crates/develop/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,17 @@ pub enum Process {
/// V7, with the Highlights/Shadows base taken of log luminance without its fine detail (clamped
/// between a fine and a 3× wider median), so gaps in dark lettering aren't lifted into bright blocks.
V8,
/// V8, with Whites and the parametric curve measured against Lightroom, and the tone curves applied as
/// Lightroom does: Whites, the parametric and point curve hue-preserving in linear ProPhoto RGB, then the
/// red, green and blue curves per channel, before the colour stage (`lightcraft_pipeline::curve_stage`).
V9,
}

impl Process {
/// Every process, oldest first.
pub const ALL: [Process; 8] = [Process::V1, Process::V2, Process::V3, Process::V4, Process::V5, Process::V6, Process::V7, Process::V8];
pub const LATEST: Process = Process::V8;
pub const ALL: [Process; 9] =
[Process::V1, Process::V2, Process::V3, Process::V4, Process::V5, Process::V6, Process::V7, Process::V8, Process::V9];
pub const LATEST: Process = Process::V9;

pub const fn version(self) -> ProcessVersion {
match self {
Expand All @@ -119,6 +124,7 @@ impl Process {
Process::V6 => ProcessVersion(6),
Process::V7 => ProcessVersion(7),
Process::V8 => ProcessVersion(8),
Process::V9 => ProcessVersion(9),
}
}
}
Expand Down
35 changes: 21 additions & 14 deletions crates/gpu/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const FIELDS: &[(&str, usize)] = &[
("SRGB_OFF", 1),
("CURVE_OFF", 1),
("CURVES", 1),
("STAGE", 1),
("STAGE_OFF", 1),
("STAGE_REFINE", 1),
("GAIN", 1),
("EV", 1),
("AIR", 1),
Expand Down Expand Up @@ -197,21 +200,22 @@ pub fn finish_block(fp: &FinishParams, masks: &[[f32; MASK_TERMS]], present: &Pr
let srgb_off = aux.len();
aux.extend_from_slice(&srgb_lut()[..]);
let curve_off = aux.len();
if let Some(c) = &fp.curves {
for l in c {
if l.v.len() != CURVE_N as usize {
// a wrong-length curve would shift every later aux offset (CURVE_OFF, MASK_OFF and
// the mask terms that follow) and make the kernel read the wrong data. `fail()`
// records the failure on this thread so the render falls back to the CPU; the
// partial `(p, aux)` returned here is never bound to a pipeline.
fail(FailKind::Fatal, format!("curve table has {} entries, expected {}", l.v.len(), CURVE_N));
// `p` is only assembled below the curve loop, so an empty block is as good as any:
// the caller (render.rs) gates on `failed()` right after this returns and bails to
// the CPU fallback before indexing `p` or uploading `aux`.
return (Vec::new(), aux);
}
aux.extend_from_slice(&l.v);
let stage_off = curve_off + fp.curves.as_ref().map_or(0, |c| c.len() * CURVE_N as usize);
// process V9's stage (red, green, blue, then the base table) or the earlier processes' curves
let tables = fp.curves.iter().flatten().chain(fp.curve_stage.iter().flat_map(|c| c.chan.iter().chain([&c.base])));
for l in tables {
if l.v.len() != CURVE_N as usize {
// a wrong-length curve would shift every later aux offset (CURVE_OFF, MASK_OFF and
// the mask terms that follow) and make the kernel read the wrong data. `fail()`
// records the failure on this thread so the render falls back to the CPU; the
// partial `(p, aux)` returned here is never bound to a pipeline.
fail(FailKind::Fatal, format!("curve table has {} entries, expected {}", l.v.len(), CURVE_N));
// `p` is only assembled below the curve loop, so an empty block is as good as any:
// the caller (render.rs) gates on `failed()` right after this returns and bails to
// the CPU fallback before indexing `p` or uploading `aux`.
return (Vec::new(), aux);
}
aux.extend_from_slice(&l.v);
}
let mask_off = aux.len();
for m in masks {
Expand Down Expand Up @@ -258,6 +262,9 @@ pub fn finish_block(fp: &FinishParams, masks: &[[f32; MASK_TERMS]], present: &Pr
p.u("SRGB_OFF", srgb_off as u32);
p.u("CURVE_OFF", curve_off as u32);
p.b("CURVES", fp.curves.is_some());
p.b("STAGE", fp.curve_stage.is_some());
p.u("STAGE_OFF", stage_off as u32);
p.f("STAGE_REFINE", fp.curve_stage.as_ref().map_or(1.0, |c| c.refine));
p.f("REFINE_SAT", fp.refine_sat);
p.f("GAIN", fp.gain);
p.f("EV", fp.ev);
Expand Down
70 changes: 70 additions & 0 deletions crates/gpu/src/wgsl/finish.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,71 @@ fn light_ops(d: vec3<f32>) -> vec3<f32> {
return mul3(PRO_TO_2020, p);
}

// A table of process V9's curve stage (`Lut1::eval`) at offset `o` in `aux`.
fn stage_lut(o: u32, x: f32) -> f32 {
let f = clamp(x, 0.0, 1.0) * f32(CURVE_N - 1u);
let i = min(u32(f), CURVE_N - 2u);
let t = f - f32(i);
return aux[o + i] + (aux[o + i + 1u] - aux[o + i]) * t;
}

// `CurveStage::apply`: the base table on the largest and smallest channel of sRGB-encoded linear ProPhoto, the
// middle one keeping its place between them in linear light, then the red, green and blue curves per channel.
fn curve_stage(d: vec3<f32>) -> vec3<f32> {
let p = mul3(PRO_FROM_2020, d);
var pc = clamp(p, vec3<f32>(0.0), vec3<f32>(1.0));
var e = vec3<f32>(srgb_exact(pc.x), srgb_exact(pc.y), srgb_exact(pc.z));
var hi = 0u;
var lo = 0u;
for (var k = 1u; k < 3u; k++) {
if (e[k] > e[hi]) {
hi = k;
}
if (e[k] < e[lo]) {
lo = k;
}
}
let off = pu(F_STAGE_OFF);
let base = off + 3u * CURVE_N;
let la = srgb_linear(stage_lut(base, e[hi]));
let lb = srgb_linear(stage_lut(base, e[lo]));
let pa = pc[hi];
let pb = pc[lo];
var curved = vec3<f32>(0.0);
for (var k = 0u; k < 3u; k++) {
var t = 1.0;
if (pa > pb) {
t = (pc[k] - pb) / (pa - pb);
}
curved[k] = stage_lut(off + k * CURVE_N, srgb_exact(clamp(lb + (la - lb) * t, 0.0, 1.0)));
}
var q = vec3<f32>(0.0);
for (var k = 0u; k < 3u; k++) {
q[k] = srgb_linear(clamp(curved[k], 0.0, 1.0));
}
let rs = pf(F_STAGE_REFINE);
if (rs < 1.0) {
// the saturation back towards the input's, at the curves' luminance
let rr = refine_saturation(e, curved, rs);
var r = vec3<f32>(0.0);
for (var k = 0u; k < 3u; k++) {
r[k] = srgb_linear(clamp(rr[k], 0.0, 1.0));
}
let yq = dot(q, PRO_Y);
let yr = dot(r, PRO_Y);
q = r;
if (yr > 1e-6) {
q = r * (yq / yr);
}
}
for (var k = 0u; k < 3u; k++) {
if (p[k] > 1.0) {
q[k] += p[k] - 1.0;
}
}
return mul3(PRO_TO_2020, q);
}

fn band_weights(h: f32) -> array<f32, 8> {
var w: array<f32, 8>;
for (var i = 0u; i < 8u; i++) {
Expand Down Expand Up @@ -664,6 +729,11 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
d = light_ops(d);
}

// --- process V9: Whites and the tone curves
if (pu(F_STAGE) != 0u) {
d = curve_stage(d);
}

// --- colour
d = color_ops(d, lt[11], lt[12]);
if (tint_on) {
Expand Down
44 changes: 44 additions & 0 deletions crates/gpu/tests/it/equivalence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,50 @@ fn light_v3_operators_match() {
}
}

/// Process V9's curve stage: Whites, the parametric curve, the point curves and Refine Saturation, on a camera curve
/// and without one, in SDR and HDR.
#[test]
fn curve_stage_matches() {
if !gpu() {
return;
}
use lightcraft_geom::Point;
let src = scene(0, 960, 640);
let curve = lightcraft_pipeline::tone::CameraTone::new(std::array::from_fn(|i| {
let x = 0.004 * 1.18f32.powi(i as i32);
[x, 1.0 - (-2.0 * x).exp()]
}))
.unwrap();
let raw = SourceInfo { raw: true, camera_tone: Some(curve), ..Default::default() };
let req = RenderRequest::fit(720, 720);
let v9 = || DevelopSettings { process: Process::V9.version(), ..Default::default() };
for v in [-100.0, -30.0, 40.0, 100.0] {
let mut s = v9();
s.light.whites = v;
check(&format!("V9 Whites {v}"), &src, &raw, &s, &req);
}
let mut s = v9();
s.curve.highlights = -40.0;
s.curve.lights = 25.0;
s.curve.darks = -15.0;
s.curve.shadows = 30.0;
check("V9 parametric", &src, &raw, &s, &req);
s.curve.master = vec![Point { x: 0.0, y: 0.05 }, Point { x: 0.5, y: 0.55 }, Point { x: 1.0, y: 0.95 }];
s.curve.red = vec![Point { x: 0.0, y: 0.0 }, Point { x: 0.4, y: 0.5 }, Point { x: 1.0, y: 1.0 }];
s.curve.blue = vec![Point { x: 0.0, y: 0.1 }, Point { x: 1.0, y: 0.9 }];
s.light.whites = -25.0;
check("V9 curves", &src, &raw, &s, &req);
s.curve.refine_saturation = 30.0;
check("V9 Refine Saturation", &src, &raw, &s, &req);
check("V9 curves, no camera curve", &src, &SourceInfo::default(), &s, &req);
s.curve.split_mid = 40.0;
check("V9 other splits", &src, &raw, &s, &req);
s.curve.split_mid = 50.0;
s.hdr.enabled = true;
s.hdr.max_ev = 2.0;
check("V9 HDR preview", &src, &raw, &s, &req);
}

/// Issue #632: the Highlights / Shadows base of each process (V1: the edge-aware filter of log
/// luminance; V2 to V7: of its fine median, V8 on: of its detail-free plane, a radius that grows with the render) matches the CPU's, and
/// a warm cache never hands one process the other's base.
Expand Down
5 changes: 3 additions & 2 deletions crates/pipeline/src/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ pub const PARAM_LUT: usize = 1024;
/// The parametric (region) curve of a [`ToneCurve`]: the four region amounts, each a cosine bump
/// over its window between two splits, summed and then forced monotone.
///
/// This is the renderer's curve, not an approximation of it — both `curve_luts` in the pipeline
/// and the curve editor in the UI use this struct so they can never disagree.
/// This is the renderer's curve, not an approximation of it: processes V1 to V8 render it, and V9
/// renders it when the splits are moved. The curve editor draws it through
/// [`crate::curve_stage::ParametricGraph`], which picks the measured regions where V9 renders those.
#[derive(Clone, Debug)]
pub struct ParametricCurve {
/// The curve, sampled and already forced monotone.
Expand Down
Loading
Loading