Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

M9.13: Minimax Don't Shrink Edges, Channel Combiner Saturation Multiplied, 3D Channel Extract anti-alias, Block Dissolve Soft Edges, locked pinning, Optimal Pixels

Brandon Thomas69202c7b3e12
diff --git a/crates/effects/src/catalog.rs b/crates/effects/src/catalog.rs
index ad47275aa..402cc2c59 100644
--- a/crates/effects/src/catalog.rs
+++ b/crates/effects/src/catalog.rs
@@ -9,13 +9,8 @@ use crate::{CATEGORIES, registry};
/// as the public behaviour documentation describes it.
pub const PARTIAL: &[(&str, &str)] = &[
("ec.blur.cameralens", "no Diffraction Fringe or Blur Map layer"),
- ("ec.channel.minimax", "no Don't Shrink Edges option"),
- ("ec.channel.combiner", "no Saturation Multiplied target"),
- ("ec.3d.channelextract", "no anti-alias option"),
("ec.color.colorama", "no Add Phase, editable Output Cycle, Modify, Pixel Selection or Masking"),
("ec.color.selectivecolor", "simplified Colors / Details layout"),
- ("ec.distort.turbulentdisplace", "no locked pinning variants"),
- ("ec.distort.opticscompensation", "no Optimal Pixels"),
("ec.distort.transform", "no shutter-angle motion blur"),
("ec.distort.reshape", "no correspondence points"),
("ec.distort.rollingshutterrepair", "Pixel Motion Detail has no effect"),
@@ -35,7 +30,6 @@ pub const PARTIAL: &[(&str, &str)] = &[
("ec.sim.waveworld", "no wireframe controls, dry-area rendering or ground group"),
("ec.stylize.glow", "no Glow Operation or arbitrary colour map"),
("ec.stylize.cartoon", "no Edge Enhancement"),
- ("ec.transition.blockdissolve", "no Soft Edges option"),
];
/// Whether Effect Controls shows parameter (or twirl-down group) `param` (spec id path,
diff --git a/crates/effects/src/channel.rs b/crates/effects/src/channel.rs
index 17b23521a..b763ac21f 100644
--- a/crates/effects/src/channel.rs
+++ b/crates/effects/src/channel.rs
@@ -90,7 +90,8 @@ const COMBINER_FROM: [&str; 14] = [
"Min RGB",
];
/// Channel Combiner's To options (a single value goes into one channel).
-const COMBINER_TO: [&str; 8] = ["Red Only", "Green Only", "Blue Only", "Alpha Only", "Lightness Only", "Hue Only", "Saturation Only", "Grayscale"];
+const COMBINER_TO: [&str; 9] =
+ ["Red Only", "Green Only", "Blue Only", "Alpha Only", "Lightness Only", "Hue Only", "Saturation Only", "Grayscale", "Saturation Multiplied"];
fn channel_combiner(ctx: &EffectCtx, mut b: Buf) -> Buf {
let from = ctx.params.e("from");
@@ -160,6 +161,13 @@ fn channel_combiner(ctx: &EffectCtx, mut b: Buf) -> Buf {
let (r, g, bb) = hsl_to_rgb(0.0, v.clamp(0.0, 1.0), 0.5);
[r, g, bb]
}
+ // Saturation Multiplied: the pixel keeps its hue and lightness; its saturation
+ // is scaled by the value.
+ 8 => {
+ let (h, s, l) = rgb_to_hsl(c[0], c[1], c[2]);
+ let (r, g, bb) = hsl_to_rgb(h, (s * v).clamp(0.0, 1.0), l);
+ [r, g, bb]
+ }
_ => [v, v, v],
}
}
@@ -175,6 +183,25 @@ fn channel_combiner(ctx: &EffectCtx, mut b: Buf) -> Buf {
/// Minimax's Direction options.
pub(crate) const MINIMAX_DIRECTIONS: [&str; 3] = ["Horizontal & Vertical", "Just Horizontal", "Just Vertical"];
+/// `p` with `rx` / `ry` zero pixels added on every side.
+fn pad_plane(p: &Plane, rx: usize, ry: usize) -> Plane {
+ let (w, h) = (p.w + 2 * rx, p.h + 2 * ry);
+ let mut out = Plane::new(w, h);
+ for y in 0..p.h {
+ out.data[(y + ry) * w + rx..(y + ry) * w + rx + p.w].copy_from_slice(&p.data[y * p.w..(y + 1) * p.w]);
+ }
+ out
+}
+
+/// The `w`×`h` interior of a plane padded by [`pad_plane`].
+fn crop_plane(p: &Plane, rx: usize, ry: usize, w: usize, h: usize) -> Plane {
+ let mut out = Plane::new(w, h);
+ for y in 0..h {
+ out.data[y * w..(y + 1) * w].copy_from_slice(&p.data[(y + ry) * p.w + rx..(y + ry) * p.w + rx + w]);
+ }
+ out
+}
+
fn minimax(ctx: &EffectCtx, mut b: Buf) -> Buf {
let r = (ctx.params.f("radius") * b.scale).round().max(0.0) as usize;
if r == 0 {
@@ -182,6 +209,7 @@ fn minimax(ctx: &EffectCtx, mut b: Buf) -> Buf {
}
let op = ctx.params.e("operation");
let ch = ctx.params.e("channel");
+ let dont_shrink = ctx.params.b("dontShrinkEdges");
let (rx, ry) = match ctx.params.e("direction") {
1 => (r, 0),
2 => (0, r),
@@ -204,12 +232,16 @@ fn minimax(ctx: &EffectCtx, mut b: Buf) -> Buf {
if !sel[k] {
continue;
}
- *pl = match op {
- 0 => morph_plane(pl, rx, ry, false),
- 1 => morph_plane(pl, rx, ry, true),
- 2 => morph_plane(&morph_plane(pl, rx, ry, false), rx, ry, true),
- _ => morph_plane(&morph_plane(pl, rx, ry, true), rx, ry, false),
+ // Beyond the layer edge is empty (0), so Minimum eats into the edges unless Don't
+ // Shrink Edges extends the edge pixels instead.
+ let padded = if dont_shrink { pl.clone() } else { pad_plane(pl, rx, ry) };
+ let out = match op {
+ 0 => morph_plane(&padded, rx, ry, false),
+ 1 => morph_plane(&padded, rx, ry, true),
+ 2 => morph_plane(&morph_plane(&padded, rx, ry, false), rx, ry, true),
+ _ => morph_plane(&morph_plane(&padded, rx, ry, true), rx, ry, false),
};
+ *pl = if dont_shrink { out } else { crop_plane(&out, rx, ry, pl.w, pl.h) };
}
let mut img = join(&planes);
img.data.par_iter_mut().for_each(|px| {
@@ -408,6 +440,7 @@ pub fn specs() -> Vec<EffectSpec> {
p("radius", "Radius", num(0.0), slider(0.0, 500.0, 0.0, 100.0, 0)),
p("channel", "Channel", Value::Enum(0), popup(&["Color", "Alpha", "Alpha and Color", "Red", "Green", "Blue"])),
p("direction", "Direction", Value::Enum(0), popup(&MINIMAX_DIRECTIONS)),
+ p("dontShrinkEdges", "Don't Shrink Edges", Value::Bool(false), ParamUi::Checkbox),
],
minimax,
),
@@ -658,4 +691,23 @@ mod tests {
assert!(close(out.get(0, 0), [0.0, 0.0, 1.0, 1.0]));
assert!(close(out.get(1, 0), [1.0, 0.0, 0.0, 1.0]));
}
+
+ #[test]
+ fn minimax_shrinks_layer_edges_unless_told_not_to() {
+ let img = Image::filled(9, 9, [1.0, 1.0, 1.0, 1.0]);
+ let shrunk = run("ec.channel.minimax", &[("radius", num(2.0)), ("operation", Value::Enum(0))], img.clone());
+ assert_eq!(shrunk.get(0, 4)[0], 0.0);
+ assert_eq!(shrunk.get(4, 4)[0], 1.0);
+ let kept = run("ec.channel.minimax", &[("radius", num(2.0)), ("operation", Value::Enum(0)), ("dontShrinkEdges", Value::Bool(true))], img);
+ assert_eq!(kept.get(0, 4)[0], 1.0);
+ }
+
+ #[test]
+ fn channel_combiner_saturation_multiplied() {
+ // From Lightness (0.5) into Saturation Multiplied halves the saturation, keeping hue.
+ let red = Image::filled(1, 1, [0.75, 0.25, 0.25, 1.0]);
+ let out = run("ec.channel.combiner", &[("from", Value::Enum(8)), ("to", Value::Enum(8))], red).get(0, 0);
+ let (h, s, l) = rgb_to_hsl(out[0], out[1], out[2]);
+ assert!((h.abs() < 1e-4 || (h - 1.0).abs() < 1e-4) && (s - 0.25).abs() < 1e-3 && (l - 0.5).abs() < 1e-3, "{h} {s} {l}");
+ }
}
diff --git a/crates/effects/src/channel3d.rs b/crates/effects/src/channel3d.rs
index 8da443889..3515204eb 100644
--- a/crates/effects/src/channel3d.rs
+++ b/crates/effects/src/channel3d.rs
@@ -31,12 +31,17 @@ fn aux(ctx: &EffectCtx) -> Option<Arc<AuxChannels>> {
/// Aux index for each buffer pixel (None outside the aux image).
fn index_map(b: &Buf, a: &AuxChannels) -> Vec<Option<usize>> {
+ index_map_at(b, a, [0.5, 0.5])
+}
+
+/// [`index_map`] sampling each pixel at sub-pixel position `at` (0..1).
+fn index_map_at(b: &Buf, a: &AuxChannels, at: [f64; 2]) -> Vec<Option<usize>> {
let (w, h) = (b.img.width as usize, b.img.height as usize);
let inv = 1.0 / b.scale.max(1e-9);
(0..w * h)
.into_par_iter()
.map(|i| {
- let (x, y) = ((i % w) as f64 + 0.5, (i / w) as f64 + 0.5);
+ let (x, y) = ((i % w) as f64 + at[0], (i / w) as f64 + at[1]);
a.index_at((x - b.offset[0]) * inv, (y - b.offset[1]) * inv)
})
.collect()
@@ -60,7 +65,28 @@ pub const EXTRACT_CHANNELS: [&str; 8] = ["Z-Depth", "Object ID", "Texture UV", "
fn channel_extract(ctx: &EffectCtx, mut b: Buf) -> Buf {
let Some(a) = aux(ctx) else { return b };
+ if ctx.params.b("antialias") {
+ // Anti-alias: average four sub-pixel samples of the channel.
+ let subs = [[0.25, 0.25], [0.75, 0.25], [0.25, 0.75], [0.75, 0.75]];
+ let imgs: Vec<Image> = subs.iter().map(|s| channel_extract_at(ctx, &b, &a, &index_map_at(&b, &a, *s))).collect::<Option<Vec<_>>>().unwrap_or_default();
+ if imgs.len() == 4 {
+ let mut out = imgs[0].clone();
+ out.data.par_iter_mut().enumerate().for_each(|(i, p)| {
+ *p = std::array::from_fn(|c| imgs.iter().map(|m| m.data[i][c]).sum::<f32>() * 0.25);
+ });
+ b.img = out;
+ }
+ return b;
+ }
let idx = index_map(&b, &a);
+ if let Some(i) = channel_extract_at(ctx, &b, &a, &idx) {
+ b.img = i;
+ }
+ b
+}
+
+/// 3D Channel Extract through one index map (None when the channel is missing).
+fn channel_extract_at(ctx: &EffectCtx, b: &Buf, a: &AuxChannels, idx: &[Option<usize>]) -> Option<Image> {
let (bp, wp) = (ctx.params.f("blackPoint") as f32, ctx.params.f("whitePoint") as f32);
// Clamp Output limits the mapped values to 0..1; Invert Depth Map flips them.
let (clamp, invert) = (ctx.params.b("clampOutput"), ctx.params.b("invertDepthMap"));
@@ -69,24 +95,20 @@ fn channel_extract(ctx: &EffectCtx, mut b: Buf) -> Buf {
let lv = |v: f32| if wp >= bp { lv(v) } else { 1.0 - cl((v - wp) / (bp - wp).max(1e-9)) };
let lv = |v: f32| if invert { 1.0 - lv(v) } else { lv(v) };
let get3 = |names: [&[&str]; 3]| -> Option<[&[f32]; 3]> { Some([a.find(names[0])?, a.find(names[1])?, a.find(names[2])?]) };
- let img: Option<Image> = match ctx.params.e("channel") {
- 0 => a.depth().map(|z| map_grey(&b, &idx, |i| lv(z[i]))),
- 1 => a.object_id().map(|c| map_grey(&b, &idx, |i| lv(c[i]))),
- 7 => a.material_id().map(|c| map_grey(&b, &idx, |i| lv(c[i]))),
- 4 => a.coverage().map(|c| map_grey(&b, &idx, |i| lv(c[i]))),
+ match ctx.params.e("channel") {
+ 0 => a.depth().map(|z| map_grey(b, idx, |i| lv(z[i]))),
+ 1 => a.object_id().map(|c| map_grey(b, idx, |i| lv(c[i]))),
+ 7 => a.material_id().map(|c| map_grey(b, idx, |i| lv(c[i]))),
+ 4 => a.coverage().map(|c| map_grey(b, idx, |i| lv(c[i]))),
2 => get3([&["UV.U", "U", "uv.x"], &["UV.V", "V", "uv.y"], &["UV.W", "W", "uv.z"]])
.or_else(|| Some([a.find(&["UV.U", "U", "uv.x"])?, a.find(&["UV.V", "V", "uv.y"])?, a.find(&["UV.V", "V", "uv.y"])?]))
- .map(|c| map_rgb(&b, &idx, |i| [lv(c[0][i]), lv(c[1][i]), 0.0])),
+ .map(|c| map_rgb(b, idx, |i| [lv(c[0][i]), lv(c[1][i]), 0.0])),
3 => get3([&["N.X", "Normal.X", "normals.x"], &["N.Y", "Normal.Y", "normals.y"], &["N.Z", "Normal.Z", "normals.z"]])
- .map(|c| map_rgb(&b, &idx, |i| [lv(c[0][i] * 0.5 + 0.5), lv(c[1][i] * 0.5 + 0.5), lv(c[2][i] * 0.5 + 0.5)])),
+ .map(|c| map_rgb(b, idx, |i| [lv(c[0][i] * 0.5 + 0.5), lv(c[1][i] * 0.5 + 0.5), lv(c[2][i] * 0.5 + 0.5)])),
5 => get3([&["BG.R", "Background.R"], &["BG.G", "Background.G"], &["BG.B", "Background.B"]])
- .map(|c| map_rgb(&b, &idx, |i| [lv(c[0][i]), lv(c[1][i]), lv(c[2][i])])),
- _ => get3([&["R"], &["G"], &["B"]]).map(|c| map_rgb(&b, &idx, |i| [c[0][i], c[1][i], c[2][i]])),
- };
- if let Some(i) = img {
- b.img = i;
+ .map(|c| map_rgb(b, idx, |i| [lv(c[0][i]), lv(c[1][i]), lv(c[2][i])])),
+ _ => get3([&["R"], &["G"], &["B"]]).map(|c| map_rgb(b, idx, |i| [c[0][i], c[1][i], c[2][i]])),
}
- b
}
fn map_grey(b: &Buf, idx: &[Option<usize>], f: impl Fn(usize) -> f32 + Sync) -> Image {
@@ -443,6 +465,7 @@ pub fn specs() -> Vec<EffectSpec> {
p("whitePoint", "White Point", num(10000.0), slider(-1.0e6, 1.0e6, -10000.0, 10000.0, 2)),
p("clampOutput", "Clamp Output", Value::Bool(true), ParamUi::Checkbox),
p("invertDepthMap", "Invert Depth Map", Value::Bool(false), ParamUi::Checkbox),
+ p("antialias", "Anti-alias", Value::Bool(false), ParamUi::Checkbox),
],
channel_extract,
),
@@ -689,4 +712,18 @@ mod tests {
let s = run_fx("ec.3d.extractor", &[("red", Value::Str("A".into()))], Image::filled(2, 2, [0.2, 0.3, 0.4, 1.0]), 0.0, EffectEnv::default());
assert_eq!(s.img.get(0, 0), [1.0, 0.3, 0.4, 1.0]);
}
+
+ #[test]
+ fn channel_extract_antialias_averages_sub_pixels() {
+ // Depth at twice the layer resolution, alternating 0 / 1000 per aux column.
+ let mut a = AuxChannels::new(40, 20, 2.0);
+ a.channels = vec![("Z".into(), (0..800).map(|i| if i % 2 == 0 { 0.0 } else { 1000.0 }).collect())];
+ let host = AuxHost(Arc::new(a));
+ let vals = [("blackPoint", num(0.0)), ("whitePoint", num(1000.0))];
+ let hard = run("ec.3d.channelextract", &vals, &host);
+ let v = hard.get(5, 5)[0];
+ assert!(v == 0.0 || v == 1.0, "{v}");
+ let soft = run("ec.3d.channelextract", &[vals.as_slice(), &[("antialias", Value::Bool(true))]].concat(), &host);
+ assert!((soft.get(5, 5)[0] - 0.5).abs() < 1e-5, "{:?}", soft.get(5, 5));
+ }
}
diff --git a/crates/effects/src/distort2.rs b/crates/effects/src/distort2.rs
index 66f038e0d..a1e58944e 100644
--- a/crates/effects/src/distort2.rs
+++ b/crates/effects/src/distort2.rs
@@ -62,7 +62,26 @@ const TURBULENT_KINDS: [&str; 9] = [
"Horizontal Displacement",
"Cross Displacement",
];
-const TURBULENT_PINNING: [&str; 8] = ["None", "Pin All", "Pin Horizontal", "Pin Vertical", "Pin Left", "Pin Top", "Pin Right", "Pin Bottom"];
+/// Turbulent Displace's Pinning options. The Locked variants also keep every displaced
+/// sample inside the layer (no edge pixels pulled in from outside) and ease the pinning over a
+/// wider band, so the pinned edges and their neighbourhood stay put.
+const TURBULENT_PINNING: [&str; 15] = [
+ "None",
+ "Pin All",
+ "Pin Horizontal",
+ "Pin Vertical",
+ "Pin Left",
+ "Pin Top",
+ "Pin Right",
+ "Pin Bottom",
+ "Pin All Locked",
+ "Pin Horizontal Locked",
+ "Pin Vertical Locked",
+ "Pin Left Locked",
+ "Pin Top Locked",
+ "Pin Right Locked",
+ "Pin Bottom Locked",
+];
fn turbulent_displace(ctx: &EffectCtx, mut b: Buf) -> Buf {
let amount = ctx.params.f("amount") * b.scale;
@@ -80,10 +99,12 @@ fn turbulent_displace(ctx: &EffectCtx, mut b: Buf) -> Buf {
let evo = ctx.params.f("evolution") / 360.0;
// Evolution Options: Cycle Evolution loops the noise every `cycle` revolutions.
let cycle = (ctx.params.b("evolutionOptions/cycleEvolution")).then(|| ctx.params.f("evolutionOptions/cycle").round().max(1.0));
- let pin = ctx.params.e("pinning");
+ let pin_raw = ctx.params.e("pinning");
+ let locked = pin_raw >= 8;
+ let pin = if locked { pin_raw - 7 } else { pin_raw };
let falloff = if (3..=5).contains(&kind) { 0.3 } else { 0.5 };
let (lx, ly, lw, lh) = layer_rect(ctx, &b);
- let edge = (lw.min(lh) * 0.1).max(1.0);
+ let edge = (lw.min(lh) * if locked { 0.25 } else { 0.1 }).max(1.0);
let seed = (ctx.seed ^ 0x7d15).wrapping_add((ctx.params.f("evolutionOptions/randomSeed") as i64 as u32).wrapping_mul(0x9e37_79b9));
let n = |u: f64, v: f64, s: u32| {
let s = seed.wrapping_add(s);
@@ -128,7 +149,11 @@ fn turbulent_displace(ctx: &EffectCtx, mut b: Buf) -> Buf {
7 => bt,
_ => 1.0,
};
- Some((x + dx * k, y + dy * k))
+ let (sx, sy) = (x + dx * k, y + dy * k);
+ if locked {
+ return Some((sx.clamp(lx + 0.5, lx + lw - 0.5), sy.clamp(ly + 0.5, ly + lh - 0.5)));
+ }
+ Some((sx, sy))
});
b
}
@@ -223,7 +248,10 @@ fn optics_compensation(ctx: &EffectCtx, mut b: Buf) -> Buf {
let f = r_ref / half.tan();
// Resize (with Reverse Lens Distortion): grow the layer so the stretched corners stay
// visible, up to 2× / 4× the layer size (Unlimited is capped at 8×).
- let resize = ctx.params.e("resize");
+ // Optimal Pixels (invalidates Resize): scale the result so the whole corrected picture
+ // fits the layer (Reverse) or fills it with no empty corners (forward).
+ let optimal = ctx.params.b("optimalPixels");
+ let resize = if optimal { 0 } else { ctx.params.e("resize") };
if reverse && resize > 0 && !ctx.adjustment {
let c = b.to_px(ctx.params.v2("viewCenter"));
let rc =
@@ -234,9 +262,21 @@ fn optics_compensation(ctx: &EffectCtx, mut b: Buf) -> Buf {
b.pad(grow.min(cap).min(4096.0).ceil() as u32);
}
let c = b.to_px(ctx.params.v2("viewCenter"));
+ let fit = if optimal {
+ let rc =
+ [(lx, ly), (lx + lw, ly), (lx, ly + lh), (lx + lw, ly + lh)].iter().map(|p| ((p.0 - c.0).powi(2) + (p.1 - c.1).powi(2)).sqrt()).fold(1.0, f64::max);
+ if reverse {
+ let th = (rc / r_ref * half).min(FRAC_PI_2 - 1e-3);
+ (f * th.tan() / rc).max(1.0)
+ } else {
+ ((rc / f).atan() / half * r_ref / rc).min(1.0)
+ }
+ } else {
+ 1.0
+ };
b.img = remap(&b.img, false, |x, y| {
let (dx, dy) = (x - c.0, y - c.1);
- let r = (dx * dx + dy * dy).sqrt();
+ let r = (dx * dx + dy * dy).sqrt() * fit;
if r < 1e-9 {
return Some((x, y));
}
@@ -249,7 +289,7 @@ fn optics_compensation(ctx: &EffectCtx, mut b: Buf) -> Buf {
}
f * th.tan()
};
- let k = rs / r;
+ let k = rs / r * fit;
Some((c.0 + dx * k, c.1 + dy * k))
});
b
@@ -717,6 +757,7 @@ pub fn specs() -> Vec<EffectSpec> {
p("reverseLensDistortion", "Reverse Lens Distortion", Value::Bool(false), ParamUi::Checkbox),
p("fovOrientation", "FOV Orientation", Value::Enum(0), popup(&["Horizontal", "Vertical", "Diagonal"])),
p("viewCenter", "View Center", pt(0.5, 0.5), ParamUi::Point),
+ p("optimalPixels", "Optimal Pixels (Invalidates Resize)", Value::Bool(false), ParamUi::Checkbox),
p("resize", "Resize", Value::Enum(0), popup(&["Off", "Max 2X", "Max 4X", "Unlimited"])),
],
optics_compensation,
@@ -1051,6 +1092,15 @@ mod tests {
// Random Seed changes the pattern.
let seeded = run("ec.distort.turbulentdisplace", &[("size", num(10.0)), ("evolutionOptions/randomSeed", num(5.0))], img);
assert!(max_diff(&seeded.img, &pinned.img) > 1e-3);
+ // Locked pinning: no sample comes from outside the layer (no transparent pixels pulled
+ // in) and the border still holds.
+ let opaque = Image::filled(40, 40, [0.5, 0.5, 0.5, 1.0]);
+ let strong = [("size", num(10.0)), ("amount", num(80.0))];
+ let left = run("ec.distort.turbulentdisplace", &[strong.as_slice(), &[("pinning", Value::Enum(4))]].concat(), opaque.clone());
+ let locked = run("ec.distort.turbulentdisplace", &[strong.as_slice(), &[("pinning", Value::Enum(11))]].concat(), opaque.clone());
+ assert!(left.img.data.iter().any(|p| p[3] < 0.99), "plain pin lets edges pull in");
+ assert!(locked.img.data.iter().all(|p| p[3] > 0.999), "locked keeps everything inside");
+ assert_eq!(TURBULENT_PINNING[11], "Pin Left Locked");
}
#[test]
@@ -1077,4 +1127,20 @@ mod tests {
let max4 = run("ec.distort.opticscompensation", &set(2), img);
assert!(max4.img.width >= max2.img.width);
}
+
+ #[test]
+ fn optics_optimal_pixels_fills_or_fits_the_layer() {
+ let img = Image::filled(32, 24, [0.5, 0.5, 0.5, 1.0]);
+ // Forward: without Optimal Pixels the corners sample outside the layer.
+ let plain = run("ec.distort.opticscompensation", &[("fieldOfView", num(120.0))], img.clone());
+ assert!(plain.img.get(0, 0)[3] < 0.5);
+ let opt = run("ec.distort.opticscompensation", &[("fieldOfView", num(120.0)), ("optimalPixels", Value::Bool(true))], img.clone());
+ assert!(opt.img.get(0, 0)[3] > 0.9 && opt.img.get(31, 23)[3] > 0.9);
+ // Reverse: everything fits; Resize is ignored.
+ let rev = [("fieldOfView", num(120.0)), ("reverseLensDistortion", Value::Bool(true)), ("optimalPixels", Value::Bool(true)), ("resize", Value::Enum(2))];
+ let r = run("ec.distort.opticscompensation", &rev, img.clone());
+ assert_eq!(r.img.width, 32);
+ // The edges of the source now sit inside the layer: empty space around them.
+ assert!(r.img.get(0, 0)[3] < 0.5 && r.img.get(16, 12)[3] > 0.9);
+ }
}
diff --git a/crates/effects/src/migrate.rs b/crates/effects/src/migrate.rs
index b2f485730..1e2c25e0e 100644
--- a/crates/effects/src/migrate.rs
+++ b/crates/effects/src/migrate.rs
@@ -153,6 +153,8 @@ pub fn legacy_default(effect: &str, param: &str) -> Option<Value> {
("ec.noise.removegrain", "noiseReductionSettings/mode") => Value::Enum(1),
// Audio: the Compressor's release was always manual.
("ec.audio.compressor", "autoRelease") => Value::Bool(false),
+ // Transition: Block Dissolve's blocks had hard edges.
+ ("ec.transition.blockdissolve", "softEdges") => Value::Bool(false),
_ => return None,
})
}
diff --git a/crates/effects/src/transition.rs b/crates/effects/src/transition.rs
index 54236edfa..2b21da597 100644
--- a/crates/effects/src/transition.rs
+++ b/crates/effects/src/transition.rs
@@ -62,14 +62,21 @@ fn block_dissolve(ctx: &EffectCtx, mut b: Buf) -> Buf {
let feather = ctx.params.f("feather") * b.scale;
let (ox, oy) = (b.offset[0], b.offset[1]);
let seed = ctx.seed ^ 0xb10c;
+ // Soft Edges (Best Quality): block edges falling between pixels are anti-aliased (4×4
+ // sub-pixel samples); off, each pixel takes its centre's block.
+ let soft = ctx.params.b("softEdges");
+ let subs: Vec<f64> = if soft { (0..4).map(|k| (k as f64 + 0.5) / 4.0).collect() } else { vec![0.5] };
+ let kept = |x: f64, y: f64| {
+ let (bx, by) = (((x - ox) / bw).floor() as i64, ((y - oy) / bh).floor() as i64);
+ hash1(bx as u32, by as u32, seed) >= done
+ };
let mut mask = Plane::new(b.img.width as usize, b.img.height as usize);
let w = mask.w;
+ let n = (subs.len() * subs.len()) as f32;
mask.data.par_chunks_mut(w.max(1)).enumerate().for_each(|(y, row)| {
- let by = ((y as f64 + 0.5 - oy) / bh).floor() as i64;
for (x, m) in row.iter_mut().enumerate() {
- let bx = ((x as f64 + 0.5 - ox) / bw).floor() as i64;
- let r = hash1(bx as u32, by as u32, seed);
- *m = if r >= done { 1.0 } else { 0.0 };
+ let hits = subs.iter().flat_map(|sy| subs.iter().map(move |sx| (*sx, *sy))).filter(|(sx, sy)| kept(x as f64 + sx, y as f64 + sy)).count();
+ *m = hits as f32 / n;
}
});
if feather > 0.0 {
@@ -466,6 +473,7 @@ pub fn specs() -> Vec<EffectSpec> {
p("blockWidth", "Block Width", num(1.0), slider(1.0, 4000.0, 1.0, 100.0, 1)),
p("blockHeight", "Block Height", num(1.0), slider(1.0, 4000.0, 1.0, 100.0, 1)),
p("feather", "Feather", num(0.0), slider(0.0, 400.0, 0.0, 50.0, 1)),
+ p("softEdges", "Soft Edges (Best Quality)", Value::Bool(true), ParamUi::Checkbox),
],
block_dissolve,
),
@@ -866,4 +874,15 @@ mod tests {
let tilt = run_t(&img, &[("completion", num(0.0)), ("cameraPosition/yRotation", num(40.0))], 0.0, None);
assert_eq!(tilt.get(0, 0)[3], 0.0);
}
+
+ #[test]
+ fn block_dissolve_soft_edges_antialias_blocks() {
+ let img = Image::filled(40, 4, [1.0, 1.0, 1.0, 1.0]);
+ let v = [("completion", num(50.0)), ("blockWidth", num(2.5)), ("blockHeight", num(4.0))];
+ let frac = |o: &Image| o.data.iter().filter(|p| p[3] > 0.01 && p[3] < 0.99).count();
+ let hard = run("ec.transition.blockdissolve", &img, &[v.as_slice(), &[("softEdges", Value::Bool(false))]].concat());
+ let soft = run("ec.transition.blockdissolve", &img, &v);
+ assert_eq!(frac(&hard), 0);
+ assert!(frac(&soft) > 0);
+ }
}
diff --git a/docs/effects.md b/docs/effects.md
index f728aa9bd..9b791cbb9 100644
--- a/docs/effects.md
+++ b/docs/effects.md
@@ -3,11 +3,11 @@
<!-- Generated from the effect registry (crates/effects/src/catalog.rs); do not edit by hand.
Regenerate: UPDATE_DOCS=1 cargo test -p effectcraft-effects --lib effects_doc_is_current -->
-EffectCraft ships 303 effects with 2742 parameters in total, grouped into the same categories as the Effects & Presets panel. Every effect is our own implementation, written from public behaviour descriptions and standard image-processing literature. Parameter names, order, popup options, units, defaults and ranges follow the reference application so that projects, expressions and muscle memory carry over.
+EffectCraft ships 303 effects with 2746 parameters in total, grouped into the same categories as the Effects & Presets panel. Every effect is our own implementation, written from public behaviour descriptions and standard image-processing literature. Parameter names, order, popup options, units, defaults and ranges follow the reference application so that projects, expressions and muscle memory carry over.
- **GPU**: 24 effects also run on the GPU compositor with identical results.
- **32**: 303 effects process 32-bit float (HDR, overbright) pixels without clamping.
-- **Status**: 275 implemented in full, 28 partial (what is missing is listed).
+- **Status**: 281 implemented in full, 22 partial (what is missing is listed).
Effects are addressed by id (`ec.<category>.<name>`) or display name in commands, scripts and the control channel, and every parameter by its id (`effects/#1/blurriness`).
@@ -15,7 +15,7 @@ Effects are addressed by id (`ec.<category>.<name>`) or display name in commands
| Effect | Id | Params | GPU | 32 | Status |
|---|---|---:|:-:|:-:|---|
-| 3D Channel Extract | `ec.3d.channelextract` | 5 | | 32 | Partial: no anti-alias option |
+| 3D Channel Extract | `ec.3d.channelextract` | 6 | | 32 | Implemented |
| Cryptomatte | `ec.3d.cryptomatte` | 4 | | 32 | Implemented |
| Depth Matte | `ec.3d.depthmatte` | 3 | | 32 | Implemented |
| Depth of Field | `ec.3d.depthoffield` | 4 | | 32 | Implemented |
@@ -71,10 +71,10 @@ Effects are addressed by id (`ec.<category>.<name>`) or display name in commands
| Blend | `ec.channel.blend` | 4 | | 32 | Implemented |
| CC Composite | `ec.channel.cccomposite` | 3 | | 32 | Implemented |
| Calculations | `ec.channel.calculations` | 9 | | 32 | Implemented |
-| Channel Combiner | `ec.channel.combiner` | 6 | | 32 | Partial: no Saturation Multiplied target |
+| Channel Combiner | `ec.channel.combiner` | 6 | | 32 | Implemented |
| Compound Arithmetic | `ec.channel.compoundarithmetic` | 6 | | 32 | Implemented |
| Invert | `ec.channel.invert` | 2 | GPU | 32 | Implemented |
-| Minimax | `ec.channel.minimax` | 4 | | 32 | Partial: no Don't Shrink Edges option |
+| Minimax | `ec.channel.minimax` | 5 | | 32 | Implemented |
| Remove Color Matting | `ec.channel.removecolormatting` | 2 | | 32 | Implemented |
| Set Channels | `ec.channel.setchannels` | 9 | | 32 | Implemented |
| Set Matte | `ec.channel.setmatte` | 6 | | 32 | Implemented |
@@ -154,7 +154,7 @@ Effects are addressed by id (`ec.<category>.<name>`) or display name in commands
| Mesh Warp | `ec.distort.meshwarp` | 3 | | 32 | Implemented |
| Mirror | `ec.distort.mirror` | 2 | | 32 | Implemented |
| Offset | `ec.distort.offset` | 2 | | 32 | Implemented |
-| Optics Compensation | `ec.distort.opticscompensation` | 5 | | 32 | Partial: no Optimal Pixels |
+| Optics Compensation | `ec.distort.opticscompensation` | 6 | | 32 | Implemented |
| Polar Coordinates | `ec.distort.polar` | 2 | | 32 | Implemented |
| Puppet | `ec.distort.puppet` | 1 | | 32 | Implemented |
| Reshape | `ec.distort.reshape` | 6 | | 32 | Partial: no correspondence points |
@@ -163,7 +163,7 @@ Effects are addressed by id (`ec.<category>.<name>`) or display name in commands
| Smear | `ec.distort.smear` | 8 | | 32 | Implemented |
| Spherize | `ec.distort.spherize` | 2 | | 32 | Implemented |
| Transform | `ec.distort.transform` | 10 | GPU | 32 | Partial: no shutter-angle motion blur |
-| Turbulent Displace | `ec.distort.turbulentdisplace` | 11 | | 32 | Partial: no locked pinning variants |
+| Turbulent Displace | `ec.distort.turbulentdisplace` | 11 | | 32 | Implemented |
| Twirl | `ec.distort.twirl` | 3 | | 32 | Implemented |
| Twirl (Legacy) | `ec.distort.twirllegacy` | 3 | | 32 | Implemented |
| Warp | `ec.distort.warp` | 5 | | 32 | Implemented |
@@ -389,7 +389,7 @@ Effects are addressed by id (`ec.<category>.<name>`) or display name in commands
| Effect | Id | Params | GPU | 32 | Status |
|---|---|---:|:-:|:-:|---|
-| Block Dissolve | `ec.transition.blockdissolve` | 4 | | 32 | Partial: no Soft Edges option |
+| Block Dissolve | `ec.transition.blockdissolve` | 5 | | 32 | Implemented |
| CC Glass Wipe | `ec.transition.ccglasswipe` | 5 | | 32 | Implemented |
| CC Grid Wipe | `ec.transition.ccgridwipe` | 7 | | 32 | Implemented |
| CC Image Wipe | `ec.transition.ccimagewipe` | 7 | | 32 | Implemented |