Compose: Softer outer glows end before Size again, no tail past it

Reverts #8039 ("Compose: Extend Softer outer glows past Size (#7899)"),
which added a range-scaled fading tail beyond Size to Softer outer glows,
on the CPU compositor and the GPU one alike, and widened the effect
margin by it.

The reference application, measured: Outer Glow, Softer, Size 60,
Range 50 % (and 100 % alike), white, Normal, Opacity 100 %, Spread 0,
Noise 0, on an opaque white shape over black (240 x 40 document, shape
over the left 100 px, full height, sampled at row 20): the glow reads 4
at 50 px from the edge, 1 at 54, and 0 from 56 to 70 px. It reaches zero
just before Size; there is no tail beyond it.

The reverted code (the two-box tent) gives, in that setup, 8-bit levels
4, 1, 0, 0, 0 at 50/54/56/60/70 px for Range 50 % (unrounded 3.56,
1.20, 0.49, 0, 0) and 2, 1, 0, 0, 0 for Range 100 % (1.78, 0.60, 0.25,
0, 0); #8039's tail lifted 56-62 px above zero. So the revert stays as
is, CPU and GPU unchanged from before #8039.

Conflicts were formatting-only (later rustfmt of #8039's lines) in
compose effects.rs, effects/paint.rs and gpu fx/builders.rs; resolved to
the pre-#8039 code. The GlowSource/GlowTechnique imports a later commit
kept in gpu fx/tests.rs for #8039's test go with the test.

New test softer_outer_glow_fades_out_before_its_size renders that
document through the CPU compositor at Range 50 % and 100 % and checks
50 and 54 px within 2 levels and 56, 60 and 70 px at exactly 0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
David MannandClaude Opus 5.5 committed 2026-10-30 16:34:03 +01:00
1 parent 3525a1d2bc
commit b9613c6caa
9 files changed
+45 -164

No files matched your search

+2 -9
View File
@@ -41,9 +41,9 @@ mod paint;
pub use bevel::{BEVEL_H_EPS, BevelGeom, BevelPaint, TextureCtx, bevel_chisel_h, bevel_geom, satin_distance};
#[cfg(test)]
use bevel::{bevel_maps, satin_map};
pub use blur::tent_kernel;
#[cfg(test)]
use blur::{blur, box_line, dilate, tent, tent_direct};
pub use blur::{softer_glow_tail_amplitude, softer_glow_tail_width, tent_kernel};
pub(crate) use composite::{VectorStroke, build_maps_prepared, composite_with_effects_prepared, map_count};
pub use composite::{build_maps, composite_with_effects, outline_share, premerges_layer, shadow_see_through, stroke_widths};
pub use distance::{FieldKind, STROKE_CHAMFER_MAX, bevel_distance_fields, distance_field, stroke_outside_exact};
@@ -89,14 +89,7 @@ pub fn margin(layer: &Layer) -> i32 {
for e in layer.effects.items.iter().filter(|e| e.enabled()) {
let r = match e {
Effect::DropShadow(s) | Effect::InnerShadow(s) => s.distance + s.size,
Effect::OuterGlow(g) => {
if g.technique == GlowTechnique::Softer {
g.size + softer_glow_tail_width(g.size)
} else {
g.size
}
}
Effect::InnerGlow(g) => g.size,
Effect::OuterGlow(g) | Effect::InnerGlow(g) => g.size,
Effect::Stroke(s) => s.size,
Effect::Satin(s) => satin_distance(s) + s.size,
Effect::BevelEmboss(b) => b.size + b.soften,
-11
View File
@@ -210,14 +210,3 @@ fn tent_fast(m: &mut Map, w: f32) {
rows_par(&t, &mut b, mh, twice);
m.v = transpose_map(&b, mh, mw);
}
/// Raw coverage at the Size boundary, scaled through the glow's Range to a subtle one-percent tail.
pub fn softer_glow_tail_amplitude(range: f32) -> f32 {
let range = if range.is_finite() { range.clamp(0.01, 1.0) } else { 1.0 };
0.005 * range
}
/// Width of the added fading tail on a Softer outer glow, capped so large settings stay local.
pub fn softer_glow_tail_width(size: f32) -> f32 {
if size.is_finite() && size > 0.0 { (size * 0.1).clamp(1.0, 6.0) } else { 0.0 }
}
+1 -26
View File
@@ -1,4 +1,4 @@
use super::blur::{blur, dilate, softer_glow_tail_amplitude, softer_glow_tail_width};
use super::blur::{blur, dilate};
use super::distance::{dist_inside, dist_outside};
use super::{
BlendMode, Buffer, Contour, Effect, FxPaint, GlobalLight, Glow, GlowSource, GlowTechnique, Gradient, GradientStyle, Map, Placement, PreparedPatterns, Rect,
@@ -303,9 +303,6 @@ pub(super) fn glow_map(shape: &Map, g: &Glow, inner: bool, origin: (i32, i32)) -
let (r, bw) = spread_split(g.size, g.spread);
let mut m = dilate(&src, r);
blur(&mut m, bw);
if !inner {
add_softer_glow_tail(&mut m, &src, g.size, g.range);
}
m
}
};
@@ -405,25 +402,3 @@ pub(super) fn paint_glow(dst: &mut Buffer, m: &Map, g: &Glow, shape_bounds: Rect
let strength = Map { w: m.w, h: m.h, v: m.v.iter().map(|v| (v * gain).min(1.0)).collect() };
paint(dst, &strength, |i| prepared.sample(1.0 - m.v.get(i).copied().unwrap_or(0.0).clamp(0.0, 1.0)), g.common.blend, g.common.opacity);
}
fn add_softer_glow_tail(map: &mut Map, shape: &Map, size: f32, range: f32) {
let width = softer_glow_tail_width(size);
if width == 0.0 {
return;
}
let amp = softer_glow_tail_amplitude(range);
let distance = dist_outside(shape);
for (coverage, distance) in map.v.iter_mut().zip(distance) {
let t = (distance + 0.5 - (size - width)) / width;
let tail = if (0.0..=1.0).contains(&t) {
amp * t * t * (3.0 - 2.0 * t)
} else if (1.0..=2.0).contains(&t) {
let u = t - 1.0;
let remaining = 1.0 - u;
amp * remaining * remaining * (1.0 + 2.0 * u)
} else {
0.0
};
*coverage = coverage.max(tail);
}
}
-50
View File
@@ -858,56 +858,6 @@ fn glows_match_photoshop() {
}
}
#[test]
fn softer_outer_glow_keeps_a_fading_tail_past_its_size() {
let mut shape = Map::new(220, 220, 0.0);
for y in 0..shape.h {
for x in 20..100 {
shape.v[y * shape.w + x] = 1.0;
}
}
let glow = Glow {
common: photocraft_doc::FxCommon::new(BlendMode::Screen, 1.0),
paint: FxPaint::Color(photocraft_color::Color::WHITE),
technique: GlowTechnique::Softer,
spread: 0.0,
size: 60.0,
contour: Contour::Linear,
anti_alias: false,
range: 0.5,
jitter: 0.0,
noise: 0.0,
source: GlowSource::Edge,
};
let m = glow_map(&shape, &glow, false, (0, 0));
let row = shape.h / 2;
let at = |distance: usize| m.v[row * m.w + 100 + distance];
assert!(at(50) > 0.024, "the softer shoulder should stay visible: {}", at(50));
assert!(at(60) > 1.0 / 255.0, "the glow must retain a visible tail at its Size: {}", at(60));
assert!(at(62) > 0.5 / 255.0, "the glow must extend beyond its Size: {}", at(62));
assert!(at(66) < 1e-6, "the added tail should fade to zero: {}", at(66));
}
#[test]
fn softer_outer_glow_margin_includes_its_tail_support() {
let glow = Glow {
common: photocraft_doc::FxCommon::new(BlendMode::Screen, 1.0),
paint: FxPaint::Color(photocraft_color::Color::WHITE),
technique: GlowTechnique::Softer,
spread: 0.0,
size: 60.0,
contour: Contour::Linear,
anti_alias: false,
range: 0.5,
jitter: 0.0,
noise: 0.0,
source: GlowSource::Edge,
};
let mut layer = Layer::raster("glow", photocraft_color::PixelFormat::RGBA8);
layer.effects.items.push(Effect::OuterGlow(glow));
assert_eq!(margin(&layer), 68);
}
#[test]
fn offsets_follow_light() {
let (dx, dy) = offset(120.0, 10.0);
+39
View File
@@ -4602,3 +4602,42 @@ fn adjustment_blend_if_judges_the_result_before_opacity() {
assert!(got.iter().zip(want).all(|(g, w)| (g - w).abs() <= 1), "black {black} white {white}: {got:?} vs Photoshop {want:?}");
}
}
/// The reference application, measured: a 240 × 40 black document, an opaque white layer over
/// its left 100 px (full height), Outer Glow Softer, white, Normal, 100 %, Spread 0, Noise 0,
/// Size 60, Range 50 % and 100 % alike. Sampled at row 20, `d` px right of the edge, the glow
/// reads 4 at 50 px, 1 at 54 and 0 from 56 to 70: it fades out just before Size, with no tail
/// beyond it (#8039 added one; reverted). On black, the red value × 255 is the glow alpha × 255,
/// compared as 8-bit levels. The tent gives 4, 1, 0, 0, 0 at Range 50 % and 2, 1, 0, 0, 0 at 100 %.
#[test]
fn softer_outer_glow_fades_out_before_its_size() {
let mut d = Document::with_background("t", Size::new(240, 40), ColorMode::Rgb, SampleType::U8, Color::BLACK);
for range in [0.5, 1.0] {
let mut l = solid_layer("shape", Rect::new(0, 0, 100, 40), [1.0; 4]);
l.effects.items = vec![Effect::OuterGlow(Glow {
common: FxCommon::new(photocraft_color::BlendMode::Normal, 1.0),
paint: FxPaint::Color(Color::WHITE),
technique: GlowTechnique::Softer,
spread: 0.0,
size: 60.0,
contour: photocraft_doc::Contour::Linear,
anti_alias: false,
range,
jitter: 0.0,
noise: 0.0,
source: GlowSource::Edge,
})];
d.layers.truncate(1);
d.layers.push(l);
let got: Vec<(i32, f32)> = [50, 54, 56, 60, 70].iter().map(|&dist| (dist, (255.0 * px(&d, 100 + dist, 20)[0]).round())).collect();
for &(dist, v) in &got {
let want = match dist {
50 => 4.0,
54 => 1.0,
_ => 0.0,
};
let tolerance = if dist >= 56 { 0.0 } else { 2.0 };
assert!((v - want).abs() <= tolerance, "range {range}, {dist} px: {v} vs the reference application's {want} ({got:?})");
}
}
}
+1 -17
View File
@@ -1449,18 +1449,6 @@ fn fs_mblur(in: VOut) -> @location(0) vec4<f32> {
@fragment
fn fs_mglow(in: VOut) -> @location(0) vec4<f32> {
let d = textureLoad(tex_a, local(in.pos), 0).r + 0.5;
if (op.p0.w > 0.5) {
let t = (d - op.p0.x) / op.p0.y;
var tail = 0.0;
if (t >= 0.0 && t <= 1.0) {
tail = op.p0.z * t * t * (3.0 - 2.0 * t);
} else if (t > 1.0 && t <= 2.0) {
let u = t - 1.0;
let remaining = 1.0 - u;
tail = op.p0.z * remaining * remaining * (1.0 + 2.0 * u);
}
return mout(tail);
}
var m = 0.5 * clamp(1.0 - (d - op.p0.x) / op.p0.y, 0.0, 1.0);
if (d <= op.p0.x) { m = 1.0; }
return mout(m);
@@ -1472,11 +1460,7 @@ fn fs_mglow(in: VOut) -> @location(0) vec4<f32> {
fn fs_mfinish(in: VOut) -> @location(0) vec4<f32> {
let p = local(in.pos);
var v = textureLoad(tex_a, p, 0).r;
if (op.p0.x > 1.5) {
v = max(v, textureLoad(tex_b, p, 0).r);
} else if (op.p0.x > 0.5) {
v = abs(v - textureLoad(tex_b, p, 0).r);
}
if (op.p0.x > 0.5) { v = abs(v - textureLoad(tex_b, p, 0).r); }
if (op.p0.y > 0.5 && op.p0.y < 1.5) { v = 1.0 - v; }
if (op.p0.z > 0.5) { v = lut(0, v); }
if (op.p0.y > 1.5) { v = 1.0 - v; }
-18
View File
@@ -226,24 +226,6 @@ impl B {
let Some(k) = blur_kernel(size) else { return src };
self.conv(src, k)
}
fn max(&mut self, a: In, b: In) -> In {
self.push(stage(Kernel::MFinish, Some(a), Some(b), [2.0, 0.0, 0.0, 0.0], 0))
}
fn softer_glow_tail(&mut self, blur: In, size: f32, range: f32) -> In {
let width = photocraft_compose::effects::softer_glow_tail_width(size);
if width == 0.0 {
return blur;
}
let distance = self.field(FieldKind::Outside, size + width);
let tail = self.push(stage(
Kernel::MGlow,
Some(distance),
None,
[size - width, width, photocraft_compose::effects::softer_glow_tail_amplitude(range), 1.0],
0,
));
self.max(blur, tail)
}
/// Separable convolution with a symmetric kernel `(radius, weights)` (two `MBlur` passes).
fn conv(&mut self, src: In, (r, w): (i32, Vec<f32>)) -> In {
if r <= 0 {
+1 -2
View File
@@ -55,8 +55,7 @@ impl B {
GlowTechnique::Softer => {
// Inner glows spread 1 - alpha.
let src = if inner { self.shift(In::Shape, 0.0, 0.0, 0.0, true) } else { In::Shape };
let m = self.spread_blur(src, (g.size, g.spread), inner, 0.0, 0.0);
if inner { m } else { self.softer_glow_tail(m, g.size, g.range) }
self.spread_blur(src, (g.size, g.spread), inner, 0.0, 0.0)
}
};
self.finish_glow(m, fx::glow_lut(g), inner, center);
+1 -31
View File
@@ -1,6 +1,6 @@
use super::*;
use photocraft_color::BlendMode;
use photocraft_doc::{FxCommon, GlowSource, GlowTechnique};
use photocraft_doc::FxCommon;
/// Filled-shape identity survives integer moves, including fractional anchors and handles.
#[test]
@@ -51,36 +51,6 @@ fn programs_key_on_geometry_not_colour() {
assert_ne!(a.key, program(&Effect::DropShadow(s), &light, false).key);
}
#[test]
fn softer_outer_glow_program_keeps_the_tent_and_adds_a_distance_tail() {
let effect = Effect::OuterGlow(photocraft_doc::Glow {
common: FxCommon::new(BlendMode::Screen, 1.0),
paint: photocraft_doc::FxPaint::Color(photocraft_color::Color::WHITE),
technique: GlowTechnique::Softer,
spread: 0.0,
size: 60.0,
contour: Contour::Linear,
anti_alias: false,
range: 0.5,
jitter: 0.0,
noise: 0.0,
source: GlowSource::Edge,
});
let kernel = blur_kernel(60.0).unwrap();
let p = program(&effect, &GlobalLight::default(), false);
let blur: Vec<_> = p.stages.iter().filter(|s| s.kernel == Kernel::MBlur).collect();
assert_eq!(blur.len(), 2);
for stage in blur {
assert_eq!(stage.radius, kernel.0);
assert_eq!(stage.lut.as_deref().unwrap(), kernel.1.as_slice());
}
let tail = p.stages.iter().find(|s| s.kernel == Kernel::MGlow).unwrap();
assert_eq!(tail.a, Some(In::Field(FieldKind::Outside)));
assert_eq!(tail.p0, [54.0, 6.0, 0.0025, 1.0]);
assert!(p.stages.iter().any(|s| s.kernel == Kernel::MFinish && s.p0[0] == 2.0));
assert!(p.fields.contains(&(FieldKind::Outside, reach_for(66.0))));
}
/// A styled group's effect shape follows its own vector mask and its children's Blend If and
/// Advanced Blending, so the cached shape must be rebuilt when any of them changes.
#[test]