M9.12: effect parameter fidelity – all categories

Align every effect's display name, category, parameter names, order,
twirl-down groups, popup options, units, defaults and ranges with the
public After Effects effect reference, and implement controls that were
ignored or missing where cheap. One commit because the categories share
the registry, migration tables and GPU kernels (only green states).

Infrastructure
- effects::migrate: saved instances are upgraded on project open
  (Session::replace_project → upgrade_effects): renamed ids
  (PARAM_ID_ALIASES), params moved into twirl-down groups, popup values
  remapped by label (POPUP_LABEL_ALIASES), refreshed names/UI hints,
  added params created with legacy_default values that keep old renders.
- flatten_params also keys nested props by match path (group/param), so
  effects declare grouped params with `group/param` ids; layer-source
  companions sit next to grouped layer params.
- lookup() resolves old effect names (EFFECT_NAME_ALIASES).
- Registry-wide test: unique ids/names, non-empty names, defaults in
  range, popup defaults within options, value kinds match UI.
- docs/effects.md generated from the registry (catalog.rs) with GPU /
  32-bpc badges and per-effect status; a test keeps it current.

Batches
- Blur & Sharpen, Channel, 3D Channel, Perspective, Text, Utility:
  Camera Lens Blur iris/highlight groups, Compound Blur layer, Camera-
  Shake Deblur method/strength, Invert full channel list (CPU HLS/YIQ),
  Set Channels/Set Matte layers, Channel Combiner targets, 3D Channel
  Extract clamp/invert.
- Color Correction: temporal smoothing + scene detect for Auto Color/
  Contrast/Levels and Shadow/Highlight, Brightness & Contrast legacy
  switch, Change to Color tolerance group, Leave Color, Photo Filter
  presets, Exposure channels, Levels clip popups, Colorama phase source,
  Color Link sample list, Lumetri groups (CPU + GPU kernels).
- Distort: Bulge, Displacement Map layer/behaviour, Magnify, Optics
  Compensation resize, Ripple conversion, Transform sampling, Turbulent
  Displace types/pinning/evolution, Wave Warp types/pinning, Twirl and
  Ripple radius fixes.
- Generate: 4-Color Gradient, Checkerboard, Grid, Circle size/feather/
  blending, Advanced Lightning types, Cell Pattern, Radio Waves, Fractal
  palettes, Scribble/Vegas names.
- Keying, Matte, Obsolete: Color Difference Key partials/views, Unmult
  controls, Key Light groups, Refine Soft/Hard Matte, Roto Brush groups,
  Mocha shape moved to Matte, Spill Suppressor accuracy, Basic/Path Text
  groups.
- Noise & Grain, Immersive Video, Audio, Time: Fractal/Turbulent Noise
  full control set (noise3.rs, GPU), grain look groups, Remove Grain,
  VR effects, Compressor/Gate/Distortion controls, Timewarp groups,
  VR Sphere to Plane name.
- Simulation: AE twirl-down groups for all simulations, Foam strength,
  Particle Playground barrel radius and mapper targets.
- Stylize, Transition: Glow looping/dimensions/alpha (CPU + GPU),
  Mosaic averaging, Cartoon groups, Roughen Edges evolution, Texturize
  layer, Gradient Wipe layer, Radial Wipe both, Card Wipe options.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Thomas
2026-10-03 00:15:06 -04:00
co-authored by Claude Opus 5.5
parent 0631ef29dc
commit 355a6255a2
51 changed files with 6799 additions and 1737 deletions
+266 -106
View File
@@ -1,5 +1,6 @@
//! Generate and Noise effects that synthesise images.
use effectcraft_color::{BlendMode, blend_pixel};
use effectcraft_keyframe::Value;
use effectcraft_project::ParamUi;
use effectcraft_raster::Px;
@@ -7,6 +8,9 @@ use rayon::prelude::*;
use crate::{Buf, EffectCtx, EffectSpec, col, num, p, popup, slider};
/// Checkerboard / Grid "Size From" options.
pub(crate) const SIZE_FROM: [&str; 3] = ["Corner Point", "Width Slider", "Width & Height Sliders"];
fn spec(id: &'static str, name: &'static str, category: &'static str, params: Vec<crate::ParamSpec>, render: crate::RenderFn) -> EffectSpec {
EffectSpec { id, name, category, params, render, gpu: false, float: true }
}
@@ -46,10 +50,74 @@ fn gradient_ramp(ctx: &EffectCtx, mut b: Buf) -> Buf {
b
}
/// Blending Mode options of the shape generators (Checkerboard, Grid, Circle): "None" shows the
/// generated pattern only; the others composite it onto the layer like layer blending modes.
pub(crate) const GEN_BLEND_MODES: [&str; 20] = [
"None",
"Normal",
"Add",
"Multiply",
"Screen",
"Overlay",
"Soft Light",
"Hard Light",
"Color Dodge",
"Color Burn",
"Darken",
"Lighten",
"Difference",
"Exclusion",
"Hue",
"Saturation",
"Color",
"Luminosity",
"Stencil Alpha",
"Silhouette Alpha",
];
fn gen_mode(i: u32) -> Option<BlendMode> {
Some(match i {
0 => return None,
2 => BlendMode::Add,
3 => BlendMode::Multiply,
4 => BlendMode::Screen,
5 => BlendMode::Overlay,
6 => BlendMode::SoftLight,
7 => BlendMode::HardLight,
8 => BlendMode::ColorDodge,
9 => BlendMode::ColorBurn,
10 => BlendMode::Darken,
11 => BlendMode::Lighten,
12 => BlendMode::Difference,
13 => BlendMode::Exclusion,
14 => BlendMode::Hue,
15 => BlendMode::Saturation,
16 => BlendMode::Color,
17 => BlendMode::Luminosity,
18 => BlendMode::StencilAlpha,
19 => BlendMode::SilhouetteAlpha,
_ => BlendMode::Normal,
})
}
/// Composite a generated premultiplied pixel `g` onto the original `o` with blending mode
/// index `mode` (into [`GEN_BLEND_MODES`]).
#[inline]
pub(crate) fn gen_blend(o: Px, g: Px, mode: u32) -> Px {
match gen_mode(mode) {
None => g,
Some(m) => blend_pixel(m, o, g, 0.5),
}
}
fn four_color(ctx: &EffectCtx, mut b: Buf) -> Buf {
let pts: Vec<((f64, f64), [f32; 4])> = (1..=4).map(|i| (b.to_px(ctx.params.v2(&format!("point{i}"))), ctx.params.color(&format!("color{i}")))).collect();
let pts: Vec<((f64, f64), [f32; 4])> =
(1..=4).map(|i| (b.to_px(ctx.params.v2(&format!("positionsColors/point{i}"))), ctx.params.color(&format!("positionsColors/color{i}")))).collect();
let blend = ctx.params.f("blend").max(1.0);
let jitter = (ctx.params.f("jitter") / 100.0).clamp(0.0, 1.0) as f32;
let op = ctx.params.f("opacity") as f32 / 100.0;
let mode = ctx.params.e("blendingMode");
let seed = ctx.seed;
b.img.rows_mut().for_each(|(y, row)| {
for (x, px) in row.iter_mut().enumerate() {
let mut acc = [0.0f64; 3];
@@ -62,26 +130,55 @@ fn four_color(ctx: &EffectCtx, mut b: Buf) -> Buf {
}
wsum += w;
}
let c = acc.map(|v| (v / wsum) as f32);
put(px, c, 1.0, 1.0 - op);
let mut c = acc.map(|v| (v / wsum) as f32);
if jitter > 0.0 {
// Dither against banding: a few code values of noise.
let n = (effectcraft_raster::hash_noise(x as u32, y as u32, seed) - 0.5) * jitter * (8.0 / 255.0);
c = c.map(|v| v + n);
}
*px = gen_blend(*px, [c[0] * op, c[1] * op, c[2] * op, op], mode);
}
});
b
}
/// Cell size of Checkerboard / Grid from Size From (Corner Point, Width Slider, Width &
/// Height Sliders), in pixels.
fn cell_size(ctx: &EffectCtx, b: &Buf, anchor: (f64, f64)) -> (f64, f64) {
let (w, h) = match ctx.params.e("sizeFrom") {
0 => {
let c = b.to_px(ctx.params.v2("corner"));
((c.0 - anchor.0).abs(), (c.1 - anchor.1).abs())
}
1 => (ctx.params.f("width") * b.scale, ctx.params.f("width") * b.scale),
_ => (ctx.params.f("width") * b.scale, ctx.params.f("height") * b.scale),
};
(w.max(1.0), h.max(1.0))
}
fn checkerboard(ctx: &EffectCtx, mut b: Buf) -> Buf {
let anchor = b.to_px(ctx.params.v2("anchor"));
let w = (ctx.params.f("width") * b.scale).max(1.0);
let h = (ctx.params.f("height") * b.scale).max(1.0);
let (w, h) = cell_size(ctx, &b, anchor);
// Feather softens the transitions; 0 keeps a half-pixel antialiased edge.
let fw = (ctx.params.f("feather/featherWidth") * b.scale).max(1.0);
let fh = (ctx.params.f("feather/featherHeight") * b.scale).max(1.0);
let c = ctx.params.color("color");
let op = ctx.params.f("opacity") as f32 / 100.0;
let mode = ctx.params.e("blendingMode");
// Signed distance (in feather units) to the nearest cell edge, positive in even cells.
let axis = |p: f64, size: f64, f: f64| -> f64 {
let u = p / size;
let fr = u - u.floor();
let d = fr.min(1.0 - fr) * size;
let s = if (u.floor() as i64).rem_euclid(2) == 0 { 1.0 } else { -1.0 };
s * (d / (f * 0.5)).min(1.0)
};
b.img.rows_mut().for_each(|(y, row)| {
for (x, px) in row.iter_mut().enumerate() {
let cx = ((x as f64 + 0.5 - anchor.0) / w).floor() as i64;
let cy = ((y as f64 + 0.5 - anchor.1) / h).floor() as i64;
if (cx + cy).rem_euclid(2) == 0 {
put(px, [c[0], c[1], c[2]], op, 0.0);
}
let sx = axis(x as f64 + 0.5 - anchor.0, w, fw);
let sy = axis(y as f64 + 0.5 - anchor.1, h, fh);
let cov = ((0.5 + 0.5 * sx * sy) as f32).clamp(0.0, 1.0) * op;
*px = gen_blend(*px, [c[0] * cov, c[1] * cov, c[2] * cov, cov], mode);
}
});
b
@@ -89,50 +186,74 @@ fn checkerboard(ctx: &EffectCtx, mut b: Buf) -> Buf {
fn grid(ctx: &EffectCtx, mut b: Buf) -> Buf {
let anchor = b.to_px(ctx.params.v2("anchor"));
let w = (ctx.params.f("width") * b.scale).max(1.0);
let h = (ctx.params.f("height") * b.scale).max(1.0);
let (w, h) = cell_size(ctx, &b, anchor);
let border = (ctx.params.f("border") * b.scale).max(0.0);
let fw = (ctx.params.f("feather/featherWidth") * b.scale).max(1.0);
let fh = (ctx.params.f("feather/featherHeight") * b.scale).max(1.0);
let invert = ctx.params.b("invertGrid");
let c = ctx.params.color("color");
let op = ctx.params.f("opacity") as f32 / 100.0;
let mode = ctx.params.e("blendingMode");
b.img.rows_mut().for_each(|(y, row)| {
for (x, px) in row.iter_mut().enumerate() {
let fx = (x as f64 + 0.5 - anchor.0).rem_euclid(w);
let fy = (y as f64 + 0.5 - anchor.1).rem_euclid(h);
let d = fx.min(w - fx).min(fy.min(h - fy));
let cov = ((border / 2.0 - d) + 0.5).clamp(0.0, 1.0) as f32;
if cov > 0.0 {
let mut g = *px;
put(&mut g, [c[0], c[1], c[2]], op, 0.0);
for i in 0..4 {
px[i] += (g[i] - px[i]) * cov;
}
let gx = (x as f64 + 0.5 - anchor.0).rem_euclid(w);
let gy = (y as f64 + 0.5 - anchor.1).rem_euclid(h);
let (dx, dy) = (gx.min(w - gx), gy.min(h - gy));
let cx = ((border / 2.0 - dx) / fw + 0.5).clamp(0.0, 1.0);
let cy = ((border / 2.0 - dy) / fh + 0.5).clamp(0.0, 1.0);
let mut cov = if border <= 0.0 { 0.0 } else { cx.max(cy) as f32 };
if invert {
cov = 1.0 - cov;
}
let a = cov * op;
*px = gen_blend(*px, [c[0] * a, c[1] * a, c[2] * a, a], mode);
}
});
b
}
/// Circle Edge options.
pub(crate) const CIRCLE_EDGES: [&str; 5] = ["None", "Edge Radius", "Thickness", "Thickness * Radius", "Thickness & Feather * Radius"];
fn circle(ctx: &EffectCtx, mut b: Buf) -> Buf {
let c = b.to_px(ctx.params.v2("center"));
let r = ctx.params.f("radius") * b.scale;
let feather = (ctx.params.f("feather") * b.scale).max(0.5);
let thick = ctx.params.f("thickness").max(0.0);
let mut f_out = ctx.params.f("feather/feather").max(0.0) * b.scale;
let mut f_in = ctx.params.f("feather/featherInner").max(0.0) * b.scale;
// Inner radius of the ring (None = solid disk).
let inner = match ctx.params.e("edge") {
1 => Some(ctx.params.f("edgeRadius") * b.scale),
2 => Some(r - thick * b.scale),
3 => Some(r - thick / 100.0 * r),
4 => {
f_out = ctx.params.f("feather/feather").max(0.0) / 100.0 * r;
f_in = ctx.params.f("feather/featherInner").max(0.0) / 100.0 * r;
Some(r - thick / 100.0 * r)
}
_ => None,
};
let (ro, ri) = match inner {
Some(i) => (r.max(i), Some(r.min(i).max(0.0))),
None => (r, None),
};
let (f_out, f_in) = (f_out.max(0.5), f_in.max(0.5));
let color = ctx.params.color("color");
let op = ctx.params.f("opacity") as f32 / 100.0;
let invert = ctx.params.b("invert");
let mode = ctx.params.e("blendingMode");
b.img.rows_mut().for_each(|(y, row)| {
for (x, px) in row.iter_mut().enumerate() {
let d = ((x as f64 + 0.5 - c.0).powi(2) + (y as f64 + 0.5 - c.1).powi(2)).sqrt();
let mut cov = ((r - d) / feather + 0.5).clamp(0.0, 1.0) as f32;
let mut cov = ((ro - d) / f_out + 0.5).clamp(0.0, 1.0) as f32;
if let Some(ri) = ri {
cov *= ((d - ri) / f_in + 0.5).clamp(0.0, 1.0) as f32;
}
if invert {
cov = 1.0 - cov;
}
if cov > 0.0 {
let mut g = *px;
put(&mut g, [color[0], color[1], color[2]], op, 0.0);
for i in 0..4 {
px[i] += (g[i] - px[i]) * cov;
}
}
let a = cov * op;
*px = gen_blend(*px, [color[0] * a, color[1] * a, color[2] * a, a], mode);
}
});
b
@@ -169,52 +290,7 @@ pub fn value_noise(x: f32, y: f32, z: f32, seed: u32) -> f32 {
l(a, b, fz)
}
fn fractal_noise(ctx: &EffectCtx, mut b: Buf) -> Buf {
let kind = ctx.params.e("fractalType");
let contrast = ctx.params.f("contrast") as f32 / 100.0;
let brightness = ctx.params.f("brightness") as f32 / 100.0;
let invert = ctx.params.b("invert");
let scale = (ctx.params.f("scale") * b.scale).max(1.0) as f32;
let off = ctx.params.v2("offset");
let rot = (ctx.params.f("rotation") as f32).to_radians();
let octaves = ctx.params.f("complexity").clamp(1.0, 20.0);
let evo = ctx.params.f("evolution") as f32 / 360.0;
let seed = ctx.params.f("seed") as u32 ^ 0x51ed;
let blend = ctx.params.f("blend") as f32 / 100.0;
let opacity = ctx.params.f("opacity") as f32 / 100.0;
let (sr, cr) = rot.sin_cos();
let n_oct = octaves.ceil() as usize;
let frac = (octaves - octaves.floor()) as f32;
let (ox, oy) = b.to_px(off);
b.img.rows_mut().for_each(|(y, row)| {
for (x, px) in row.iter_mut().enumerate() {
let (dx, dy) = (x as f32 + 0.5 - ox as f32, y as f32 + 0.5 - oy as f32);
let (u, v) = ((dx * cr + dy * sr) / scale, (-dx * sr + dy * cr) / scale);
let mut sum = 0.0;
let mut amp = 1.0;
let mut norm = 0.0;
let mut f = 1.0;
for o in 0..n_oct {
let w = if o + 1 == n_oct && frac > 0.0 { frac } else { 1.0 };
let mut n = value_noise(u * f, v * f, evo + o as f32 * 7.31, seed + o as u32);
if kind == 1 {
n = 1.0 - (n * 2.0 - 1.0).abs(); // turbulent / ridged
}
sum += n * amp * w;
norm += amp * w;
amp *= 0.5;
f *= 2.0;
}
let mut val = sum / norm.max(1e-6);
val = ((val - 0.5) * contrast + 0.5 + brightness).clamp(0.0, 1.0);
if invert {
val = 1.0 - val;
}
put(px, [val, val, val], opacity, blend);
}
});
b
}
// Fractal Noise lives in `noise3` (with Turbulent Noise).
pub fn specs() -> Vec<EffectSpec> {
let pt = |x, y| Value::Vec2([x, y]);
@@ -239,16 +315,18 @@ pub fn specs() -> Vec<EffectSpec> {
"4-Color Gradient",
"Generate",
vec![
p("point1", "Point 1", pt(0.1, 0.1), ParamUi::Point),
p("color1", "Color 1", col(1.0, 1.0, 0.0), ParamUi::Color),
p("point2", "Point 2", pt(0.9, 0.1), ParamUi::Point),
p("color2", "Color 2", col(0.0, 1.0, 0.0), ParamUi::Color),
p("point3", "Point 3", pt(0.1, 0.9), ParamUi::Point),
p("color3", "Color 3", col(1.0, 0.0, 1.0), ParamUi::Color),
p("point4", "Point 4", pt(0.9, 0.9), ParamUi::Point),
p("color4", "Color 4", col(0.0, 0.0, 1.0), ParamUi::Color),
p("positionsColors/point1", "Point 1", pt(0.1, 0.1), ParamUi::Point),
p("positionsColors/color1", "Color 1", col(1.0, 1.0, 0.0), ParamUi::Color),
p("positionsColors/point2", "Point 2", pt(0.9, 0.1), ParamUi::Point),
p("positionsColors/color2", "Color 2", col(0.0, 1.0, 0.0), ParamUi::Color),
p("positionsColors/point3", "Point 3", pt(0.1, 0.9), ParamUi::Point),
p("positionsColors/color3", "Color 3", col(1.0, 0.0, 1.0), ParamUi::Color),
p("positionsColors/point4", "Point 4", pt(0.9, 0.9), ParamUi::Point),
p("positionsColors/color4", "Color 4", col(0.0, 0.0, 1.0), ParamUi::Color),
p("blend", "Blend", num(100.0), slider(1.0, 1000.0, 1.0, 1000.0, 1)),
p("jitter", "Jitter", num(0.0), slider(0.0, 100.0, 0.0, 100.0, 1)),
p("opacity", "Opacity", num(100.0), slider(0.0, 100.0, 0.0, 100.0, 1)),
p("blendingMode", "Blending Mode", Value::Enum(0), popup(&GEN_BLEND_MODES[..18])),
],
four_color,
),
@@ -258,10 +336,15 @@ pub fn specs() -> Vec<EffectSpec> {
"Generate",
vec![
p("anchor", "Anchor", pt(0.0, 0.0), ParamUi::Point),
p("sizeFrom", "Size From", Value::Enum(1), popup(&SIZE_FROM)),
p("corner", "Corner", pt(0.1, 0.1), ParamUi::Point),
p("width", "Width", num(64.0), slider(1.0, 4000.0, 1.0, 400.0, 1)),
p("height", "Height", num(64.0), slider(1.0, 4000.0, 1.0, 400.0, 1)),
p("feather/featherWidth", "Width", num(0.0), slider(0.0, 1000.0, 0.0, 50.0, 1)),
p("feather/featherHeight", "Height", num(0.0), slider(0.0, 1000.0, 0.0, 50.0, 1)),
p("color", "Color", col(1.0, 1.0, 1.0), ParamUi::Color),
p("opacity", "Opacity", num(100.0), slider(0.0, 100.0, 0.0, 100.0, 1)),
p("blendingMode", "Blending Mode", Value::Enum(0), popup(&GEN_BLEND_MODES)),
],
checkerboard,
),
@@ -271,11 +354,17 @@ pub fn specs() -> Vec<EffectSpec> {
"Generate",
vec![
p("anchor", "Anchor", pt(0.0, 0.0), ParamUi::Point),
p("sizeFrom", "Size From", Value::Enum(1), popup(&SIZE_FROM)),
p("corner", "Corner", pt(0.1, 0.1), ParamUi::Point),
p("width", "Width", num(64.0), slider(1.0, 4000.0, 1.0, 400.0, 1)),
p("height", "Height", num(64.0), slider(1.0, 4000.0, 1.0, 400.0, 1)),
p("border", "Border", num(2.0), slider(0.0, 400.0, 0.0, 40.0, 1)),
p("feather/featherWidth", "Width", num(0.0), slider(0.0, 1000.0, 0.0, 50.0, 1)),
p("feather/featherHeight", "Height", num(0.0), slider(0.0, 1000.0, 0.0, 50.0, 1)),
p("invertGrid", "Invert Grid", Value::Bool(false), ParamUi::Checkbox),
p("color", "Color", col(1.0, 1.0, 1.0), ParamUi::Color),
p("opacity", "Opacity", num(100.0), slider(0.0, 100.0, 0.0, 100.0, 1)),
p("blendingMode", "Blending Mode", Value::Enum(0), popup(&GEN_BLEND_MODES)),
],
grid,
),
@@ -286,32 +375,103 @@ pub fn specs() -> Vec<EffectSpec> {
vec![
p("center", "Center", pt(0.5, 0.5), ParamUi::Point),
p("radius", "Radius", num(75.0), slider(0.0, 4000.0, 0.0, 1000.0, 1)),
p("feather", "Feather Outer Edge", num(0.0), slider(0.0, 1000.0, 0.0, 100.0, 1)),
p("edge", "Edge", Value::Enum(0), popup(&CIRCLE_EDGES)),
p("edgeRadius", "Edge Radius", num(0.0), slider(0.0, 4000.0, 0.0, 1000.0, 1)),
p("thickness", "Thickness", num(10.0), slider(0.0, 4000.0, 0.0, 100.0, 1)),
p("feather/feather", "Feather Outer Edge", num(0.0), slider(0.0, 1000.0, 0.0, 100.0, 1)),
p("feather/featherInner", "Feather Inner Edge", num(0.0), slider(0.0, 1000.0, 0.0, 100.0, 1)),
p("invert", "Invert Circle", Value::Bool(false), ParamUi::Checkbox),
p("color", "Color", col(1.0, 1.0, 1.0), ParamUi::Color),
p("opacity", "Opacity", num(100.0), slider(0.0, 100.0, 0.0, 100.0, 1)),
p("blendingMode", "Blending Mode", Value::Enum(0), popup(&GEN_BLEND_MODES)),
],
circle,
),
spec(
"ec.noise.fractal",
"Fractal Noise",
"Noise & Grain",
vec![
p("fractalType", "Fractal Type", Value::Enum(0), popup(&["Basic", "Turbulent Smooth"])),
p("invert", "Invert", Value::Bool(false), ParamUi::Checkbox),
p("contrast", "Contrast", num(100.0), slider(0.0, 10000.0, 0.0, 400.0, 1)),
p("brightness", "Brightness", num(0.0), slider(-10000.0, 10000.0, -200.0, 200.0, 1)),
p("scale", "Scale", num(100.0), slider(1.0, 10000.0, 20.0, 600.0, 1)),
p("offset", "Offset Turbulence", pt(0.5, 0.5), ParamUi::Point),
p("rotation", "Rotation", num(0.0), ParamUi::Angle),
p("complexity", "Complexity", num(6.0), slider(1.0, 20.0, 1.0, 10.0, 1)),
p("evolution", "Evolution", num(0.0), ParamUi::Angle),
p("seed", "Random Seed", num(0.0), slider(0.0, 100000.0, 0.0, 1000.0, 0)),
p("opacity", "Opacity", num(100.0), slider(0.0, 100.0, 0.0, 100.0, 1)),
p("blend", "Blend With Original", num(0.0), slider(0.0, 100.0, 0.0, 100.0, 1)),
],
fractal_noise,
),
]
}
#[cfg(test)]
mod generator_tests {
use super::*;
use crate::{EffectEnv, run_fx};
use effectcraft_raster::Image;
fn red() -> Image {
Image::filled(32, 32, [1.0, 0.0, 0.0, 1.0])
}
#[test]
fn checkerboard_blending_none_shows_pattern_only_and_size_from_width() {
let set = [("width", num(8.0)), ("height", num(2.0))];
// None (default): the off squares are transparent; Width Slider makes 8×8 squares.
let o = run_fx("ec.generate.checkerboard", &set, red(), 0.0, EffectEnv::default());
assert!(o.img.get(3, 3)[3] > 0.99 && o.img.get(3, 3)[1] > 0.99, "{:?}", o.img.get(3, 3));
assert!(o.img.get(11, 3)[3] < 0.01);
assert!(o.img.get(3, 6)[3] > 0.99, "height ignored with Width Slider");
// Width & Height Sliders: 8×2 cells; Normal keeps the layer under the off squares.
let o = run_fx(
"ec.generate.checkerboard",
&[set[0].clone(), set[1].clone(), ("sizeFrom", Value::Enum(2)), ("blendingMode", Value::Enum(1))],
red(),
0.0,
EffectEnv::default(),
);
assert!(o.img.get(3, 2)[0] > 0.99 && o.img.get(3, 2)[1] < 0.01, "second row of cells is off");
// Corner Point: cell size from the anchor-corner rectangle.
let o = run_fx("ec.generate.checkerboard", &[("sizeFrom", Value::Enum(0)), ("corner", Value::Vec2([4.0, 4.0]))], red(), 0.0, EffectEnv::default());
assert!(o.img.get(1, 1)[3] > 0.99 && o.img.get(5, 1)[3] < 0.01);
}
#[test]
fn grid_invert_and_stencil() {
let set = [("width", num(10.0)), ("border", num(2.0))];
let o = run_fx("ec.generate.grid", &set, red(), 0.0, EffectEnv::default());
assert!(o.img.get(0, 5)[3] > 0.9, "line at the anchor");
assert!(o.img.get(5, 5)[3] < 0.01, "cell interior is empty with None");
let o = run_fx("ec.generate.grid", &[set[0].clone(), set[1].clone(), ("invertGrid", Value::Bool(true))], red(), 0.0, EffectEnv::default());
assert!(o.img.get(5, 5)[3] > 0.99 && o.img.get(0, 5)[3] < 0.1);
// Stencil Alpha: the layer shows only through the grid lines.
let o = run_fx("ec.generate.grid", &[set[0].clone(), set[1].clone(), ("blendingMode", Value::Enum(18))], red(), 0.0, EffectEnv::default());
assert!(o.img.get(0, 5)[0] > 0.9 && o.img.get(5, 5)[3] < 0.01);
}
#[test]
fn circle_edge_makes_a_ring() {
let c = ("center", Value::Vec2([16.0, 16.0]));
let disk = run_fx("ec.generate.circle", &[c.clone(), ("radius", num(10.0))], red(), 0.0, EffectEnv::default());
assert!(disk.img.get(16, 16)[3] > 0.99 && disk.img.get(30, 16)[3] < 0.01);
let ring = run_fx(
"ec.generate.circle",
&[c.clone(), ("radius", num(10.0)), ("edge", Value::Enum(2)), ("thickness", num(3.0))],
red(),
0.0,
EffectEnv::default(),
);
assert!(ring.img.get(16, 16)[3] < 0.01, "hole in the middle");
assert!(ring.img.get(24, 16)[3] > 0.99, "{:?}", ring.img.get(24, 16));
let er =
run_fx("ec.generate.circle", &[c, ("radius", num(10.0)), ("edge", Value::Enum(1)), ("edgeRadius", num(5.0))], red(), 0.0, EffectEnv::default());
assert!(er.img.get(16, 16)[3] < 0.01 && er.img.get(23, 16)[3] > 0.99);
}
#[test]
fn four_color_blending_mode_and_opacity() {
let pts: Vec<(&str, Value)> = (1..=4)
.map(|i| match i {
1 => ("positionsColors/point1", Value::Vec2([0.0, 0.0])),
2 => ("positionsColors/point2", Value::Vec2([32.0, 0.0])),
3 => ("positionsColors/point3", Value::Vec2([0.0, 32.0])),
_ => ("positionsColors/point4", Value::Vec2([32.0, 32.0])),
})
.collect();
let mut half = pts.clone();
half.push(("opacity", num(50.0)));
// None: the gradient alone at half opacity.
let o = run_fx("ec.generate.fourcolor", &half, red(), 0.0, EffectEnv::default());
assert!((o.img.get(16, 16)[3] - 0.5).abs() < 1e-3);
// Normal: over the opaque layer.
half.push(("blendingMode", Value::Enum(1)));
let o = run_fx("ec.generate.fourcolor", &half, red(), 0.0, EffectEnv::default());
assert!((o.img.get(16, 16)[3] - 1.0).abs() < 1e-3);
}
}