PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge PR #7638: Map the bevel's shading through its gloss contour, not its light (#7360)
aionggd8865fc6827c
diff --cc crates/compose/src/effects.rsindex 867b44eb5,b98326f2c..3e755dfb9--- a/crates/compose/src/effects.rs+++ b/crates/compose/src/effects.rs@@@ -1656,36 -1637,32 +1651,42 @@@ fn bevel_maps(shape: &Map, b: &Bevel, llet on_bevel = |x: i64, y: i64| {hmap.get(x, y) > BEVEL_H_EPS || (reach_past && [(1, 0), (-1, 0), (0, 1), (0, -1)].iter().any(|(dx, dy)| hmap.get(x + dx, y + dy) > BEVEL_H_EPS))};+ // The gloss contour remaps the shading `n · light` before it splits into highlight (above+ // what it maps a flat face's `sin(altitude)` to) and shadow. Applied to the highlight and shadow amounts+ // instead, a contour that starts high (Rolling Slope - Descending) lit every pixel the light+ // missed, so a bevelled glyph's flat face took the full highlight (#7360) where Photoshop+ // leaves it at the layer's colour. The Linear contour changes nothing either way.+ let gloss = contour_lut(&b.gloss_contour);let shade_into = |depth: f32, region_kind: u8| -> (Map, Map) {let (mut hi, mut sh) = (Map::new(shape.w, shape.h, 0.0), Map::new(shape.w, shape.h, 0.0));- for y in 0..shape.h as i64 {- for x in 0..shape.w as i64 {- let i = y as usize * shape.w + x as usize;- let gx = (hmap.get(x + 1, y) - hmap.get(x - 1, y)) * 0.5 * depth;- let gy = (hmap.get(x, y + 1) - hmap.get(x, y - 1)) * 0.5 * depth;- let n = [-gx, -gy, 1.0];- let len = (n[0] * n[0] + n[1] * n[1] + 1.0).sqrt();- let shade = (n[0] * light_v[0] + n[1] * light_v[1] + n[2] * light_v[2]) / len;- let region = if region_kind == 0 { shape.v[i] } else { f32::from(shape.v[i] < 1.0 - INSIDE_EPS && on_bevel(x, y)) };- let k = gloss.as_ref().map_or(shade - se, |l| lut_at(l, shade) - lut_at(l, se));- if k > 0.0 {- hi.v[i] = (k / (1.0 - se).max(1e-3)).clamp(0.0, 1.0) * region;- } else {- sh.v[i] = (-k / se.max(1e-3)).clamp(0.0, 1.0) * region;+ // Rows on threads: every pixel reads only `hmap` and `shape`.+ par_units(+ hi.v.len(),+ &mut hi.v,+ shape.w,+ &mut sh.v,+ shape.w,+ || (),+ |_, y, hi_row, sh_row| {+ let y = y as i64;+ for x in 0..shape.w as i64 {+ let i = y as usize * shape.w + x as usize;+ let gx = (hmap.get(x + 1, y) - hmap.get(x - 1, y)) * 0.5 * depth;+ let gy = (hmap.get(x, y + 1) - hmap.get(x, y - 1)) * 0.5 * depth;+ let n = [-gx, -gy, 1.0];+ let len = (n[0] * n[0] + n[1] * n[1] + 1.0).sqrt();+ let shade = (n[0] * light_v[0] + n[1] * light_v[1] + n[2] * light_v[2]) / len;+ let region = if region_kind == 0 { shape.v[i] } else { f32::from(shape.v[i] < 1.0 - INSIDE_EPS && on_bevel(x, y)) };- let k = shade - se;++ let k = gloss.as_ref().map_or(shade - se, |l| lut_at(l, shade) - lut_at(l, se));+ if k > 0.0 {+ hi_row[x as usize] = (k / (1.0 - se).max(1e-3)).clamp(0.0, 1.0) * region;+ } else {+ sh_row[x as usize] = (-k / se.max(1e-3)).clamp(0.0, 1.0) * region;+ }}- }- }+ },+ );- (apply_contour(hi, &b.gloss_contour), apply_contour(sh, &b.gloss_contour))+ (hi, sh)};let maps = match g.paint {BevelPaint::Inner | BevelPaint::Outer => {