Let the tone curve continue past 1.0, and test that nothing clips

The tone curve clamped its input to [0, 1] and its output back to 1.0
around a 2.2 gamma, mid-chain — master and per-channel both. So any
edit with a curve made every scene value above 1.0 the same number
before the view transform ever saw it: D19's fourth finding. Beyond its
last point the curve now continues along its last span, whose secant
is the tangent the spline already gives that point, so the join is
smooth and an identity curve stays the identity to any height. The only
clamp left is the floor at zero, where there is no light to curve.

FR-DEV-2's acceptance test is how the rule stays true.
`scene_referred_until_the_view` wraps every point operation, at
non-neutral settings, between a gain of sixteen and one of a
sixty-fourth, with an identity in the view transform's place, and
renders a ramp from 0.4 to 15.2 times sensor saturation through it. The
output must still increase with the input and still separate the top of
the ramp. Run against the previous commit's tone curve it fails with
[21, 29, 33, 33, 33, 33, 33, 33]; every other operation already passed.
It renders on a device because dr-pipeline has none, and the spec's
pointer to it says so.
This commit is contained in:
2026-09-27 16:52:55 -04:00
parent 657f8f19ff
commit 0682d05f95
5 changed files with 265 additions and 30 deletions
+56 -19
View File
@@ -488,6 +488,36 @@ fn curve_eval(
}",
};
/// TRACES: FR-DEV-2
/// The curve continued past its last point, for scene values above the
/// widget's axis.
const CURVE_EXTEND: Helper = Helper {
name: "curve_extend",
source: "\
// A five-point curve at `x`, continued past its last point along the slope of
// its last span.
//
// The widget draws a 0..1 axis, and scene-referred values do not stop at 1
// (D19): exposure and highlight recovery put them above it, and the view
// transform after every operation is what brings them down. Flat past the last
// point — which is what `curve_eval` gives, and what this curve did until
// D19 — made every one of them the same number, a hard clip in the middle of
// the chain. Continued along the last span instead, an identity curve stays
// the identity to any height, and a curve that lifts the highlights keeps
// lifting them. The slope is the last span's secant, which is also the
// tangent `curve_eval` gives the last point, so the join is smooth; monotone
// points make it non-negative.
fn curve_extend(
x0: f32, y0: f32, x1: f32, y1: f32, x2: f32, y2: f32,
x3: f32, y3: f32, x4: f32, y4: f32, x: f32,
) -> f32 {
if (x <= x4) {
return curve_eval(x0, y0, x1, y1, x2, y2, x3, y3, x4, y4, x);
}
return y4 + (x - x4) * max((y4 - y3) / (x4 - x3), 0.0);
}",
};
/// One colour component through its own curve.
const CHANNEL_CURVE: Helper = Helper {
name: "channel_curve",
@@ -504,20 +534,21 @@ const CHANNEL_CURVE: Helper = Helper {
// it changes the proportions between the components, which is what makes it
// chromatic where the master is tonal.
//
// The clamp is the curve's promise rather than an oversight: its last point
// *is* white, so a component arriving above the axis takes the value the curve
// gives at 1. The master does the same to a luminance above 1, through the
// gain it applies; a channel curve that instead let highlights past unchanged
// would tint them differently from every tone below them, which reads as a
// coloured fringe along a blown edge.
// Above the axis the curve continues along its last span (`curve_extend`),
// exactly as the master's does, so a highlight is tinted the way every tone
// just below it is — a component that stopped at the curve's top instead
// would put a coloured fringe along a blown edge, and flattened every
// scene-referred highlight into one value besides (D19). Below zero there is
// no light to curve; the floor is the one clamp left, and it is at zero, not
// at one.
fn channel_curve(
v: f32,
x0: f32, y0: f32, x1: f32, y1: f32, x2: f32, y2: f32,
x3: f32, y3: f32, x4: f32, y4: f32,
) -> f32 {
let encoded = pow(clamp(v, 0.0, 1.0), 1.0 / 2.2);
let curved = curve_eval(x0, y0, x1, y1, x2, y2, x3, y3, x4, y4, encoded);
return pow(clamp(curved, 0.0, 1.0), 2.2);
let encoded = pow(max(v, 0.0), 1.0 / 2.2);
let curved = curve_extend(x0, y0, x1, y1, x2, y2, x3, y3, x4, y4, encoded);
return pow(max(curved, 0.0), 2.2);
}",
};
@@ -535,10 +566,11 @@ static MASTER_HELPERS: &[Helper] = &[
helpers::APPLY_TONE_GAIN,
CURVE_SPAN,
CURVE_EVAL,
CURVE_EXTEND,
];
/// The per-channel curves alone.
static CHANNEL_HELPERS: &[Helper] = &[CURVE_SPAN, CURVE_EVAL, CHANNEL_CURVE];
static CHANNEL_HELPERS: &[Helper] = &[CURVE_SPAN, CURVE_EVAL, CURVE_EXTEND, CHANNEL_CURVE];
/// Both.
static ALL_HELPERS: &[Helper] = &[
@@ -546,6 +578,7 @@ static ALL_HELPERS: &[Helper] = &[
helpers::APPLY_TONE_GAIN,
CURVE_SPAN,
CURVE_EVAL,
CURVE_EXTEND,
CHANNEL_CURVE,
];
@@ -553,16 +586,17 @@ static ALL_HELPERS: &[Helper] = &[
const MASTER_BODY: &str = "\
let luma = luminance(c);
if (luma > 0.0001) {
// The curve is authored on a display-referred 0..1 axis, which is where
// the eye reads tone and where the widget's grid lives. Scene-referred
// luminance is unbounded, so it is encoded to that axis, curved, and
// decoded back — otherwise a point placed at the middle of the grid
// would not correspond to the middle of the visible range.
let encoded = pow(clamp(luma, 0.0, 1.0), 1.0 / 2.2);
// The curve is authored on a 0..1 axis, which is where the widget's grid
// lives, with a 2.2 gamma so that a point placed at the middle of the
// grid means the middle of the visible range. Scene-referred luminance
// does not stop at 1: above the axis the curve continues along its last
// span (`curve_extend`) rather than clipping, because the view transform
// after every operation is what brings a highlight down (D19).
let encoded = pow(luma, 1.0 / 2.2);
let curved = curve_eval(x0, y0, x1, y1, x2, y2, x3, y3, x4, y4, encoded);
let curved = curve_extend(x0, y0, x1, y1, x2, y2, x3, y3, x4, y4, encoded);
let decoded = pow(clamp(curved, 0.0, 1.0), 2.2);
let decoded = pow(max(curved, 0.0), 2.2);
// Applied as a ratio so hue is preserved, exactly as contrast does.
c = apply_tone_gain(c, decoded / luma);
}";
@@ -1288,7 +1322,10 @@ mod tests {
c.set_param(P2_Y, 0.7);
let body = c.wgsl_body();
assert!(body.contains("curve_eval("), "the master curve is missing");
assert!(
body.contains("curve_extend("),
"the master curve is missing"
);
assert!(
!body.contains("channel_curve("),
"an untouched channel reached the shader:\n{body}"