#3464: Drop Shadow: keep the whole blur when the padding budget cuts the margin

Drop Shadow pads its buffer by Distance + 1.5 x Softness, but the pixel
budget (#2261) cuts that margin for a large Softness: from about 870 on
a 1080p layer. The box passes then dropped what they spread past the
edge, so the shadow came out too faint: at the centre of a 64 x 48
layer, 0.11 of the Gaussian at Softness 8000. With a cut margin the CPU now blurs as
if the buffer went on with transparency (the Gaussian is unchanged,
sigma = Softness / 2). The GPU hands that case to the CPU and keeps
every margin that fits, so those results are unchanged.

Measured on an M-series Mac: 1080p at Softness 30000 takes 0.10 s, and
a 4096 x 4096 layer (an 8192 x 8192 buffer) takes 0.99 s on the CPU.

The pad is computed once for both paths (drop_shadow_pad) and saturates
instead of overflowing on a huge Softness.
This commit is contained in:
arnav-hiwarkar committed 2026-11-17 16:24:22 +05:30
1 parent c7505fcafc
commit 8903090007
4 files changed
+81 -6

No files matched your search

+5 -1
View File
@@ -411,8 +411,12 @@ fn drop_shadow(e: &mut Enc, ctx: &EffectCtx, mut b: GBuf) -> Option<GBuf> {
let dist = ctx.params.f("distance") * b.scale;
let soft = ctx.params.f("softness") * b.scale;
let only = ctx.params.b("shadowOnly");
let pad = (dist + soft * 1.5).ceil() as u32 + 2;
let pad = effectcraft_effects::drop_shadow_pad(dist, soft);
if !ctx.adjustment {
// A margin cut to the pixel budget: the CPU blurs on past the buffer's edge (#3464).
if soft > 0.0 && effectcraft_effects::pad_within_budget(b.img.width, b.img.height, pad) < pad {
return None;
}
b.pad(e, pad)?;
}
let (dx, dy) = (dir.sin() * dist, -dir.cos() * dist);
+33
View File
@@ -760,6 +760,39 @@ fn box_blur_horizontal_rows_match_cpu_beyond_256() {
}
}
/// #3464: Drop Shadow's Softness reaches 30000. While the padded buffer holds the blur the GPU
/// runs it (1000, the old maximum, on a 70 × 44 layer); once the pixel budget cuts the padding
/// the CPU blurs past the buffer's edge, so the GPU hands the effect over and the render still
/// matches, with and without Shadow Only.
#[test]
fn drop_shadow_large_softness_matches_cpu() {
effect_case("ec.perspective.dropshadow", &[("distance", n(6.0)), ("softness", n(1000.0)), ("opacity", n(100.0))]);
let Some(g) = gpu() else { return };
for only in [false, true] {
let vals = [("distance", n(6.0)), ("softness", n(30000.0)), ("opacity", n(100.0)), ("shadowOnly", Value::Bool(only))];
let spec = effectcraft_effects::find("ec.perspective.dropshadow").unwrap();
let mut params = effectcraft_effects::Params {
values: spec.params.iter().map(|ps| (ps.id.to_string(), effectcraft_effects::default_value(ps, [70.0, 44.0]))).collect(),
};
for (k, v) in &vals {
params.values.insert(k.to_string(), v.clone());
}
let ctx = effectcraft_effects::EffectCtx { params: &params, time: 0.0, layer_size: [70.0, 44.0], seed: 11, adjustment: false, env: Default::default() };
let buf = effectcraft_effects::Buf { img: pattern(7, 70, 44), offset: [0.0, 0.0], scale: 1.0 };
let step = effectcraft_render::FxStep { spec, ctx };
assert!(effectcraft_render::Accelerator::effects(g, &[step], &buf, None).is_none(), "the GPU hands a cut margin to the CPU");
for depth in [BitDepth::Bpc8, BitDepth::Bpc32] {
let mut s = Scene::new(depth);
let bg = s.solid([0.15, 0.1, 0.2], 97, 61);
s.push(bg);
let mut l = s.footage(70, 44);
s.effect(&mut l, "ec.perspective.dropshadow", &vals);
s.push(l);
check(&format!("drop shadow 30000 only {only} {depth:?}"), compare_at(&s, opts(), Tick::ZERO), 0.0);
}
}
}
#[test]
fn gpu_effects_match_cpu() {
// Sigma 3 px and up and even radii, so the half-scale pass stays on the GPU too (#1939).