M13.28: GPU generators (fx_gen2): Lightning, Advanced Lightning, Beam, Lens Flare, Radio Waves, Vegas, Stroke, Scribble, Write-on, Paint Bucket, Eyedropper Fill, CC Glue Gun, CC Threads, Audio Spectrum/Waveform, Basic Text, Path Text
The geometry stays on the CPU as per-frame plans shared with the CPU effects (bolts, mask strokes, scribbles, contour segments, audio marks, glyph strokes, waves, flood-fill region, eyedropper sample); segments and convex polygons are tile-binned and rasterised on the GPU with the CPU's coverage functions. CPU output unchanged (gen_golden). CC Threads' exact ties at round parameter values are a documented exception; Fractal stays on the CPU (needs f64). Regenerated docs/effects.md, docs/parity.md EFF-5. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5df9cde182
commit
c4315818da
@@ -208,15 +208,18 @@ fn ellipse(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
|
||||
// ---------------------------------------------------------------- Lens Flare
|
||||
|
||||
struct Ghost {
|
||||
t: f64,
|
||||
r: f64,
|
||||
c: [f32; 3],
|
||||
k: f32,
|
||||
ring: bool,
|
||||
/// A Lens Flare ghost: position along the flare axis, radius (fraction of the diagonal), colour,
|
||||
/// strength, ring or disc.
|
||||
pub struct Ghost {
|
||||
pub t: f64,
|
||||
pub r: f64,
|
||||
pub c: [f32; 3],
|
||||
pub k: f32,
|
||||
pub ring: bool,
|
||||
}
|
||||
|
||||
fn ghosts(lens: u32) -> Vec<Ghost> {
|
||||
/// The ghosts of Lens Type `lens`.
|
||||
pub fn flare_ghosts(lens: u32) -> Vec<Ghost> {
|
||||
let g = |t, r, c: [f32; 3], k, ring| Ghost { t, r, c, k, ring };
|
||||
match lens {
|
||||
1 => vec![
|
||||
@@ -246,7 +249,7 @@ fn lens_flare(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let (x0, y0, w, h) = layer_rect(ctx, &b);
|
||||
let c = (x0 + w * 0.5, y0 + h * 0.5);
|
||||
let diag = (w * w + h * h).sqrt().max(1.0);
|
||||
let gs = ghosts(lens);
|
||||
let gs = flare_ghosts(lens);
|
||||
let (core_k, rays, halo_r) = match lens {
|
||||
1 => (0.035, 6.0, 0.18),
|
||||
2 => (0.02, 12.0, 0.3),
|
||||
@@ -392,9 +395,9 @@ fn reflect(v: f64, lo: f64, hi: f64) -> f64 {
|
||||
|
||||
/// The source shape of a contour wave: signed distance (buffer px, negative inside) on the
|
||||
/// buffer grid, and the point of the shape that sits on the Producer Point.
|
||||
struct Contour {
|
||||
sdf: Plane,
|
||||
anchor: (f64, f64),
|
||||
pub struct Contour {
|
||||
pub sdf: Plane,
|
||||
pub anchor: (f64, f64),
|
||||
}
|
||||
|
||||
/// Image Contours: the region of the source layer whose Value Channel passes Value Threshold.
|
||||
@@ -494,16 +497,27 @@ fn mask_contour(ctx: &EffectCtx, b: &Buf) -> Option<Contour> {
|
||||
}
|
||||
|
||||
/// One live wave.
|
||||
struct Wave {
|
||||
centre: (f64, f64),
|
||||
radius: f64,
|
||||
half_width: f64,
|
||||
rotation: f64,
|
||||
fade: f32,
|
||||
color: [f32; 4],
|
||||
opacity: f32,
|
||||
pub struct Wave {
|
||||
pub centre: (f64, f64),
|
||||
pub radius: f64,
|
||||
pub half_width: f64,
|
||||
pub rotation: f64,
|
||||
pub fade: f32,
|
||||
pub color: [f32; 4],
|
||||
pub opacity: f32,
|
||||
/// Polygon outline (unit shape rotated and scaled), or None for a circle / contour.
|
||||
outline: Option<Vec<(f64, f64)>>,
|
||||
pub outline: Option<Vec<(f64, f64)>>,
|
||||
}
|
||||
|
||||
/// Radio Waves, shared with the GPU compositor (effectcraft-gpu `fx_gen2`): the live waves,
|
||||
/// oldest first, and the contour they ripple from (Image Contours / Mask).
|
||||
pub struct RadioPlan {
|
||||
pub waves: Vec<Wave>,
|
||||
pub contour: Option<Contour>,
|
||||
/// Anti-aliasing width (px) from Render Quality.
|
||||
pub aa: f64,
|
||||
/// Stroke Profile.
|
||||
pub profile: u32,
|
||||
}
|
||||
|
||||
/// Radio Waves: waves are born at Frequency per second at the Producer Point and grow at
|
||||
@@ -513,7 +527,9 @@ struct Wave {
|
||||
/// channel, Mask waves from a mask. With Parameters Are Set At Birth each wave keeps the values
|
||||
/// it was born with; Each Frame applies the current values to every wave. Stroke draws each wave
|
||||
/// with its Profile across the width.
|
||||
fn radio_waves(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
/// [`RadioPlan`] of Radio Waves on `b`'s geometry (`None` = no contour: the layer passes
|
||||
/// through).
|
||||
pub fn radio_plan(ctx: &EffectCtx, b: &Buf) -> Option<RadioPlan> {
|
||||
let cur = ctx.params;
|
||||
let t = ctx.time.max(0.0);
|
||||
let freq = cur.f("waveMotion/frequency").max(0.01);
|
||||
@@ -524,14 +540,14 @@ fn radio_waves(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let aa = 0.5 + 1.5 / quality;
|
||||
let profile = cur.e("waveStroke/profile");
|
||||
let reflection = cur.b("waveMotion/reflection");
|
||||
let (lx, ly, lw, lh) = layer_rect(ctx, &b);
|
||||
let (lx, ly, lw, lh) = layer_rect(ctx, b);
|
||||
let contour = match wave_type {
|
||||
1 => image_contour(ctx, &b),
|
||||
2 => mask_contour(ctx, &b),
|
||||
1 => image_contour(ctx, b),
|
||||
2 => mask_contour(ctx, b),
|
||||
_ => None,
|
||||
};
|
||||
if wave_type != 0 && contour.is_none() {
|
||||
return b;
|
||||
return None;
|
||||
}
|
||||
let k_hi = (t * freq).floor() as i64;
|
||||
let k_lo = (((t - life_now) * freq).floor() as i64 - 1).max(0).max(k_hi - 256);
|
||||
@@ -598,6 +614,11 @@ fn radio_waves(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
Some(RadioPlan { waves, contour, aa, profile })
|
||||
}
|
||||
|
||||
fn radio_waves(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let Some(RadioPlan { waves, contour, aa, profile }) = radio_plan(ctx, &b) else { return b };
|
||||
map_xy(&mut b.img, |x, y, px| {
|
||||
let mut out = px;
|
||||
// Older waves first, so newer ones sit on top.
|
||||
@@ -634,7 +655,9 @@ fn radio_waves(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
|
||||
// ---------------------------------------------------------------- Advanced Lightning
|
||||
|
||||
type Seg = ((f64, f64), (f64, f64), f32);
|
||||
/// A bolt segment of Advanced Lightning: start, end (buffer px) and intensity.
|
||||
pub type BoltSeg = ((f64, f64), (f64, f64), f32);
|
||||
type Seg = BoltSeg;
|
||||
|
||||
/// Advanced Lightning's Lightning Type options.
|
||||
const LIGHTNING_TYPES: [&str; 8] = ["Direction", "Strike", "Breaking", "Bouncy", "Omni", "Anywhere", "Vertical", "Two-Way Strike"];
|
||||
@@ -715,7 +738,9 @@ fn bolt(cfg: &BoltCfg, a: (f64, f64), z: (f64, f64), depth: u32, inten: f32, mai
|
||||
}
|
||||
}
|
||||
|
||||
fn lightning_segments(ctx: &EffectCtx, b: &Buf) -> Vec<Seg> {
|
||||
/// Advanced Lightning's bolt on `b` (shared with the GPU compositor; `b.img` is read only for
|
||||
/// Alpha Obstacle).
|
||||
pub fn lightning_segments(ctx: &EffectCtx, b: &Buf) -> Vec<Seg> {
|
||||
let kind = ctx.params.e("lightningType");
|
||||
let decay_main = ctx.params.b("decayMainCore");
|
||||
let o = b.to_px(ctx.params.v2("origin"));
|
||||
|
||||
+213
-68
@@ -33,7 +33,7 @@ fn pct() -> ParamUi {
|
||||
|
||||
/// A round-capped line segment in buffer pixels with radius `r` and intensity `v`.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(crate) struct Seg {
|
||||
pub struct Seg {
|
||||
pub a: [f64; 2],
|
||||
pub b: [f64; 2],
|
||||
pub r: f64,
|
||||
@@ -89,7 +89,7 @@ pub(crate) fn raster_segs(w: usize, h: usize, segs: &[Seg], hardness: f64) -> Pl
|
||||
}
|
||||
|
||||
/// Segments along a polyline (buffer px).
|
||||
pub(crate) fn poly_segs(pts: &[[f64; 2]], closed: bool, r: f64, v: f32, out: &mut Vec<Seg>) {
|
||||
pub fn poly_segs(pts: &[[f64; 2]], closed: bool, r: f64, v: f32, out: &mut Vec<Seg>) {
|
||||
let n = pts.len();
|
||||
if n == 1 {
|
||||
out.push(Seg { a: pts[0], b: pts[0], r, v });
|
||||
@@ -147,6 +147,81 @@ pub(crate) fn paint(img: &mut Image, cov: &Plane, color: [f32; 4], opacity: f32,
|
||||
});
|
||||
}
|
||||
|
||||
/// Coverage of a plan-drawn generator: round-capped segments rasterised by [`raster_segs`]
|
||||
/// with `hardness`, or the union of convex polygons ([`raster_convex`]).
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Coverage {
|
||||
Segs { segs: Vec<Seg>, hardness: f64 },
|
||||
Convex(Vec<Vec<[f64; 2]>>),
|
||||
}
|
||||
|
||||
impl Coverage {
|
||||
fn raster(&self, w: usize, h: usize) -> Plane {
|
||||
match self {
|
||||
Coverage::Segs { segs, hardness } => raster_segs(w, h, segs, *hardness),
|
||||
Coverage::Convex(polys) => raster_convex(w, h, polys),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Stroke, Scribble, Vegas and Write-on, shared with the GPU compositor (effectcraft-gpu
|
||||
/// `fx_gen2`): the coverage and how it is painted. `style` 0–2 as [`paint`] (On Original
|
||||
/// Image, On Transparent, Reveal Original Image), 3 = under the layer (Vegas' Composite Under).
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PaintPlan {
|
||||
pub cov: Coverage,
|
||||
pub color: [f32; 4],
|
||||
pub opacity: f32,
|
||||
pub style: u32,
|
||||
}
|
||||
|
||||
/// Draw a [`PaintPlan`].
|
||||
fn draw_paint(b: &mut Buf, plan: &PaintPlan) {
|
||||
let cov = plan.cov.raster(b.img.width as usize, b.img.height as usize);
|
||||
if plan.style == 3 {
|
||||
let color = plan.color;
|
||||
b.img.data.par_iter_mut().zip(cov.data.par_iter()).for_each(|(px, &c)| {
|
||||
let a = c * color[3];
|
||||
*px = over([color[0] * a, color[1] * a, color[2] * a, a], *px);
|
||||
});
|
||||
} else {
|
||||
paint(&mut b.img, &cov, plan.color, plan.opacity, plan.style);
|
||||
}
|
||||
}
|
||||
|
||||
/// Generators drawn from a plan that need the layer's own pixels (`b.img`) to build it.
|
||||
pub fn plan_reads_pixels(id: &str, ctx: &EffectCtx) -> bool {
|
||||
match id {
|
||||
// Image Contours read the layer itself when no (resolvable) Input Layer is chosen.
|
||||
"ec.generate.vegas" => ctx.params.e("stroke") == 0,
|
||||
"ec.generate.paintbucket" | "ec.generate.eyedropperfill" => true,
|
||||
"ec.generate.advancedlightning" => ctx.params.f("alphaObstacle").clamp(-10.0, 10.0) != 0.0,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// [`PaintPlan`] of Stroke, Scribble, Vegas or Write-on on `b`'s geometry (`b.img` is read
|
||||
/// only when [`plan_reads_pixels`]). `None`: Scribble without a usable mask (the layer is
|
||||
/// cleared when it composites On Transparent, else kept).
|
||||
pub fn paint_plan(id: &str, ctx: &EffectCtx, b: &Buf) -> Option<PaintPlan> {
|
||||
match id {
|
||||
"ec.generate.stroke" => Some(stroke_plan(ctx, b)),
|
||||
"ec.generate.scribble" => scribble_plan(ctx, b),
|
||||
"ec.generate.vegas" => Some(vegas_plan(ctx, b)),
|
||||
"ec.generate.writeon" => Some(write_on_plan(ctx, b)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Scribble's Composite as a [`paint`] style.
|
||||
pub fn scribble_style(ctx: &EffectCtx) -> u32 {
|
||||
match ctx.params.e("composite") {
|
||||
0 => 0,
|
||||
2 => 2,
|
||||
_ => 1,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn over(dst: Px, src: Px) -> Px {
|
||||
let k = 1.0 - src[3];
|
||||
@@ -602,21 +677,22 @@ pub(crate) fn raster_convex(w: usize, h: usize, polys: &[Vec<[f64; 2]>]) -> Plan
|
||||
}
|
||||
|
||||
fn scribble(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
match scribble_plan(ctx, &b) {
|
||||
Some(plan) => draw_paint(&mut b, &plan),
|
||||
None if scribble_style(ctx) == 1 => b.img = Image::new(b.img.width, b.img.height),
|
||||
None => {}
|
||||
}
|
||||
b
|
||||
}
|
||||
|
||||
fn scribble_plan(ctx: &EffectCtx, b: &Buf) -> Option<PaintPlan> {
|
||||
let pr = ctx.params;
|
||||
let which = pr.e("scribble");
|
||||
let polys: Vec<_> = if which == 0 { mask_px(ctx, &b, pr.f("mask").round().max(1.0) as usize).into_iter().collect() } else { all_masks_px(ctx, &b) };
|
||||
let polys: Vec<_> = if which == 0 { mask_px(ctx, b, pr.f("mask").round().max(1.0) as usize).into_iter().collect() } else { all_masks_px(ctx, b) };
|
||||
let polys: Vec<_> = polys.into_iter().filter(|p| p.0.len() >= 3).map(|(p, c, i)| (p, c, i && which == 2)).collect();
|
||||
let style = match pr.e("composite") {
|
||||
0 => 0,
|
||||
2 => 2,
|
||||
_ => 1,
|
||||
};
|
||||
let (w, h) = (b.img.width as usize, b.img.height as usize);
|
||||
let style = scribble_style(ctx);
|
||||
if polys.is_empty() {
|
||||
if style == 1 {
|
||||
b.img = Image::new(b.img.width, b.img.height);
|
||||
}
|
||||
return b;
|
||||
return None;
|
||||
}
|
||||
let sc = b.scale;
|
||||
let fill = pr.e("fillType");
|
||||
@@ -742,24 +818,26 @@ fn scribble(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
for part in &parts {
|
||||
poly_segs(part, false, r, 1.0, &mut segs);
|
||||
}
|
||||
raster_segs(w, h, &segs, 0.9)
|
||||
Coverage::Segs { segs, hardness: 0.9 }
|
||||
} else {
|
||||
let polys = stroke_outline(&parts, r, cap, join, pr.f("edgeOptions/miterLimit").max(1.0));
|
||||
raster_convex(w, h, &polys)
|
||||
Coverage::Convex(stroke_outline(&parts, r, cap, join, pr.f("edgeOptions/miterLimit").max(1.0)))
|
||||
};
|
||||
let color = pr.color("color");
|
||||
paint(&mut b.img, &cov, color, (pr.f("opacity") / 100.0) as f32, style);
|
||||
b
|
||||
Some(PaintPlan { cov, color: pr.color("color"), opacity: (pr.f("opacity") / 100.0) as f32, style })
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Stroke
|
||||
|
||||
fn stroke(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let plan = stroke_plan(ctx, &b);
|
||||
draw_paint(&mut b, &plan);
|
||||
b
|
||||
}
|
||||
|
||||
fn stroke_plan(ctx: &EffectCtx, b: &Buf) -> PaintPlan {
|
||||
let pr = ctx.params;
|
||||
let all = pr.b("allMasks");
|
||||
let polys: Vec<_> = if all { all_masks_px(ctx, &b) } else { mask_px(ctx, &b, pr.f("path").round() as usize).into_iter().collect() };
|
||||
let polys: Vec<_> = if all { all_masks_px(ctx, b) } else { mask_px(ctx, b, pr.f("path").round() as usize).into_iter().collect() };
|
||||
let style = pr.e("paintStyle");
|
||||
let (w, h) = (b.img.width as usize, b.img.height as usize);
|
||||
let size = (pr.f("brushSize") * b.scale).max(0.1);
|
||||
let r = size * 0.5;
|
||||
let hard = pr.f("brushHardness") / 100.0;
|
||||
@@ -795,9 +873,7 @@ fn stroke(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
}
|
||||
}
|
||||
}
|
||||
let cov = raster_segs(w, h, &segs, hard);
|
||||
paint(&mut b.img, &cov, pr.color("color"), (pr.f("opacity") / 100.0) as f32, style);
|
||||
b
|
||||
PaintPlan { cov: Coverage::Segs { segs, hardness: hard }, color: pr.color("color"), opacity: (pr.f("opacity") / 100.0) as f32, style }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Vegas
|
||||
@@ -889,13 +965,19 @@ fn contours(pl: &Plane, thr: f32) -> Vec<(Vec<[f64; 2]>, bool)> {
|
||||
}
|
||||
|
||||
fn vegas(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let plan = vegas_plan(ctx, &b);
|
||||
draw_paint(&mut b, &plan);
|
||||
b
|
||||
}
|
||||
|
||||
fn vegas_plan(ctx: &EffectCtx, b: &Buf) -> PaintPlan {
|
||||
let pr = ctx.params;
|
||||
let (w, h) = (b.img.width as usize, b.img.height as usize);
|
||||
let sc = b.scale;
|
||||
let paths: Vec<(Vec<[f64; 2]>, bool)> = if pr.e("stroke") == 1 {
|
||||
mask_px(ctx, &b, pr.f("path").round() as usize).map(|(p, c, _)| vec![(p, c)]).unwrap_or_default()
|
||||
mask_px(ctx, b, pr.f("path").round() as usize).map(|(p, c, _)| vec![(p, c)]).unwrap_or_default()
|
||||
} else {
|
||||
let src = layer_or_self(ctx, &b, "inputLayer", true, pr.e("ifLayerSizesDiffer") == 1);
|
||||
let src = layer_or_self(ctx, b, "inputLayer", true, pr.e("ifLayerSizesDiffer") == 1);
|
||||
let ch = pr.e("channel");
|
||||
let inv = pr.b("invertInput");
|
||||
let mut pl = Plane::from_image(&src, |px| {
|
||||
@@ -981,20 +1063,13 @@ fn vegas(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
}
|
||||
}
|
||||
}
|
||||
let cov = raster_segs(w, h, &segs, hard);
|
||||
let color = pr.color("color");
|
||||
match pr.e("blendMode") {
|
||||
1 => paint(&mut b.img, &cov, color, 1.0, 0),
|
||||
2 => {
|
||||
b.img.data.par_iter_mut().zip(cov.data.par_iter()).for_each(|(px, &c)| {
|
||||
let a = c * color[3];
|
||||
*px = over([color[0] * a, color[1] * a, color[2] * a, a], *px);
|
||||
});
|
||||
}
|
||||
3 => paint(&mut b.img, &cov, color, 1.0, 2),
|
||||
_ => paint(&mut b.img, &cov, color, 1.0, 1),
|
||||
}
|
||||
b
|
||||
let style = match pr.e("blendMode") {
|
||||
1 => 0,
|
||||
2 => 3,
|
||||
3 => 2,
|
||||
_ => 1,
|
||||
};
|
||||
PaintPlan { cov: Coverage::Segs { segs, hardness: hard }, color: pr.color("color"), opacity: 1.0, style }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Write-on / Glue Gun
|
||||
@@ -1003,13 +1078,21 @@ fn vegas(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
/// (parameter histories are not passed in), so the stroke is drawn as the dabs laid along
|
||||
/// the current position — a single dab when the brush is static. Deterministic.
|
||||
fn write_on(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let plan = write_on_plan(ctx, &b);
|
||||
draw_paint(&mut b, &plan);
|
||||
b
|
||||
}
|
||||
|
||||
fn write_on_plan(ctx: &EffectCtx, b: &Buf) -> PaintPlan {
|
||||
let pr = ctx.params;
|
||||
let (w, h) = (b.img.width as usize, b.img.height as usize);
|
||||
let q = b.to_px(pr.v2("brushPosition"));
|
||||
let r = (pr.f("brushSize") * b.scale * 0.5).max(0.05);
|
||||
let cov = raster_segs(w, h, &[Seg { a: [q.0, q.1], b: [q.0, q.1], r, v: 1.0 }], pr.f("brushHardness") / 100.0);
|
||||
paint(&mut b.img, &cov, pr.color("color"), (pr.f("brushOpacity") / 100.0) as f32, pr.e("paintStyle"));
|
||||
b
|
||||
PaintPlan {
|
||||
cov: Coverage::Segs { segs: vec![Seg { a: [q.0, q.1], b: [q.0, q.1], r, v: 1.0 }], hardness: pr.f("brushHardness") / 100.0 },
|
||||
color: pr.color("color"),
|
||||
opacity: (pr.f("brushOpacity") / 100.0) as f32,
|
||||
style: pr.e("paintStyle"),
|
||||
}
|
||||
}
|
||||
|
||||
fn glue_gun(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
@@ -1071,12 +1154,11 @@ fn glue_gun(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
|
||||
// ---------------------------------------------------------------- Paint Bucket
|
||||
|
||||
fn paint_bucket(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
/// Paint Bucket's filled region (1 inside) on `b`: the flood fill from the Fill Point over the
|
||||
/// layer's pixels (shared with the GPU compositor, which reads the layer back for it).
|
||||
pub fn paint_bucket_region(ctx: &EffectCtx, b: &Buf) -> Plane {
|
||||
let pr = ctx.params;
|
||||
let (w, h) = (b.img.width as usize, b.img.height as usize);
|
||||
if w == 0 || h == 0 {
|
||||
return b;
|
||||
}
|
||||
let fp = b.to_px(pr.v2("fillPoint"));
|
||||
let (sx, sy) = (fp.0.floor() as i64, fp.1.floor() as i64);
|
||||
let sel = pr.e("fillSelector");
|
||||
@@ -1127,6 +1209,16 @@ fn paint_bucket(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
}
|
||||
}
|
||||
}
|
||||
region
|
||||
}
|
||||
|
||||
fn paint_bucket(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let pr = ctx.params;
|
||||
let (w, h) = (b.img.width as usize, b.img.height as usize);
|
||||
if w == 0 || h == 0 {
|
||||
return b;
|
||||
}
|
||||
let region = paint_bucket_region(ctx, &b);
|
||||
if pr.b("viewThreshold") {
|
||||
b.img.data.par_iter_mut().zip(region.data.par_iter()).for_each(|(px, &v)| *px = [v, v, v, 1.0]);
|
||||
return b;
|
||||
@@ -1200,6 +1292,21 @@ fn paint_bucket(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
// ---------------------------------------------------------------- Eyedropper Fill
|
||||
|
||||
fn eyedropper_fill(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let pr = ctx.params;
|
||||
let fill = eyedropper_color(ctx, &b);
|
||||
let keep_alpha = pr.b("maintainOriginalAlpha");
|
||||
let blend = (pr.f("blendWithOriginal") / 100.0) as f32;
|
||||
b.img.data.par_iter_mut().for_each(|px| {
|
||||
let a = if keep_alpha { px[3] } else { fill[3] };
|
||||
let f = premul([fill[0], fill[1], fill[2]], a);
|
||||
*px = crate::util::lerp4(f, *px, blend);
|
||||
});
|
||||
b
|
||||
}
|
||||
|
||||
/// Eyedropper Fill's sampled colour (straight RGB, alpha) from the layer's pixels (shared with
|
||||
/// the GPU compositor, which reads the layer back for it).
|
||||
pub fn eyedropper_color(ctx: &EffectCtx, b: &Buf) -> Px {
|
||||
let pr = ctx.params;
|
||||
let (w, h) = (b.img.width as i64, b.img.height as i64);
|
||||
let c = b.to_px(pr.v2("samplePoint"));
|
||||
@@ -1250,7 +1357,7 @@ fn eyedropper_fill(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
}
|
||||
}
|
||||
}
|
||||
let fill: Px = if n > 0.0 {
|
||||
if n > 0.0 {
|
||||
if mode == 3 {
|
||||
let a = (acc[3] / n) as f32;
|
||||
let s = if a > 1e-6 { [(acc[0] / n) as f32 / a, (acc[1] / n) as f32 / a, (acc[2] / n) as f32 / a] } else { [0.0; 3] };
|
||||
@@ -1260,15 +1367,7 @@ fn eyedropper_fill(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
}
|
||||
} else {
|
||||
[0.0, 0.0, 0.0, 0.0]
|
||||
};
|
||||
let keep_alpha = pr.b("maintainOriginalAlpha");
|
||||
let blend = (pr.f("blendWithOriginal") / 100.0) as f32;
|
||||
b.img.data.par_iter_mut().for_each(|px| {
|
||||
let a = if keep_alpha { px[3] } else { fill[3] };
|
||||
let f = premul([fill[0], fill[1], fill[2]], a);
|
||||
*px = crate::util::lerp4(f, *px, blend);
|
||||
});
|
||||
b
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- CC Threads
|
||||
@@ -1455,9 +1554,57 @@ fn draw_marks(b: &mut Buf, segs_core: &[Seg], thickness: f64, softness: f64, ins
|
||||
});
|
||||
}
|
||||
|
||||
fn audio_spectrum(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
/// Audio Spectrum / Audio Waveform, shared with the GPU compositor (effectcraft-gpu `fx_gen2`):
|
||||
/// the marks (the audio analysis runs on the CPU) and how [`draw_marks`] colours them.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MarksPlan {
|
||||
pub segs: Vec<Seg>,
|
||||
pub thickness: f64,
|
||||
pub softness: f64,
|
||||
pub inside: [f32; 4],
|
||||
pub outside: [f32; 4],
|
||||
pub composite: bool,
|
||||
}
|
||||
|
||||
/// [`MarksPlan`] of Audio Spectrum or Audio Waveform on `b`'s geometry (`None` = no audio:
|
||||
/// the layer passes through).
|
||||
pub fn marks_plan(id: &str, ctx: &EffectCtx, b: &Buf) -> Option<MarksPlan> {
|
||||
match id {
|
||||
"ec.generate.audiospectrum" => spectrum_plan(ctx, b),
|
||||
"ec.generate.audiowaveform" => waveform_plan(ctx, b),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn marks(ctx: &EffectCtx, segs: Vec<Seg>, thick: f64, soft: f64) -> MarksPlan {
|
||||
let pr = ctx.params;
|
||||
let Some(samples) = audio_window(ctx, pr.f("audioDuration"), pr.f("audioOffset"), 0) else { return b };
|
||||
MarksPlan {
|
||||
segs,
|
||||
thickness: thick,
|
||||
softness: soft * 2.0,
|
||||
inside: pr.color("insideColor"),
|
||||
outside: pr.color("outsideColor"),
|
||||
composite: pr.b("compositeOnOriginal"),
|
||||
}
|
||||
}
|
||||
|
||||
fn audio_spectrum(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
if let Some(m) = spectrum_plan(ctx, &b) {
|
||||
draw_marks(&mut b, &m.segs, m.thickness, m.softness, m.inside, m.outside, m.composite);
|
||||
}
|
||||
b
|
||||
}
|
||||
|
||||
fn audio_waveform(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
if let Some(m) = waveform_plan(ctx, &b) {
|
||||
draw_marks(&mut b, &m.segs, m.thickness, m.softness, m.inside, m.outside, m.composite);
|
||||
}
|
||||
b
|
||||
}
|
||||
|
||||
fn spectrum_plan(ctx: &EffectCtx, b: &Buf) -> Option<MarksPlan> {
|
||||
let pr = ctx.params;
|
||||
let samples = audio_window(ctx, pr.f("audioDuration"), pr.f("audioOffset"), 0)?;
|
||||
let n = samples.len().next_power_of_two().max(64);
|
||||
let mut re = vec![0.0; n];
|
||||
let mut im = vec![0.0; n];
|
||||
@@ -1480,7 +1627,7 @@ fn audio_spectrum(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let soft = pr.f("softness") / 100.0;
|
||||
let disp = pr.e("displayOptions");
|
||||
let side = pr.e("sideOptions");
|
||||
let base = Baseline::new(ctx, &b);
|
||||
let base = Baseline::new(ctx, b);
|
||||
let mut tops = Vec::with_capacity(bands);
|
||||
let mut segs = Vec::new();
|
||||
for i in 0..bands {
|
||||
@@ -1522,19 +1669,18 @@ fn audio_spectrum(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
}
|
||||
}
|
||||
}
|
||||
draw_marks(&mut b, &segs, thick, soft * 2.0, pr.color("insideColor"), pr.color("outsideColor"), pr.b("compositeOnOriginal"));
|
||||
b
|
||||
Some(marks(ctx, segs, thick, soft))
|
||||
}
|
||||
|
||||
fn audio_waveform(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
fn waveform_plan(ctx: &EffectCtx, b: &Buf) -> Option<MarksPlan> {
|
||||
let pr = ctx.params;
|
||||
let Some(samples) = audio_window(ctx, pr.f("audioDuration"), pr.f("audioOffset"), pr.e("waveformOptions")) else { return b };
|
||||
let samples = audio_window(ctx, pr.f("audioDuration"), pr.f("audioOffset"), pr.e("waveformOptions"))?;
|
||||
let count = pr.f("displayedSamples").round().clamp(2.0, 4096.0) as usize;
|
||||
let max_h = pr.f("maximumHeight") * b.scale;
|
||||
let thick = (pr.f("thickness") * b.scale).max(0.1);
|
||||
let soft = pr.f("softness") / 100.0;
|
||||
let disp = pr.e("displayOptions");
|
||||
let base = Baseline::new(ctx, &b);
|
||||
let base = Baseline::new(ctx, b);
|
||||
let m = samples.len();
|
||||
let mut pts = Vec::with_capacity(count);
|
||||
let mut segs = Vec::new();
|
||||
@@ -1567,8 +1713,7 @@ fn audio_waveform(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
} else if disp == 2 {
|
||||
segs.extend(pts.iter().map(|&q| Seg { a: q, b: q, r: thick * 0.5, v: 1.0 }));
|
||||
}
|
||||
draw_marks(&mut b, &segs, thick, soft * 2.0, pr.color("insideColor"), pr.color("outsideColor"), pr.b("compositeOnOriginal"));
|
||||
b
|
||||
Some(marks(ctx, segs, thick, soft))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- registry
|
||||
|
||||
@@ -89,7 +89,12 @@ pub use stylize2::strobe_on;
|
||||
pub use blur2::{camera_lens_plain, camera_lens_spans};
|
||||
pub use generate::gen_mode;
|
||||
pub use generate2::pattern_kind as cell_pattern_kind;
|
||||
pub use generate2::{BoltSeg, Contour, Ghost, RadioPlan, Wave, flare_ghosts, lightning_segments, radio_plan};
|
||||
pub use generate3::{
|
||||
Coverage, MarksPlan, PaintPlan, Seg, eyedropper_color, marks_plan, paint_bucket_region, paint_plan, plan_reads_pixels, poly_segs, scribble_style,
|
||||
};
|
||||
pub use noise::GrainLook;
|
||||
pub use textfx::{BoltPlan, TextLook, TextPass, bolt_plan, text_passes};
|
||||
pub use transition::place_layer;
|
||||
// effectcraft-gpu fx_noise.
|
||||
pub use keying2::{InnerOuterPlan, inner_outer_plan};
|
||||
@@ -1040,6 +1045,24 @@ pub const GPU_EFFECTS: &[&str] = &[
|
||||
"ec.key.innerouter",
|
||||
"ec.key.ccsimplewireremoval",
|
||||
"ec.obsolete.basic3d",
|
||||
// effectcraft-gpu fx_gen2 (generators, part C: CPU plans rasterised on the GPU)
|
||||
"ec.obsolete.lightning",
|
||||
"ec.generate.advancedlightning",
|
||||
"ec.generate.beam",
|
||||
"ec.generate.lensflare",
|
||||
"ec.generate.radiowaves",
|
||||
"ec.generate.vegas",
|
||||
"ec.generate.stroke",
|
||||
"ec.generate.scribble",
|
||||
"ec.generate.writeon",
|
||||
"ec.generate.paintbucket",
|
||||
"ec.generate.eyedropperfill",
|
||||
"ec.generate.ccgluegun",
|
||||
"ec.generate.ccthreads",
|
||||
"ec.generate.audiospectrum",
|
||||
"ec.generate.audiowaveform",
|
||||
"ec.obsolete.basictext",
|
||||
"ec.obsolete.pathtext",
|
||||
];
|
||||
|
||||
/// Effects whose output depends on [`EffectCtx::time`] directly (not only through animated
|
||||
|
||||
@@ -173,13 +173,35 @@ fn layout_line(text: &str, origin: [f64; 2], size: f64, tracking: f64, proportio
|
||||
}
|
||||
|
||||
/// How text paints: fill/stroke display option, colours, and compositing.
|
||||
struct TextLook {
|
||||
display: u32,
|
||||
fill: [f32; 4],
|
||||
stroke: [f32; 4],
|
||||
stroke_w: f64,
|
||||
on_original: bool,
|
||||
opacity: f32,
|
||||
/// How text is drawn: Display Options (0 fill only, 1 stroke only, 2 fill over stroke, 3 stroke
|
||||
/// over fill), colours, stroke width (buffer px), on the layer or on transparency, opacity.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct TextLook {
|
||||
pub display: u32,
|
||||
pub fill: [f32; 4],
|
||||
pub stroke: [f32; 4],
|
||||
pub stroke_w: f64,
|
||||
pub on_original: bool,
|
||||
pub opacity: f32,
|
||||
}
|
||||
|
||||
/// One drawing pass of Basic Text / Path Text, shared with the GPU compositor (effectcraft-gpu
|
||||
/// `fx_gen2`): glyph stroke polylines (buffer px) of radius `r`, drawn with `look` over the
|
||||
/// result of the previous pass.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TextPass {
|
||||
pub polys: Vec<Vec<[f64; 2]>>,
|
||||
pub r: f64,
|
||||
pub look: TextLook,
|
||||
}
|
||||
|
||||
/// The [`TextPass`]es of Basic Text or Path Text on `b`'s geometry.
|
||||
pub fn text_passes(id: &str, ctx: &EffectCtx, b: &Buf) -> Option<Vec<TextPass>> {
|
||||
match id {
|
||||
"ec.obsolete.basictext" => Some(vec![basic_text_pass(ctx, b)]),
|
||||
"ec.obsolete.pathtext" => Some(path_text_passes(ctx, b)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn over(dst: Px, src: Px) -> Px {
|
||||
@@ -508,6 +530,12 @@ fn timecode_fx(ctx: &EffectCtx, b: Buf) -> Buf {
|
||||
// ---------------------------------------------------------------- Basic Text
|
||||
|
||||
fn basic_text(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let pass = basic_text_pass(ctx, &b);
|
||||
draw_text(&mut b, &pass.polys, pass.r, &pass.look);
|
||||
b
|
||||
}
|
||||
|
||||
fn basic_text_pass(ctx: &EffectCtx, b: &Buf) -> TextPass {
|
||||
let pr = ctx.params;
|
||||
let size = (pr.f("size") * b.scale).max(0.5);
|
||||
let tracking = pr.f("tracking") * b.scale;
|
||||
@@ -527,21 +555,27 @@ fn basic_text(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let y = pos.1 + unit(size) * 3.0 + (i as f64 - (n - 1.0) * 0.5) * lead;
|
||||
layout_line(l, [x, y], size, tracking, true, &mut polys);
|
||||
}
|
||||
let look = look_from(ctx, &b, "compositeOnOriginal");
|
||||
draw_text(&mut b, &polys, weight(size), &look);
|
||||
b
|
||||
let look = look_from(ctx, b, "compositeOnOriginal");
|
||||
TextPass { polys, r: weight(size), look }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Path Text
|
||||
|
||||
fn path_text(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
for pass in path_text_passes(ctx, &b) {
|
||||
draw_text(&mut b, &pass.polys, pass.r, &pass.look);
|
||||
}
|
||||
b
|
||||
}
|
||||
|
||||
fn path_text_passes(ctx: &EffectCtx, b: &Buf) -> Vec<TextPass> {
|
||||
let pr = ctx.params;
|
||||
let g = |group: &str, id: &str| grouped(pr, group, id).cloned().unwrap_or(Value::Scalar(0.0));
|
||||
let px = |id: &str| {
|
||||
let q = b.to_px(g("pathOptions/controlPoints", id).as_vec2());
|
||||
[q.0, q.1]
|
||||
};
|
||||
let (mut path, mut closed) = match mask_px(ctx, &b, g("pathOptions", "customPath").as_f64().round() as usize) {
|
||||
let (mut path, mut closed) = match mask_px(ctx, b, g("pathOptions", "customPath").as_f64().round() as usize) {
|
||||
Some((p, c, _)) => (p, c),
|
||||
None => match g("pathOptions", "shapeType").as_enum() {
|
||||
1 | 2 => {
|
||||
@@ -675,12 +709,13 @@ fn path_text(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut look = look_from(ctx, &b, "compositeOnOriginal");
|
||||
let mut look = look_from(ctx, b, "compositeOnOriginal");
|
||||
let base_op = look.opacity;
|
||||
let mut first = true;
|
||||
for (alpha, polys) in &polys_by_alpha {
|
||||
look.opacity = base_op * alpha;
|
||||
draw_text(&mut b, polys, weight(size), &look);
|
||||
let mut passes = Vec::new();
|
||||
for (alpha, polys) in polys_by_alpha.iter_mut() {
|
||||
look.opacity = base_op * *alpha;
|
||||
passes.push(TextPass { polys: std::mem::take(polys), r: weight(size), look });
|
||||
if first {
|
||||
// Later passes go over the first one.
|
||||
look.on_original = true;
|
||||
@@ -688,9 +723,9 @@ fn path_text(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
}
|
||||
}
|
||||
if polys_by_alpha.is_empty() {
|
||||
draw_text(&mut b, &[], weight(size), &look);
|
||||
passes.push(TextPass { polys: vec![], r: weight(size), look });
|
||||
}
|
||||
b
|
||||
passes
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Lightning (obsolete)
|
||||
@@ -750,7 +785,53 @@ impl Bolt<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Lightning, shared with the GPU compositor (effectcraft-gpu `fx_gen2`): the bolt segments
|
||||
/// (outer radius per segment) and how they are drawn.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BoltPlan {
|
||||
pub segs: Vec<Seg>,
|
||||
/// Width (buffer px): the glow's blur.
|
||||
pub width: f64,
|
||||
/// Core Width (fraction of each segment's radius).
|
||||
pub core: f64,
|
||||
pub outside: [f32; 4],
|
||||
pub inside: [f32; 4],
|
||||
/// Blending Mode: 0 normal, 1 add, 2 screen.
|
||||
pub mode: u32,
|
||||
}
|
||||
|
||||
fn lightning(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let plan = bolt_plan(ctx, &b);
|
||||
let (segs, width, core) = (&plan.segs, plan.width, plan.core);
|
||||
let (wd, ht) = (b.img.width as usize, b.img.height as usize);
|
||||
let outer = raster_segs(wd, ht, segs, 0.0);
|
||||
let core_segs: Vec<Seg> = segs.iter().map(|g| Seg { r: (g.r * core).max(0.3), ..*g }).collect();
|
||||
let inner = raster_segs(wd, ht, &core_segs, 0.6);
|
||||
let glow = gauss_plane(&outer, width * 0.5, width * 0.5);
|
||||
let (oc, ic, mode) = (plan.outside, plan.inside, plan.mode);
|
||||
b.img.data.par_iter_mut().enumerate().for_each(|(i, px)| {
|
||||
let o = outer.data[i].max(glow.data[i] * 0.8);
|
||||
let c = inner.data[i];
|
||||
let a = o.max(c).min(1.0);
|
||||
if a <= 0.0 {
|
||||
return;
|
||||
}
|
||||
let t = if a > 0.0 { c / a } else { 0.0 };
|
||||
let colr = [oc[0] + (ic[0] - oc[0]) * t, oc[1] + (ic[1] - oc[1]) * t, oc[2] + (ic[2] - oc[2]) * t];
|
||||
*px = match mode {
|
||||
1 => [px[0] + colr[0] * a, px[1] + colr[1] * a, px[2] + colr[2] * a, (px[3] + a * (1.0 - px[3])).min(1.0)],
|
||||
2 => {
|
||||
let sc = |d: f32, s: f32| d + s - d * s;
|
||||
[sc(px[0], colr[0] * a), sc(px[1], colr[1] * a), sc(px[2], colr[2] * a), sc(px[3], a)]
|
||||
}
|
||||
_ => over(*px, [colr[0] * a, colr[1] * a, colr[2] * a, a]),
|
||||
};
|
||||
});
|
||||
b
|
||||
}
|
||||
|
||||
/// [`BoltPlan`] of Lightning on `b`'s geometry.
|
||||
pub fn bolt_plan(ctx: &EffectCtx, b: &Buf) -> BoltPlan {
|
||||
let pr = ctx.params;
|
||||
let s = b.to_px(pr.v2("startPoint"));
|
||||
let e = b.to_px(pr.v2("endPoint"));
|
||||
@@ -816,33 +897,7 @@ fn lightning(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
bolt.out.push(Seg { a: wpair[0], b: wpair[1], r: width * 0.5 * w * v, v: 1.0 });
|
||||
}
|
||||
}
|
||||
let (wd, ht) = (b.img.width as usize, b.img.height as usize);
|
||||
let outer = raster_segs(wd, ht, &segs, 0.0);
|
||||
let core_segs: Vec<Seg> = segs.iter().map(|g| Seg { r: (g.r * core).max(0.3), ..*g }).collect();
|
||||
let inner = raster_segs(wd, ht, &core_segs, 0.6);
|
||||
let glow = gauss_plane(&outer, width * 0.5, width * 0.5);
|
||||
let oc = pr.color("outsideColor");
|
||||
let ic = pr.color("insideColor");
|
||||
let mode = pr.e("blendingMode");
|
||||
b.img.data.par_iter_mut().enumerate().for_each(|(i, px)| {
|
||||
let o = outer.data[i].max(glow.data[i] * 0.8);
|
||||
let c = inner.data[i];
|
||||
let a = o.max(c).min(1.0);
|
||||
if a <= 0.0 {
|
||||
return;
|
||||
}
|
||||
let t = if a > 0.0 { c / a } else { 0.0 };
|
||||
let colr = [oc[0] + (ic[0] - oc[0]) * t, oc[1] + (ic[1] - oc[1]) * t, oc[2] + (ic[2] - oc[2]) * t];
|
||||
*px = match mode {
|
||||
1 => [px[0] + colr[0] * a, px[1] + colr[1] * a, px[2] + colr[2] * a, (px[3] + a * (1.0 - px[3])).min(1.0)],
|
||||
2 => {
|
||||
let sc = |d: f32, s: f32| d + s - d * s;
|
||||
[sc(px[0], colr[0] * a), sc(px[1], colr[1] * a), sc(px[2], colr[2] * a), sc(px[3], a)]
|
||||
}
|
||||
_ => over(*px, [colr[0] * a, colr[1] * a, colr[2] * a, a]),
|
||||
};
|
||||
});
|
||||
b
|
||||
BoltPlan { segs, width, core, outside: pr.color("outsideColor"), inside: pr.color("insideColor"), mode: pr.e("blendingMode") }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- registry
|
||||
|
||||
Reference in New Issue
Block a user