mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-20 09:05:51 +00:00
Merge upstream/main into cache-defaults-3298
This commit is contained in:
commit
6bea5fa6ae
66 files changed
+2992
-883
No files matched your search
@@ -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);
|
||||
@@ -592,7 +596,7 @@ fn pointwise(e: &mut Enc, id: &str, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
|
||||
let (ox, oy) = b.to_px(pr.v2("transform/offset"));
|
||||
let s = f("transform/scale");
|
||||
let (sw, sh) = if pr.b("transform/uniformScaling") { (s, s) } else { (f("transform/scaleWidth"), f("transform/scaleHeight")) };
|
||||
let sub = (f("subSettings/subScaling") / 100.0).clamp(0.1, 1.0);
|
||||
let sub = effectcraft_effects::sub_scaling_ratio(f("subSettings/subScaling"));
|
||||
p.u[0] = [10, kind, octaves.ceil() as u32, f("evolutionOptions/seed") as u32 ^ 0x51ed];
|
||||
p.u[1] = [pr.b("invert") as u32, pr.e("overflow"), mode, 0];
|
||||
p.f[0] = [
|
||||
@@ -608,7 +612,7 @@ fn pointwise(e: &mut Enc, id: &str, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
|
||||
(f("opacity") as f32 / 100.0).clamp(0.0, 1.0),
|
||||
(sh * effectcraft_effects::NOISE_CELL * b.scale).max(1.0) as f32,
|
||||
];
|
||||
p.f[3] = [(f("subSettings/subInfluence") as f32 / 100.0).clamp(0.0, 1.0), 1.0 / sub as f32, 0.0, 0.0];
|
||||
p.f[3] = [(f("subSettings/subInfluence") as f32 / 100.0).clamp(0.0, 1.0), 1.0 / sub as f32, effectcraft_effects::OCTAVE_SCALE_MAX, 0.0];
|
||||
}
|
||||
_ => return None,
|
||||
}
|
||||
|
||||
@@ -172,10 +172,9 @@ fn cc_lens(e: &mut Enc, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
|
||||
}
|
||||
|
||||
fn turbulent(e: &mut Enc, ctx: &EffectCtx, mut b: GBuf) -> Option<GBuf> {
|
||||
let amount = ctx.params.f("amount") * b.scale;
|
||||
if amount.abs() < 1e-9 {
|
||||
let Some(amount) = effectcraft_effects::turbulent_amount_px(ctx, b.scale) else {
|
||||
return Some(b);
|
||||
}
|
||||
};
|
||||
let kind = ctx.params.e("displacement");
|
||||
let size = (ctx.params.f("size") * b.scale).max(1.0);
|
||||
if ctx.params.b("resizeLayer") && !ctx.adjustment {
|
||||
|
||||
@@ -100,14 +100,14 @@ fn radial_blur(e: &mut Enc, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
|
||||
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_degrees(i, amount).to_radians().sin_cos();
|
||||
data.extend([s as f32, c as f32]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,9 +289,25 @@ fn box_pass(gid: vec3<u32>, horizontal: bool) {
|
||||
}
|
||||
let norm = 1.0 / f32(2 * r + 1);
|
||||
var acc = vec4<f32>(0.0);
|
||||
for (var i = b0 - r; i <= b0 + r; i++) {
|
||||
// The starting window, as the CPU sums it: the pixels inside the line once each, and the
|
||||
// repeated edge pixels counted rather than visited (a radius far past the line, such as
|
||||
// Gaussian Blur's at Blurriness 30000, would otherwise loop over it once per pixel).
|
||||
let lo = b0 - r;
|
||||
let hi = b0 + r;
|
||||
for (var i = max(lo, 0); i <= min(hi, n - 1); i++) {
|
||||
acc += line_get(horizontal, line, i, n, repeat);
|
||||
}
|
||||
if (repeat) {
|
||||
let before = f32(max(-lo, 0));
|
||||
let after = f32(max(hi - (n - 1), 0));
|
||||
// A zero count adds nothing (0 * NaN would be NaN).
|
||||
if (before > 0.0) {
|
||||
acc += line_get(horizontal, line, 0, n, repeat) * before;
|
||||
}
|
||||
if (after > 0.0) {
|
||||
acc += line_get(horizontal, line, n - 1, n, repeat) * after;
|
||||
}
|
||||
}
|
||||
let b1 = min(b0 + block, n);
|
||||
for (var i = b0; i < b1; i++) {
|
||||
if (horizontal) {
|
||||
@@ -618,7 +634,8 @@ fn straight(px: vec4<f32>) -> vec3<f32> {
|
||||
// 9 Gradient Ramp f[0] = (sx, sy, ex, ey); f[1] = start colour; f[2] = end colour;
|
||||
// f[3] = (len2, scatter, blend); u[0] = (_, radial, seed)
|
||||
// 10 Fractal Noise f[0] = (contrast, brightness, scale x, frac); f[1] = (ox, oy, sr, cr);
|
||||
// f[2] = (evo, blend, opacity, scale y); f[3] = (sub influence, 1 / sub scaling);
|
||||
// f[2] = (evo, blend, opacity, scale y); f[3] = (sub influence, 1 / sub scaling,
|
||||
// OCTAVE_SCALE_MAX);
|
||||
// u[0] = (_, kind, n_oct, seed); u[1] = (invert, overflow, normal blend)
|
||||
@compute @workgroup_size(16, 16)
|
||||
fn pointwise(@builtin(global_invocation_id) gid: vec3<u32>) {
|
||||
@@ -856,6 +873,7 @@ fn pointwise(@builtin(global_invocation_id) gid: vec3<u32>) {
|
||||
let scale_y = P.f[2].w;
|
||||
let infl = P.f[3].x;
|
||||
let fmul = P.f[3].y;
|
||||
let fmax = P.f[3].z;
|
||||
let frac = P.f[0].w;
|
||||
let ox = P.f[1].x;
|
||||
let oy = P.f[1].y;
|
||||
@@ -888,7 +906,8 @@ fn pointwise(@builtin(global_invocation_id) gid: vec3<u32>) {
|
||||
sum += n * amp * w;
|
||||
norm += amp * w;
|
||||
amp *= infl;
|
||||
f *= fmul;
|
||||
// noise3::next_octave: the frequency stays within OCTAVE_SCALE_MAX (#3486).
|
||||
f = clamp(f * fmul, 1.0 / fmax, fmax);
|
||||
}
|
||||
var val = sum / max(norm, 1e-6);
|
||||
val = (val - 0.5) * contrast + 0.5 + brightness;
|
||||
|
||||
@@ -761,6 +761,68 @@ 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 and matches the CPU (1000, the old maximum, on a 70 × 44 layer). Once the pixel
|
||||
/// budget cuts the padding only the CPU blurs past the buffer's edge, so the GPU declines the
|
||||
/// effect; the render then takes it on the CPU at 8 and 32 bpc, 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: ¶ms, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// #3460: a box radius far past the image (Gaussian Blur's at Blurriness 30000 is about 15000 px)
|
||||
/// starts each running sum as the CPU does, the pixels inside once and the repeated edges
|
||||
/// counted, so the GPU matches it along rows and columns, with and without repeated edges.
|
||||
#[test]
|
||||
fn box_passes_with_a_radius_far_past_the_image_match_cpu() {
|
||||
let Some(g) = gpu() else { return };
|
||||
let img = pattern(5, 96, 40);
|
||||
let up = g.ctx.upload_image(&img).expect("upload");
|
||||
let tol = tolerance(BitDepth::Bpc32);
|
||||
for repeat in [true, false] {
|
||||
let mut e = crate::context::Enc::new(&g.ctx);
|
||||
let r = [15_000usize; 3];
|
||||
let out = crate::effects::box_passes(&mut e, &up, &r, &r, repeat);
|
||||
let got = e.download(&out).expect("download");
|
||||
let want = effectcraft_raster::box_blur(&img, 15_000, 15_000, 3, repeat);
|
||||
assert_eq!((got.width, got.height), (want.width, want.height));
|
||||
let d = diff(&want, &got, tol);
|
||||
assert_eq!(d.over, 0, "repeat {repeat}: max {} at {:?} on {}", d.max, d.worst, g.ctx.name);
|
||||
}
|
||||
}
|
||||
|
||||
/// #3460: Gaussian Blur's highest Blurriness, 30000, renders the same on the GPU as on the CPU,
|
||||
/// with the padding cut to the effect pixel budget and with Repeat Edge Pixels.
|
||||
#[test]
|
||||
fn gaussian_blur_at_the_highest_blurriness_matches_cpu() {
|
||||
effect_case("ec.blur.gaussian", &[("blurriness", n(30000.0))]);
|
||||
effect_case("ec.blur.gaussian", &[("blurriness", n(30000.0)), ("repeatEdge", Value::Bool(true))]);
|
||||
}
|
||||
|
||||
#[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).
|
||||
|
||||
@@ -57,6 +57,14 @@ fn turbulent_displace_and_cc_lens() {
|
||||
],
|
||||
);
|
||||
effect_case("ec.distort.turbulentdisplace", &[("displacement", e(8)), ("size", n(15.0)), ("pinning", e(6))]);
|
||||
// #3469: both ends of After Effects' Amount range, resized and pinned, and an expression's
|
||||
// Amount past it.
|
||||
effect_case("ec.distort.turbulentdisplace", &[("size", n(30.0)), ("amount", n(10000.0))]);
|
||||
effect_case(
|
||||
"ec.distort.turbulentdisplace",
|
||||
&[("displacement", e(1)), ("size", n(25.0)), ("amount", n(-10000.0)), ("pinning", e(1)), ("resizeLayer", on())],
|
||||
);
|
||||
effect_case("ec.distort.turbulentdisplace", &[("displacement", e(7)), ("amount", n(f64::INFINITY)), ("pinning", e(2))]);
|
||||
// #943: Evolution moves the pattern at a constant rate on both paths, including steps of a
|
||||
// few degrees and angles past a whole revolution, where an eased evolution axis diverges.
|
||||
for evolution in [10.0, 37.0, 400.0, 725.5] {
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -75,6 +75,8 @@ fn edge_preserving_blurs() {
|
||||
fn sharpen_and_unsharp_mask() {
|
||||
effect_case("ec.blur.sharpen", &[("amount", n(60.0))]);
|
||||
effect_case("ec.blur.sharpen", &[("amount", n(250.0))]);
|
||||
// #3466: the top of After Effects' range (80 × the difference from the blur).
|
||||
effect_case("ec.blur.sharpen", &[("amount", n(4000.0))]);
|
||||
effect_case("ec.blur.unsharp", &[("amount", n(120.0)), ("radius", n(4.0))]);
|
||||
effect_case("ec.blur.unsharp", &[("amount", n(80.0)), ("radius", n(2.5)), ("threshold", n(12.0))]);
|
||||
}
|
||||
@@ -136,6 +138,24 @@ fn turbulent_noise() {
|
||||
effect_case("ec.noise.turbulent", &[("fractalType", e(7)), ("noiseType", e(0)), ("transform/perspectiveOffset", on()), ("opacity", n(70.0))]);
|
||||
}
|
||||
|
||||
/// #3486: Sub Scaling above 100 % on both GPU paths (the `pointwise` kernel for the plain
|
||||
/// settings, `fxn_fractal` for Perspective Offset and Turbulent Noise), up to After Effects'
|
||||
/// 10000 at the highest Complexity.
|
||||
#[test]
|
||||
fn fractal_noise_sub_scaling_above_100() {
|
||||
for sub in [200.0, 10000.0] {
|
||||
effect_case("ec.noise.fractal", &[("subSettings/subScaling", n(sub)), ("complexity", n(20.0))]);
|
||||
effect_case(
|
||||
"ec.noise.fractal",
|
||||
&[("subSettings/subScaling", n(sub)), ("complexity", n(20.0)), ("transform/perspectiveOffset", on()), ("evolution", n(90.0))],
|
||||
);
|
||||
effect_case(
|
||||
"ec.noise.turbulent",
|
||||
&[("subSettings/subScaling", n(sub)), ("complexity", n(20.0)), ("evolution", n(120.0)), ("evolutionOptions/turbulenceFactor", n(10.0))],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fractal_noise_other_modes() {
|
||||
effect_case("ec.noise.fractal", &[("noiseType", e(3)), ("fractalType", e(4)), ("blendingMode", e(3))]);
|
||||
|
||||
@@ -218,6 +218,13 @@ fn twirl_legacy_ripple_pulse_power_pin() {
|
||||
// Perspective below 100 %: blended toward the bilinear inverse.
|
||||
effect_case("ec.distort.ccpowerpin", &[("topRight", pt(80.0, -6.0)), ("bottomLeft", pt(-4.0, 50.0)), ("perspective", n(0.0))]);
|
||||
effect_case("ec.distort.ccpowerpin", &[("topLeft", pt(12.0, 6.0)), ("bottomRight", pt(75.0, 30.0)), ("perspective", n(40.0)), ("expandTop", n(15.0))]);
|
||||
// #3492: Expansion down to -200; opposite sides adding up to less than -100 % flip the source,
|
||||
// and Top -50 / Bottom -50 leave it zero high.
|
||||
effect_case("ec.distort.ccpowerpin", &[("topRight", pt(80.0, -6.0)), ("expandTop", n(-200.0)), ("expandBottom", n(-100.0)), ("expandLeft", n(-150.0))]);
|
||||
effect_case(
|
||||
"ec.distort.ccpowerpin",
|
||||
&[("bottomLeft", pt(-4.0, 50.0)), ("perspective", n(40.0)), ("expandTop", n(-50.0)), ("expandBottom", n(-50.0)), ("expandRight", n(-200.0))],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user