M13.28: GPU pixel ports (fx_pixel2): CC Cross/Radial/Vector Blur, Reduce Interlace Flicker, CC Composite, Color Link, Cineon, HDR Compander/Highlight Compression, Grow Bounds, CC Overbrights, CC Block Load, CC Burn Film, CC Glass/Plastic, CC HexTile, CC Mr. Smoothie, Inner/Outer Key, CC Simple Wire Removal, Basic 3D
Inner/Outer Key's trimap and Cleanup strokes, Color Link's sample and CC Glass/Plastic's light are shared with the CPU effects (CPU output unchanged: gen_golden). CC Plastic now reads its Bump Layer (it read the nonexistent bumpMap id). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
764c3a31ad
commit
5df9cde182
@@ -716,13 +716,26 @@ fn sample_color(img: &Image, how: u32, clip: f64) -> ([f32; 3], f32) {
|
||||
|
||||
/// Color Link: colours the layer with a colour sampled from the Source Layer (its source, no
|
||||
/// masks or effects) or, with no source layer, from the layer itself.
|
||||
fn color_link(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
/// Color Link's sampled colour (RGB) and alpha: from the Source Layer, or from `img` (the
|
||||
/// layer's own pixels; `None` = the caller has not read them back) when no source is chosen.
|
||||
/// `None` when the own pixels are needed but not given.
|
||||
pub fn color_link_sample(ctx: &EffectCtx, img: Option<&Image>) -> Option<([f32; 3], f32)> {
|
||||
let how = ctx.params.e("sampleSource");
|
||||
let clip = ctx.params.f("clip") / 100.0;
|
||||
let (c, sa) = match ctx.layer_param("sourceLayer", false) {
|
||||
Some(match ctx.layer_param("sourceLayer", false) {
|
||||
Some(lp) => sample_color(&lp.buf.img, how, clip),
|
||||
None => sample_color(&b.img, how, clip),
|
||||
};
|
||||
None => sample_color(img?, how, clip),
|
||||
})
|
||||
}
|
||||
|
||||
/// Color Link's Blending Mode.
|
||||
pub fn color_link_mode(ctx: &EffectCtx) -> BlendMode {
|
||||
LINK_MODES[(ctx.params.e("blendingMode") as usize).min(LINK_MODES.len() - 1)].1
|
||||
}
|
||||
|
||||
fn color_link(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let how = ctx.params.e("sampleSource");
|
||||
let Some((c, sa)) = color_link_sample(ctx, Some(&b.img)) else { return b };
|
||||
let op = (ctx.params.f("opacity") / 100.0).clamp(0.0, 1.0) as f32;
|
||||
let stencil = ctx.params.b("stencilOriginalAlpha");
|
||||
if how >= 6 {
|
||||
@@ -737,7 +750,7 @@ fn color_link(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
});
|
||||
return b;
|
||||
}
|
||||
let mode = LINK_MODES[(ctx.params.e("blendingMode") as usize).min(LINK_MODES.len() - 1)].1;
|
||||
let mode = color_link_mode(ctx);
|
||||
let src = [c[0] * op, c[1] * op, c[2] * op, op];
|
||||
b.img.data.par_iter_mut().for_each(|px| {
|
||||
let a0 = px[3];
|
||||
|
||||
@@ -101,24 +101,40 @@ fn mask_sdf(ctx: &EffectCtx, b: &Buf, idx: &[u32]) -> Option<Plane> {
|
||||
Some(pl)
|
||||
}
|
||||
|
||||
fn inner_outer_key(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
/// Inner/Outer Key's geometry (shared with the GPU compositor, effectcraft-gpu `fx_pixel2`):
|
||||
/// the trimap of the selected masks and the Cleanup brush strokes, in buffer pixels.
|
||||
pub struct InnerOuterPlan {
|
||||
/// 1 = known foreground, 0 = known background, 0.5 = unknown.
|
||||
pub tri: Plane,
|
||||
/// Some pixel is unknown (edge colours are estimated and decontaminated).
|
||||
pub unknown: bool,
|
||||
/// Blur radius of the local foreground / background colour estimates.
|
||||
pub sigma: f64,
|
||||
/// Cleanup strokes in order: (matte target, coverage per pixel; negative = beyond the brush).
|
||||
pub strokes: Vec<(f32, Vec<f32>)>,
|
||||
/// Edge Thin, Edge Feather (buffer px), Edge Threshold, Invert Extraction, Blend with Original.
|
||||
pub thin: f64,
|
||||
pub feather: f64,
|
||||
pub threshold: f32,
|
||||
pub invert: bool,
|
||||
pub original: f32,
|
||||
}
|
||||
|
||||
/// [`InnerOuterPlan`] of an Inner/Outer Key instance on `b`'s geometry (`None` = no foreground
|
||||
/// mask: the layer passes through).
|
||||
pub fn inner_outer_plan(ctx: &EffectCtx, b: &Buf) -> Option<InnerOuterPlan> {
|
||||
// Foreground (Inside) plus Additional Foreground 1–10; likewise for the background.
|
||||
let fg_idx: Vec<u32> =
|
||||
std::iter::once(ctx.params.e("foreground")).chain((1..=10).map(|k| ctx.params.e(&format!("additionalForeground/foreground{k}")))).collect();
|
||||
let bg_idx: Vec<u32> =
|
||||
std::iter::once(ctx.params.e("background")).chain((1..=10).map(|k| ctx.params.e(&format!("additionalBackground/background{k}")))).collect();
|
||||
let radius = (ctx.params.f("singleMaskHighlightRadius") * b.scale) as f32;
|
||||
let thin = ctx.params.f("edgeThin") * b.scale;
|
||||
let feather = ctx.params.f("edgeFeather") * b.scale;
|
||||
let thr = (ctx.params.f("edgeThreshold") / 100.0) as f32;
|
||||
let invert = ctx.params.b("invertExtraction");
|
||||
let orig = (ctx.params.f("blendWithOriginal") / 100.0) as f32;
|
||||
let (w, h) = (b.img.width as usize, b.img.height as usize);
|
||||
// Trimap: 1 = known foreground, 0 = known background, 0.5 = unknown.
|
||||
let fg = mask_plane(ctx, &b, &fg_idx);
|
||||
let bg = mask_plane(ctx, &b, &bg_idx);
|
||||
let fg = mask_plane(ctx, b, &fg_idx);
|
||||
let bg = mask_plane(ctx, b, &bg_idx);
|
||||
let tri: Plane = match (fg, bg) {
|
||||
(None, _) => return b,
|
||||
(None, _) => return None,
|
||||
(Some(f), Some(bk)) => f.zip_map(&bk, |f, bk| {
|
||||
if f > 0.5 {
|
||||
1.0
|
||||
@@ -132,7 +148,7 @@ fn inner_outer_key(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
if radius <= 0.0 {
|
||||
f
|
||||
} else {
|
||||
let sdf = mask_sdf(ctx, &b, &fg_idx).unwrap_or(f);
|
||||
let sdf = mask_sdf(ctx, b, &fg_idx).unwrap_or(f);
|
||||
sdf.map(|d| {
|
||||
if d > radius {
|
||||
1.0
|
||||
@@ -146,11 +162,50 @@ fn inner_outer_key(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
}
|
||||
};
|
||||
let unknown = tri.data.par_iter().any(|&t| t > 0.25 && t < 0.75);
|
||||
let sigma = (radius.max(4.0) as f64).max(w.min(h) as f64 * 0.02);
|
||||
// Cleanup Foreground / Background: brush strokes along mask paths that paint the matte
|
||||
// towards opaque / transparent (Brush Radius, Brush Pressure).
|
||||
let mut strokes = Vec::new();
|
||||
for (side, target) in [("Foreground", 1.0f32), ("Background", 0.0)] {
|
||||
for k in 1..=10 {
|
||||
let g = format!("cleanup{side}/cleanup{side}{k}");
|
||||
let idx = ctx.params.e(&format!("{g}/path"));
|
||||
let Some(m) = (idx > 0).then(|| ctx.env.masks.get(idx as usize - 1)).flatten() else { continue };
|
||||
let rad = (ctx.params.f(&format!("{g}/brushRadius")) * b.scale).max(0.5);
|
||||
let pressure = (ctx.params.f(&format!("{g}/brushPressure")) / 100.0).clamp(0.0, 1.0) as f32;
|
||||
let pts: Vec<[f64; 2]> = m.points.iter().map(|q| [q[0] * b.scale + b.offset[0], q[1] * b.scale + b.offset[1]]).collect();
|
||||
let cov: Vec<f32> = (0..w * h)
|
||||
.into_par_iter()
|
||||
.map(|i| {
|
||||
let (x, y) = ((i % w) as f64 + 0.5, (i / w) as f64 + 0.5);
|
||||
let d = dist_to_poly(&pts, m.closed, x, y);
|
||||
if d < rad + 1.0 { ((rad - d) / rad.max(1.0) * 2.0).clamp(0.0, 1.0) as f32 * pressure } else { -1.0 }
|
||||
})
|
||||
.collect();
|
||||
strokes.push((target, cov));
|
||||
}
|
||||
}
|
||||
Some(InnerOuterPlan {
|
||||
tri,
|
||||
unknown,
|
||||
sigma,
|
||||
strokes,
|
||||
thin: ctx.params.f("edgeThin") * b.scale,
|
||||
feather: ctx.params.f("edgeFeather") * b.scale,
|
||||
threshold: (ctx.params.f("edgeThreshold") / 100.0) as f32,
|
||||
invert: ctx.params.b("invertExtraction"),
|
||||
original: (ctx.params.f("blendWithOriginal") / 100.0) as f32,
|
||||
})
|
||||
}
|
||||
|
||||
fn inner_outer_key(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let Some(plan) = inner_outer_plan(ctx, &b) else { return b };
|
||||
let InnerOuterPlan { tri, unknown, sigma, strokes, thin, feather, threshold: thr, invert, original: orig } = plan;
|
||||
let (w, h) = (b.img.width as usize, b.img.height as usize);
|
||||
let mut alpha = tri.clone();
|
||||
let mut colours: Option<Vec<[f32; 3]>> = None;
|
||||
if unknown {
|
||||
// Local foreground / background colour estimates: normalised blurs over known regions.
|
||||
let sigma = (radius.max(4.0) as f64).max(w.min(h) as f64 * 0.02);
|
||||
let known_f = tri.map(|t| if t > 0.75 { 1.0 } else { 0.0 });
|
||||
let known_b = tri.map(|t| if t < 0.25 { 1.0 } else { 0.0 });
|
||||
let straight: Vec<[f32; 3]> = b.img.data.par_iter().map(|&px| unpremul(px).0).collect();
|
||||
@@ -190,25 +245,12 @@ fn inner_outer_key(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
// Cleanup Foreground / Background: brush strokes along mask paths that paint the matte
|
||||
// towards opaque / transparent (Brush Radius, Brush Pressure).
|
||||
for (side, target) in [("Foreground", 1.0f32), ("Background", 0.0)] {
|
||||
for k in 1..=10 {
|
||||
let g = format!("cleanup{side}/cleanup{side}{k}");
|
||||
let idx = ctx.params.e(&format!("{g}/path"));
|
||||
let Some(m) = (idx > 0).then(|| ctx.env.masks.get(idx as usize - 1)).flatten() else { continue };
|
||||
let rad = (ctx.params.f(&format!("{g}/brushRadius")) * b.scale).max(0.5);
|
||||
let pressure = (ctx.params.f(&format!("{g}/brushPressure")) / 100.0).clamp(0.0, 1.0) as f32;
|
||||
let pts: Vec<[f64; 2]> = m.points.iter().map(|q| [q[0] * b.scale + b.offset[0], q[1] * b.scale + b.offset[1]]).collect();
|
||||
alpha.data.par_iter_mut().enumerate().for_each(|(i, a)| {
|
||||
let (x, y) = ((i % w) as f64 + 0.5, (i / w) as f64 + 0.5);
|
||||
let d = dist_to_poly(&pts, m.closed, x, y);
|
||||
if d < rad + 1.0 {
|
||||
let cov = ((rad - d) / rad.max(1.0) * 2.0).clamp(0.0, 1.0) as f32 * pressure;
|
||||
*a += (target - *a) * cov;
|
||||
}
|
||||
});
|
||||
}
|
||||
for (target, cov) in &strokes {
|
||||
alpha.data.par_iter_mut().zip(cov.par_iter()).for_each(|(a, &c)| {
|
||||
if c >= 0.0 {
|
||||
*a += (target - *a) * c;
|
||||
}
|
||||
});
|
||||
}
|
||||
if thin.abs() > 0.01 {
|
||||
alpha = morph_frac(&alpha, thin.abs(), thin < 0.0);
|
||||
|
||||
@@ -71,7 +71,7 @@ pub use color_fx::{
|
||||
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, auto_correct_settings, equalize_tables, luma_clip_points, shadow_highlight_amounts};
|
||||
pub use color2::{Curve, auto_correct_settings, color_link_mode, color_link_sample, equalize_tables, luma_clip_points, shadow_highlight_amounts};
|
||||
pub use color3::OffsetCurve;
|
||||
pub use distort::transform_shutter;
|
||||
pub use distort2::{MAGNIFY_MODES, bezier_grid, parse_mesh};
|
||||
@@ -92,8 +92,10 @@ pub use generate2::pattern_kind as cell_pattern_kind;
|
||||
pub use noise::GrainLook;
|
||||
pub use transition::place_layer;
|
||||
// effectcraft-gpu fx_noise.
|
||||
pub use keying2::{InnerOuterPlan, inner_outer_plan};
|
||||
pub use noise::remove_grain_level;
|
||||
pub use noise3::{FractalGpu, fractal_gpu};
|
||||
pub use stylize3::{BumpLight, bump_layer_id};
|
||||
pub use textfx::{TextLayer, text_layer};
|
||||
pub use time_fx::{PixelMotion, TimewarpPlan, TwStep, posterized_time, time_frames, timewarp_crop, timewarp_plan};
|
||||
// effectcraft-gpu fx_tone.
|
||||
@@ -1017,6 +1019,27 @@ pub const GPU_EFFECTS: &[&str] = &[
|
||||
"ec.time.ccwidetime",
|
||||
"ec.time.pixelmotionblur",
|
||||
"ec.time.timewarp",
|
||||
// effectcraft-gpu fx_pixel2 (pixel ports, part C)
|
||||
"ec.blur.cccross",
|
||||
"ec.blur.ccradial",
|
||||
"ec.blur.ccvector",
|
||||
"ec.blur.reduceflicker",
|
||||
"ec.channel.cccomposite",
|
||||
"ec.color.colorlink",
|
||||
"ec.utility.cineon",
|
||||
"ec.utility.hdrcompander",
|
||||
"ec.utility.hdrcompression",
|
||||
"ec.utility.growbounds",
|
||||
"ec.utility.ccoverbrights",
|
||||
"ec.stylize.ccblockload",
|
||||
"ec.stylize.ccburnfilm",
|
||||
"ec.stylize.ccglass",
|
||||
"ec.stylize.cchextile",
|
||||
"ec.stylize.ccmrsmoothie",
|
||||
"ec.stylize.ccplastic",
|
||||
"ec.key.innerouter",
|
||||
"ec.key.ccsimplewireremoval",
|
||||
"ec.obsolete.basic3d",
|
||||
];
|
||||
|
||||
/// Effects whose output depends on [`EffectCtx::time`] directly (not only through animated
|
||||
|
||||
@@ -180,9 +180,14 @@ fn burn_film(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
|
||||
const BUMP_PROPS: [&str; 6] = ["Red", "Green", "Blue", "Alpha", "Luminance", "Lightness"];
|
||||
|
||||
/// The bump-map layer parameter: CC Glass's Bump Map, CC Plastic's Bump Layer.
|
||||
pub fn bump_layer_id(ctx: &EffectCtx) -> &'static str {
|
||||
if ctx.params.get("bumpLayer").is_some() { "bumpLayer" } else { "bumpMap" }
|
||||
}
|
||||
|
||||
/// Height field (0..1) from the bump-map layer (or the layer itself), softened.
|
||||
fn height_field(ctx: &EffectCtx, b: &Buf) -> Plane {
|
||||
let src = layer_or_self(ctx, b, "bumpMap", true, false);
|
||||
let src = layer_or_self(ctx, b, bump_layer_id(ctx), true, false);
|
||||
let prop = ctx.params.e("property");
|
||||
let mut pl = Plane::from_image(&src, |p| {
|
||||
let (c, a) = unpremul(p);
|
||||
@@ -203,30 +208,31 @@ fn height_field(ctx: &EffectCtx, b: &Buf) -> Plane {
|
||||
pl
|
||||
}
|
||||
|
||||
struct Light {
|
||||
intensity: f32,
|
||||
color: [f32; 3],
|
||||
point: bool,
|
||||
pos: (f64, f64),
|
||||
/// The effect light and surface of CC Glass / CC Plastic (shared with the GPU compositor).
|
||||
pub struct BumpLight {
|
||||
pub intensity: f32,
|
||||
pub color: [f32; 3],
|
||||
pub point: bool,
|
||||
pub pos: (f64, f64),
|
||||
/// Distant light direction (towards the light).
|
||||
dir: [f32; 3],
|
||||
height: f32,
|
||||
ambient: f32,
|
||||
diffuse: f32,
|
||||
specular: f32,
|
||||
shininess: f32,
|
||||
metal: f32,
|
||||
pub dir: [f32; 3],
|
||||
pub height: f32,
|
||||
pub ambient: f32,
|
||||
pub diffuse: f32,
|
||||
pub specular: f32,
|
||||
pub shininess: f32,
|
||||
pub metal: f32,
|
||||
}
|
||||
|
||||
impl Light {
|
||||
fn from(ctx: &EffectCtx, b: &Buf) -> Light {
|
||||
impl BumpLight {
|
||||
pub fn from(ctx: &EffectCtx, b: &Buf) -> BumpLight {
|
||||
let pr = &ctx.params;
|
||||
let elev = (pr.f("lightHeight").clamp(-100.0, 100.0) / 100.0 * 90.0).to_radians();
|
||||
let az = pr.f("lightDirection").to_radians();
|
||||
let dir = [(az.sin() * elev.cos()) as f32, (-az.cos() * elev.cos()) as f32, elev.sin() as f32];
|
||||
let c = pr.color("lightColor");
|
||||
let rough = pr.f("roughness").clamp(0.001, 1.0) as f32;
|
||||
Light {
|
||||
BumpLight {
|
||||
intensity: (pr.f("lightIntensity") / 100.0) as f32,
|
||||
color: [c[0], c[1], c[2]],
|
||||
point: pr.e("lightType") == 1,
|
||||
@@ -288,7 +294,7 @@ fn glass(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let height = ctx.params.f("height") as f32 / 100.0;
|
||||
let k = height * 25.0;
|
||||
let disp = ctx.params.f("displacement") * b.scale * 0.25;
|
||||
let light = Light::from(ctx, &b);
|
||||
let light = BumpLight::from(ctx, &b);
|
||||
let src = b.img.clone();
|
||||
b.img.rows_mut().for_each(|(y, row)| {
|
||||
for (x, px) in row.iter_mut().enumerate() {
|
||||
@@ -321,7 +327,7 @@ fn plastic(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
hf = hf.map(|v| v.clamp(lo.min(hi), hi.max(lo)));
|
||||
}
|
||||
let k = ctx.params.f("height") as f32 / 100.0 * 25.0;
|
||||
let light = Light::from(ctx, &b);
|
||||
let light = BumpLight::from(ctx, &b);
|
||||
b.img.rows_mut().for_each(|(y, row)| {
|
||||
for (x, px) in row.iter_mut().enumerate() {
|
||||
if px[3] <= 0.0 {
|
||||
|
||||
Reference in New Issue
Block a user