From e6ed3a2a4c65b7d371c242297f6e492e48ebd3f9 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 17:11:28 -0800 Subject: [PATCH] Effects: Glowing Edges scales its glow by the whole object's strongest edge at every zoom Glowing Edges divides each pixel's edge strength by the strongest edge in its input (crates/effects/src/pixel/edges.rs:45-56), but its reach let the renderer crop the raster to the view once the object passed the pixel budget. A zoomed-in frame then took the peak from the part in view, so the same edge glowed at a different brightness depending on the zoom and on where the view was, and a pan within a kept crop's margin kept the earlier crop's peak. Glowing Edges now has no nearby reach, as Torn Edges and Cutout, whose results also depend on the whole object: past the budget the whole object is filtered at a lower resolution, and whole-pixel pans reuse that raster. --- crates/effects/src/pixel.rs | 6 ++--- crates/render/src/fx/tests.rs | 50 +++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/crates/effects/src/pixel.rs b/crates/effects/src/pixel.rs index f6c33079c0..116b1ea20b 100644 --- a/crates/effects/src/pixel.rs +++ b/crates/effects/src/pixel.rs @@ -717,7 +717,6 @@ impl PixelFx { PixelFx::Charcoal { thickness, detail, .. } => Some(sketch_ink::charcoal_reach(thickness, detail)), PixelFx::Photocopy { detail, .. } => Some(sketch_ink::copy_reach(detail)), PixelFx::Stamp { smoothness, .. } => Some(sketch_ink::stamp_reach(smoothness)), - PixelFx::GlowingEdges { width, smoothness, .. } => Some(width.max(smoothness * 3.0)), // The cells around the pixel's, and the cells around theirs. // (Without a usable grid there are no dots: see `pixelate::color_halftone`.) PixelFx::ColorHalftone { max_radius, .. } => { @@ -740,8 +739,9 @@ impl PixelFx { PixelFx::WaterPaper { fiber_length, .. } => { Some(sketch::water_paper_shift(fiber_length) + 3.0 * (0.06 * fiber_length.clamp(3.0, 50.0)).max(0.35)) } - // Cutout's palette and Torn Edges' peak-normalised edges come from the whole object. - PixelFx::Cutout { .. } | PixelFx::TornEdges { .. } => None, + // Cutout's palette and the peak-normalized edges of Torn Edges and Glowing Edges come + // from the whole object. + PixelFx::Cutout { .. } | PixelFx::TornEdges { .. } | PixelFx::GlowingEdges { .. } => None, // The softened tones around the pixel. PixelFx::NeonGlow { size, .. } => Some(3.0 * artistic::glow_spread(size)), PixelFx::PlasticWrap { smoothness, .. } => Some(artistic::plastic_reach(smoothness)), diff --git a/crates/render/src/fx/tests.rs b/crates/render/src/fx/tests.rs index 21e0e9fbd9..c551162d2f 100644 --- a/crates/render/src/fx/tests.rs +++ b/crates/render/src/fx/tests.rs @@ -3016,6 +3016,56 @@ fn photoshop_filters_on_content_larger_than_the_budget() { } } +/// Glowing Edges scales every edge by the strongest one in the object, so a zoomed-in frame draws +/// a point's glow as the whole object draws it. The object is a white 4 × 80 pt bar beside +/// stripes 0.5 pt wide and 1 pt apart, whose edges lie close together and glow strongest, on +/// black. At 400 % the whole object fits the pixel budget; at 6400 % a 200 × 200 view shows only +/// the bar's left edge, and the stripes lie beyond what the effect reads around the view. The pans +/// move the view 10 and 20 pixels, the second within the margin a raster made again at the same +/// zoom keeps, which reaches the stripes. +#[test] +fn glowing_edges_zoomed_in_glow_as_bright_as_in_the_whole_object() { + use vectorcraft_geom::{PathData, SubPath}; + let rect = |x0: f64, y0: f64, x1: f64, y1: f64| { + SubPath::polyline(&[Point::new(x0, y0), Point::new(x1, y0), Point::new(x1, y1), Point::new(x0, y1)], true) + }; + let mut subpaths = vec![rect(10.0, 10.0, 14.0, 90.0)]; + subpaths.extend((0..30).map(|i| rect(16.0 + f64::from(i), 10.0, 16.5 + f64::from(i), 90.0))); + let mut d = Document::new(100.0, 100.0); + let mut ap = Appearance::basic(Paint::solid(Color::rgb(1.0, 1.0, 1.0)), Paint::None, 0.0); + ap.effects = + vec![Effect { id: "stylize.glowingEdges".into(), params: json!({"edgeWidth": 1, "edgeBrightness": 6, "smoothness": 1}), visible: true }]; + let n = Node::path(d.alloc_id(), PathData::new(subpaths), ap); + let l = d.layers[0].id; + d.insert(Some(l), 0, n).unwrap(); + let opts = RenderOptions { background: Some([0, 0, 0, 255]), ..Default::default() }; + // Just inside the bar's left edge. + let at = Point::new(10.125, 50.0); + let glow = |img: &Rendered, view: Affine| { + let p = view * at; + img.pixel(p.x.floor() as u32, p.y.floor() as u32)[0] + }; + let whole_view = Affine::scale(4.0); + let mut whole = Renderer::new(); + let whole_img = whole.render(&d, 400, 400, whole_view, &opts); + assert_eq!(whole.stats.view_sized, 0, "at 400 % the whole object is one raster"); + let whole = glow(&whole_img, whole_view); + let zoomed = |dx: f64| Affine::translate((100.0 - dx, 100.0)) * Affine::scale(64.0) * Affine::translate((-at.x, -at.y)); + let mut r = Renderer::new(); + let mut seen = vec![]; + for dx in [0.0, 10.0, 20.0] { + let view = zoomed(dx); + let panned = glow(&r.render(&d, 200, 200, view, &opts), view); + let fresh = glow(&Renderer::new().render(&d, 200, 200, view, &opts), view); + seen.push((dx, panned, fresh)); + assert!(panned.abs_diff(fresh) <= 2, "panned {dx} px, the frame draws the glow a fresh renderer draws: {seen:?}"); + } + assert!(r.stats.view_sized > 0, "at 6400 % the object is over the pixel budget"); + for (dx, panned, _) in &seen { + assert!(panned.abs_diff(whole) <= 24, "panned {dx} px, the glow is as bright as the whole object's {whole}: {seen:?}"); + } +} + /// #5308: an image's Inner Glow follows its visible pixels, not its frame. A 40 × 40 image whose /// left half is transparent and right half opaque black, on a black page, with a white glow from /// the edges: the transparent half stays black, and the glow lights the opaque half's left edge