From f98c3e9ba2da86ced94a34f7c9bf1a1fe7489d33 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Tue, 17 Nov 2026 16:09:38 +0530 Subject: [PATCH] #3467: Radial Blur Zoom past 200 stays on its side of the centre MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Zoom spreads its 32 samples over scales 1 ± Amount / 200 about the centre. Past Amount 200, which the range now allows, that reaches below 0 and samples the layer mirrored through the centre: at 1000 a layer white on the left and black on the right turned the right half 35 % grey. raster::radial_blur_zoom_scale keeps the old scales up to 200 exactly and spreads the samples evenly from the centre to 1 + Amount / 200 beyond. The CPU and GPU paths both take their samples from it. Work per pixel stays at 32 samples at any Amount. --- crates/effects/src/misc.rs | 20 +++++++++++ crates/gpu/src/fx_generate.rs | 8 ++--- crates/gpu/src/tests/fx_generate.rs | 3 ++ crates/raster/src/blur.rs | 53 ++++++++++++++++++++++++++--- crates/raster/src/lib.rs | 5 ++- docs/effects-parity.md | 1 + 6 files changed, 81 insertions(+), 9 deletions(-) diff --git a/crates/effects/src/misc.rs b/crates/effects/src/misc.rs index 168dd6110..ea196fc11 100644 --- a/crates/effects/src/misc.rs +++ b/crates/effects/src/misc.rs @@ -1148,6 +1148,26 @@ mod tests { } } + /// Amount takes After Effects' valid range up to 1000 (#3467), Zoom 1000 a spread of 10. + /// Zoom samples along the ray from the centre through the pixel, never past the centre: on a + /// layer white left of the centre and black right of it, the right half stays black (scales + /// below 0 sampled the white half mirrored through the centre). Both Antialiasing settings. + #[test] + fn radial_blur_zoom_at_the_largest_amount_stays_on_its_side_of_the_centre() { + let mut img = effectcraft_raster::Image::filled(64, 32, [0.0, 0.0, 0.0, 1.0]); + img.rows_mut().for_each(|(_, row)| row.iter_mut().take(32).for_each(|px| *px = [1.0, 1.0, 1.0, 1.0])); + for aa in 0..2 { + let vals = [("amount", num(1000.0)), ("type", Value::Enum(1)), ("center", Value::Vec2([32.5, 16.5])), ("antialiasing", Value::Enum(aa))]; + let o = run_fx("ec.blur.radial", &vals, img.clone(), 0.0, EffectEnv::default()); + for y in 0..32 { + for x in 33..64 { + let p = o.img.get(x, y); + assert!(p[0].abs() < 1e-5 && (p[3] - 1.0).abs() < 1e-5, "aa {aa} ({x}, {y}): {p:?}"); + } + } + } + } + /// Spin and Zoom at both ends of Amount (0..1000) and both Antialiasing settings give finite /// colours over an opaque layer and keep it opaque (#3467). #[test] diff --git a/crates/gpu/src/fx_generate.rs b/crates/gpu/src/fx_generate.rs index 2dda38f45..6e9594f60 100644 --- a/crates/gpu/src/fx_generate.rs +++ b/crates/gpu/src/fx_generate.rs @@ -100,14 +100,14 @@ fn radial_blur(e: &mut Enc, ctx: &EffectCtx, b: GBuf) -> Option { if amount.abs() < 1e-6 { return Some(b); } - let n = 32usize; + // The CPU's samples (`raster::radial_blur`). + let n = effectcraft_raster::RADIAL_BLUR_SAMPLES; let mut data = Vec::with_capacity(2 * n); for i in 0..n { - let t = i as f64 / (n - 1) as f64 - 0.5; if zoom { - data.push((1.0 + t * amount) as f32); + data.push(effectcraft_raster::radial_blur_zoom_scale(i, amount) as f32); } else { - let (s, c) = (t * amount).to_radians().sin_cos(); + let (s, c) = effectcraft_raster::radial_blur_spin_angle(i, amount).to_radians().sin_cos(); data.extend([s as f32, c as f32]); } } diff --git a/crates/gpu/src/tests/fx_generate.rs b/crates/gpu/src/tests/fx_generate.rs index f8482b5ab..02ec75b11 100644 --- a/crates/gpu/src/tests/fx_generate.rs +++ b/crates/gpu/src/tests/fx_generate.rs @@ -24,6 +24,9 @@ fn radial_blur() { effect_case("ec.blur.radial", &[("amount", n(12.0))]); effect_case("ec.blur.radial", &[("amount", n(30.0)), ("type", e(1)), ("center", pt(20.3, 14.7))]); effect_case("ec.blur.radial", &[("amount", n(-45.0)), ("center", pt(50.0, 30.0))]); + // Amount's largest value, 1000 (#3467): Spin over ±500°, Zoom from the centre outwards. + effect_case("ec.blur.radial", &[("amount", n(1000.0)), ("center", pt(20.3, 14.7))]); + effect_case("ec.blur.radial", &[("amount", n(1000.0)), ("type", e(1)), ("center", pt(20.3, 14.7)), ("antialiasing", e(1))]); } #[test] diff --git a/crates/raster/src/blur.rs b/crates/raster/src/blur.rs index 76e51f865..751e0f5d0 100644 --- a/crates/raster/src/blur.rs +++ b/crates/raster/src/blur.rs @@ -300,24 +300,49 @@ pub fn directional_blur(img: &Image, angle_deg: f64, length: f64) -> Image { out } +/// Samples [`radial_blur`] averages per pixel at every amount, so the work per pixel stays the +/// same up to Radial Blur's largest Amount (1000). The GPU path takes the same count. +pub const RADIAL_BLUR_SAMPLES: usize = 32; + +/// Where sample `i` of [`RADIAL_BLUR_SAMPLES`] lies in the blur's spread, from −0.5 to 0.5. +fn radial_blur_t(i: usize) -> f64 { + i as f64 / (RADIAL_BLUR_SAMPLES - 1) as f64 - 0.5 +} + +/// Spin sample `i`'s rotation in degrees for a spin of `amount` degrees. +pub fn radial_blur_spin_angle(i: usize, amount: f64) -> f64 { + radial_blur_t(i) * amount +} + +/// Zoom sample `i`'s scale about the centre for a zoom of `amount` (a fraction of the distance +/// to the centre): evenly over `1 ± amount / 2`. Past a spread of 2 (Radial Blur's Amount 200) +/// that would reach below 0 and sample the point mirrored through the centre, so the samples +/// spread evenly from the centre (0) to `1 + amount / 2` instead (#3467). +pub fn radial_blur_zoom_scale(i: usize, amount: f64) -> f64 { + let t = radial_blur_t(i); + if amount.abs() <= 2.0 { + return 1.0 + t * amount; + } + (t + 0.5) * (1.0 + amount.abs() / 2.0) +} + /// Radial blur around `center`: `spin` (degrees) or zoom (`amount` as a fraction of distance). pub fn radial_blur(img: &Image, center: (f64, f64), amount: f64, zoom: bool) -> Image { if amount.abs() < 1e-6 { return img.clone(); } - let n = 32usize; + let n = RADIAL_BLUR_SAMPLES; let mut out = Image::new(img.width, img.height); out.rows_mut().for_each(|(y, row)| { for (x, px) in row.iter_mut().enumerate() { let (vx, vy) = (x as f64 + 0.5 - center.0, y as f64 + 0.5 - center.1); let mut acc = [0.0f32; 4]; for i in 0..n { - let t = i as f64 / (n - 1) as f64 - 0.5; let (sx, sy) = if zoom { - let k = 1.0 + t * amount; + let k = radial_blur_zoom_scale(i, amount); (center.0 + vx * k, center.1 + vy * k) } else { - let (s, c) = (t * amount).to_radians().sin_cos(); + let (s, c) = radial_blur_spin_angle(i, amount).to_radians().sin_cos(); (center.0 + vx * c - vy * s, center.1 + vx * s + vy * c) }; // Samples outside the image repeat its edge: After Effects' Radial Blur keeps a @@ -337,6 +362,26 @@ pub fn radial_blur(img: &Image, center: (f64, f64), amount: f64, zoom: bool) -> mod tests { use super::*; + /// Zoom spreads up to 2 keep `1 ± spread / 2` exactly as before (#3467); wider ones run + /// from the centre (scale 0) out to `1 + spread / 2`, evenly and never below 0. + #[test] + fn radial_blur_zoom_scales_never_cross_the_centre() { + let n = RADIAL_BLUR_SAMPLES; + for amount in [0.2, 1.0, 2.0, -1.5] { + for i in 0..n { + let t = i as f64 / (n - 1) as f64 - 0.5; + assert_eq!(radial_blur_zoom_scale(i, amount), 1.0 + t * amount, "amount {amount} sample {i}"); + } + } + for amount in [2.5, 10.0, -10.0] { + let k: Vec = (0..n).map(|i| radial_blur_zoom_scale(i, amount)).collect(); + assert_eq!(k[0], 0.0, "amount {amount}"); + assert!((k[n - 1] - (1.0 + amount.abs() / 2.0)).abs() < 1e-12, "amount {amount}: {k:?}"); + let step = k[n - 1] / (n - 1) as f64; + assert!(k.windows(2).all(|w| (w[1] - w[0] - step).abs() < 1e-12), "amount {amount}: {k:?}"); + } + } + /// The sampled Gaussian pass as it was (one pixel at a time, bounds-checked taps): the /// row-wise passes must match it to the bit. fn gauss_pass_per_pixel(img: &Image, sigma: f64, vertical: bool, repeat: bool) -> Image { diff --git a/crates/raster/src/lib.rs b/crates/raster/src/lib.rs index e18a24c63..852065db4 100644 --- a/crates/raster/src/lib.rs +++ b/crates/raster/src/lib.rs @@ -17,7 +17,10 @@ pub mod yuv; use effectcraft_color::{BlendMode, blend_pixel}; use rayon::prelude::*; -pub use blur::{box_blur, directional_blur, gaussian_blur, gaussian_blur_exact, gaussian_is_exact, radial_blur}; +pub use blur::{ + RADIAL_BLUR_SAMPLES, box_blur, directional_blur, gaussian_blur, gaussian_blur_exact, gaussian_is_exact, radial_blur, radial_blur_spin_angle, + radial_blur_zoom_scale, +}; pub use channels3d::AuxChannels; pub use warp::{Sampling, WarpOpts, accumulate_warp, composite_warp, composite_warp_changed, composite_warp_reference, resample}; diff --git a/docs/effects-parity.md b/docs/effects-parity.md index b07c624f8..9d6ca232f 100644 --- a/docs/effects-parity.md +++ b/docs/effects-parity.md @@ -64,6 +64,7 @@ the GPU is performance, not parity. | Date | Change | Summary | |---|---|---| +| 2026-11-17 | minor | Radial Blur: Amount takes After Effects' valid range 0..1000 (slider and default unchanged); Zoom past 200 spreads its samples from the centre outwards instead of sampling the layer mirrored through the centre (CPU and GPU) | | 2026-11-12 | minor | Parameters take After Effects' recorded valid ranges (hard range; defaults and sliders unchanged): Levels (Individual Controls) levels −10000..10000 and Gamma from 0; 4-Color Gradient Blend to 10000 and Jitter to 500 %; Change Color Hue Transform ±1800°; Noise HLS (and Auto) amounts to 1000 % and Grain Size from 0; Grid Border to 2000; Venetian Blinds Width 1..32000 and Feather to 32000; Radial Wipe Feather to 32000; Scatter Amount to 1000; Beam thicknesses to 4000; Transform Scale ±30000 %; Turbulent Displace Random Seed to 100000. A test checks every mapped parameter's range against the recorded table (CPU and GPU) | | 2026-10-19 | minor | Glow (original colours): bright pass per channel, 8 × (value − threshold + 0.061), measured against After Effects 2026 (CPU and GPU) | | 2026-10-19 | minor | Glow (colour channels): the glow covers the layer's blurred alpha, blur σ = 0.384 × radius, measured against After Effects 2026 renders (CPU and GPU) |