From 43a2cfdf6d03323f4fbc1c02376f8d71a725e857 Mon Sep 17 00:00:00 2001 From: Justin Campos <20252457+juswus2000@users.noreply.github.com> Date: Sat, 10 Oct 2026 19:16:14 +0200 Subject: [PATCH] Bevel contour: drop the glow-style Range stretch (#2498) The bevel Contour element mapped the height through contour(min(v / range, 1)), the glow transfer. At the default 50 % range that flattened a Linear contour to a bevel half as wide as Photoshop's: on a real 18 px smooth inner bevel at 136 % depth the top-edge highlight was gone 15 px in, where Photoshop's is still 0.19 at 16 px. The contour alone matches that file (bad pixels 0.38 % -> 0.03 %, max error 63 -> 25 / 255) and lowers the bad pixels of every contour oracle (bevel-inner-contour-ramp-peak 25.9 -> 21.8 %, -double-ring-aa-r70 25.2 -> 21.0 %, bevel-pillow-chisel-hard-gloss-and-contour 11.4 -> 7.2 %); the other 23 bevel oracles are unchanged. What Range does instead is open. CPU (compose) and GPU (fx) share the new bevel_contour_lut. Co-authored-by: Justin Campos Co-authored-by: Claude Opus 5.5 --- crates/compose/src/effects.rs | 24 ++++++++++++++++++++++-- crates/gpu/src/fx.rs | 4 ++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/crates/compose/src/effects.rs b/crates/compose/src/effects.rs index e2ae63b5b71..c52b39dadff 100644 --- a/crates/compose/src/effects.rs +++ b/crates/compose/src/effects.rs @@ -915,6 +915,16 @@ pub fn ranged_lut(contour: &Contour, range: f32) -> Option> { ) } +/// The bevel Contour element's height transfer: the contour alone. Unlike a glow's, its Range is +/// not a `v / range` stretch: that flattened a Linear contour at the default 50 % to a bevel half +/// as wide as Photoshop's (a real 18 px smooth inner bevel at 136 % depth: top-edge highlight gone +/// 15 px in, Photoshop's still 0.19 at 16 px), and dropping it lowers the bad pixels of every +/// contour oracle (bevel-inner-contour-ramp-peak 25.9 → 21.8 %, -double-ring-aa-r70 25.2 → 21.0 %, +/// bevel-pillow-chisel-hard-gloss-and-contour 11.4 → 7.2 %). What Range does instead is still open. +pub fn bevel_contour_lut(c: &photocraft_doc::BevelContour) -> Vec { + contour_lut(&c.contour).unwrap_or_else(|| (0..4096).map(|k| k as f32 / 4095.0).collect()) +} + fn apply_lut(m: Map, l: Option>) -> Map { match l { None => m, @@ -1480,9 +1490,9 @@ fn bevel_height(shape: &Map, b: &Bevel, g: &BevelGeom, tex: &TextureCtx, pattern } h }; - // Contour element: the height profile through the contour over its range. + // Contour element: the height profile through the contour. if let Some(c) = &b.contour { - h = apply_lut(h, Some(ranged_lut(&c.contour, c.range).unwrap_or_else(|| (0..4096).map(|k| k as f32 / 4095.0).collect()))); + h = apply_lut(h, Some(bevel_contour_lut(c))); } // Texture element: the pattern's luminance as extra height, scaled so a full-contrast step // at 100 % depth slopes like the bevel at its depth. @@ -2799,6 +2809,16 @@ mod tests { assert!(at(24, 12) > 0.1 && (at(24, 12) - at(24, 13)).abs() < 1e-3); } + #[test] + fn linear_bevel_contour_leaves_the_height_alone_at_any_range() { + for range in [0.5, 0.7, 1.0] { + let lut = bevel_contour_lut(&photocraft_doc::BevelContour { contour: Contour::Linear, range, anti_alias: false }); + for v in [0.0f32, 0.25, 0.5, 0.75, 1.0] { + assert!((lut_at(&lut, v) - v).abs() < 1e-3, "range {range}: {v} -> {}", lut_at(&lut, v)); + } + } + } + #[test] fn bevel_contour_and_texture_shape_the_height() { let shape = square(40, 6, 34); diff --git a/crates/gpu/src/fx.rs b/crates/gpu/src/fx.rs index a74ff10a466..edd4e87b6c8 100644 --- a/crates/gpu/src/fx.rs +++ b/crates/gpu/src/fx.rs @@ -367,8 +367,8 @@ pub(crate) fn program_with(e: &Effect, light: &GlobalLight, vector_shape: bool, if g.chisel_soft > 0.0 { b.conv(h, photocraft_compose::effects::tent_kernel(g.chisel_soft)) } else { h } }; if let Some(c) = &bv.contour { - // Contour element: the height through the contour over its range. - let lut = photocraft_compose::effects::ranged_lut(&c.contour, c.range).unwrap_or_else(|| (0..4096).map(|k| k as f32 / 4095.0).collect()); + // Contour element: the height through the contour (`bevel_contour_lut`). + let lut = photocraft_compose::effects::bevel_contour_lut(c); let mut st = stage(Kernel::MFinish, Some(h), None, [0.0, 0.0, 1.0, 0.0], 0); st.lut = Some(Arc::new(lut)); h = b.push(st);