Merge main into M13.12

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Thomas
2026-10-03 09:51:48 -04:00
co-authored by Claude Opus 5.5
335 changed files with 29661 additions and 398 deletions
+4
View File
@@ -87,6 +87,10 @@ const CPU_ONLY_CONTROLS: &[(&str, &[&str])] = &[
),
("ec.noise.addgrain", &["viewingMode", "preset", "color/redBalance", "color/greenBalance", "color/blueBalance", "previewRegion/"]),
("ec.blur.cameralens", &["irisProperties/diffractionFringe", "blurMap/blurMapLayer"]),
("ec.noise.removegrain", &["temporalFiltering/enabled"]),
("ec.distort.liquify", &["viewFreezeAreaMask", "viewMesh"]),
("ec.matte.refinesoft", &["reduceChatter", "useMotionBlur", "invert"]),
("ec.matte.refinehard", &["reduceChatter", "useMotionBlur", "invert"]),
];
/// Whether the GPU kernel of effect `id` covers the instance's current settings (see
+65 -38
View File
@@ -330,10 +330,21 @@ fn stretch(v: f32, lo: f32, hi: f32) -> f32 {
/// 0 = Auto Levels (per channel), 1 = Auto Contrast (shared), 2 = Auto Color (per channel + neutral mids).
fn auto_correct(ctx: &EffectCtx, mut b: Buf, kind: u32) -> Buf {
let blend = (ctx.params.f("blend") / 100.0).clamp(0.0, 1.0) as f32;
let (ranges, gam) = auto_correct_settings(ctx, &b.img, kind);
map_ca(&mut b.img, |c, a| {
let o = [0, 1, 2].map(|k| stretch(c[k], ranges[k].0, ranges[k].1).powf(gam[k]));
(lerp3(o, c, blend), a)
});
b
}
/// What Auto Levels (`kind` 0), Auto Contrast (1) and Auto Color (2) measure on `img`: each
/// channel's input range (low, high) and gamma. (The GPU effects apply them.)
pub fn auto_correct_settings(ctx: &EffectCtx, img: &Image, kind: u32) -> ([(f32, f32); 3], [f32; 3]) {
let black = ctx.params.f("blackClip").clamp(0.0, 49.0) / 100.0;
let white = ctx.params.f("whiteClip").clamp(0.0, 49.0) / 100.0;
let blend = (ctx.params.f("blend") / 100.0).clamp(0.0, 1.0) as f32;
let h = smoothed_histograms(ctx, &b.img);
let h = smoothed_histograms(ctx, img);
let ranges: [(f32, f32); 3] = if kind == 1 {
let mut combined = vec![0.0; BINS];
for k in 0..3 {
@@ -350,7 +361,7 @@ fn auto_correct(ctx: &EffectCtx, mut b: Buf, kind: u32) -> Buf {
let mut gam = [1.0f32; 3];
if kind == 2 && ctx.params.b("snapNeutralMidtones") {
let mut sums = [0.0f64; 4];
for px in &b.img.data {
for px in &img.data {
let (c, a) = unpremul(*px);
if a > 1e-4 {
for k in 0..3 {
@@ -369,11 +380,7 @@ fn auto_correct(ctx: &EffectCtx, mut b: Buf, kind: u32) -> Buf {
}
}
}
map_ca(&mut b.img, |c, a| {
let o = [0, 1, 2].map(|k| stretch(c[k], ranges[k].0, ranges[k].1).powf(gam[k]));
(lerp3(o, c, blend), a)
});
b
(ranges, gam)
}
fn auto_levels(ctx: &EffectCtx, b: Buf) -> Buf {
@@ -397,24 +404,12 @@ fn cdf(h: &[f64]) -> Vec<f32> {
.collect()
}
fn equalize(ctx: &EffectCtx, mut b: Buf) -> Buf {
let amt = (ctx.params.f("amount") / 100.0).clamp(0.0, 1.0) as f32;
if amt <= 0.0 {
return b;
}
let style = ctx.params.e("style");
let h = histograms(&b.img);
let look = |c: &Vec<f32>, v: f32| c[((v.clamp(0.0, 1.0) * (BINS - 1) as f32).round() as usize).min(BINS - 1)];
/// Equalize's lookup tables (`BINS` entries each) for `img`: the R, G and B cumulative
/// histograms (Style RGB), the luminance one (Brightness) or the combined one (Photoshop Style).
pub fn equalize_tables(img: &Image, style: u32) -> Vec<Vec<f32>> {
let h = histograms(img);
match style {
1 => {
let c = cdf(&h[3]);
map_ca(&mut b.img, |col, a| {
let l = luminance(col[0], col[1], col[2]);
let nl = look(&c, l);
let o = if l > 1e-5 { col.map(|v| v * nl / l) } else { [nl; 3] };
(lerp3(col, o, amt), a)
});
}
1 => vec![cdf(&h[3])],
2 => {
let mut combined = vec![0.0; BINS];
for k in 0..3 {
@@ -422,12 +417,34 @@ fn equalize(ctx: &EffectCtx, mut b: Buf) -> Buf {
combined[i] += h[k][i];
}
}
let c = cdf(&combined);
map_ca(&mut b.img, |col, a| (lerp3(col, col.map(|v| look(&c, v)), amt), a));
vec![cdf(&combined)]
}
_ => vec![cdf(&h[0]), cdf(&h[1]), cdf(&h[2])],
}
}
fn equalize(ctx: &EffectCtx, mut b: Buf) -> Buf {
let amt = (ctx.params.f("amount") / 100.0).clamp(0.0, 1.0) as f32;
if amt <= 0.0 {
return b;
}
let style = ctx.params.e("style");
let t = equalize_tables(&b.img, style);
let look = |c: &Vec<f32>, v: f32| c[((v.clamp(0.0, 1.0) * (BINS - 1) as f32).round() as usize).min(BINS - 1)];
match style {
1 => {
map_ca(&mut b.img, |col, a| {
let l = luminance(col[0], col[1], col[2]);
let nl = look(&t[0], l);
let o = if l > 1e-5 { col.map(|v| v * nl / l) } else { [nl; 3] };
(lerp3(col, o, amt), a)
});
}
2 => {
map_ca(&mut b.img, |col, a| (lerp3(col, col.map(|v| look(&t[0], v)), amt), a));
}
_ => {
let cs = [cdf(&h[0]), cdf(&h[1]), cdf(&h[2])];
map_ca(&mut b.img, |col, a| (lerp3(col, [0, 1, 2].map(|k| look(&cs[k], col[k])), amt), a));
map_ca(&mut b.img, |col, a| (lerp3(col, [0, 1, 2].map(|k| look(&t[k], col[k])), amt), a));
}
}
b
@@ -436,17 +453,29 @@ fn equalize(ctx: &EffectCtx, mut b: Buf) -> Buf {
// ---------------------------------------------------------------------------------------------
// Shadow/Highlight
fn shadow_highlight(ctx: &EffectCtx, mut b: Buf) -> Buf {
/// Shadow/Highlight's shadow and highlight amounts for `img` (Auto Amounts measures them).
pub fn shadow_highlight_amounts(ctx: &EffectCtx, img: &Image) -> (f32, f32) {
let (mut s_amt, mut h_amt) = (ctx.params.f("shadowAmount") as f32 / 100.0, ctx.params.f("highlightAmount") as f32 / 100.0);
let luma = Plane::luma(&b.img);
let src_hist = histograms(&b.img);
if ctx.params.b("autoAmounts") {
// Temporal Smoothing / Scene Detect average the analysis over neighbouring frames.
let mean =
if ctx.params.f("temporalSmoothing") > 0.0 { hist_mean(&smoothed_histograms(ctx, &b.img)[3]) as f32 } else { hist_mean(&src_hist[3]) as f32 };
let mean = if ctx.params.f("temporalSmoothing") > 0.0 { hist_mean(&smoothed_histograms(ctx, img)[3]) } else { hist_mean(&histograms(img)[3]) } as f32;
s_amt = ((0.6 - mean) * 1.5).clamp(0.0, 1.0) * 0.8 + 0.1;
h_amt = ((mean - 0.6) * 1.5).clamp(0.0, 1.0) * 0.8;
}
(s_amt, h_amt)
}
/// The luminance values clipping `black` / `white` fractions of `img`'s alpha-weighted
/// luminance histogram (Shadow/Highlight's Black / White Clip).
pub fn luma_clip_points(img: &Image, black: f64, white: f64) -> (f32, f32) {
clip_points(&histograms(img)[3], black, white)
}
fn shadow_highlight(ctx: &EffectCtx, mut b: Buf) -> Buf {
let (s_amt, h_amt) = shadow_highlight_amounts(ctx, &b.img);
let luma = Plane::luma(&b.img);
let (bc, wc) = (ctx.params.f("moreOptions/blackClip").clamp(0.0, 49.0) / 100.0, ctx.params.f("moreOptions/whiteClip").clamp(0.0, 49.0) / 100.0);
let clip0 = (bc > 0.0 || wc > 0.0).then(|| luma_clip_points(&b.img, bc, wc));
let s_tw = (ctx.params.f("moreOptions/shadowTonalWidth") as f32 / 100.0).max(0.01);
let h_tw = (ctx.params.f("moreOptions/highlightTonalWidth") as f32 / 100.0).max(0.01);
let s_r = ctx.params.f("moreOptions/shadowRadius").max(0.0) * b.scale / 2.0;
@@ -478,10 +507,8 @@ fn shadow_highlight(ctx: &EffectCtx, mut b: Buf) -> Buf {
// Black / White Clip: the adjusted image's extremes (ignoring those fractions of pixels)
// are mapped back onto the original's, so lifting shadows or recovering highlights doesn't
// flatten the ends of the tonal range.
let (bc, wc) = (ctx.params.f("moreOptions/blackClip").clamp(0.0, 49.0) / 100.0, ctx.params.f("moreOptions/whiteClip").clamp(0.0, 49.0) / 100.0);
if bc > 0.0 || wc > 0.0 {
let (lo0, hi0) = clip_points(&src_hist[3], bc, wc);
let (lo1, hi1) = clip_points(&histograms(&b.img)[3], bc, wc);
if let Some((lo0, hi0)) = clip0 {
let (lo1, hi1) = luma_clip_points(&b.img, bc, wc);
if (lo0, hi0) != (lo1, hi1) && hi1 - lo1 > 1e-3 {
let k = (hi0 - lo0) / (hi1 - lo1);
map_ca(&mut b.img, |c, a| (c.map(|v| (lo0 + (v - lo1) * k).max(0.0)), a));
+3 -3
View File
@@ -269,7 +269,7 @@ fn parse_points(s: &str) -> Vec<(f32, f32)> {
/// around (x = 0 and x = 1 are the same hue); the others are flat beyond their end points.
/// Tabulated as offsets `y − 0.5`.
#[derive(Clone, Debug)]
pub(crate) struct OffsetCurve {
pub struct OffsetCurve {
lut: Vec<f32>,
}
@@ -277,7 +277,7 @@ impl OffsetCurve {
const N: usize = 512;
/// `None` for an empty or flat-neutral curve.
pub(crate) fn parse(s: &str, periodic: bool) -> Option<OffsetCurve> {
pub fn parse(s: &str, periodic: bool) -> Option<OffsetCurve> {
let pts = parse_points(s);
if pts.is_empty() || pts.iter().all(|p| (p.1 - 0.5).abs() < 1e-6) {
return None;
@@ -327,7 +327,7 @@ impl OffsetCurve {
}
/// Offset from neutral at `x` (clamped to 0..1).
pub(crate) fn at(&self, x: f32) -> f32 {
pub fn at(&self, x: f32) -> f32 {
let f = x.clamp(0.0, 1.0) * Self::N as f32;
let i = (f as usize).min(Self::N - 1);
let t = f - i as f32;
+1 -1
View File
@@ -354,7 +354,7 @@ fn magnify(ctx: &EffectCtx, mut b: Buf) -> Buf {
}
/// Magnify's Blending Mode choices after "None".
const MAGNIFY_MODES: [BlendMode; 17] = [
pub const MAGNIFY_MODES: [BlendMode; 17] = [
BlendMode::Normal,
BlendMode::Add,
BlendMode::Multiply,
+4 -2
View File
@@ -325,7 +325,9 @@ pub fn build_mesh(strokes: &[LiquifyStroke], w: f64, h: f64, frozen: &(dyn Fn(f6
type MeshCache = Mutex<HashMap<u64, Arc<Mesh>>>;
fn cached_mesh(ctx: &EffectCtx) -> Arc<Mesh> {
/// Liquify's displacement mesh for the instance (replayed strokes, cached; also used by the
/// GPU kernels).
pub fn liquify_mesh(ctx: &EffectCtx) -> Arc<Mesh> {
use std::hash::{Hash, Hasher};
let text = ctx.params.s("distortionMesh");
let mask = ctx.params.f("freezeAreaMask").round() as usize;
@@ -369,7 +371,7 @@ fn liquify(ctx: &EffectCtx, mut b: Buf) -> Buf {
if ctx.params.s("distortionMesh").trim().is_empty() && !show_freeze && !show_mesh {
return b;
}
let mesh = cached_mesh(ctx);
let mesh = liquify_mesh(ctx);
let off = ctx.params.v2("distortionMeshOffset");
let mesh_color = ctx.params.color("meshColor");
let src = b.img.clone();
+112 -4
View File
@@ -66,25 +66,36 @@ use std::collections::HashMap;
use std::sync::OnceLock;
pub use card3d::{CompLight, CompScene};
pub use color_fx::{COLORAMA_PRESETS, ColoramaPalette};
pub use color_fx::{
HUESAT_CHANNELS, LEVELS_CHANNELS, exposure_settings, fill_uses_masks, huesat_ranges_identity, levels_channel_ids, levels_channels_identity, levels_clip,
HUESAT_CHANNELS, HUESAT_RANGES, LEVELS_CHANNELS, PHOTO_FILTER_CUSTOM, PHOTO_FILTERS, exposure_settings, fill_uses_masks, huesat_ranges_identity,
levels_channel_ids, levels_channel_settings, levels_channels_identity, levels_clip,
};
pub use color2::Curve;
pub use color2::{Curve, auto_correct_settings, equalize_tables, luma_clip_points, shadow_highlight_amounts};
pub use color3::OffsetCurve;
pub use distort::transform_shutter;
pub use distort2::parse_mesh;
pub use distort2::{MAGNIFY_MODES, parse_mesh};
pub use distort4::liquify_mesh;
use effectcraft_keyframe::Value;
use effectcraft_project::build::Ids;
use effectcraft_project::{GroupKind, ParamUi, PropGroup, Property};
pub use effectcraft_raster::{AuxChannels, Image};
pub use misc::{INVERT_ALPHA, INVERT_CHANNELS, glow_operation};
pub use misc::{INVERT_ALPHA, INVERT_CHANNELS, glow_ab_t, glow_operation};
pub use sim::particle_state;
pub use sim3::playground_state;
pub use stylize2::strobe_on;
// CPU helpers the GPU kernels share (effectcraft-gpu).
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 noise::GrainLook;
pub use transition::place_layer;
// effectcraft-gpu fx_noise.
pub use noise::remove_grain_level;
pub use noise3::{FractalGpu, fractal_gpu};
pub use time_fx::{posterized_time, time_frames};
// effectcraft-gpu fx_tone.
pub use ocio::color_stabilizer_maps;
/// Effect categories in Effects & Presets order.
pub const CATEGORIES: &[&str] = &[
@@ -806,6 +817,103 @@ pub const GPU_EFFECTS: &[&str] = &[
"ec.color.selectivecolor",
"ec.key.linearcolor",
"ec.keying.keylight",
// effectcraft-gpu fx_key (keying, matte, channel)
"ec.key.colorkey",
"ec.key.luma",
"ec.key.colorrange",
"ec.key.extract",
"ec.key.differencematte",
"ec.key.colordifference",
"ec.key.screen",
"ec.key.spill",
"ec.key.advancedspill",
"ec.key.keycleaner",
"ec.key.unmult",
"ec.matte.simplechoker",
"ec.matte.mattechoker",
"ec.matte.refinesoft",
"ec.matte.refinehard",
"ec.channel.setmatte",
"ec.channel.setchannels",
"ec.channel.shiftchannels",
"ec.channel.removecolormatting",
"ec.channel.arithmetic",
"ec.channel.solidcomposite",
"ec.channel.combiner",
"ec.channel.blend",
"ec.channel.calculations",
"ec.channel.compoundarithmetic",
// effectcraft-gpu fx_tone (colour correction)
"ec.color.levelsic",
"ec.color.gammapedestalgain",
"ec.color.photofilter",
"ec.color.changecolor",
"ec.color.changetocolor",
"ec.color.leavecolor",
"ec.color.broadcast",
"ec.color.colorbalancehls",
"ec.color.videolimiter",
"ec.color.psarbitrarymap",
"ec.color.cctoner",
"ec.color.cccoloroffset",
"ec.color.cckernel",
"ec.color.autolevels",
"ec.color.autocontrast",
"ec.color.autocolor",
"ec.color.equalize",
"ec.color.shadowhighlight",
"ec.color.cccolorneutralizer",
"ec.color.colorstabilizer",
// effectcraft-gpu fx_stylize (stylize, distort)
"ec.stylize.posterize",
"ec.stylize.threshold",
"ec.stylize.ccthreshold",
"ec.stylize.ccthresholdrgb",
"ec.stylize.strobe",
"ec.stylize.ccvignette",
"ec.stylize.scatter",
"ec.stylize.brushstrokes",
"ec.stylize.roughenedges",
"ec.stylize.texturize",
"ec.stylize.motiontile",
"ec.stylize.cckaleida",
"ec.stylize.ccrepetile",
"ec.distort.mirror",
"ec.distort.offset",
"ec.distort.polar",
"ec.distort.spherize",
"ec.distort.cornerpin",
"ec.distort.opticscompensation",
"ec.distort.magnify",
"ec.distort.ccslant",
"ec.distort.ccsmear",
"ec.distort.ccsplit",
"ec.distort.ccsplit2",
"ec.distort.cctiler",
"ec.distort.ccgriddler",
"ec.distort.liquify",
"ec.distort.twirllegacy",
"ec.distort.ccripplepulse",
"ec.distort.ccpowerpin",
"ec.distort.ccflomotion",
// effectcraft-gpu fx_noise (noise, blur, time)
"ec.noise.turbulent",
"ec.noise.median",
"ec.noise.medianlegacy",
"ec.noise.dustscratches",
"ec.noise.removegrain",
"ec.noise.noisealpha",
"ec.noise.noisehls",
"ec.noise.noisehlsauto",
"ec.blur.smart",
"ec.blur.bilateral",
"ec.blur.sharpen",
"ec.blur.unsharp",
"ec.blur.compound",
"ec.blur.channel",
"ec.channel.minimax",
"ec.time.echo",
"ec.time.posterizetime",
];
/// Effects whose output depends on [`EffectCtx::time`] directly (not only through animated
+1 -1
View File
@@ -103,7 +103,7 @@ fn unsharp(ctx: &EffectCtx, mut b: Buf) -> Buf {
/// Position (0 = Color A, 1 = Color B) in Glow's A & B gradient for brightness `l`: `loops`
/// cycles starting at `phase` (revolutions), shaped by Color Looping (0 Sawtooth A>B,
/// 1 Sawtooth B>A, 2 Triangle A>B>A, 3 Triangle B>A>B) and biased so `mid` maps to the middle.
pub(crate) fn glow_ab_t(l: f32, looping: u32, loops: f32, phase: f32, mid: f32) -> f32 {
pub fn glow_ab_t(l: f32, looping: u32, loops: f32, phase: f32, mid: f32) -> f32 {
let u = l.clamp(0.0, 1.0) * loops.max(0.0) + phase;
let mut t = u - u.floor();
if u > 0.0 && t <= 0.0 {
+23 -14
View File
@@ -477,6 +477,28 @@ pub(crate) fn sampling_boxes(ctx: &EffectCtx, img: &Image, scale: f64) -> Vec<(u
sample_boxes(img, n, s)
}
/// The grain level (0.5..2) measured in the sample boxes of `img`.
fn grain_level(img: &Image, boxes: &[(usize, usize, usize)]) -> f32 {
let mut m = vec![false; img.data.len()];
let w = img.width as usize;
for &(x, y, s) in boxes {
for yy in y..y + s {
for xx in x..x + s {
m[yy * w + xx] = true;
}
}
}
let st = crate::noise2::grain_stats_masked(img, Some(&m));
let s = (st.std[0] + st.std[1] + st.std[2]) / 3.0;
if boxes.is_empty() { 1.0 } else { (s / 0.02).clamp(0.5, 2.0) }
}
/// Remove Grain's measured grain level for buffer `b` without Temporal Filtering (the GPU
/// kernels' spatial pass, effectcraft-gpu `fx_noise`).
pub fn remove_grain_level(ctx: &EffectCtx, b: &Buf) -> f32 {
grain_level(&b.img, &sampling_boxes(ctx, &b.img, b.scale))
}
fn remove_grain(ctx: &EffectCtx, mut b: Buf) -> Buf {
let pr = ctx.params;
let amt = pr.f("noiseReductionSettings/noiseReduction") as f32;
@@ -535,20 +557,7 @@ fn remove_grain(ctx: &EffectCtx, mut b: Buf) -> Buf {
}
}
// The grain level measured in the sample boxes scales the smoothing.
let level = {
let mut m = vec![false; b.img.data.len()];
let w = b.img.width as usize;
for &(x, y, s) in &boxes {
for yy in y..y + s {
for xx in x..x + s {
m[yy * w + xx] = true;
}
}
}
let st = crate::noise2::grain_stats_masked(&b.img, Some(&m));
let s = (st.std[0] + st.std[1] + st.std[2]) / 3.0;
if boxes.is_empty() { 1.0 } else { (s / 0.02).clamp(0.5, 2.0) }
};
let level = grain_level(&b.img, &boxes);
let passes = pr.f("noiseReductionSettings/passes").round().clamp(1.0, 8.0) as usize;
let multichannel = pr.e("noiseReductionSettings/mode") == 0;
let texture = (pr.f("fineTuning/texture") as f32).clamp(0.0, 1.0);
+83
View File
@@ -326,6 +326,89 @@ impl Fractal {
}
}
/// Fractal / Turbulent Noise resolved for the GPU kernel (effectcraft-gpu `fx_noise`): the
/// per-pixel constants and, per octave, the terms [`Fractal::raw`] computes before touching the
/// pixel, in the same f32 order.
pub struct FractalGpu {
pub kind: u32,
pub noise_type: u32,
pub seed: u32,
pub invert: bool,
pub overflow: u32,
pub contrast: f32,
pub brightness: f32,
/// Rotation (sin, cos).
pub rot: (f32, f32),
pub size: [f32; 2],
/// Cycle Evolution: (t, cycle, t / cycle).
pub cycle: Option<[f32; 3]>,
pub sub_rotation: bool,
/// Σ amplitude × weight (the normaliser).
pub norm: f32,
/// Per octave: origin x, y, sub-rotation sin, cos, frequency, amplitude, weight, evolution
/// (turbulence applied), z offset, Dynamic Progressive warp factor.
pub octaves: Vec<[f32; 10]>,
/// Blending Mode (`None` = the noise alone), Opacity and Blend With Original.
pub mode: Option<BlendMode>,
pub opacity: f32,
pub blend: f32,
}
/// [`FractalGpu`] for a buffer with `offset` / `scale`.
pub fn fractal_gpu(ctx: &EffectCtx, offset: [f64; 2], scale: f64, turbulent: bool) -> FractalGpu {
let b = Buf { img: effectcraft_raster::Image::new(0, 0), offset, scale };
let fr = Fractal::from_params(ctx, &b, turbulent);
let n_oct = fr.octaves.ceil() as usize;
let frac = fr.octaves - fr.octaves.floor();
let (mut norm, mut amp, mut f, mut depth) = (0.0f32, 1.0f32, 1.0f32, 1.0f32);
let mut octaves = Vec::with_capacity(n_oct);
for o in 0..n_oct {
let w = if o + 1 == n_oct && frac > 0.0 { frac } else { 1.0 };
let of = o as f32;
let k = if fr.perspective { depth } else { 1.0 } * (1.0 + fr.turbulence * of);
let mut org = fr.origin;
if k != 1.0 {
org = [fr.center[0] + (fr.origin[0] - fr.center[0]) * k, fr.center[1] + (fr.origin[1] - fr.center[1]) * k];
}
if !fr.center_subscale {
org = [org[0] + fr.sub_offset[0] * of, org[1] + fr.sub_offset[1] * of];
}
let (s, c) = (fr.sub_rotation * of).sin_cos();
let evo = fr.evolution * (1.0 + fr.turbulence * of);
let dk = if fr.kind == 6 { 0.5 + of * 0.35 } else { 1.0 };
octaves.push([org[0], org[1], s, c, f, amp, w, evo, of * 7.31, dk]);
norm += amp * w;
amp *= fr.influence;
f /= fr.sub_scaling;
depth *= fr.sub_scaling;
}
let cycle = fr.cycle.map(|c| {
let t = fr.evolution.rem_euclid(c);
[t, c, t / c]
});
FractalGpu {
kind: fr.kind,
noise_type: fr.noise_type,
seed: fr.seed,
invert: fr.invert,
overflow: fr.overflow,
contrast: fr.contrast,
brightness: fr.brightness,
rot: fr.rot,
size: fr.size,
cycle,
sub_rotation: fr.sub_rotation != 0.0,
norm,
octaves,
mode: match ctx.params.get("blendingMode").map(Value::as_enum).unwrap_or(BLEND_NONE) {
BLEND_NONE => None,
m => Some(BLEND_MODES.get(m as usize).and_then(|l| BlendMode::from_name(l)).unwrap_or(BlendMode::Normal)),
},
opacity: (ctx.params.f("opacity") as f32 / 100.0).clamp(0.0, 1.0),
blend: ctx.params.f("blend") as f32 / 100.0,
}
}
/// Map a value by an [`OVERFLOWS`] option.
pub fn overflow(v: f32, mode: u32) -> f32 {
match mode {
+40
View File
@@ -905,6 +905,46 @@ fn curve3(xs: [f64; 3], ys: [f64; 3], v: f64) -> f64 {
a.1 + (c.1 - a.1) * (v - a.0) / (c.0 - a.0).max(1e-9)
}
/// Color Stabilizer's correction of buffer `b` as one piecewise-linear map per channel (points
/// with increasing x; the end segments extend), the same maps [`color_stabilizer`] applies.
/// `None` without a host or reference frame (the layer passes through). (The GPU effect.)
pub fn color_stabilizer_maps(ctx: &EffectCtx, b: &Buf) -> Option<[Vec<(f64, f64)>; 3]> {
let reference = ctx.env.host?.self_at(ctx.params.f("referenceFrame"), ctx.env.effect_index)?;
let r = ctx.params.f("sampleSize").max(0.5);
let pts = [ctx.params.v2("blackPoint"), ctx.params.v2("midPoint"), ctx.params.v2("whitePoint")];
let cur = pts.map(|pt| sample_mean(b, pt, r));
let refv = pts.map(|pt| sample_mean(&reference, pt, r));
let mode = ctx.params.e("stabilize");
Some([0, 1, 2].map(|k| {
let offset = |c0: f64, r0: f64| vec![(0.0, r0 - c0), (1.0, 1.0 + r0 - c0)];
match mode {
0 => offset(cur[0][k], refv[0][k]),
1 => {
let (c0, c1, r0, r1) = (cur[0][k], cur[2][k], refv[0][k], refv[2][k]);
if (c1 - c0).abs() < 1e-6 {
offset(c0, r0)
} else if c0 < c1 {
vec![(c0, r0), (c1, r1)]
} else {
vec![(c1, r1), (c0, r0)]
}
}
_ => {
let mut v = vec![(0.0, 0.0)];
let mut pairs: Vec<(f64, f64)> = (0..3).map(|i| (cur[i][k], refv[i][k])).collect();
pairs.sort_by(|a, b| a.0.total_cmp(&b.0));
for (x, y) in pairs {
if x > v.last().expect("non-empty").0 + 1e-4 && x < 1.0 - 1e-4 {
v.push((x, y));
}
}
v.push((1.0, 1.0));
v
}
}
}))
}
fn color_stabilizer(ctx: &EffectCtx, mut b: Buf) -> Buf {
let Some(host) = ctx.env.host else { return b };
let Some(reference) = host.self_at(ctx.params.f("referenceFrame"), ctx.env.effect_index) else { return b };
+2 -1
View File
@@ -223,7 +223,8 @@ fn scatter(ctx: &EffectCtx, mut b: Buf) -> Buf {
// ---- Strobe Light ----
pub(crate) fn strobe_on(time: f64, duration: f64, period: f64, prob: f64, seed: u32) -> bool {
/// Whether Strobe Light flashes at `time` (also used by the GPU kernels).
pub fn strobe_on(time: f64, duration: f64, period: f64, prob: f64, seed: u32) -> bool {
if period <= 0.0 {
return false;
}
+6
View File
@@ -219,6 +219,12 @@ fn fetch(ctx: &EffectCtx, times: &[f64]) -> Option<Frames> {
Some(Frames { grid, imgs })
}
/// The layer's frames at layer times `times` placed on one grid (the GPU Echo / Posterize Time,
/// effectcraft-gpu `fx_noise`): (grid buffer, one image per time). `None` without a host.
pub fn time_frames(ctx: &EffectCtx, times: &[f64]) -> Option<(Buf, Vec<Image>)> {
fetch(ctx, times).map(|f| (f.grid, f.imgs))
}
fn with_img(grid: Buf, img: Image) -> Buf {
Buf { img, ..grid }
}