#3469: Turbulent Displace stays finite at any Amount

Expressions are not clamped to the hard range. Padding computed
amount.abs().ceil() as u32 + 1, which overflowed (a panic in debug builds)
from about 4.3e9 on both the CPU and GPU paths, a NaN Amount filled the
layer with NaN, and an infinite one sent infinite coordinates to the
samplers' integer pixel positions.

turbulent_amount_px, shared by both paths, skips a zero or NaN Amount and
bounds the rest to 2^24 px. Values inside the hard range are unchanged.
Tests cover both ends of the range with every displacement kind, pinning
and Resize Layer (finite, padding within budget), Amounts past it, and
CPU/GPU agreement at -10000, 10000 and infinity.
This commit is contained in:
arnav-hiwarkar
2026-11-17 16:13:10 +05:30
parent 2e17ed1d83
commit 040fe61b84
5 changed files with 68 additions and 8 deletions
+56 -3
View File
@@ -85,11 +85,24 @@ const TURBULENT_PINNING: [&str; 15] = [
"Pin Bottom Locked",
];
/// The largest Amount, in buffer pixels, Turbulent Displace displaces by: 2^24, exact in f32.
/// Only an expression gets past the -10000..10000 hard range. At this bound nearly every sample
/// already lands far outside any buffer, and the padding and the CPU and GPU samplers' integer
/// pixel positions (the gradient kinds move up to 2.5 × Amount) stay in range.
const TURBULENT_MAX_AMOUNT_PX: f64 = 16_777_216.0;
/// Turbulent Displace's Amount at `scale`, in buffer pixels, bounded to
/// ±[`TURBULENT_MAX_AMOUNT_PX`]; `None` when nothing moves (zero, or not a number). Shared with
/// the GPU path.
pub fn turbulent_amount_px(ctx: &EffectCtx, scale: f64) -> Option<f64> {
let amount = ctx.params.f("amount") * scale;
(amount.abs() >= 1e-9).then(|| amount.clamp(-TURBULENT_MAX_AMOUNT_PX, TURBULENT_MAX_AMOUNT_PX))
}
fn turbulent_displace(ctx: &EffectCtx, mut b: Buf) -> Buf {
let amount = ctx.params.f("amount") * b.scale;
if amount.abs() < 1e-9 {
let Some(amount) = turbulent_amount_px(ctx, b.scale) else {
return b;
}
};
// TURBULENT_KINDS order: the "Smoother" variants (3, 4, 5) use a gentler octave falloff.
let kind = ctx.params.e("displacement");
let size = (ctx.params.f("size") * b.scale).max(1.0);
@@ -1020,6 +1033,46 @@ mod tests {
assert_eq!((min, max, slider_min, slider_max), (-10000.0, 10000.0, -200.0, 200.0));
}
/// #3469: at either end of Amount's range, with every displacement kind, resized or not and
/// pinned or not, the output stays finite, in its alpha range and within the padding budget.
#[test]
fn turbulent_displace_extreme_amounts_stay_finite_and_bounded() {
let img = test_img(32, 24);
// Resize Layer grows the buffer to the padding budget (16 Mpx here), so it runs with two
// kinds; the rest stay layer-sized.
let cases = (0..9).flat_map(|kind| [(kind, 0, 0.0), (kind, 1, 0.0), (kind, 8, 0.0)]).chain([(0, 3, 1.0), (4, 14, 1.0)]);
for amount in [-10000.0, 10000.0] {
for (kind, pin, resize) in cases.clone() {
let set = [("amount", num(amount)), ("displacement", Value::Enum(kind)), ("pinning", Value::Enum(pin)), ("resizeLayer", num(resize))];
let o = run("ec.distort.turbulentdisplace", &set, img.clone());
let what = format!("amount {amount} kind {kind} pinning {pin} resize {resize}");
assert!(o.img.data.iter().all(|p| p.iter().all(|v| v.is_finite()) && (0.0..=1.0 + 1e-5).contains(&p[3])), "{what}");
let area = u64::from(o.img.width) * u64::from(o.img.height);
assert!(area <= 16_777_216, "{what}: {}x{}", o.img.width, o.img.height);
}
}
}
/// #3469: an Amount past the hard range, which only an expression produces, renders without
/// overflowing the padding or the sampler's pixel positions and stays finite (a plain, a
/// gradient and the cross kind; unpinned, pinned and locked); one that is not a number leaves
/// the layer as it is.
#[test]
fn turbulent_displace_unbounded_amounts_do_not_crash() {
let img = test_img(32, 24);
let cases = [0, 1, 8].into_iter().flat_map(|kind| [(kind, 0, 0.0), (kind, 1, 0.0), (kind, 11, 0.0)]).chain([(0, 1, 1.0)]);
for amount in [1e12, -1e300, f64::MAX, f64::INFINITY, f64::NEG_INFINITY] {
for (kind, pin, resize) in cases.clone() {
let set = [("amount", num(amount)), ("displacement", Value::Enum(kind)), ("pinning", Value::Enum(pin)), ("resizeLayer", num(resize))];
let o = run("ec.distort.turbulentdisplace", &set, img.clone());
assert!(o.img.data.iter().all(|p| p.iter().all(|v| v.is_finite())), "{amount} kind {kind} pinning {pin} resize {resize}");
}
}
for resize in [0.0, 1.0] {
assert_eq!(run("ec.distort.turbulentdisplace", &[("amount", num(f64::NAN)), ("resizeLayer", num(resize))], img.clone()).img, img);
}
}
#[test]
fn griddler_default_is_identity() {
let img = test_img(32, 24);
+1 -1
View File
@@ -84,7 +84,7 @@ pub use color_fx::{COLORAMA_PRESETS, ColoramaPalette};
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_grow, transform_matrix_px, transform_shutter};
pub use distort2::{MAGNIFY_MODES, bezier_grid, parse_mesh};
pub use distort2::{MAGNIFY_MODES, bezier_grid, parse_mesh, turbulent_amount_px};
pub use distort3::{RESHAPE_POINTS, ReshapeSetup, SmearSetup, cc_smear_pad, reshape_setup, smear_setup, warp_inverse_map};
pub use distort4::liquify_mesh;
use effectcraft_keyframe::Value;
+2 -3
View File
@@ -172,10 +172,9 @@ fn cc_lens(e: &mut Enc, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
}
fn turbulent(e: &mut Enc, ctx: &EffectCtx, mut b: GBuf) -> Option<GBuf> {
let amount = ctx.params.f("amount") * b.scale;
if amount.abs() < 1e-9 {
let Some(amount) = effectcraft_effects::turbulent_amount_px(ctx, b.scale) else {
return Some(b);
}
};
let kind = ctx.params.e("displacement");
let size = (ctx.params.f("size") * b.scale).max(1.0);
if ctx.params.b("resizeLayer") && !ctx.adjustment {
+8
View File
@@ -57,6 +57,14 @@ fn turbulent_displace_and_cc_lens() {
],
);
effect_case("ec.distort.turbulentdisplace", &[("displacement", e(8)), ("size", n(15.0)), ("pinning", e(6))]);
// #3469: both ends of After Effects' Amount range, resized and pinned, and an expression's
// Amount past it.
effect_case("ec.distort.turbulentdisplace", &[("size", n(30.0)), ("amount", n(10000.0))]);
effect_case(
"ec.distort.turbulentdisplace",
&[("displacement", e(1)), ("size", n(25.0)), ("amount", n(-10000.0)), ("pinning", e(1)), ("resizeLayer", on())],
);
effect_case("ec.distort.turbulentdisplace", &[("displacement", e(7)), ("amount", n(f64::INFINITY)), ("pinning", e(2))]);
// #943: Evolution moves the pattern at a constant rate on both paths, including steps of a
// few degrees and angles past a whole revolution, where an eased evolution axis diverges.
for evolution in [10.0, 37.0, 400.0, 725.5] {
+1 -1
View File
@@ -64,7 +64,7 @@ the GPU is performance, not parity.
| Date | Change | Summary |
|---|---|---|
| 2026-11-17 | minor | Turbulent Displace: Amount takes After Effects' recorded valid range, −10000..10000 (default and the −200..200 slider unchanged) |
| 2026-11-17 | minor | Turbulent Displace: Amount takes After Effects' recorded valid range, −10000..10000 (default and the −200..200 slider unchanged). Past it (an expression's value) the displacement is bounded to 2^24 px and a NaN Amount leaves the layer unchanged, so padding and sampling stay finite (CPU and GPU) |
| 2026-11-12 | minor | Parameters take After Effects' recorded valid ranges (hard range; defaults and sliders unchanged): Levels (Individual Controls) levels −10000..10000 and Gamma from 0; 4-Color Gradient Blend to 10000 and Jitter to 500 %; Change Color Hue Transform ±1800°; Noise HLS (and Auto) amounts to 1000 % and Grain Size from 0; Grid Border to 2000; Venetian Blinds Width 1..32000 and Feather to 32000; Radial Wipe Feather to 32000; Scatter Amount to 1000; Beam thicknesses to 4000; Transform Scale ±30000 %; Turbulent Displace Random Seed to 100000. A test checks every mapped parameter's range against the recorded table (CPU and GPU) |
| 2026-10-19 | minor | Glow (original colours): bright pass per channel, 8 × (value − threshold + 0.061), measured against After Effects 2026 (CPU and GPU) |
| 2026-10-19 | minor | Glow (colour channels): the glow covers the layer's blurred alpha, blur σ = 0.384 × radius, measured against After Effects 2026 renders (CPU and GPU) |