EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Venetian Blinds: stripes from the layer centre, Gaussian feather on both edges, as After Effects
vangel7647b3582a0a1a
diff --git a/crates/effects/src/lib.rs b/crates/effects/src/lib.rsindex 89be21ddb..ff10c99c9 100644--- a/crates/effects/src/lib.rs+++ b/crates/effects/src/lib.rs@@ -85,7 +85,7 @@ use effectcraft_keyframe::Value;use effectcraft_project::build::Ids;use effectcraft_project::{GroupKind, ParamUi, PropGroup, Property};pub use effectcraft_raster::{AuxChannels, Image};-pub use misc::{INVERT_ALPHA, INVERT_CHANNELS, glow_ab_t, glow_operation, glow_sigma};+pub use misc::{INVERT_ALPHA, INVERT_CHANNELS, glow_ab_t, glow_operation, glow_sigma, venetian_cover, venetian_origin};pub use sim::particle_state;pub use sim3::{PgBlit, PgPlan, playground_plan, playground_state};pub use stylize2::strobe_on;diff --git a/crates/effects/src/misc.rs b/crates/effects/src/misc.rsindex 848a04f2d..90306be08 100644--- a/crates/effects/src/misc.rs+++ b/crates/effects/src/misc.rs@@ -556,16 +556,58 @@ fn radial_wipe(ctx: &EffectCtx, mut b: Buf) -> Buf {b}+/// Standard normal CDF Φ (Abramowitz & Stegun 7.1.26 erf, |error| < 1.5e-7).+fn norm_cdf(z: f64) -> f64 {+ let x = z.abs() / std::f64::consts::SQRT_2;+ let t = 1.0 / (1.0 + 0.327_591_1 * x);+ let poly = t * (0.254_829_592 + t * (-0.284_496_736 + t * (1.421_413_741 + t * (-1.453_152_027 + t * 1.061_405_429))));+ let erf = 1.0 - poly * (-x * x).exp();+ if z >= 0.0 { 0.5 * (1.0 + erf) } else { 0.5 * (1.0 - erf) }+}++/// Venetian Blinds: how much of a pixel at phase `d` (0..`width`) a band of `done × width`+/// covers, its two edges softened by a Gaussian of σ = Feather / 2 (σ in the units of `width`).+/// Fitted to After Effects 2026 (Completion 40, Direction 30, Width 50, Feather 5 on 960 × 540+/// and 480 × 270 layers): band from phase 0 to done × width, both edges Gaussian, within 6/255.+pub fn venetian_cover(d: f64, width: f64, done: f64, sigma: f64) -> f64 {+ let band = done * width;+ if sigma < 1e-3 {+ return if d < band { 1.0 } else { 0.0 };+ }+ // Wider than a few blinds the stripes blur into an even veil.+ if sigma > 8.0 * width {+ return done.clamp(0.0, 1.0);+ }+ let n = ((4.0 * sigma / width).ceil() as i64 + 1).clamp(1, 40);+ let mut t = 0.0;+ for k in -n..=n {+ let u = d + k as f64 * width;+ t += norm_cdf(u / sigma) - norm_cdf((u - band) / sigma);+ }+ t.clamp(0.0, 1.0)+}++/// Venetian Blinds' phase origin in layer pixels: the layer centre plus 0.6 px (fitted to the+/// AE renders above; the stripes are measured from the layer's centre, not its corner).+pub fn venetian_origin(layer_size: [f64; 2]) -> [f64; 2] {+ [layer_size[0] / 2.0 + 0.6, layer_size[1] / 2.0 + 0.6]+}+fn venetian(ctx: &EffectCtx, mut b: Buf) -> Buf {- let done = ctx.params.f("completion") / 100.0;+ let done = (ctx.params.f("completion") / 100.0).clamp(0.0, 1.0);+ if done <= 0.0 {+ return b;+ }let ang = ctx.params.f("direction").to_radians();let width = (ctx.params.f("width") * b.scale).max(1.0);- let feather = (ctx.params.f("feather") * b.scale).max(0.001);+ let sigma = ctx.params.f("feather").max(0.0) * b.scale / 2.0;let (dx, dy) = (ang.cos(), ang.sin());+ let (ox, oy) = b.to_px(venetian_origin(ctx.layer_size));b.img.rows_mut().for_each(|(y, row)| {+ let ry = (y as f64 + 0.5 - oy) * dy;for (x, px) in row.iter_mut().enumerate() {- let d = ((x as f64 + 0.5) * dx + (y as f64 + 0.5) * dy).rem_euclid(width);- let k = ((d - done * width) / feather + 0.5).clamp(0.0, 1.0) as f32;+ let d = ((x as f64 + 0.5 - ox) * dx + ry).rem_euclid(width);+ let k = (1.0 - venetian_cover(d, width, done, sigma)) as f32;for c in px.iter_mut() {*c *= k;}@@ -869,6 +911,50 @@ mod tests {}}+ /// After Effects 2026, Venetian Blinds Completion 40, Direction 30, Width 50, Feather 5 on+ /// an opaque 480 × 270 layer: alpha (0..255) along row y = 135. The transparent band starts+ /// at the layer centre's phase, both edges are Gaussian (σ = Feather / 2).+ #[test]+ fn venetian_blinds_match_after_effects() {+ let img = effectcraft_raster::Image::filled(480, 270, [0.5, 0.5, 0.5, 1.0]);+ let vals = [("completion", Value::Scalar(40.0)), ("direction", Value::Scalar(30.0)), ("width", Value::Scalar(50.0)), ("feather", Value::Scalar(5.0))];+ let o = run_fx("ec.transition.venetian", &vals, img, 0.0, EffectEnv::default());+ let ae = [+ (200, 5.0),+ (203, 47.0),+ (206, 145.0),+ (209, 228.0),+ (212, 253.0),+ (224, 255.0),+ (236, 238.0),+ (239, 168.0),+ (242, 66.0),+ (245, 10.0),+ (251, 0.0),+ (257, 2.0),+ (260, 31.0),+ ];+ for (x, a) in ae {+ let got = o.img.get(x, 135)[3] * 255.0;+ assert!((got - a).abs() <= 6.0, "x {x}: alpha {got} vs AE {a}");+ }+ // No completion leaves the layer; full completion clears it; no feather is a hard edge.+ let full = [("completion", Value::Scalar(100.0)), ("feather", Value::Scalar(5.0))];+ let img = effectcraft_raster::Image::filled(40, 20, [0.5, 0.5, 0.5, 1.0]);+ assert!(run_fx("ec.transition.venetian", &full, img.clone(), 0.0, EffectEnv::default()).img.data.iter().all(|p| p[3] < 1e-4));+ assert_eq!(run_fx("ec.transition.venetian", &[("completion", Value::Scalar(0.0))], img.clone(), 0.0, EffectEnv::default()).img, img);+ let hard = run_fx(+ "ec.transition.venetian",+ &[("completion", Value::Scalar(50.0)), ("width", Value::Scalar(10.0)), ("feather", Value::Scalar(0.0))],+ img,+ 0.0,+ EffectEnv::default(),+ );+ assert!(hard.img.data.iter().all(|p| p[3] == 0.0 || p[3] == 1.0));+ // A feather far wider than the blinds is an even veil.+ assert_eq!(venetian_cover(3.0, 10.0, 0.5, 1e9), 0.5);+ }+#[test]fn glow_operation_and_arbitrary_map() {// Pixels addressed in layer space (Glow pads its buffer).diff --git a/crates/gpu/src/fx_generate.rs b/crates/gpu/src/fx_generate.rsindex 3744ec4fa..7f2678a57 100644--- a/crates/gpu/src/fx_generate.rs+++ b/crates/gpu/src/fx_generate.rs@@ -204,24 +204,32 @@ fn linear_wipe(e: &mut Enc, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {}fn venetian(e: &mut Enc, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {- let done = ctx.params.f("completion") / 100.0;+ let done = (ctx.params.f("completion") / 100.0).clamp(0.0, 1.0);+ if done <= 0.0 {+ return Some(b);+ }let ang = ctx.params.f("direction").to_radians();let width = (ctx.params.f("width") * b.scale).max(1.0);- let feather = (ctx.params.f("feather") * b.scale).max(0.001);+ let sigma = ctx.params.f("feather").max(0.0) * b.scale / 2.0;+ // The CPU's even veil and term count (effects::venetian_cover).+ if sigma > 8.0 * width {+ return None;+ }let (dx, dy) = (ang.cos(), ang.sin());- let mut data = Vec::with_capacity((6 * b.img.width + 2 * b.img.height) as usize);+ let (ox, oy) = b.to_px(effectcraft_effects::venetian_origin(ctx.layer_size));+ let mut data = Vec::with_capacity((4 * b.img.width + 2 * b.img.height) as usize);for x in 0..b.img.width {- let cx = ((x as f64 + 0.5) * dx).rem_euclid(width);- data.extend(hl(cx - done * width));- data.extend(hl(cx - width - done * width));+ let cx = ((x as f64 + 0.5 - ox) * dx).rem_euclid(width);+ data.extend(hl(cx));data.extend(hl(cx - width));}for y in 0..b.img.height {- data.extend(hl(((y as f64 + 0.5) * dy).rem_euclid(width)));+ data.extend(hl(((y as f64 + 0.5 - oy) * dy).rem_euclid(width)));}let mut p = Params::default();- p.u[0][0] = 6 * b.img.width;- p.f[0][0] = feather as f32;+ p.u[0][0] = 4 * b.img.width;+ p.u[0][1] = if sigma < 1e-3 { 0 } else { ((4.0 * sigma / width).ceil() as u32 + 1).clamp(1, 40) };+ p.f[0] = [width as f32, (done * width) as f32, sigma as f32, 0.0];run(e, "gen_venetian", &p, b, None, Some(&data))}diff --git a/crates/gpu/src/shaders/fx_generate.wgsl b/crates/gpu/src/shaders/fx_generate.wgslindex 2b571d582..aa132217a 100644--- a/crates/gpu/src/shaders/fx_generate.wgsl+++ b/crates/gpu/src/shaders/fx_generate.wgsl@@ -42,6 +42,15 @@ fn gen_sum(a: vec2<f32>, b: vec2<f32>) -> f32 {return (a.x + b.x) + (a.y + b.y);}+// Standard normal CDF (Abramowitz & Stegun 7.1.26 erf; effects::misc::norm_cdf).+fn gen_norm_cdf(z: f32) -> f32 {+ let x = abs(z) * 0.70710678;+ let t = 1.0 / (1.0 + 0.3275911 * x);+ let poly = t * (0.254829592 + t * (-0.284496736 + t * (1.421413741 + t * (-1.453152027 + t * 1.061405429))));+ let erf = 1.0 - poly * exp(-x * x);+ return select(0.5 * (1.0 - erf), 0.5 * (1.0 + erf), z >= 0.0);+}+// ---------------------------------------------------------------- Radial Blur (raster::radial_blur)// u[0] = (zoom, samples); f[0] = (cx, cy); data = per sample (sin, cos) (spin) or k (zoom).@@ -238,9 +247,9 @@ fn gen_linear_wipe(@builtin(global_invocation_id) gid: vec3<u32>) {textureStore(out, p, textureLoad(src, p, 0) * k);}-// Venetian Blinds. Per column (6 floats): (cx − done·w), (cx − w − done·w), (cx − w) as-// (hi, lo), with cx = ((x + 0.5)·dx) mod w; per row (2 floats): ((y + 0.5)·dy) mod w.-// u[0].x = row table offset; f[0].x = feather.+// Venetian Blinds (effects::venetian_cover). Per column (4 floats): cx, (cx − w) as (hi, lo),+// with cx = ((x + 0.5 − ox)·dx) mod w; per row (2 floats): ((y + 0.5 − oy)·dy) mod w.+// u[0] = (row table offset, Gaussian terms per side, 0 = hard edge); f[0] = (w, band, σ).@compute @workgroup_size(16, 16)fn gen_venetian(@builtin(global_invocation_id) gid: vec3<u32>) {let dims = out_dims();@@ -248,18 +257,28 @@ fn gen_venetian(@builtin(global_invocation_id) gid: vec3<u32>) {if (p.x >= dims.x || p.y >= dims.y) {return;}- let col = 6u * u32(p.x);+ let col = 4u * u32(p.x);let row = gen_hl(P.u[0].x + 2u * u32(p.y));// (d mod w) wraps once the column and row terms reach w.- let wrapped = gen_sum(gen_hl(col + 4u), row) >= 0.0;- var t: f32;- if (wrapped) {- t = gen_sum(gen_hl(col + 2u), row);+ var d = gen_sum(gen_hl(col), row);+ if (gen_sum(gen_hl(col + 2u), row) >= 0.0) {+ d = gen_sum(gen_hl(col + 2u), row);+ }+ let w = P.f[0].x;+ let band = P.f[0].y;+ let sigma = P.f[0].z;+ let n = i32(P.u[0].y);+ var t = 0.0;+ if (n == 0) {+ t = select(0.0, 1.0, d < band);} else {- t = gen_sum(gen_hl(col), row);+ for (var k = -n; k <= n; k++) {+ let u = d + f32(k) * w;+ t += gen_norm_cdf(u / sigma) - gen_norm_cdf((u - band) / sigma);+ }}- let k = clamp(t / P.f[0].x + 0.5, 0.0, 1.0);- textureStore(out, p, textureLoad(src, p, 0) * k);+ let cover = clamp(t, 0.0, 1.0);+ textureStore(out, p, textureLoad(src, p, 0) * (1.0 - cover));}// Angle (degrees, clockwise from up) of the pixel vector rotated by rotation `r` (0 = start,diff --git a/docs/effects-parity.md b/docs/effects-parity.mdindex ffc478182..f4da80ba7 100644--- a/docs/effects-parity.md+++ b/docs/effects-parity.md@@ -45,7 +45,7 @@ corpus compares renders, each effect is assumed to differ somewhere, and users k| Stylize | 25 | 25 | Glow's halo (coverage of a dim layer's edge) and blur width match After Effects 2026 renders; glows above the threshold match too (each channel 8 × (value − threshold + 0.061), measured at three thresholds and two radii); Composite Original's labels are swapped against After Effects (EffectCraft's On Top adds the glow over the original, which After Effects calls Behind); Motion Tile output size (#369) || Text | 2 | 2 | — || Time | 8 | 8 | #535 (Pixel Motion Blur, Vector Detail) is closed |-| Transition | 17 | 17 | — |+| Transition | 17 | 17 | Venetian Blinds matches After Effects 2026 renders (band phase from the layer centre, Gaussian feather on both edges) except within ~6 px of the layer edge (up to 48/255) || Utility | 9 | 7 | — |Third-party bundles in After Effects (Cineware, Mocha AE) are out of scope; Keylight is@@ -67,6 +67,7 @@ the GPU is performance, not parity.| 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) || 2026-10-19 | minor | Radial Blur repeats the edge instead of sampling transparency outside the layer, measured against After Effects 2026 renders (CPU and GPU) |+| 2026-10-19 | minor | Venetian Blinds: stripes measured from the layer centre, both band edges Gaussian (σ = Feather / 2), measured against After Effects 2026 (CPU and GPU) || 2026-10-12 | minor | Parameters 3,014 to 3,017 (effects.md); #303, #514, #526, #533–#536 marked closed instead of pending || 2026-10-12 | minor | Effect colour labels (26.5) added in Effect Controls || 2026-10-12 | minor | Tint's Swap Colors button and agent-drivable command (#963); undo/redo, instance targeting, animated layer-time edits and invalid-input tests |