Merge origin/main (M13.22 GPU effects part A) into M13.23: both GPU effect lists (236), docs recounted

This commit is contained in:
Brandon Thomas
2026-10-04 00:17:37 -04:00
33 changed files with 3570 additions and 179 deletions
+4 -2
View File
@@ -91,8 +91,8 @@ const CPU_ONLY_CONTROLS: &[(&str, &[&str])] = &[
];
/// Whether the GPU kernel of effect `id` covers the instance's current settings (see
/// [`CPU_ONLY_CONTROLS`]; plus Cell Pattern's HQ variants and Turbulent Displace's locked
/// pinning).
/// [`CPU_ONLY_CONTROLS`]; plus Cell Pattern's HQ variants, Turbulent Displace's locked
/// pinning, Warp's strong Fisheye / Twist and Timewarp with a Matte Layer).
pub fn gpu_supported(id: &str, ctx: &crate::EffectCtx) -> bool {
match id {
"ec.generate.cellpattern" if (6..=10).contains(&ctx.params.e("cellPattern")) => return false,
@@ -110,6 +110,8 @@ pub fn gpu_supported(id: &str, ctx: &crate::EffectCtx) -> bool {
return false;
}
}
// Timewarp's Matte Layer (foreground and background on their own vectors).
"ec.time.timewarp" if ctx.params.get("matteLayer").and_then(effectcraft_keyframe::Value::as_layer).is_some() => return false,
// Fisheye / Twist (a crease at the unit circle) bent past 50 % or with Horizontal /
// Vertical Distortion: Newton's inverse wanders chaotically before converging near the
// fold, so f32 lands on other pixels than the CPU's f64.
+36 -1
View File
@@ -94,7 +94,8 @@ pub use transition::place_layer;
// effectcraft-gpu fx_noise.
pub use noise::remove_grain_level;
pub use noise3::{FractalGpu, fractal_gpu};
pub use time_fx::{posterized_time, time_frames};
pub use textfx::{TextLayer, text_layer};
pub use time_fx::{PixelMotion, TimewarpPlan, TwStep, posterized_time, time_frames, timewarp_crop, timewarp_plan};
// effectcraft-gpu fx_tone.
pub use ocio::color_stabilizer_maps;
// GPU effects, part B (3D Channel, Immersive Video, colour management, simulation render passes).
@@ -982,6 +983,40 @@ pub const GPU_EFFECTS: &[&str] = &[
"ec.sim.shatter",
"ec.sim.carddance",
"ec.transition.cardwipe",
// effectcraft-gpu fx_light (the CC light family)
"ec.generate.cclightrays",
"ec.generate.cclightburst",
"ec.generate.cclightsweep",
"ec.transition.cclightwipe",
// effectcraft-gpu fx_transition (transitions, perspective)
"ec.transition.blockdissolve",
"ec.transition.ccglasswipe",
"ec.transition.ccgridwipe",
"ec.transition.ccimagewipe",
"ec.transition.ccjaws",
"ec.transition.cclinesweep",
"ec.transition.ccradialscalewipe",
"ec.transition.ccscalewipe",
"ec.transition.cctwister",
"ec.transition.ccwarpomatic",
"ec.perspective.radialshadow",
"ec.distort.ccbender",
"ec.distort.ccblobbylize",
"ec.perspective.cccylinder",
"ec.perspective.ccsphere",
"ec.perspective.ccspotlight",
"ec.perspective.ccenvironment",
"ec.perspective.3dglasses",
// effectcraft-gpu fx_text (glyph coverage rasterised on the CPU)
"ec.text.numbers",
"ec.text.timecode",
// effectcraft-gpu fx_time (frames fetched by the host, combined on the GPU)
"ec.time.timedifference",
"ec.time.timedisplacement",
"ec.time.ccforcemotionblur",
"ec.time.ccwidetime",
"ec.time.pixelmotionblur",
"ec.time.timewarp",
];
/// Effects whose output depends on [`EffectCtx::time`] directly (not only through animated
+4 -2
View File
@@ -90,8 +90,10 @@ fn cc_environment(ctx: &EffectCtx, mut b: Buf) -> Buf {
let ex = u.rem_euclid(1.0) * esz[0] * es + eo[0];
let ey = v.clamp(0.0, 1.0) * esz[1] * es + eo[1];
let e = env_img.sample_bilinear_clamped(ex, ey);
let (ec, _) = unpremul(e);
*px = premul(ec, a);
// Straight colour, with nearly transparent texels fading to black continuously
// (a hard 1e-6 cut-off would turn the float noise of the filtered map into colour).
let k = 1.0 / e[3].max(1e-3);
*px = premul([e[0] * k, e[1] * k, e[2] * k], a);
}
});
b
+122 -46
View File
@@ -192,9 +192,9 @@ fn tint(c: [f32; 4], a: f32) -> Px {
[c[0] * a, c[1] * a, c[2] * a, a]
}
/// Draw text polylines with the given look (`r` = glyph stroke radius in px).
fn draw_text(b: &mut Buf, polys: &[Vec<[f64; 2]>], r: f64, look: &TextLook) {
let (w, h) = (b.img.width as usize, b.img.height as usize);
/// Coverage of text polylines (`r` = glyph stroke radius in px): the fill and, when the look
/// strokes, the stroke ring.
fn text_coverage(w: usize, h: usize, polys: &[Vec<[f64; 2]>], r: f64, look: &TextLook) -> (Plane, Option<Plane>) {
let segs_at = |rad: f64| {
let mut s = Vec::new();
for pl in polys {
@@ -211,24 +211,35 @@ fn draw_text(b: &mut Buf, polys: &[Vec<[f64; 2]>], r: f64, look: &TextLook) {
let inner = if r - sw * 0.5 > 0.05 { raster_segs(w, h, &segs_at(r - sw * 0.5), 1.0) } else { Plane::new(w, h) };
Some(outer.zip_map(&inner, |a, b| (a - b).max(0.0)))
};
(fill, ring)
}
/// One pixel of drawn text: `px` under the fill / stroke coverages `f`, `s` (opacity applied).
fn text_px(px: Px, f: f32, s: f32, look: &TextLook) -> Px {
let mut out = if look.on_original { px } else { [0.0; 4] };
match look.display {
1 => out = over(out, tint(look.stroke, s)),
2 => {
out = over(out, tint(look.stroke, s));
out = over(out, tint(look.fill, f));
}
3 => {
out = over(out, tint(look.fill, f));
out = over(out, tint(look.stroke, s));
}
_ => out = over(out, tint(look.fill, f)),
}
out
}
/// Draw text polylines with the given look (`r` = glyph stroke radius in px).
fn draw_text(b: &mut Buf, polys: &[Vec<[f64; 2]>], r: f64, look: &TextLook) {
let (fill, ring) = text_coverage(b.img.width as usize, b.img.height as usize, polys, r, look);
let op = look.opacity;
b.img.data.par_iter_mut().enumerate().for_each(|(i, px)| {
let mut out = if look.on_original { *px } else { [0.0; 4] };
let f = fill.data[i] * op;
let s = ring.as_ref().map(|r| r.data[i]).unwrap_or(0.0) * op;
match look.display {
1 => out = over(out, tint(look.stroke, s)),
2 => {
out = over(out, tint(look.stroke, s));
out = over(out, tint(look.fill, f));
}
3 => {
out = over(out, tint(look.fill, f));
out = over(out, tint(look.stroke, s));
}
_ => out = over(out, tint(look.fill, f)),
}
*px = out;
*px = text_px(*px, f, s, look);
});
}
@@ -337,7 +348,18 @@ fn numbers_text(ctx: &EffectCtx) -> String {
}
}
fn numbers(ctx: &EffectCtx, mut b: Buf) -> Buf {
/// What Numbers or Timecode draws: glyph polylines, stroke radius and look, whether the layer
/// stays under the text, and Timecode's box (`[x0, x1, y0, y1]` in buffer pixels, colour,
/// opacity × colour alpha).
struct TextPlan {
polys: Vec<Vec<[f64; 2]>>,
r: f64,
look: TextLook,
keep: bool,
boxed: Option<([f64; 4], [f32; 4], f32)>,
}
fn numbers_plan(ctx: &EffectCtx, b: &Buf) -> TextPlan {
let flat = ungroup(ctx.params);
let ctx = &EffectCtx { params: &flat, time: ctx.time, layer_size: ctx.layer_size, seed: ctx.seed, adjustment: ctx.adjustment, env: ctx.env };
let pr = ctx.params;
@@ -349,11 +371,81 @@ fn numbers(ctx: &EffectCtx, mut b: Buf) -> Buf {
let wdt = line_width(&text, size, tracking, prop);
let mut polys = Vec::new();
layout_line(&text, [pos.0 - wdt * 0.5, pos.1 + unit(size) * 3.0], size, tracking, prop, &mut polys);
let look = look_from(ctx, &b, "compositeOnOriginal");
draw_text(&mut b, &polys, weight(size), &look);
let mut look = look_from(ctx, b, "compositeOnOriginal");
let keep = look.on_original;
look.on_original = true;
TextPlan { polys, r: weight(size), look, keep, boxed: None }
}
/// Timecode's box over pixel (`x`, `y`).
fn box_px(px: Px, x: usize, y: usize, (r, bc, a): ([f64; 4], [f32; 4], f32)) -> Px {
let [x0, x1, y0, y1] = r;
let fy = y as f64 + 0.5;
let cy = ((fy - y0 + 0.5).clamp(0.0, 1.0) * (y1 - fy + 0.5).clamp(0.0, 1.0)) as f32;
if cy <= 0.0 {
return px;
}
let fx = x as f64 + 0.5;
let cx = ((fx - x0 + 0.5).clamp(0.0, 1.0) * (x1 - fx + 0.5).clamp(0.0, 1.0)) as f32;
let k = cx * cy * a;
if k > 0.0 { over(px, [bc[0] * k, bc[1] * k, bc[2] * k, k]) } else { px }
}
fn draw_plan(mut b: Buf, plan: &TextPlan) -> Buf {
let w = b.img.width as usize;
let (fill, ring) = text_coverage(w, b.img.height as usize, &plan.polys, plan.r, &plan.look);
let op = plan.look.opacity;
b.img.data.par_iter_mut().enumerate().for_each(|(i, px)| {
let mut o = if plan.keep { *px } else { [0.0; 4] };
if let Some(bx) = plan.boxed {
o = box_px(o, i % w.max(1), i / w.max(1), bx);
}
let f = fill.data[i] * op;
let s = ring.as_ref().map(|r| r.data[i]).unwrap_or(0.0) * op;
*px = text_px(o, f, s, &plan.look);
});
b
}
fn numbers(ctx: &EffectCtx, b: Buf) -> Buf {
let plan = numbers_plan(ctx, &b);
draw_plan(b, &plan)
}
/// Numbers and Timecode for the GPU compositor (effectcraft-gpu `fx_text`): the glyph
/// coverage is rasterised here (the fill in x, the stroke ring in y, opacity applied), the
/// kernel composites it.
#[derive(Clone, Debug)]
pub struct TextLayer {
pub coverage: Image,
/// Display Options (0 fill only, 1 stroke only, 2 fill over stroke, 3 stroke over fill).
pub display: u32,
pub fill: [f32; 4],
pub stroke: [f32; 4],
/// The layer stays under the text (else the text is drawn on transparency).
pub keep: bool,
/// Timecode's box: `[x0, x1, y0, y1]` (buffer pixels), colour, opacity × colour alpha.
pub boxed: Option<([f64; 4], [f32; 4], f32)>,
}
/// [`TextLayer`] of Numbers (`ec.text.numbers`) or Timecode (`ec.text.timecode`) on a buffer
/// of `b`'s geometry.
pub fn text_layer(id: &str, ctx: &EffectCtx, b: &Buf) -> Option<TextLayer> {
let plan = match id {
"ec.text.numbers" => numbers_plan(ctx, b),
"ec.text.timecode" => timecode_plan(ctx, b),
_ => return None,
};
let (w, h) = (b.img.width as usize, b.img.height as usize);
let (fill, ring) = text_coverage(w, h, &plan.polys, plan.r, &plan.look);
let op = plan.look.opacity;
let mut coverage = Image::new(b.img.width, b.img.height);
coverage.data.par_iter_mut().enumerate().for_each(|(i, px)| {
*px = [fill.data[i] * op, ring.as_ref().map(|r| r.data[i]).unwrap_or(0.0) * op, 0.0, 0.0];
});
Some(TextLayer { coverage, display: plan.look.display, fill: plan.look.fill, stroke: plan.look.stroke, keep: plan.keep, boxed: plan.boxed })
}
// ---------------------------------------------------------------- Timecode
/// SMPTE drop-frame label for nominal 30/60 fps rates.
@@ -368,7 +460,7 @@ fn drop_frame(frames: i64, nominal: i64) -> String {
format!("{:02};{:02};{:02};{:02}", adj / (nominal * 3600), (adj / (nominal * 60)) % 60, (adj / nominal) % 60, adj % nominal)
}
fn timecode_fx(ctx: &EffectCtx, mut b: Buf) -> Buf {
fn timecode_plan(ctx: &EffectCtx, b: &Buf) -> TextPlan {
let pr = ctx.params;
let src = pr.e("timeSource");
let (t, fps) = match src {
@@ -397,36 +489,20 @@ fn timecode_fx(ctx: &EffectCtx, mut b: Buf) -> Buf {
let pos = b.to_px(pr.v2("textPosition"));
let wdt = line_width(&text, size, 0.0, false);
let op = (pr.f("opacity") / 100.0) as f32;
if !pr.b("renderOnOriginal") {
b.img = Image::new(b.img.width, b.img.height);
}
if pr.b("showBox") {
let boxed = pr.b("showBox").then(|| {
let bc = pr.color("boxColor");
let pad = size * 0.25;
let (x0, x1) = (pos.0 - wdt * 0.5 - pad, pos.0 + wdt * 0.5 + pad);
let (y0, y1) = (pos.1 - size * 0.5, pos.1 + size * 0.5);
let a = op * bc[3];
b.img.rows_mut().for_each(|(y, row)| {
let fy = y as f64 + 0.5;
let cy = ((fy - y0 + 0.5).clamp(0.0, 1.0) * (y1 - fy + 0.5).clamp(0.0, 1.0)) as f32;
if cy <= 0.0 {
return;
}
for (x, px) in row.iter_mut().enumerate() {
let fx = x as f64 + 0.5;
let cx = ((fx - x0 + 0.5).clamp(0.0, 1.0) * (x1 - fx + 0.5).clamp(0.0, 1.0)) as f32;
let k = cx * cy * a;
if k > 0.0 {
*px = over(*px, [bc[0] * k, bc[1] * k, bc[2] * k, k]);
}
}
});
}
([pos.0 - wdt * 0.5 - pad, pos.0 + wdt * 0.5 + pad, pos.1 - size * 0.5, pos.1 + size * 0.5], bc, op * bc[3])
});
let mut polys = Vec::new();
layout_line(&text, [pos.0 - wdt * 0.5, pos.1 + unit(size) * 3.0], size, 0.0, false, &mut polys);
let look = TextLook { display: 0, fill: pr.color("textColor"), stroke: [0.0; 4], stroke_w: 0.0, on_original: true, opacity: op };
draw_text(&mut b, &polys, weight(size), &look);
b
TextPlan { polys, r: weight(size), look, keep: pr.b("renderOnOriginal"), boxed }
}
fn timecode_fx(ctx: &EffectCtx, b: Buf) -> Buf {
let plan = timecode_plan(ctx, &b);
draw_plan(b, &plan)
}
// ---------------------------------------------------------------- Basic Text
+122 -19
View File
@@ -680,23 +680,56 @@ fn fetch_layer(ctx: &EffectCtx, id: &str, times: &[f64], grid: &Buf) -> Option<V
)
}
/// Timewarp. Whole Frames shows the nearest source frame, Frame Mix cross-fades the two
/// neighbouring frames and Pixel Motion builds the in-between frame along estimated motion
/// vectors (block-matching optical flow, [`effectcraft_raster::flow`]) tuned by the Tuning
/// group. A Matte Layer splits foreground and background so each moves on its own vectors; a
/// Warp Layer supplies the motion instead of the layer itself. Motion Blur averages Shutter
/// Samples instants across the shutter.
fn timewarp(ctx: &EffectCtx, b: Buf) -> Buf {
if ctx.env.host.is_none() {
return b;
/// One output instant of a Timewarp without a Matte Layer: a fetched frame, a cross-fade of two,
/// or the in-between frame built along a motion field ([`TimewarpPlan::flows`]).
#[derive(Clone, Copy, Debug)]
pub enum TwStep {
Whole(usize),
Mix(usize, usize, f32),
Motion { a: usize, b: usize, w: f32, flow: usize },
}
/// Timewarp without a Matte Layer, prepared for the GPU compositor (effectcraft-gpu `fx_time`):
/// the fetched frames on one grid, the instants across the shutter (with their weights) and the
/// motion fields (block matching on the CPU). [`TimewarpPlan::render_cpu`] is the CPU effect.
pub struct TimewarpPlan {
pub grid: Buf,
pub frames: Vec<Image>,
pub steps: Vec<(TwStep, f32)>,
pub flows: Vec<Flow>,
pub pm: PixelMotion,
}
impl TimewarpPlan {
pub fn render_cpu(&self) -> Buf {
let f = &self.frames;
let imgs: Vec<Image> = self
.steps
.iter()
.map(|(s, _)| match *s {
TwStep::Whole(i) => f[i].clone(),
TwStep::Mix(i, j, w) => effectcraft_raster::flow::mix(&f[i], &f[j], w),
TwStep::Motion { a, b, w, flow } => timewarp_interpolate(&f[a], &f[b], w, &self.flows[flow], &self.pm),
})
.collect();
let weights: Vec<f32> = self.steps.iter().map(|(_, w)| *w).collect();
let img = if imgs.len() == 1 { imgs.into_iter().next().unwrap_or_default() } else { average(&imgs, &weights) };
with_img(self.grid.clone(), img)
}
}
/// Source-crop the edges of a frame (Pixel Motion works on cropped frames).
pub fn timewarp_crop(img: &Image, pm: &PixelMotion) -> Image {
crop_edges(img, pm.crops)
}
/// The source instants Timewarp shows at the frame (with their weights) and the layer times
/// they need: (instants, frame times, frames per second).
fn timewarp_instants(ctx: &EffectCtx) -> (Vec<(f64, f32)>, Vec<f64>, f64) {
let fps = ctx.fps();
let by_frame = ctx.params.e("adjustTimeBy") == 1;
let speed = ctx.params.f("speed");
let src = timewarp_source_time(ctx.time, by_frame, speed, ctx.params.f("sourceFrame"), fps);
let method = ctx.params.e("method");
let one = method > 0 && ctx.params.b("tuning/buildFromOneImage");
// Instants of source time (with weights) across the shutter.
let mut instants: Vec<(f64, f32)> = vec![];
if ctx.params.b("motionBlur/enableMotionBlur") {
let angle = if ctx.params.e("motionBlur/shutterControl") == 1 { ctx.params.f("motionBlur/shutterAngle") } else { 180.0 };
@@ -709,18 +742,88 @@ fn timewarp(ctx: &EffectCtx, b: Buf) -> Buf {
} else {
instants.push((src, 1.0));
}
// Each instant needs the frame at or before it and the next one.
let split = |s: f64| {
let f = s * fps;
let f0 = (f + 1e-6).floor();
(f0, ((f - f0) as f32).max(0.0))
};
let mut times: Vec<f64> = vec![];
for &(s, _) in &instants {
let (f0, _) = split(s);
let (f0, _) = tw_split(s, fps);
times.push(f0 / fps);
times.push((f0 + 1.0) / fps);
}
(instants, times, fps)
}
/// The frame at or before source time `s` and the fraction to the next one.
fn tw_split(s: f64, fps: f64) -> (f64, f32) {
let f = s * fps;
let f0 = (f + 1e-6).floor();
(f0, ((f - f0) as f32).max(0.0))
}
/// [`TimewarpPlan`] of a Timewarp instance without a Matte Layer. `None` without the effect host
/// (the layer passes through) or with a Matte Layer.
pub fn timewarp_plan(ctx: &EffectCtx) -> Option<TimewarpPlan> {
ctx.env.host?;
if ctx.params.get("matteLayer").and_then(Value::as_layer).is_some() {
return None;
}
let (instants, times, fps) = timewarp_instants(ctx);
let method = ctx.params.e("method");
let one = method > 0 && ctx.params.b("tuning/buildFromOneImage");
let fr = fetch(ctx, &times)?;
let pm = PixelMotion::from(ctx, fr.grid.scale);
let warps = fetch_layer(ctx, "warpLayer", &times, &fr.grid);
let idx = |t: f64| times.iter().position(|q| (q - t).abs() < 1e-9).unwrap_or(0);
let mut flows: Vec<(i64, Flow)> = vec![];
let mut steps = vec![];
for &(s, wgt) in &instants {
let (f0, frac) = tw_split(s, fps);
let (i0, i1) = (idx(f0 / fps), idx((f0 + 1.0) / fps));
let step = if method == 0 || frac < 1e-4 || (one && method == 1) {
let pick = if method == 0 || frac < 1e-4 { 0.0 } else { frac.round() };
TwStep::Whole(if pick < 0.5 { i0 } else { i1 })
} else if method == 1 {
TwStep::Mix(i0, i1, frac)
} else {
let key = f0 as i64;
let flow = match flows.iter().position(|(k, _)| *k == key) {
Some(k) => k,
None => {
let f = match &warps {
Some(w) => timewarp_flow(&w[i0], &w[i1], &pm),
None => timewarp_flow(&fr.imgs[i0], &fr.imgs[i1], &pm),
};
flows.push((key, f));
flows.len() - 1
}
};
TwStep::Motion { a: i0, b: i1, w: frac, flow }
};
steps.push((step, wgt));
}
Some(TimewarpPlan { grid: fr.grid, frames: fr.imgs, steps, flows: flows.into_iter().map(|(_, f)| f).collect(), pm })
}
/// Timewarp. Whole Frames shows the nearest source frame, Frame Mix cross-fades the two
/// neighbouring frames and Pixel Motion builds the in-between frame along estimated motion
/// vectors (block-matching optical flow, [`effectcraft_raster::flow`]) tuned by the Tuning
/// group. A Matte Layer splits foreground and background so each moves on its own vectors; a
/// Warp Layer supplies the motion instead of the layer itself. Motion Blur averages Shutter
/// Samples instants across the shutter.
fn timewarp(ctx: &EffectCtx, b: Buf) -> Buf {
if ctx.env.host.is_none() {
return b;
}
if ctx.params.get("matteLayer").and_then(Value::as_layer).is_none() {
return match timewarp_plan(ctx) {
Some(plan) => plan.render_cpu(),
None => b,
};
}
// Instants of source time (with weights) across the shutter; each needs the frame at or
// before it and the next one.
let (instants, times, fps) = timewarp_instants(ctx);
let split = |s: f64| tw_split(s, fps);
let method = ctx.params.e("method");
let one = method > 0 && ctx.params.b("tuning/buildFromOneImage");
let Some(fr) = fetch(ctx, &times) else { return b };
let grid = fr.grid.clone();
let frame = |t: f64| -> &Image {