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:
Brandon Thomas
2026-10-04 02:56:00 -04:00
co-authored by Claude Opus 5.5
parent 5df9cde182
commit c4315818da
16 changed files with 2005 additions and 171 deletions
+2
View File
@@ -325,6 +325,7 @@ impl GpuContext {
include_str!("shaders/fx_text.wgsl"),
include_str!("shaders/fx_time.wgsl"),
include_str!("shaders/fx_pixel2.wgsl"),
include_str!("shaders/fx_gen2.wgsl"),
include_str!("shaders/sky.wgsl"),
]
.concat();
@@ -394,6 +395,7 @@ impl GpuContext {
.chain(crate::fx_text::KERNELS)
.chain(crate::fx_time::KERNELS)
.chain(crate::fx_pixel2::KERNELS)
.chain(crate::fx_gen2::KERNELS)
.chain(crate::adv3d::SKY_KERNELS)
.map(|e| (e, &layout))
.chain(EXT_ENTRIES.iter().map(|e| (e, &layout_ext)))
+1
View File
@@ -176,6 +176,7 @@ fn apply(e: &mut Enc, id: &str, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
_ if crate::fx_text::IDS.contains(&id) => crate::fx_text::apply(e, id, ctx, b),
_ if crate::fx_time::IDS.contains(&id) => crate::fx_time::apply(e, id, ctx, b),
_ if crate::fx_pixel2::IDS.contains(&id) => crate::fx_pixel2::apply(e, id, ctx, b),
_ if crate::fx_gen2::IDS.contains(&id) => crate::fx_gen2::apply(e, id, ctx, b),
_ => pointwise(e, id, ctx, b),
}
}
+561
View File
@@ -0,0 +1,561 @@
//! GPU effects, generators of part C (kernels in `shaders/fx_gen2.wgsl`, every entry point
//! prefixed `fg2_`): Lightning, Advanced Lightning, Beam, Fractal, Lens Flare, Radio Waves,
//! Vegas, Stroke, Scribble, Write-on, Paint Bucket, Eyedropper Fill, CC Glue Gun, CC Threads,
//! Audio Spectrum, Audio Waveform, Basic Text and Path Text.
//!
//! Geometry stays on the CPU and is shared with the CPU effect as a per-frame plan: the bolts
//! (`effects::bolt_plan`, `effects::lightning_segments`), mask strokes, scribbles and contour
//! segments (`effects::paint_plan`), audio marks (`effects::marks_plan`: the FFT and peak
//! analysis), glyph strokes (`effects::text_passes`), live waves and their contour
//! (`effects::radio_plan`), Paint Bucket's flood-filled region and Eyedropper Fill's sampled
//! colour (both over the read-back layer). The plans' segments and polygons are binned into
//! 16 × 16 tiles on the CPU and rasterised here with the CPU's coverage functions
//! (`raster_segs`' smooth round caps, `raster_convex`'s 4 × 4 samples); the colouring, glows
//! (util::gauss_plane) and compositing run here too. Beam, Lens Flare, CC Glue Gun and CC
//! Threads are closed-form kernels.
//!
//! Fractal stays on the CPU: its escape iteration needs f64 (WGSL has none, and Metal's fast
//! math defeats double-f32 emulation); in f32, orbits near the set escape at other iterations
//! on 0.3–1.5 % of the pixels even at low magnification.
use effectcraft_effects::{Buf, Coverage, EffectCtx};
use effectcraft_raster::Image;
use crate::context::{Enc, GpuImage, Params};
use crate::effects::GBuf;
use crate::fx_pixel2::gauss_plane;
/// Compute entry points in `fx_gen2.wgsl`.
pub(crate) const KERNELS: &[&str] = &[
"fg2_segs",
"fg2_convex",
"fg2_paint",
"fg2_marks",
"fg2_pair",
"fg2_bolt",
"fg2_adv_bolt",
"fg2_text",
"fg2_radio",
"fg2_beam",
"fg2_flare",
"fg2_glue",
"fg2_threads",
"fg2_bucket",
"fg2_bucket_cov",
"fg2_eyedropper",
];
/// Effect ids implemented here.
pub(crate) const IDS: &[&str] = &[
"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",
];
/// Largest item table (floats) the raster kernels take; bigger plans render on the CPU.
const MAX_FLOATS: usize = 1 << 24;
const TILE: i32 = 16;
/// "No minimum radius" for a segment variant.
const NO_MIN: f32 = -3.0e38;
/// Run effect `id` (one of [`IDS`]); `None` = this parameter combination runs on the CPU.
pub(crate) fn apply(e: &mut Enc, id: &str, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
match id {
"ec.obsolete.lightning" => lightning(e, ctx, b),
"ec.generate.advancedlightning" => advanced_lightning(e, ctx, b),
"ec.generate.beam" => beam(e, ctx, b),
"ec.generate.lensflare" => lens_flare(e, ctx, b),
"ec.generate.radiowaves" => radio_waves(e, ctx, b),
"ec.generate.vegas" | "ec.generate.stroke" | "ec.generate.scribble" | "ec.generate.writeon" => paint(e, id, ctx, b),
"ec.generate.paintbucket" => paint_bucket(e, ctx, b),
"ec.generate.eyedropperfill" => eyedropper(e, ctx, b),
"ec.generate.ccgluegun" => glue_gun(e, ctx, b),
"ec.generate.ccthreads" => threads(e, ctx, b),
"ec.generate.audiospectrum" | "ec.generate.audiowaveform" => marks(e, id, ctx, b),
"ec.obsolete.basictext" | "ec.obsolete.pathtext" => text(e, id, ctx, b),
_ => None,
}
}
/// A same-size per-pixel kernel over the buffer.
fn run(e: &mut Enc, entry: &str, p: &Params, mut b: GBuf, aux: Option<&GpuImage>, data: Option<&wgpu::Buffer>) -> Option<GBuf> {
let out = e.scratch(b.img.width, b.img.height);
e.pixels(entry, p, &b.img, aux, &out, data);
b.img = out;
Some(b)
}
/// The buffer on the CPU for building a plan: its pixels when `pixels` (read back), else only
/// its geometry.
fn cpu_buf(e: &mut Enc, b: &GBuf, pixels: bool) -> Option<Buf> {
let img = if pixels { e.download(&b.img)? } else { Image { width: b.img.width, height: b.img.height, data: vec![] } };
Some(Buf { img, offset: b.offset, scale: b.scale })
}
fn rgb(c: [f32; 4]) -> [f32; 4] {
[c[0], c[1], c[2], 0.0]
}
// ---------------------------------------------------------------- tiled item raster
/// Items with their integer pixel bounds, binned into 16 × 16 tiles.
struct Items {
stride: usize,
recs: Vec<f32>,
w: i32,
h: i32,
tiles: Vec<Vec<u32>>,
tx: i32,
}
impl Items {
fn new(stride: usize, w: u32, h: u32) -> Items {
let (w, h) = (w as i32, h as i32);
let tx = (w + TILE - 1) / TILE;
let ty = (h + TILE - 1) / TILE;
Items { stride, recs: vec![], w, h, tiles: vec![vec![]; (tx * ty).max(0) as usize], tx }
}
/// Add an item (`rec` = its fields, without the bounds) covering float bounds `bb`
/// ([x0, y0, x1, y1]).
fn push(&mut self, bb: [f64; 4], rec: &[f32]) {
if !bb.iter().all(|v| v.is_finite()) {
return;
}
let x0 = bb[0].floor().max(0.0) as i32;
let y0 = bb[1].floor().max(0.0) as i32;
let x1 = (bb[2].ceil().min(self.w as f64 - 1.0)) as i32;
let y1 = (bb[3].ceil().min(self.h as f64 - 1.0)) as i32;
if x1 < x0 || y1 < y0 || bb[2] < 0.0 || bb[3] < 0.0 {
return;
}
let i = (self.recs.len() / self.stride) as u32;
let start = self.recs.len();
self.recs.extend_from_slice(rec);
self.recs.resize(start + self.stride - 4, 0.0);
self.recs.extend([x0 as f32, y0 as f32, x1 as f32, y1 as f32]);
for ty in y0 / TILE..=y1 / TILE {
for tx in x0 / TILE..=x1 / TILE {
self.tiles[(ty * self.tx + tx) as usize].push(i);
}
}
}
/// Kernel data (tile offsets, item indices, items), the items' offset and the tile count
/// across. `None` when too large.
fn data(self) -> Option<(Vec<f32>, u32, u32)> {
let n_tiles = self.tiles.len();
let n_idx: usize = self.tiles.iter().map(Vec::len).sum();
let total = n_tiles + 1 + n_idx + self.recs.len();
if total > MAX_FLOATS {
return None;
}
let mut d = Vec::with_capacity(total);
let base = (n_tiles + 1) as f32;
let mut at = 0usize;
for t in &self.tiles {
d.push(base + at as f32);
at += t.len();
}
d.push(base + at as f32);
for t in &self.tiles {
d.extend(t.iter().map(|&i| i as f32));
}
let items_at = d.len() as u32;
d.extend(self.recs);
Some((d, items_at, self.tx.max(0) as u32))
}
}
/// A coverage of the segment raster: radius max(r · `mul` + `add`, `min`) and hardness
/// (generate3::raster_segs), or Advanced Lightning's linear core.
#[derive(Clone, Copy)]
struct Variant {
mul: f64,
add: f64,
min: f64,
hard: f64,
linear: bool,
}
impl Variant {
fn plain(hard: f64) -> Variant {
Variant { mul: 1.0, add: 0.0, min: NO_MIN as f64, hard, linear: false }
}
fn radius(&self, r: f64) -> f64 {
(r * self.mul + self.add).max(self.min)
}
}
/// Rasterise segments (a, b, radius, value) into up to four coverages (x, y, z, w), one per
/// variant, max-combined as raster_segs.
fn raster_segs(e: &mut Enc, w: u32, h: u32, segs: impl Iterator<Item = ([f64; 2], [f64; 2], f64, f32)>, variants: &[Variant]) -> Option<GpuImage> {
let mut items = Items::new(10, w, h);
for (a, z, r, v) in segs {
let pad = variants.iter().map(|k| k.radius(r)).fold(f64::NEG_INFINITY, f64::max) + 1.0;
let bb = [a[0].min(z[0]) - pad, a[1].min(z[1]) - pad, a[0].max(z[0]) + pad, a[1].max(z[1]) + pad];
items.push(bb, &[a[0] as f32, a[1] as f32, z[0] as f32, z[1] as f32, r as f32, v]);
}
let (data, items_at, tx) = items.data()?;
let buf = e.data(&data);
let mut p = Params::default();
p.u[0] = [items_at, 10, tx, variants.len() as u32];
for (k, v) in variants.iter().enumerate() {
p.f[k] = [v.mul as f32, v.add as f32, v.min as f32, v.hard as f32];
p.u[1][0] |= (v.linear as u32) << k;
}
let out = e.scratch(w, h);
let dummy = e.zeros(1, 1);
e.pixels("fg2_segs", &p, &dummy, None, &out, Some(&buf));
Some(out)
}
/// A plan's coverage (x).
fn coverage(e: &mut Enc, w: u32, h: u32, cov: &Coverage) -> Option<GpuImage> {
match cov {
Coverage::Segs { segs, hardness } => raster_segs(e, w, h, segs.iter().map(|s| (s.a, s.b, s.r, s.v)), &[Variant::plain(*hardness)]),
Coverage::Convex(polys) => {
const STRIDE: usize = 1 + 32 + 4;
let mut items = Items::new(STRIDE, w, h);
for poly in polys {
if poly.len() < 3 {
continue;
}
if poly.len() > 16 {
return None;
}
let mut rec = vec![poly.len() as f32];
let mut bb = [f64::INFINITY, f64::INFINITY, f64::NEG_INFINITY, f64::NEG_INFINITY];
for q in poly {
rec.extend([q[0] as f32, q[1] as f32]);
bb = [bb[0].min(q[0]), bb[1].min(q[1]), bb[2].max(q[0]), bb[3].max(q[1])];
}
items.push(bb, &rec);
}
let (data, items_at, tx) = items.data()?;
let buf = e.data(&data);
let mut p = Params::default();
p.u[0] = [items_at, STRIDE as u32, tx, 0];
let out = e.scratch(w, h);
let dummy = e.zeros(1, 1);
e.pixels("fg2_convex", &p, &dummy, None, &out, Some(&buf));
Some(out)
}
}
}
// ---------------------------------------------------------------- Stroke, Scribble, Vegas, Write-on
fn paint(e: &mut Enc, id: &str, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
let cpu = cpu_buf(e, &b, effectcraft_effects::plan_reads_pixels(id, ctx))?;
let Some(plan) = effectcraft_effects::paint_plan(id, ctx, &cpu) else {
// Scribble without a usable mask: cleared On Transparent, else unchanged.
if id == "ec.generate.scribble" && effectcraft_effects::scribble_style(ctx) == 1 {
let img = e.image(b.img.width, b.img.height);
return Some(GBuf { img, ..b });
}
return Some(b);
};
let cov = coverage(e, b.img.width, b.img.height, &plan.cov)?;
let mut p = Params::default();
p.u[0][0] = plan.style;
p.f[0] = plan.color;
p.f[1][0] = plan.opacity;
run(e, "fg2_paint", &p, b, Some(&cov), None)
}
// ---------------------------------------------------------------- Audio Spectrum / Waveform
fn marks(e: &mut Enc, id: &str, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
let cpu = cpu_buf(e, &b, false)?;
let Some(m) = effectcraft_effects::marks_plan(id, ctx, &cpu) else { return Some(b) };
let core = Variant::plain(1.0);
let halo = if m.softness > 0.0 { Variant { add: m.thickness * m.softness.max(0.0) + 0.5, ..Variant::plain(0.0) } } else { core };
let cov = raster_segs(e, b.img.width, b.img.height, m.segs.iter().map(|s| (s.a, s.b, s.r, s.v)), &[core, halo])?;
let mut p = Params::default();
p.u[0][0] = m.composite as u32;
p.f[0] = m.inside;
p.f[1] = m.outside;
run(e, "fg2_marks", &p, b, Some(&cov), None)
}
// ---------------------------------------------------------------- Lightning / Advanced Lightning
fn lightning(e: &mut Enc, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
let cpu = cpu_buf(e, &b, false)?;
let plan = effectcraft_effects::bolt_plan(ctx, &cpu);
let (w, h) = (b.img.width, b.img.height);
let core = Variant { mul: plan.core, min: 0.3, ..Variant::plain(0.6) };
let cov = raster_segs(e, w, h, plan.segs.iter().map(|s| (s.a, s.b, s.r, s.v)), &[Variant::plain(0.0), core])?;
let glow = gauss_plane(e, &cov, plan.width * 0.5, plan.width * 0.5);
let m = e.scratch(w, h);
e.pixels("fg2_pair", &Params::default(), &cov, Some(&glow), &m, None);
let mut p = Params::default();
p.u[0][0] = plan.mode;
p.f[0] = rgb(plan.outside);
p.f[1] = rgb(plan.inside);
run(e, "fg2_bolt", &p, b, Some(&m), None)
}
fn advanced_lightning(e: &mut Enc, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
let pr = ctx.params;
let cpu = cpu_buf(e, &b, effectcraft_effects::plan_reads_pixels("ec.generate.advancedlightning", ctx))?;
let core_r = (pr.f("coreSettings/coreRadius") * b.scale).max(0.3);
let glow_r = pr.f("glowSettings/glowRadius") * b.scale;
let segs = effectcraft_effects::lightning_segments(ctx, &cpu);
let (w, h) = (b.img.width, b.img.height);
let linear = Variant { linear: true, ..Variant::plain(0.0) };
let core = raster_segs(e, w, h, segs.iter().map(|(a, z, i)| ([a.0, a.1], [z.0, z.1], core_r, *i)), &[linear])?;
let glow = glow_r > 0.5;
let blurred = if glow { gauss_plane(e, &core, glow_r / 3.0, glow_r / 3.0) } else { core.clone() };
let m = e.scratch(w, h);
e.pixels("fg2_pair", &Params::default(), &core, Some(&blurred), &m, None);
let mut p = Params::default();
p.u[0] = [pr.b("compositeOnOriginal") as u32, glow as u32, 0, 0];
p.f[0] = [(pr.f("coreSettings/coreOpacity") / 100.0) as f32, (pr.f("glowSettings/glowOpacity") / 100.0) as f32, 0.0, 0.0];
p.f[1] = rgb(pr.color("coreSettings/coreColor"));
p.f[2] = rgb(pr.color("glowSettings/glowColor"));
run(e, "fg2_adv_bolt", &p, b, Some(&m), None)
}
// ---------------------------------------------------------------- Basic Text / Path Text
fn text(e: &mut Enc, id: &str, ctx: &EffectCtx, mut b: GBuf) -> Option<GBuf> {
let cpu = cpu_buf(e, &b, false)?;
let passes = effectcraft_effects::text_passes(id, ctx, &cpu)?;
let (w, h) = (b.img.width, b.img.height);
for pass in passes {
let look = pass.look;
let mut segs = Vec::new();
for pl in &pass.polys {
effectcraft_effects::poly_segs(pl, false, pass.r, 1.0, &mut segs);
}
let sw = look.stroke_w.max(0.0);
let at = |add: f64| Variant { add, min: 0.05, ..Variant::plain(1.0) };
let cov = raster_segs(e, w, h, segs.iter().map(|s| (s.a, s.b, s.r, s.v)), &[at(0.0), at(sw * 0.5), at(-sw * 0.5)])?;
let mut p = Params::default();
p.u[0] = [look.display, look.on_original as u32, (look.display != 0 && sw > 0.0) as u32, (pass.r - sw * 0.5 > 0.05) as u32];
p.f[0] = look.fill;
p.f[1] = look.stroke;
p.f[2][0] = look.opacity;
b = run(e, "fg2_text", &p, b, Some(&cov), None)?;
}
Some(b)
}
// ---------------------------------------------------------------- Radio Waves
fn radio_waves(e: &mut Enc, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
let cpu = cpu_buf(e, &b, false)?;
let Some(plan) = effectcraft_effects::radio_plan(ctx, &cpu) else { return Some(b) };
let n = plan.waves.len();
let mut data = Vec::with_capacity(n * 13);
let mut outlines = Vec::new();
for wv in &plan.waves {
let (off, cnt) = match &wv.outline {
Some(o) => {
let off = n * 13 + outlines.len();
outlines.extend(o.iter().flat_map(|q| [q.0 as f32, q.1 as f32]));
(off, o.len())
}
None => (0, 0),
};
data.extend([
wv.centre.0 as f32,
wv.centre.1 as f32,
wv.radius as f32,
wv.half_width as f32,
wv.rotation as f32,
wv.fade,
wv.color[0],
wv.color[1],
wv.color[2],
wv.color[3],
wv.opacity,
off as f32,
cnt as f32,
]);
}
data.extend(outlines);
if data.len() > MAX_FLOATS {
return None;
}
let mut p = Params::default();
p.u[0] = [n as u32, plan.contour.is_some() as u32, plan.profile, 0];
p.f[0][0] = plan.aa as f32;
let sdf = match &plan.contour {
Some(c) => {
let mut img = Image::new(c.sdf.w as u32, c.sdf.h as u32);
for (px, &v) in img.data.iter_mut().zip(&c.sdf.data) {
px[0] = v;
}
p.f[0][1] = c.anchor.0 as f32;
p.f[0][2] = c.anchor.1 as f32;
Some(e.g.upload_image(&img)?)
}
None => None,
};
let buf = e.data(&data);
run(e, "fg2_radio", &p, b, sdf.as_ref(), Some(&buf))
}
// ---------------------------------------------------------------- Beam / Lens Flare
fn beam(e: &mut Enc, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
let pr = ctx.params;
let s = b.to_px(pr.v2("startPoint"));
let en = b.to_px(pr.v2("endPoint"));
let len = (pr.f("length") / 100.0).clamp(0.0, 1.0);
let time = (pr.f("time") / 100.0).clamp(0.0, 1.0);
let t0 = time * (1.0 - len);
let (dx, dy) = (en.0 - s.0, en.1 - s.1);
let mut p = Params::default();
p.u[0] = [pr.b("perspective3d") as u32, pr.b("compositeOnOriginal") as u32, (len > 0.0) as u32, 0];
p.f[0] = [s.0 as f32, s.1 as f32, dx as f32, dy as f32];
p.f[1] = [t0 as f32, (t0 + len) as f32, (pr.f("startThickness") * b.scale) as f32, (pr.f("endThickness") * b.scale) as f32];
p.f[2] = [(pr.f("softness") / 100.0).clamp(0.0, 1.0) as f32, (dx * dx + dy * dy).max(1e-9) as f32, 0.0, 0.0];
p.f[3] = rgb(pr.color("insideColor"));
p.f[4] = rgb(pr.color("outsideColor"));
run(e, "fg2_beam", &p, b, None, None)
}
fn lens_flare(e: &mut Enc, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
let pr = ctx.params;
let f = b.to_px(pr.v2("flareCenter"));
let lens = pr.e("lensType");
let (w, h) = (ctx.layer_size[0] * b.scale, ctx.layer_size[1] * b.scale);
let c = (b.offset[0] + w * 0.5, b.offset[1] + h * 0.5);
let diag = (w * w + h * h).sqrt().max(1.0);
let (core_k, rays, halo_r) = match lens {
1 => (0.035, 6.0, 0.18),
2 => (0.02, 12.0, 0.3),
_ => (0.03, 8.0, 0.25),
};
let ghosts = effectcraft_effects::flare_ghosts(lens);
let data: Vec<f32> = ghosts.iter().flat_map(|g| [g.t as f32, g.r as f32, g.c[0], g.c[1], g.c[2], g.k, g.ring as u32 as f32]).collect();
let mut p = Params::default();
p.u[0][0] = ghosts.len() as u32;
p.f[0] = [f.0 as f32, f.1 as f32, c.0 as f32, c.1 as f32];
p.f[1] = [diag as f32, core_k, rays, halo_r];
p.f[2] = [(pr.f("flareBrightness") / 100.0) as f32, (pr.f("blendWithOriginal") / 100.0) as f32, 0.0, 0.0];
let buf = e.data(&data);
run(e, "fg2_flare", &p, b, None, Some(&buf))
}
// ---------------------------------------------------------------- CC Glue Gun / CC Threads
fn glue_gun(e: &mut Enc, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
let pr = ctx.params;
let q = b.to_px(pr.v2("brushPosition"));
let rad = (pr.f("strokeWidth") * b.scale * 0.5).max(0.5);
let refl = pr.f("reflection").to_radians();
let strength = (pr.f("strength") / 100.0) as f32;
let beads = (pr.f("density").max(0.0).round() as usize).clamp(1, 32);
let hash = |i: usize, k: u32| effectcraft_raster::hash_noise(i as u32, k, ctx.seed) as f64;
// generate3::glue_gun's beads.
let mut data = Vec::with_capacity(beads * 3);
for i in 0..beads {
let a = hash(i, 1) * 2.0 * std::f64::consts::PI;
let d = if i == 0 { 0.0 } else { hash(i, 2) * rad * 0.35 };
data.extend([(q.0 + a.cos() * d) as f32, (q.1 + a.sin() * d) as f32, (rad * (0.75 + 0.25 * hash(i, 3))) as f32]);
}
let mut p = Params::default();
p.u[0] = [beads as u32, (pr.e("style") == 1) as u32, 0, 0];
p.f[0] = [(refl.cos() * 0.6) as f32, (-refl.sin() * 0.6) as f32, 0.53, strength];
p.f[1][0] = strength.clamp(0.0, 1.0).max(0.3);
let buf = e.data(&data);
run(e, "fg2_glue", &p, b, None, Some(&buf))
}
fn threads(e: &mut Enc, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
let pr = ctx.params;
let sc = b.scale;
let (sn, cs) = pr.f("direction").to_radians().sin_cos();
let c = b.to_px(pr.v2("center"));
let mut p = Params::default();
p.u[0][0] = pr.f("overlaps").round().clamp(1.0, 20.0) as u32;
p.f[0] = [c.0 as f32, c.1 as f32, sn as f32, cs as f32];
p.f[1] = [
(pr.f("width") * sc).max(1.0) as f32,
(pr.f("height") * sc).max(1.0) as f32,
(pr.f("coverage") / 100.0).clamp(0.0, 1.0) as f32,
(pr.f("shadowing") / 100.0) as f32,
];
p.f[2][0] = (pr.f("texture") / 100.0) as f32;
run(e, "fg2_threads", &p, b, None, None)
}
// ---------------------------------------------------------------- Paint Bucket / Eyedropper Fill
fn paint_bucket(e: &mut Enc, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
let pr = ctx.params;
let cpu = cpu_buf(e, &b, true)?;
let region = effectcraft_effects::paint_bucket_region(ctx, &cpu);
let (w, h) = (b.img.width, b.img.height);
let mut img = Image::new(w, h);
for (px, &v) in img.data.iter_mut().zip(&region.data) {
px[0] = v;
}
let region = e.g.upload_image(&img)?;
let cov_kernel = |e: &mut Enc, mode: u32, a: &GpuImage, x: &GpuImage| {
let mut p = Params::default();
p.u[0][0] = mode;
let out = e.scratch(w, h);
e.pixels("fg2_bucket_cov", &p, a, Some(x), &out, None);
out
};
if pr.b("viewThreshold") {
let img = cov_kernel(e, 1, &region, &region);
return Some(GBuf { img, ..b });
}
let sc = b.scale;
use crate::fx_color::{DILATE_X, ERODE_X, morph_frac};
let cov = match pr.e("stroke") {
1 => {
let s = pr.f("featherSoftness") * sc * 0.5;
if s > 0.05 { gauss_plane(e, &region, s, s) } else { region }
}
2 => morph_frac(e, &region, pr.f("spreadRadius") * sc, DILATE_X),
3 => morph_frac(e, &region, pr.f("spreadRadius") * sc, ERODE_X),
4 => {
let r = pr.f("strokeWidth") * sc;
let out = morph_frac(e, &region, r * 0.5, DILATE_X);
let inn = morph_frac(e, &region, r * 0.5, ERODE_X);
cov_kernel(e, 2, &out, &inn)
}
_ => {
let blurred = gauss_plane(e, &region, 0.5, 0.5);
cov_kernel(e, 0, &region, &blurred)
}
};
let mut p = Params::default();
p.u[0][0] = pr.e("blendingMode");
p.f[0] = pr.color("color");
p.f[1][0] = (pr.f("opacity") / 100.0) as f32;
run(e, "fg2_bucket", &p, b, Some(&cov), None)
}
fn eyedropper(e: &mut Enc, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
let cpu = cpu_buf(e, &b, true)?;
let fill = effectcraft_effects::eyedropper_color(ctx, &cpu);
let mut p = Params::default();
p.u[0][0] = ctx.params.b("maintainOriginalAlpha") as u32;
p.f[0] = fill;
p.f[1][0] = (ctx.params.f("blendWithOriginal") / 100.0) as f32;
run(e, "fg2_eyedropper", &p, b, None, None)
}
+10 -6
View File
@@ -22,14 +22,15 @@
//! GPU effects ([`effectcraft_effects::GPU_EFFECTS`]) run as compute kernels with the CPU
//! effect's exact steps (padding, box-blur radii, parameter conversions); chains of them are
//! uploaded and read back once. Each family lives in its own module with its own WGSL file
//! (`fx_color`, `fx_depth`, `fx_distort`, `fx_extra`, `fx_generate`, `fx_key`, `fx_light`,
//! `fx_lut`, `fx_noise`, `fx_pixel2`, `fx_sim`, `fx_stylize`, `fx_text`, `fx_time`, `fx_tone`,
//! `fx_transition`, `fx_vr`, `fx_warp`); settings a kernel cannot match fall back to the CPU
//! (`catalog::gpu_supported`, or `None` from the family's `apply`).
//! (`fx_color`, `fx_depth`, `fx_distort`, `fx_extra`, `fx_gen2`, `fx_generate`, `fx_key`,
//! `fx_light`, `fx_lut`, `fx_noise`, `fx_pixel2`, `fx_sim`, `fx_stylize`, `fx_text`, `fx_time`,
//! `fx_tone`, `fx_transition`, `fx_vr`, `fx_warp`); settings a kernel cannot match fall back to
//! the CPU (`catalog::gpu_supported`, or `None` from the family's `apply`).
//! The 3D Channel effects read the layer's aux channels as an extra texture (`fx_depth`), the
//! colour-management effects interpret colour programs built next to the CPU effects
//! (`fx_lut`), and simulations keep their state on the CPU and rasterise its per-frame plan here
//! (`fx_sim`).
//! (`fx_lut`), simulations keep their state on the CPU and rasterise its per-frame plan here
//! (`fx_sim`), and so do the geometry generators (`fx_gen2`: bolts, strokes, glyphs, audio
//! marks, waves).
//!
//! Working textures come from a pool (`context::Pool`): a frame allocates several full-frame
//! RGBA f32 images per layer, and creating and zeroing those cost more than compositing a small
@@ -59,6 +60,7 @@ mod fx_color;
mod fx_depth;
mod fx_distort;
mod fx_extra;
mod fx_gen2;
mod fx_generate;
mod fx_key;
mod fx_light;
@@ -323,6 +325,8 @@ mod tests_fx_distort;
#[cfg(test)]
mod tests_fx_extra;
#[cfg(test)]
mod tests_fx_gen2;
#[cfg(test)]
mod tests_fx_generate;
#[cfg(test)]
mod tests_fx_key;
+805
View File
@@ -0,0 +1,805 @@
// GPU effects, generators of part C: see src/fx_gen2.rs. Every entry point is prefixed `fg2_`.
// Geometry computed on the CPU (bolts, strokes, glyphs, audio marks, waves) arrives as item
// tables in `data` — tile offsets, item indices, items (as fx_sim's tiled raster) — and is
// rasterised here with the CPU's coverage functions; closed-form generators run per pixel.
fn fg2_inside(p: vec2<i32>) -> bool {
let d = out_dims();
return p.x < d.x && p.y < d.y;
}
// util::unpremul (colour 0 below alpha 1e-6).
fn fg2_unpremul(p: vec4<f32>) -> vec3<f32> {
if (p.w > 1e-6) {
return p.xyz / p.w;
}
return vec3<f32>(0.0);
}
// util::smoothstep.
fn fg2_smoothstep(e0: f32, e1: f32, x: f32) -> f32 {
if (abs(e1 - e0) < 1e-9) {
return select(1.0, 0.0, x < e0);
}
let t = clamp((x - e0) / (e1 - e0), 0.0, 1.0);
return t * t * (3.0 - 2.0 * t);
}
// Premultiplied "over": `s` on top of `d`.
fn fg2_over(d: vec4<f32>, s: vec4<f32>) -> vec4<f32> {
return s + d * (1.0 - s.w);
}
// The tile's item range: (first index slot, end slot).
fn fg2_tile(p: vec2<i32>, tiles_x: u32) -> vec2<u32> {
let tile = u32(p.y / 16) * tiles_x + u32(p.x / 16);
return vec2<u32>(u32(data[tile]), u32(data[tile + 1u]));
}
// Whether pixel `p` lies in the integer bounds stored at the end of item `at` (stride `stride`).
fn fg2_in_bounds(p: vec2<i32>, at: u32, stride: u32) -> bool {
let bb = at + stride - 4u;
return !(f32(p.x) < data[bb] || f32(p.y) < data[bb + 1u] || f32(p.x) > data[bb + 2u] || f32(p.y) > data[bb + 3u]);
}
// ---------------------------------------------------------------- segments (generate3::raster_segs)
// Items: (ax, ay, bx, by, radius, value, bounds). Up to four coverages per pixel (x, y, z, w),
// variant k with radius max(r · f[k].x + f[k].y, f[k].z) and hardness f[k].w, max-combined;
// bit k of u[1].x selects Advanced Lightning's linear core (clamp(r − d + 0.5, 0, 1)) instead.
// u[0] = (items at, stride, tiles x, variants).
@compute @workgroup_size(16, 16)
fn fg2_segs(@builtin(global_invocation_id) gid: vec3<u32>) {
let p = vec2<i32>(gid.xy);
if (!fg2_inside(p)) {
return;
}
let stride = P.u[0].y;
let nv = P.u[0].w;
let rg = fg2_tile(p, P.u[0].z);
let px = f32(p.x) + 0.5;
let py = f32(p.y) + 0.5;
var o = vec4<f32>(0.0);
for (var k = rg.x; k < rg.y; k++) {
let at = P.u[0].x + u32(data[k]) * stride;
if (!fg2_in_bounds(p, at, stride)) {
continue;
}
let ax = data[at];
let ay = data[at + 1u];
let dx = data[at + 2u] - ax;
let dy = data[at + 3u] - ay;
let r = data[at + 4u];
let v = data[at + 5u];
let l2 = dx * dx + dy * dy;
var t = 0.0;
if (l2 > 1e-12) {
t = clamp(((px - ax) * dx + (py - ay) * dy) / l2, 0.0, 1.0);
}
let ex = px - ax - dx * t;
let ey = py - ay - dy * t;
let d = sqrt(ex * ex + ey * ey);
for (var j = 0u; j < nv; j++) {
let vf = P.f[j];
let rk = max(r * vf.x + vf.y, vf.z);
var c = 0.0;
if (((P.u[1].x >> j) & 1u) != 0u) {
c = clamp(rk - d + 0.5, 0.0, 1.0) * v;
} else {
let inner = rk * clamp(vf.w, 0.0, 1.0) - 0.5;
let outer = rk + 0.5;
if (d >= outer) {
continue;
}
if (d <= inner) {
c = v;
} else {
c = (1.0 - fg2_smoothstep(inner, outer, d)) * v;
}
}
if (c > o[j]) {
o[j] = c;
}
}
}
textureStore(out, p, o);
}
// ---------------------------------------------------------------- convex polygons (generate3::raster_convex)
// Items: (vertex count, 16 vertex pairs, bounds); coverage = union, 4 × 4 samples per pixel.
// u[0] = (items at, stride, tiles x).
fn fg2_in_poly(at: u32, x: f32, y: f32) -> bool {
let n = u32(data[at]);
var sgn = 0.0;
for (var i = 0u; i < n; i++) {
let j = (i + 1u) % n;
let ax = data[at + 1u + 2u * i];
let ay = data[at + 2u + 2u * i];
let bx = data[at + 1u + 2u * j];
let by = data[at + 2u + 2u * j];
let c = (bx - ax) * (y - ay) - (by - ay) * (x - ax);
if (abs(c) < 1e-12) {
continue;
}
if (sgn == 0.0) {
sgn = sign(c);
} else if (sign(c) != sgn) {
return false;
}
}
return true;
}
@compute @workgroup_size(16, 16)
fn fg2_convex(@builtin(global_invocation_id) gid: vec3<u32>) {
let p = vec2<i32>(gid.xy);
if (!fg2_inside(p)) {
return;
}
let stride = P.u[0].y;
let rg = fg2_tile(p, P.u[0].z);
var o = 0.0;
for (var k = rg.x; k < rg.y; k++) {
let at = P.u[0].x + u32(data[k]) * stride;
if (!fg2_in_bounds(p, at, stride)) {
continue;
}
var hit = 0;
for (var sy = 0; sy < 4; sy++) {
for (var sx = 0; sx < 4; sx++) {
if (fg2_in_poly(at, f32(p.x) + (f32(sx) + 0.5) / 4.0, f32(p.y) + (f32(sy) + 0.5) / 4.0)) {
hit += 1;
}
}
}
o = max(o, f32(hit) / 16.0);
}
textureStore(out, p, vec4<f32>(o, 0.0, 0.0, 0.0));
}
// ---------------------------------------------------------------- painting
// generate3::paint (style 0 on the layer, 1 on transparency, 2 reveal) and Vegas' Composite
// Under (3). aux = coverage (x); u[0].x = style; f[0] = colour; f[1].x = opacity.
@compute @workgroup_size(16, 16)
fn fg2_paint(@builtin(global_invocation_id) gid: vec3<u32>) {
let p = vec2<i32>(gid.xy);
if (!fg2_inside(p)) {
return;
}
let px = textureLoad(src, p, 0);
let c = textureLoad(aux, p, 0).x;
let col = P.f[0];
var o: vec4<f32>;
if (P.u[0].x == 3u) {
let a = c * col.w;
o = fg2_over(vec4<f32>(col.xyz * a, a), px);
} else {
let a = clamp(c * P.f[1].x * col.w, 0.0, 1.0);
let s = vec4<f32>(col.xyz * a, a);
switch P.u[0].x {
case 1u: {
o = s;
}
case 2u: {
o = px * a;
}
default: {
o = fg2_over(px, s);
}
}
}
textureStore(out, p, o);
}
// generate3::draw_marks: aux = (core, halo); u[0].x = composite; f[0] = inside, f[1] = outside.
@compute @workgroup_size(16, 16)
fn fg2_marks(@builtin(global_invocation_id) gid: vec3<u32>) {
let p = vec2<i32>(gid.xy);
if (!fg2_inside(p)) {
return;
}
let cv = textureLoad(aux, p, 0);
let c = cv.x;
let a = max(c, cv.y);
var base = vec4<f32>(0.0);
if (P.u[0].x != 0u) {
base = textureLoad(src, p, 0);
}
if (a <= 0.0) {
textureStore(out, p, base);
return;
}
let t = c / a;
let col = P.f[1].xyz + (P.f[0].xyz - P.f[1].xyz) * t;
textureStore(out, p, fg2_over(base, vec4<f32>(col * a, a)));
}
// (src.x, aux.x) into (x, y), src.y into z: a coverage next to its blurred copy.
@compute @workgroup_size(16, 16)
fn fg2_pair(@builtin(global_invocation_id) gid: vec3<u32>) {
let p = vec2<i32>(gid.xy);
if (!fg2_inside(p)) {
return;
}
let s = textureLoad(src, p, 0);
textureStore(out, p, vec4<f32>(s.x, textureLoad(aux, p, 0).x, s.y, 0.0));
}
// textfx::lightning's composite: aux = (outer, glow, core); u[0].x = blending mode;
// f[0] = outside colour, f[1] = inside colour.
@compute @workgroup_size(16, 16)
fn fg2_bolt(@builtin(global_invocation_id) gid: vec3<u32>) {
let p = vec2<i32>(gid.xy);
if (!fg2_inside(p)) {
return;
}
let px = textureLoad(src, p, 0);
let m = textureLoad(aux, p, 0);
let o = max(m.x, m.y * 0.8);
let c = m.z;
let a = min(max(o, c), 1.0);
if (a <= 0.0) {
textureStore(out, p, px);
return;
}
let t = c / a;
let oc = P.f[0].xyz;
let colr = oc + (P.f[1].xyz - oc) * t;
var r: vec4<f32>;
switch P.u[0].x {
case 1u: {
r = vec4<f32>(px.xyz + colr * a, min(px.w + a * (1.0 - px.w), 1.0));
}
case 2u: {
let s = vec4<f32>(colr * a, a);
r = px + s - px * s;
}
default: {
r = fg2_over(px, vec4<f32>(colr * a, a));
}
}
textureStore(out, p, r);
}
// generate2::advanced_lightning's composite: aux = (core, blurred core); u[0] = (composite, glow);
// f[0] = (core opacity, glow opacity); f[1] = core colour, f[2] = glow colour.
@compute @workgroup_size(16, 16)
fn fg2_adv_bolt(@builtin(global_invocation_id) gid: vec3<u32>) {
let p = vec2<i32>(gid.xy);
if (!fg2_inside(p)) {
return;
}
let px = textureLoad(src, p, 0);
let m = textureLoad(aux, p, 0);
let cv = m.x * P.f[0].x;
var g = 0.0;
if (P.u[0].y != 0u) {
g = min(m.y * 3.0, 1.0);
}
let gv = g * P.f[0].y;
let l = P.f[1].xyz * cv + P.f[2].xyz * gv;
let la = min(max(cv, gv), 1.0);
if (P.u[0].x != 0u) {
let k = clamp(la, 0.0, 1.0);
textureStore(out, p, vec4<f32>(px.xyz + l, clamp(px.w + k * (1.0 - px.w), 0.0, 1.0)));
} else {
textureStore(out, p, vec4<f32>(l, la));
}
}
// textfx::text_px over the previous pass: aux = (fill, outer, inner) coverages.
// u[0] = (display, keep the layer, stroked, inner ring); f[0] = fill, f[1] = stroke colour;
// f[2].x = opacity.
fn fg2_tint(c: vec4<f32>, a0: f32) -> vec4<f32> {
let a = clamp(a0 * c.w, 0.0, 1.0);
return vec4<f32>(c.xyz * a, a);
}
@compute @workgroup_size(16, 16)
fn fg2_text(@builtin(global_invocation_id) gid: vec3<u32>) {
let p = vec2<i32>(gid.xy);
if (!fg2_inside(p)) {
return;
}
let cov = textureLoad(aux, p, 0);
let op = P.f[2].x;
let f = cov.x * op;
var ring = 0.0;
if (P.u[0].z != 0u) {
var inner = 0.0;
if (P.u[0].w != 0u) {
inner = cov.z;
}
ring = max(cov.y - inner, 0.0);
}
let s = ring * op;
var o = vec4<f32>(0.0);
if (P.u[0].y != 0u) {
o = textureLoad(src, p, 0);
}
let fill = fg2_tint(P.f[0], f);
let stroke = fg2_tint(P.f[1], s);
switch P.u[0].x {
case 1u: {
o = fg2_over(o, stroke);
}
case 2u: {
o = fg2_over(fg2_over(o, stroke), fill);
}
case 3u: {
o = fg2_over(fg2_over(o, fill), stroke);
}
default: {
o = fg2_over(o, fill);
}
}
textureStore(out, p, o);
}
// ---------------------------------------------------------------- Radio Waves (generate2::radio_waves)
// data: waves (stride 13: cx, cy, radius, half width, rotation, fade, colour rgba, opacity,
// outline offset, outline vertices), then outline vertices (x, y relative to the centre).
// aux = the contour's signed distance (x) when u[0].y. u[0] = (waves, contour, profile);
// f[0] = (anti-aliasing, anchor x, anchor y).
fn fg2_rw_profile(kind: u32, u0: f32) -> f32 {
let u = clamp(u0, -1.0, 1.0);
switch kind {
case 1u: {
return (1.0 - u) * 0.5;
}
case 2u: {
return (1.0 + u) * 0.5;
}
case 3u: {
return 1.0 - abs(u);
}
case 4u: {
return cos(u * 1.5707963267948966);
}
case 5u: {
if (u < 0.0) {
return 1.0 + u;
}
return 1.0;
}
case 6u: {
if (u > 0.0) {
return 1.0 - u;
}
return 1.0;
}
default: {
return 1.0;
}
}
}
// generate2::outline_dist.
fn fg2_outline_dist(off: u32, n: u32, dx: f32, dy: f32) -> f32 {
let r = sqrt(dx * dx + dy * dy);
if (r < 1e-9) {
var m = 3.0e38;
for (var k = 0u; k < n; k++) {
let x = data[off + 2u * k];
let y = data[off + 2u * k + 1u];
m = min(m, sqrt(x * x + y * y));
}
return m;
}
let dir = vec2<f32>(dx / r, dy / r);
var best = 3.0e38;
for (var k = 0u; k < n; k++) {
let j = (k + 1u) % n;
let p0 = vec2<f32>(data[off + 2u * k], data[off + 2u * k + 1u]);
let p1 = vec2<f32>(data[off + 2u * j], data[off + 2u * j + 1u]);
let e = p1 - p0;
let den = dir.x * e.y - dir.y * e.x;
if (abs(den) < 1e-12) {
continue;
}
let t = (p0.x * e.y - p0.y * e.x) / den;
let q = vec2<f32>(dir.x * t - p0.x, dir.y * t - p0.y);
let el2 = max(e.x * e.x + e.y * e.y, 1e-12);
let s = (q.x * e.x + q.y * e.y) / el2;
if (t <= 0.0 || s < -1e-5 || s > 1.0 + 1e-5) {
continue;
}
best = min(best, abs(r - t) * abs(den) / sqrt(el2));
}
return best;
}
// util::point_in_poly (even-odd).
fn fg2_point_in_poly(off: u32, n: u32, x: f32, y: f32) -> bool {
if (n < 3u) {
return false;
}
var inside = false;
var j = n - 1u;
for (var i = 0u; i < n; i++) {
let ax = data[off + 2u * i];
let ay = data[off + 2u * i + 1u];
let bx = data[off + 2u * j];
let by = data[off + 2u * j + 1u];
if ((ay > y) != (by > y) && x < (bx - ax) * (y - ay) / (by - ay) + ax) {
inside = !inside;
}
j = i;
}
return inside;
}
@compute @workgroup_size(16, 16)
fn fg2_radio(@builtin(global_invocation_id) gid: vec3<u32>) {
let p = vec2<i32>(gid.xy);
if (!fg2_inside(p)) {
return;
}
var o = textureLoad(src, p, 0);
let aa = P.f[0].x;
for (var w = 0u; w < P.u[0].x; w++) {
let at = w * 13u;
let dx = f32(p.x) + 0.5 - data[at];
let dy = f32(p.y) + 0.5 - data[at + 1u];
let radius = data[at + 2u];
let hw = data[at + 3u];
let n = u32(data[at + 12u]);
var d: f32;
if (P.u[0].y != 0u) {
let rot = data[at + 4u];
let s = sin(-rot);
let c = cos(-rot);
let rx = dx * c - dy * s;
let ry = dx * s + dy * c;
d = sample_bilinear_clamped(aux, P.f[0].y + rx, P.f[0].z + ry).x - radius;
} else if (n > 0u) {
let off = u32(data[at + 11u]);
let ud = fg2_outline_dist(off, n, dx, dy);
d = select(ud, -ud, fg2_point_in_poly(off, n, dx, dy));
} else {
d = sqrt(dx * dx + dy * dy) - radius;
}
let ad = abs(d);
let cov = clamp((hw - ad) / aa + 0.5, 0.0, 1.0);
if (cov <= 0.0) {
continue;
}
let u = clamp(d / hw, -1.0, 1.0);
let col = vec4<f32>(data[at + 6u], data[at + 7u], data[at + 8u], data[at + 9u]);
let a = cov * fg2_rw_profile(P.u[0].z, u) * data[at + 5u] * data[at + 10u] * col.w;
o = fg2_over(o, vec4<f32>(col.xyz * a, a));
}
textureStore(out, p, o);
}
// ---------------------------------------------------------------- Beam (generate2::beam)
// u[0] = (3D perspective, composite, length > 0); f[0] = (sx, sy, dx, dy); f[1] = (t0, t1,
// start thickness, end thickness); f[2] = (softness, |d|², ...); f[3] = inside, f[4] = outside.
@compute @workgroup_size(16, 16)
fn fg2_beam(@builtin(global_invocation_id) gid: vec3<u32>) {
let p = vec2<i32>(gid.xy);
if (!fg2_inside(p)) {
return;
}
let px = textureLoad(src, p, 0);
let s = P.f[0].xy;
let d = P.f[0].zw;
let t0 = P.f[1].x;
let t1 = P.f[1].y;
let soft = P.f[2].x;
let vx = f32(p.x) + 0.5 - s.x;
let vy = f32(p.y) + 0.5 - s.y;
let tc = clamp((vx * d.x + vy * d.y) / P.f[2].y, t0, t1);
let ex = vx - d.x * tc;
let ey = vy - d.y * tc;
let dist = sqrt(ex * ex + ey * ey);
var tk = tc;
if (!(P.u[0].x != 0u || t1 - t0 < 1e-9)) {
tk = (tc - t0) / (t1 - t0);
}
let hw = max((P.f[1].z + (P.f[1].w - P.f[1].z) * tk) * 0.5, 0.25);
let tt = dist / hw;
var a = 0.0;
if (P.u[0].z == 0u) {
a = 0.0;
} else if (soft > 1e-3) {
a = 1.0 - fg2_smoothstep(1.0 - soft, 1.0, tt);
} else {
a = clamp(hw - dist + 0.5, 0.0, 1.0);
}
let cc = P.f[3].xyz + (P.f[4].xyz - P.f[3].xyz) * fg2_smoothstep(0.0, 1.0, tt);
let g = vec4<f32>(cc * a, a);
if (P.u[0].y != 0u) {
textureStore(out, p, fg2_over(px, g));
} else {
textureStore(out, p, g);
}
}
// ---------------------------------------------------------------- Lens Flare (generate2::lens_flare)
// data: ghosts (t, r, colour rgb, k, ring); u[0] = ghosts; f[0] = (fx, fy, cx, cy);
// f[1] = (diagonal, core k, rays, halo r); f[2] = (brightness, blend).
@compute @workgroup_size(16, 16)
fn fg2_flare(@builtin(global_invocation_id) gid: vec3<u32>) {
let p = vec2<i32>(gid.xy);
if (!fg2_inside(p)) {
return;
}
let px = textureLoad(src, p, 0);
let f = P.f[0].xy;
let c = P.f[0].zw;
let diag = P.f[1].x;
let dx = f32(p.x) + 0.5 - f.x;
let dy = f32(p.y) + 0.5 - f.y;
let r = sqrt(dx * dx + dy * dy) / diag;
let th = atan2(dy, dx);
let ck = r / P.f[1].y;
let core = 1.5 * exp(-(ck * ck)) + 0.25 * exp(-r / 0.12);
let streak = powz(abs(cos(P.f[1].z * 0.5 * th)), 40.0) * exp(-r / 0.3) * 0.35;
let hk = (r - P.f[1].w) / 0.012;
let halo = exp(-(hk * hk)) * 0.12;
let base = core + streak;
var l = vec3<f32>(base, base * 0.95, base * 0.85);
l += vec3<f32>(halo * 0.6, halo * 0.8, halo);
for (var i = 0u; i < P.u[0].x; i++) {
let at = i * 7u;
let gt = data[at];
let gr = data[at + 1u];
let gx = f.x + (c.x - f.x) * gt;
let gy = f.y + (c.y - f.y) * gt;
let ex = f32(p.x) + 0.5 - gx;
let ey = f32(p.y) + 0.5 - gy;
let d = sqrt(ex * ex + ey * ey) / diag;
var v: f32;
if (data[at + 6u] != 0.0) {
let q = (d - gr) / (gr * 0.12);
v = exp(-(q * q));
} else {
v = fg2_smoothstep(gr, gr * 0.8, d);
}
l += vec3<f32>(data[at + 2u], data[at + 3u], data[at + 4u]) * data[at + 5u] * v;
}
l = l * P.f[2].x;
let la = min(max(max(l.x, l.y), l.z), 1.0);
let k = clamp(la, 0.0, 1.0);
let o = vec4<f32>(px.xyz + l, clamp(px.w + k * (1.0 - px.w), 0.0, 1.0));
textureStore(out, p, o + (px - o) * P.f[2].y);
}
// ---------------------------------------------------------------- CC Glue Gun (generate3::glue_gun)
// data: beads (x, y, radius); u[0] = (beads, glue only); f[0] = (light x, y, z, strength);
// f[1].x = strength weight (clamp(strength, 0, 1) max 0.3).
@compute @workgroup_size(16, 16)
fn fg2_glue(@builtin(global_invocation_id) gid: vec3<u32>) {
let p = vec2<i32>(gid.xy);
if (!fg2_inside(p)) {
return;
}
let px = textureLoad(src, p, 0);
let glue_only = P.u[0].y != 0u;
let fx = f32(p.x) + 0.5;
let fy = f32(p.y) + 0.5;
var best_h = 0.0;
var best_d = vec2<f32>(0.0);
var best_r = 1.0;
for (var i = 0u; i < P.u[0].x; i++) {
let r = data[i * 3u + 2u];
let dx = (fx - data[i * 3u]) / r;
let dy = (fy - data[i * 3u + 1u]) / r;
let d2 = dx * dx + dy * dy;
if (d2 < 1.0) {
let hgt = sqrt(1.0 - d2);
if (hgt > best_h) {
best_h = hgt;
best_d = vec2<f32>(dx, dy);
best_r = r;
}
}
}
if (best_h <= 0.0) {
textureStore(out, p, select(px, vec4<f32>(0.0), glue_only));
return;
}
let nrm = vec3<f32>(best_d, best_h);
let ndl = max(dot(nrm, P.f[0].xyz), 0.0);
let spec = powz(ndl, 24.0);
let strength = P.f[0].w;
let s = sample_bilinear_clamped(src, fx - nrm.x * best_r * 0.5 * strength, fy - nrm.y * best_r * 0.5 * strength);
let edge = fg2_smoothstep(0.0, 0.15, best_h);
let shade = 0.65 + 0.35 * ndl;
let g = vec4<f32>(s.xyz * shade + vec3<f32>(spec), max(s.w, 0.6));
let gp = vec4<f32>(min(g.xyz, vec3<f32>(g.w + spec)), min(g.w, 1.0));
var base = px;
if (glue_only) {
base = vec4<f32>(0.0);
}
var o = base + (gp - base) * (edge * P.f[1].x);
o.w = clamp(o.w, 0.0, 1.0);
textureStore(out, p, o);
}
// ---------------------------------------------------------------- CC Threads (generate3::threads)
// u[0] = (overlaps); f[0] = (cx, cy, sin, cos); f[1] = (thread width, height, coverage,
// shadowing); f[2].x = texture.
@compute @workgroup_size(16, 16)
fn fg2_threads(@builtin(global_invocation_id) gid: vec3<u32>) {
let p = vec2<i32>(gid.xy);
if (!fg2_inside(p)) {
return;
}
let c = P.f[0].xy;
let sn = P.f[0].z;
let cs = P.f[0].w;
let tw = P.f[1].x;
let th = P.f[1].y;
let coverage = P.f[1].z;
let shadow = P.f[1].w;
let tex_amt = P.f[2].x;
let overlaps = i32(P.u[0].x);
let dx = f32(p.x) + 0.5 - c.x;
let dy = f32(p.y) + 0.5 - c.y;
let u = dx * cs + dy * sn;
let v = -dx * sn + dy * cs;
let ci = i32(floor(u / tw));
let cj = i32(floor(v / th));
let fu = u / tw - f32(ci);
let fv = v / th - f32(cj);
let in_h = abs(fv - 0.5) < coverage * 0.5;
let in_v = abs(fu - 0.5) < coverage * 0.5;
let h_top = ((ci + cj) % (2 * overlaps) + 2 * overlaps) % (2 * overlaps) < overlaps;
var horizontal: bool;
if (in_h && in_v) {
horizontal = h_top;
} else if (in_h) {
horizontal = true;
} else if (in_v) {
horizontal = false;
} else {
textureStore(out, p, vec4<f32>(0.0));
return;
}
var su = u;
var sv = (f32(cj) + 0.5) * th;
if (!horizontal) {
su = (f32(ci) + 0.5) * tw;
sv = v;
}
let s = sample_bilinear_clamped(src, c.x + su * cs - sv * sn, c.y + su * sn + sv * cs);
let half_cov = max(coverage * 0.5, 1e-6);
var across = (fu - 0.5) / half_cov;
var along = fv;
if (horizontal) {
across = (fv - 0.5) / half_cov;
along = fu;
}
let profile = sqrt(max(1.0 - across * across, 0.0));
let dive = 1.0 - abs(along - 0.5) * 2.0;
let under = select(1.0, 0.0, horizontal == h_top);
let shade = 1.0 - shadow * (1.0 - profile) * 0.8 - shadow * 0.25 * (1.0 - dive) * under;
var fib = 1.0;
if (tex_amt > 0.0) {
let seed = bitcast<u32>(ci) ^ (bitcast<u32>(cj) << 8u);
fib = 1.0 - tex_amt * 0.3 * hash_noise(u32(max(along * 64.0, 0.0)), u32(max(across * 8.0 + 8.0, 0.0)), seed);
}
let k = max(shade * fib, 0.0);
textureStore(out, p, vec4<f32>(s.xyz * k, s.w));
}
// ---------------------------------------------------------------- Paint Bucket / Eyedropper Fill (generate3)
// Paint Bucket's fill: aux = coverage (x); u[0] = (mode); f[0] = colour; f[1].x = opacity.
@compute @workgroup_size(16, 16)
fn fg2_bucket(@builtin(global_invocation_id) gid: vec3<u32>) {
let p = vec2<i32>(gid.xy);
if (!fg2_inside(p)) {
return;
}
let px = textureLoad(src, p, 0);
let c = textureLoad(aux, p, 0).x;
let col = P.f[0];
let mode = P.u[0].x;
let k = clamp(c * P.f[1].x * col.w, 0.0, 1.0);
if (k <= 0.0) {
textureStore(out, p, select(px, vec4<f32>(0.0), mode == 9u));
return;
}
let dc = fg2_unpremul(px);
let da = select(max(px.w, 0.0), px.w, px.w > 1e-6);
let fc = col.xyz;
var mixed = fc;
switch mode {
case 1u: {
mixed = dc + fc;
}
case 2u: {
mixed = dc * fc;
}
case 3u: {
mixed = vec3<f32>(1.0) - (vec3<f32>(1.0) - dc) * (vec3<f32>(1.0) - fc);
}
case 4u, 5u, 6u, 7u: {
let d = rgb_to_hsl(dc);
let f = rgb_to_hsl(fc);
switch mode {
case 4u: {
mixed = hsl_to_rgb(f.x, d.y, d.z);
}
case 5u: {
mixed = hsl_to_rgb(d.x, f.y, d.z);
}
case 6u: {
mixed = hsl_to_rgb(f.x, f.y, d.z);
}
default: {
mixed = hsl_to_rgb(d.x, d.y, f.z);
}
}
}
default: {}
}
var o: vec4<f32>;
switch mode {
case 8u: {
o = fg2_over(vec4<f32>(fc * k, k), px);
}
case 9u: {
o = vec4<f32>(fc * k, k);
}
case 0u: {
o = fg2_over(px, vec4<f32>(fc * k, k));
}
default: {
if (da <= 1e-6) {
o = px;
} else {
let c3 = dc + (mixed - dc) * k;
o = vec4<f32>(c3 * da, da);
}
}
}
textureStore(out, p, o);
}
// Paint Bucket's coverage from the region (x): u[0].x = 0 antialias (aux = the blurred region),
// 1 = view threshold, 2 = stroke ring (aux = the eroded region, src = the dilated one).
@compute @workgroup_size(16, 16)
fn fg2_bucket_cov(@builtin(global_invocation_id) gid: vec3<u32>) {
let p = vec2<i32>(gid.xy);
if (!fg2_inside(p)) {
return;
}
let a = textureLoad(src, p, 0).x;
let b = textureLoad(aux, p, 0).x;
switch P.u[0].x {
case 0u: {
// src = the region, aux = its blur.
textureStore(out, p, vec4<f32>(select(b, max(b, 0.5), a > 0.0), 0.0, 0.0, 0.0));
}
case 1u: {
textureStore(out, p, vec4<f32>(a, a, a, 1.0));
}
default: {
textureStore(out, p, vec4<f32>(max(a - b, 0.0), 0.0, 0.0, 0.0));
}
}
}
// Eyedropper Fill: u[0].x = keep alpha; f[0] = fill (straight, alpha); f[1].x = blend.
@compute @workgroup_size(16, 16)
fn fg2_eyedropper(@builtin(global_invocation_id) gid: vec3<u32>) {
let p = vec2<i32>(gid.xy);
if (!fg2_inside(p)) {
return;
}
let px = textureLoad(src, p, 0);
let a = select(P.f[0].w, px.w, P.u[0].x != 0u);
let f = vec4<f32>(P.f[0].xyz * a, a);
textureStore(out, p, f + (px - f) * P.f[1].x);
}
+2 -2
View File
@@ -57,7 +57,7 @@ fn gpu_adjustment_chains_match_the_cpu() {
#[test]
fn mixed_adjustment_chains_fall_back_per_effect() {
let mut stack = gpu_stack();
stack.insert(1, ("ec.stylize.ccplastic", vec![]));
stack.insert(1, ("ec.distort.rollingshutterrepair", vec![]));
stack.push(("ec.stylize.glow", vec![("threshold", n(30.0))]));
for depth in [BitDepth::Bpc8, BitDepth::Bpc32] {
let s = adjustment_scene(depth, &stack, true);
@@ -93,7 +93,7 @@ impl FxTarget for Probe {
fn adjustment_stacks_split_into_gpu_runs_and_cpu_steps() {
let Some(g) = gpu() else { return };
let mut stack = gpu_stack();
stack.insert(1, ("ec.stylize.ccplastic", vec![]));
stack.insert(1, ("ec.generate.fractal", vec![]));
let s = adjustment_scene(BitDepth::Bpc32, &stack, false);
let mut r = Renderer::new(&s.p, &Pattern, RenderOpts { backend: Backend::Gpu, ..opts() });
r.accel = Some(g);
+1 -1
View File
@@ -466,7 +466,7 @@ fn gpu_compositor_draws_split_advanced_3d_runs_and_skies() {
// A varying environment image (so the sky's lookup shows; a CPU effect, so the frame's
// only readback is its own).
let mut next = p.next_id;
let spec = effectcraft_effects::find("ec.generate.lensflare").unwrap();
let spec = effectcraft_effects::find("ec.generate.fractal").unwrap();
let ramp = effectcraft_effects::instantiate(spec, &mut build::Ids(&mut next), spec.name, [32.0, 16.0]);
p.next_id = next;
if case == 3 {
+1 -1
View File
@@ -26,7 +26,7 @@ fn deferred_gpu() -> Option<(&'static Gpu, std::sync::MutexGuard<'static, ()>)>
/// Footage with GPU effects around a CPU-only one, a solid with Glow, and a precomp whose
/// layer is blurred inside and outside (a chain whose input is another chain's result).
fn scene() -> Scene {
let cpu_only = "ec.blur.ccradial";
let cpu_only = "ec.generate.fractal";
assert!(!effectcraft_effects::GPU_EFFECTS.contains(&cpu_only));
let mut s = Scene::new(BitDepth::Bpc32);
let mut bg = s.footage(97, 61);
+176
View File
@@ -0,0 +1,176 @@
//! GPU generators of part C (Lightning, Advanced Lightning, Beam, Lens Flare, Radio
//! Waves, Vegas, Stroke, Scribble, Write-on, Paint Bucket, Eyedropper Fill, CC Glue Gun, CC
//! Threads, Audio Spectrum, Audio Waveform, Basic Text, Path Text) vs the CPU effects (the
//! oracle): direct on a buffer with masks, another layer and audio at full and half resolution
//! and as adjustment, and composited at 8 and 32 bpc.
use effectcraft_keyframe::Value;
use effectcraft_time::Tick;
use crate::tests::{c, n};
use crate::tests_fx_pixel2::{e, env_case, env_case_allow, env_case_at, off, on, pt};
fn layer(id: u64) -> Value {
Value::Layer(Some(id))
}
fn text(s: &str) -> Value {
Value::Str(s.into())
}
#[test]
fn lightning() {
env_case("ec.obsolete.lightning", &[]);
env_case(
"ec.obsolete.lightning",
&[("branching", n(0.9)), ("rebranching", n(0.6)), ("detailLevel", n(4.0)), ("blendingMode", e(1)), ("pullForce", n(40.0))],
);
env_case("ec.obsolete.lightning", &[("blendingMode", e(2)), ("rerunAtEachFrame", on()), ("fixedEndpoint", on()), ("coreWidth", n(0.8))]);
env_case("ec.generate.advancedlightning", &[]);
env_case("ec.generate.advancedlightning", &[("lightningType", e(4)), ("forking", n(60.0)), ("decayMainCore", on()), ("expertSettings/coreDrain", n(40.0))]);
env_case(
"ec.generate.advancedlightning",
&[("alphaObstacle", n(6.0)), ("compositeOnOriginal", off()), ("expertSettings/fractalType", e(2)), ("glowSettings/glowRadius", n(10.0))],
);
env_case("ec.generate.advancedlightning", &[("lightningType", e(7)), ("glowSettings/glowRadius", n(0.0)), ("coreSettings/coreRadius", n(1.5))]);
}
#[test]
fn closed_form() {
env_case("ec.generate.beam", &[]);
env_case("ec.generate.beam", &[("length", n(70.0)), ("time", n(40.0)), ("softness", n(0.0)), ("perspective3d", off()), ("compositeOnOriginal", off())]);
env_case("ec.generate.beam", &[("startThickness", n(3.0)), ("endThickness", n(20.0)), ("insideColor", c(0.3, 0.9, 1.0))]);
env_case("ec.generate.lensflare", &[]);
env_case("ec.generate.lensflare", &[("lensType", e(1)), ("flareCenter", pt(50.0, 30.0)), ("blendWithOriginal", n(30.0))]);
env_case("ec.generate.lensflare", &[("lensType", e(2)), ("flareBrightness", n(160.0))]);
env_case("ec.generate.ccgluegun", &[]);
env_case("ec.generate.ccgluegun", &[("density", n(12.0)), ("strokeWidth", n(40.0)), ("style", e(1)), ("strength", n(60.0))]);
let t = |vals: &[(&str, Value)]| env_case_allow("ec.generate.ccthreads", vals, THREAD_TIES);
t(&[]);
t(&[("texture", n(0.0))]);
// Generic values: no ties.
env_case("ec.generate.ccthreads", &[("width", n(13.1)), ("height", n(17.3)), ("overlaps", n(2.0)), ("direction", n(23.0)), ("texture", n(0.0))]);
env_case(
"ec.generate.ccthreads",
&[("width", n(9.3)), ("height", n(11.1)), ("coverage", n(55.3)), ("shadowing", n(90.0)), ("texture", n(40.0)), ("center", pt(33.7, 21.9))],
);
}
/// CC Threads decides per pixel which thread band it lies in and which fibre (the position
/// across / along the thread times 8 / 64, truncated) shades it: at parameter values that put
/// pixel centres exactly on a band edge or fibre boundary (the defaults do), f32 and the CPU's
/// f64 can land on either side.
const THREAD_TIES: f64 = 0.05;
#[test]
fn radio_waves() {
let t = Tick::from_seconds_f64(1.3);
env_case_at("ec.generate.radiowaves", &[("waveMotion/expansion", n(30.0))], 0.0, t);
env_case_at(
"ec.generate.radiowaves",
&[
("polygon/sides", n(5.0)),
("polygon/star", on()),
("waveMotion/spin", n(30.0)),
("waveStroke/profile", e(4)),
("waveMotion/velocity", n(20.0)),
("waveMotion/expansion", n(25.0)),
],
0.0,
t,
);
env_case_at(
"ec.generate.radiowaves",
&[("waveType", e(1)), ("imageContour/sourceLayer", layer(9)), ("waveStroke/fadeOutTime", n(1.0)), ("waveMotion/expansion", n(10.0))],
0.0,
t,
);
env_case_at(
"ec.generate.radiowaves",
&[
("waveType", e(2)),
("waveMask/mask", n(1.0)),
("waveMotion/reflection", on()),
("waveMotion/velocity", n(40.0)),
("waveMotion/expansion", n(15.0)),
("waveStroke/profile", e(5)),
],
0.0,
t,
);
}
#[test]
fn strokes() {
env_case("ec.generate.stroke", &[]);
env_case("ec.generate.stroke", &[("allMasks", on()), ("spacing", n(80.0)), ("paintStyle", e(1)), ("end", n(70.0)), ("brushSize", n(6.0))]);
env_case("ec.generate.stroke", &[("path", n(3.0)), ("paintStyle", e(2)), ("start", n(20.0)), ("brushHardness", n(10.0))]);
env_case("ec.generate.scribble", &[]);
env_case("ec.generate.scribble", &[("scribble", e(1)), ("fillType", e(2)), ("edgeOptions/endCap", e(2)), ("edgeOptions/join", e(1)), ("composite", e(0))]);
env_case(
"ec.generate.scribble",
&[("mask", n(2.0)), ("fillType", e(1)), ("edgeOptions/join", e(2)), ("wiggleType", e(2)), ("end", n(60.0)), ("composite", e(2))],
);
env_case("ec.generate.scribble", &[("mask", n(3.0))]);
env_case("ec.generate.vegas", &[]);
env_case("ec.generate.vegas", &[("stroke", e(1)), ("path", n(3.0)), ("blendMode", e(2)), ("segments", n(12.0)), ("randomPhase", on())]);
env_case("ec.generate.vegas", &[("inputLayer", layer(9)), ("blendMode", e(3)), ("shorterContoursHave", e(1)), ("threshold", n(30.0))]);
env_case("ec.generate.vegas", &[("stroke", e(1)), ("path", n(1.0)), ("blendMode", e(0)), ("width", n(5.0)), ("hardness", n(0.9))]);
env_case("ec.generate.writeon", &[]);
env_case("ec.generate.writeon", &[("brushPosition", pt(20.0, 30.0)), ("brushSize", n(14.0)), ("paintStyle", e(1))]);
env_case("ec.generate.writeon", &[("paintStyle", e(2)), ("brushHardness", n(20.0)), ("brushOpacity", n(60.0))]);
}
#[test]
fn fills() {
env_case("ec.generate.paintbucket", &[]);
env_case(
"ec.generate.paintbucket",
&[("fillPoint", pt(10.0, 10.0)), ("fillSelector", e(1)), ("tolerance", n(60.0)), ("stroke", e(4)), ("strokeWidth", n(4.0))],
);
env_case("ec.generate.paintbucket", &[("fillPoint", pt(35.0, 22.0)), ("fillSelector", e(2)), ("stroke", e(1)), ("color", c(0.2, 0.9, 0.4))]);
env_case("ec.generate.paintbucket", &[("stroke", e(2)), ("spreadRadius", n(2.5)), ("tolerance", n(120.0)), ("blendingMode", e(5))]);
env_case("ec.generate.paintbucket", &[("stroke", e(3)), ("tolerance", n(90.0)), ("blendingMode", e(9))]);
env_case("ec.generate.paintbucket", &[("viewThreshold", on()), ("tolerance", n(80.0))]);
env_case("ec.generate.paintbucket", &[("tolerance", n(100.0)), ("blendingMode", e(8)), ("opacity", n(70.0))]);
env_case("ec.generate.eyedropperfill", &[]);
env_case(
"ec.generate.eyedropperfill",
&[("samplePoint", pt(12.0, 30.0)), ("sampleRadius", n(6.0)), ("averagePixelColors", e(3)), ("blendWithOriginal", n(30.0))],
);
env_case("ec.generate.eyedropperfill", &[("sampleRadius", n(9.0)), ("averagePixelColors", e(1)), ("maintainOriginalAlpha", on())]);
env_case("ec.generate.eyedropperfill", &[("sampleRadius", n(4.0)), ("averagePixelColors", e(2))]);
}
#[test]
fn audio() {
let a = || ("audioLayer", layer(9));
env_case("ec.generate.audiospectrum", &[a()]);
env_case("ec.generate.audiospectrum", &[a(), ("displayOptions", e(1)), ("sideOptions", e(2)), ("compositeOnOriginal", on())]);
env_case("ec.generate.audiospectrum", &[a(), ("displayOptions", e(2)), ("path", n(3.0)), ("softness", n(0.0))]);
env_case("ec.generate.audiowaveform", &[a()]);
env_case("ec.generate.audiowaveform", &[a(), ("displayOptions", e(0)), ("waveformOptions", e(2)), ("usePolarPath", on())]);
env_case("ec.generate.audiowaveform", &[a(), ("displayOptions", e(2)), ("path", n(1.0)), ("compositeOnOriginal", on())]);
}
#[test]
fn text_effects() {
env_case("ec.obsolete.basictext", &[]);
env_case("ec.obsolete.basictext", &[("text", text("Hi\nthere")), ("fillAndStroke/displayOptions", e(2)), ("alignment", e(0)), ("size", n(14.0))]);
env_case("ec.obsolete.basictext", &[("fillAndStroke/displayOptions", e(3)), ("fillAndStroke/strokeWidth", n(5.0)), ("compositeOnOriginal", on())]);
env_case("ec.obsolete.basictext", &[("fillAndStroke/displayOptions", e(1)), ("fillAndStroke/strokeWidth", n(1.0)), ("size", n(20.0))]);
env_case("ec.obsolete.pathtext", &[]);
env_case(
"ec.obsolete.pathtext",
&[("pathOptions/shapeType", e(1)), ("advanced/visibleCharacters", n(2.5)), ("advanced/fadeTime", n(50.0)), ("character/size", n(14.0))],
);
env_case(
"ec.obsolete.pathtext",
&[
("pathOptions/customPath", n(3.0)),
("fillAndStroke/displayOptions", e(2)),
("advanced/jitterSettings/rotationJitterMax", n(20.0)),
("compositeOnOriginal", on()),
],
);
}
+7 -2
View File
@@ -120,6 +120,11 @@ pub(crate) fn env_case(id: &str, vals: &[(&str, Value)]) {
/// [`env_case`] allowing a fraction of pixels over the tolerance (documented exceptions).
pub(crate) fn env_case_allow(id: &str, vals: &[(&str, Value)], allow: f64) {
env_case_at(id, vals, allow, Tick::ZERO);
}
/// [`env_case_allow`] with the composited frames at comp time `t`.
pub(crate) fn env_case_at(id: &str, vals: &[(&str, Value)], allow: f64, t: Tick) {
direct_env(id, vals, allow);
for depth in [BitDepth::Bpc8, BitDepth::Bpc32] {
let mut s = Scene::new(depth);
@@ -135,8 +140,8 @@ pub(crate) fn env_case_allow(id: &str, vals: &[(&str, Value)], allow: f64) {
s.effect(&mut l, id, vals);
set(&mut l, "transform/rotation", Value::Scalar(8.0));
s.push(l);
check(&format!("{id} {vals:?} {depth:?}"), compare_at(&s, opts(), Tick::ZERO), allow);
check(&format!("{id} {vals:?} {depth:?} half"), compare_at(&s, RenderOpts { scale: 0.5, ..opts() }, Tick::ZERO), allow);
check(&format!("{id} {vals:?} {depth:?}"), compare_at(&s, opts(), t), allow);
check(&format!("{id} {vals:?} {depth:?} half"), compare_at(&s, RenderOpts { scale: 0.5, ..opts() }, t), allow);
}
}