Merge M13.9 gpu noise, blurs and time (fx_noise)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -87,6 +87,7 @@ 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"]),
|
||||
];
|
||||
|
||||
/// Whether the GPU kernel of effect `id` covers the instance's current settings (see
|
||||
|
||||
@@ -86,6 +86,10 @@ 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};
|
||||
|
||||
/// Effect categories in Effects & Presets order.
|
||||
pub const CATEGORIES: &[&str] = &[
|
||||
@@ -855,6 +859,23 @@ pub const GPU_EFFECTS: &[&str] = &[
|
||||
// effectcraft-gpu fx_stylize (stylize, distort)
|
||||
//
|
||||
// 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",
|
||||
//
|
||||
];
|
||||
|
||||
|
||||
+23
-14
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user