The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.
Rust ffmpegfree-video-editormodel-context-protocolnon-linear-editoroffline-firstopen-source-video-editorself-hostedvideo-editingvideo-editing-automationvideo-editing-softwarevideo-editing-toolsvideo-editorvoice-cloningyoutube-automationyoutube-shorts
fix(effects): shapes stay round, transitions keep alpha, glows pass white
Jareer66aa332b50e0
diff --git a/src/crates/concat-effects/packages/concat.bloom-pulse/effect.wgsl b/src/crates/concat-effects/packages/concat.bloom-pulse/effect.wgslindex 1f714a3a..ec7e9f8e 100644--- a/src/crates/concat-effects/packages/concat.bloom-pulse/effect.wgsl+++ b/src/crates/concat-effects/packages/concat.bloom-pulse/effect.wgsl@@ -74,6 +74,6 @@ fn effect(uv: vec2<f32>) -> vec4<f32> {let c = sample(uv);let pulse = 0.6 + 0.4 * sin(frame.time * params.speed);let strength = params.amount * 0.01 * pulse;- let bloom = clamp(to_display(down_at(uv).rgb) * strength, vec3<f32>(0.0), vec3<f32>(1.0));+ let bloom = max(to_display(down_at(uv).rgb) * strength, vec3<f32>(0.0));return vec4<f32>(from_display(screen(to_display(c.rgb), bloom)), c.a);}diff --git a/src/crates/concat-effects/packages/concat.clean/fixtures.toml b/src/crates/concat-effects/packages/concat.clean/fixtures.tomlindex 58f0949b..2a78b19c 100644--- a/src/crates/concat-effects/packages/concat.clean/fixtures.toml+++ b/src/crates/concat-effects/packages/concat.clean/fixtures.toml@@ -1,10 +1,11 @@# Colours in the working space: linear light, 1.0 the white of an SDR-# picture. Pinned from the format 1 shader, so the look is what it was.+# picture. Pinned from the format 1 shader, so the look is what it was,+# but for its hue turn, which no longer shifts a colour it does not turn.[[probe]]name = "default"input = [0.3, 0.2, 0.12, 1]-expect = [0.30273, 0.1969, 0.11334, 1]+expect = [0.30786, 0.20093, 0.11627, 1][[probe]]name = "minimum"diff --git a/src/crates/concat-effects/packages/concat.clock-wipe/effect.wgsl b/src/crates/concat-effects/packages/concat.clock-wipe/effect.wgslindex 5d9a3f9c..3838d54e 100644--- a/src/crates/concat-effects/packages/concat.clock-wipe/effect.wgsl+++ b/src/crates/concat-effects/packages/concat.clock-wipe/effect.wgsl@@ -1,12 +1,19 @@+// A hand sweeps clockwise from twelve. The angle is taken in pixels, so the+// hand turns at an even pace on a wide frame, and both of its edges - the+// sweeping one and the one it set out from - are a pixel soft.fn transition(uv: vec2<f32>, progress: f32) -> vec4<f32> {let p = smoothstep(0.0, 1.0, progress);- let c = uv - vec2<f32>(0.5);+ if (p >= 1.0) {+ return to_at(uv);+ }+ let c = (uv - vec2<f32>(0.5)) * frame.size;var a = atan2(c.x, -c.y);if (a < 0.0) {a = a + 6.28318530718;}- if (a < p * 6.28318530718) {- return to_at(uv);- }- return from_at(uv);+ // Arc lengths in pixels from the pixel to each edge.+ let r = length(c);+ let swept = clamp((p * 6.28318530718 - a) * r + 0.5, 0.0, 1.0);+ let started = clamp(a * r + 0.5, 0.0, 1.0);+ return mix(from_at(uv), to_at(uv), swept * started);}diff --git a/src/crates/concat-effects/packages/concat.clock-wipe/fixtures.toml b/src/crates/concat-effects/packages/concat.clock-wipe/fixtures.tomlindex b058470d..2f1c5199 100644--- a/src/crates/concat-effects/packages/concat.clock-wipe/fixtures.toml+++ b/src/crates/concat-effects/packages/concat.clock-wipe/fixtures.toml@@ -1,9 +1,10 @@# Colours in the working space: linear light, 1.0 the white of an SDR-# picture. A cut from one colour to another, and its middle pixel.+# picture. A cut from one colour to another, and its middle pixel - which+# lies a pixel from the centre, so the hand's soft edge is part of it.[[probe]]name = "default"input = [0.8, 0.5, 0.3, 1]to = [0.05, 0.15, 0.4, 1]progress = 0.37-expect = [0.7998, 0.5, 0.30005, 1]+expect = [0.64307, 0.427, 0.3208, 1]diff --git a/src/crates/concat-effects/packages/concat.fair/fixtures.toml b/src/crates/concat-effects/packages/concat.fair/fixtures.tomlindex a7eabb9b..49a49a70 100644--- a/src/crates/concat-effects/packages/concat.fair/fixtures.toml+++ b/src/crates/concat-effects/packages/concat.fair/fixtures.toml@@ -1,10 +1,11 @@# Colours in the working space: linear light, 1.0 the white of an SDR-# picture. Pinned from the format 1 shader, so the look is what it was.+# picture. Pinned from the format 1 shader, so the look is what it was,+# but for its hue turn, which no longer shifts a colour it does not turn.[[probe]]name = "default"input = [0.3, 0.2, 0.12, 1]-expect = [0.36328, 0.24792, 0.16125, 1]+expect = [0.36841, 0.25171, 0.1643, 1][[probe]]name = "minimum"diff --git a/src/crates/concat-effects/packages/concat.glitch-transition/effect.wgsl b/src/crates/concat-effects/packages/concat.glitch-transition/effect.wgslindex 27bb2e27..25ef2ba9 100644--- a/src/crates/concat-effects/packages/concat.glitch-transition/effect.wgsl+++ b/src/crates/concat-effects/packages/concat.glitch-transition/effect.wgsl@@ -11,7 +11,7 @@ fn transition(uv: vec2<f32>, progress: f32) -> vec4<f32> {from_at(vec2<f32>(clamp(ux + k * 0.01, 0.0, 1.0), uv.y)).r,from_at(vec2<f32>(ux, uv.y)).g,from_at(vec2<f32>(clamp(ux - k * 0.01, 0.0, 1.0), uv.y)).b,- 1.0,+ from_at(vec2<f32>(ux, uv.y)).a,);let b = to_at(vec2<f32>(clamp(uv.x - jitter, 0.0, 1.0), uv.y));return mix(a, b, smoothstep(0.0, 1.0, progress));diff --git a/src/crates/concat-effects/packages/concat.iris/effect.wgsl b/src/crates/concat-effects/packages/concat.iris/effect.wgslindex 45bd30e7..9f236d08 100644--- a/src/crates/concat-effects/packages/concat.iris/effect.wgsl+++ b/src/crates/concat-effects/packages/concat.iris/effect.wgsl@@ -2,7 +2,9 @@ struct Params { softness: f32 }fn transition(uv: vec2<f32>, progress: f32) -> vec4<f32> {let p = smoothstep(0.0, 1.0, progress);- let d = distance(uv, vec2<f32>(0.5)) / 0.7071068;+ // A circle in pixels, measured in half-diagonals so it opens all the+ // way to the corners of any frame.+ let d = length((uv - vec2<f32>(0.5)) * frame.size) / (0.5 * length(frame.size));let radius = p * 1.15;let soft = max(params.softness * 0.01, 0.02);let m = smoothstep(radius - soft, radius + soft, d);diff --git a/src/crates/concat-effects/packages/concat.peach/fixtures.toml b/src/crates/concat-effects/packages/concat.peach/fixtures.tomlindex ce63354b..1e9ea873 100644--- a/src/crates/concat-effects/packages/concat.peach/fixtures.toml+++ b/src/crates/concat-effects/packages/concat.peach/fixtures.toml@@ -1,10 +1,11 @@# Colours in the working space: linear light, 1.0 the white of an SDR-# picture. Pinned from the format 1 shader, so the look is what it was.+# picture. Pinned from the format 1 shader, so the look is what it was,+# but for its hue turn, which no longer shifts a colour it does not turn.[[probe]]name = "default"input = [0.3, 0.2, 0.12, 1]-expect = [0.34595, 0.22803, 0.14636, 1]+expect = [0.35059, 0.23145, 0.14905, 1][[probe]]name = "minimum"diff --git a/src/crates/concat-effects/packages/concat.retro-cartoon/effect.wgsl b/src/crates/concat-effects/packages/concat.retro-cartoon/effect.wgslindex ce257163..6260b0c4 100644--- a/src/crates/concat-effects/packages/concat.retro-cartoon/effect.wgsl+++ b/src/crates/concat-effects/packages/concat.retro-cartoon/effect.wgsl@@ -4,7 +4,9 @@ struct Params { levels: f32, ink: f32 }fn effect(uv: vec2<f32>) -> vec4<f32> {let c = sample(uv);let levels = max(round(params.levels), 2.0);- let flat = floor(c.rgb * levels) / (levels - 1.0);+ // White is the top band; light past it is left past it, not stretched.+ let bands = min(floor(c.rgb * levels), vec3<f32>(levels - 1.0)) / (levels - 1.0);+ let flat = select(bands, c.rgb, c.rgb > vec3<f32>(1.0));let ink = edge_at(uv) * params.ink / 100.0;return vec4<f32>(flat * (1.0 - ink), c.a);}diff --git a/src/crates/concat-effects/packages/concat.rgb-split-wipe/effect.wgsl b/src/crates/concat-effects/packages/concat.rgb-split-wipe/effect.wgslindex 0eab8194..8863b4ed 100644--- a/src/crates/concat-effects/packages/concat.rgb-split-wipe/effect.wgsl+++ b/src/crates/concat-effects/packages/concat.rgb-split-wipe/effect.wgsl@@ -8,13 +8,13 @@ fn transition(uv: vec2<f32>, progress: f32) -> vec4<f32> {from_at(vec2<f32>(uv.x + k, uv.y)).r,from_at(uv).g,from_at(vec2<f32>(uv.x - k, uv.y)).b,- 1.0,+ from_at(uv).a,);let b = vec4<f32>(to_at(vec2<f32>(uv.x - k, uv.y)).r,to_at(uv).g,to_at(vec2<f32>(uv.x + k, uv.y)).b,- 1.0,+ to_at(uv).a,);return mix(a, b, smoothstep(0.0, 1.0, progress));}diff --git a/src/crates/concat-effects/packages/concat.shape-wipe/effect.wgsl b/src/crates/concat-effects/packages/concat.shape-wipe/effect.wgslindex 1a9d4a85..576d43f8 100644--- a/src/crates/concat-effects/packages/concat.shape-wipe/effect.wgsl+++ b/src/crates/concat-effects/packages/concat.shape-wipe/effect.wgsl@@ -24,7 +24,11 @@ fn star_d(p: vec2<f32>) -> f32 {fn transition(uv: vec2<f32>, progress: f32) -> vec4<f32> {let p = smoothstep(0.0, 1.0, progress);- let c = (uv - vec2<f32>(0.5)) * 2.0;+ // The shapes in units of half the frame's shorter side, so a circle is+ // round on any frame; `reach` is how far out its corners are.+ let unit = 0.5 * min(frame.size.x, frame.size.y);+ let c = (uv - vec2<f32>(0.5)) * frame.size / unit;+ let reach = length(frame.size) / (2.0 * unit);var d: f32;if (params.shape < 0.5) {d = length(c);@@ -33,7 +37,7 @@ fn transition(uv: vec2<f32>, progress: f32) -> vec4<f32> {} else {d = star_d(c);}- let threshold = p * 3.0 - 1.0;+ let threshold = p * (reach + 1.6) - 1.0;let soft = max(params.softness * 0.01, 0.02) * 1.5;let m = smoothstep(threshold - soft, threshold + soft, d);return mix(to_at(uv), from_at(uv), m);diff --git a/src/crates/concat-effects/packages/concat.shape-wipe/fixtures.toml b/src/crates/concat-effects/packages/concat.shape-wipe/fixtures.tomlindex 1d5620fc..4633e847 100644--- a/src/crates/concat-effects/packages/concat.shape-wipe/fixtures.toml+++ b/src/crates/concat-effects/packages/concat.shape-wipe/fixtures.toml@@ -22,4 +22,4 @@ at = "max"input = [0.8, 0.5, 0.3, 1]to = [0.05, 0.15, 0.4, 1]progress = 0.37-expect = [0.25342, 0.245, 0.37256, 1]+expect = [0.25195, 0.24426, 0.3728, 1]diff --git a/src/crates/concat-effects/packages/concat.spin/effect.wgsl b/src/crates/concat-effects/packages/concat.spin/effect.wgslindex 3e4672df..800cf6a7 100644--- a/src/crates/concat-effects/packages/concat.spin/effect.wgsl+++ b/src/crates/concat-effects/packages/concat.spin/effect.wgsl@@ -4,12 +4,15 @@ fn in_bounds(uv: vec2<f32>) -> bool {return uv.x >= 0.0 && uv.x <= 1.0 && uv.y >= 0.0 && uv.y <= 1.0;}+/// Where `uv` was before the picture turned by `angle` and grew by `scale`+/// about its centre. The turn is taken in pixels, so a frame wider than it+/// is tall turns rigidly rather than shearing.fn spin_uv(uv: vec2<f32>, angle: f32, scale: f32) -> vec2<f32> {- let c = uv - vec2<f32>(0.5);+ let c = (uv - vec2<f32>(0.5)) * frame.size;let s = sin(angle);let co = cos(angle);let r = vec2<f32>(c.x * co - c.y * s, c.x * s + c.y * co) / max(scale, 0.0001);- return r + vec2<f32>(0.5);+ return r / frame.size + vec2<f32>(0.5);}fn transition(uv: vec2<f32>, progress: f32) -> vec4<f32> {diff --git a/src/crates/concat-effects/packages/concat.swirl/effect.wgsl b/src/crates/concat-effects/packages/concat.swirl/effect.wgslindex 1e5e0a6f..cd39ac38 100644--- a/src/crates/concat-effects/packages/concat.swirl/effect.wgsl+++ b/src/crates/concat-effects/packages/concat.swirl/effect.wgsl@@ -1,12 +1,14 @@struct Params { twist: f32 }+/// Where `uv` was before the twist. Taken in pixels, so the swirl is round+/// on any frame; its reach is measured in heights of the frame.fn swirl_uv(uv: vec2<f32>, amount: f32) -> vec2<f32> {- let c = uv - vec2<f32>(0.5);- let d = length(c);+ let c = (uv - vec2<f32>(0.5)) * frame.size;+ let d = length(c) / frame.size.y;let a = amount * (1.0 - smoothstep(0.0, 0.7, d));let s = sin(a);let co = cos(a);- return vec2<f32>(c.x * co - c.y * s, c.x * s + c.y * co) + vec2<f32>(0.5);+ return vec2<f32>(c.x * co - c.y * s, c.x * s + c.y * co) / frame.size + vec2<f32>(0.5);}// The twist peaks at the middle of the cut and resolves at both ends.diff --git a/src/crates/concat-effects/src/shader.rs b/src/crates/concat-effects/src/shader.rsindex 6ed7e3cd..07bd5d13 100644--- a/src/crates/concat-effects/src/shader.rs+++ b/src/crates/concat-effects/src/shader.rs@@ -386,10 +386,13 @@ fn film_curve(rgb: vec3<f32>, toe: f32, shoulder: f32) -> vec3<f32> {}/// Every hue turned by `degrees`, brightness held: a rotation in the-/// YIQ plane, the same for every pixel.+/// YIQ plane, the same for every pixel. YIQ is built on Rec. 601's luma,+/// not `luma`'s Rec. 709: its rows and their inverse only undo each other+/// with the weights they were made with, so a turn of nothing is the+/// colour it was.fn hue_rotate(rgb: vec3<f32>, degrees: f32) -> vec3<f32> {let a = radians(degrees);- let y = luma(rgb);+ let y = dot(rgb, vec3<f32>(0.299, 0.587, 0.114));let i = dot(rgb, vec3<f32>(0.596, -0.274, -0.322));let q = dot(rgb, vec3<f32>(0.211, -0.523, 0.312));let i2 = i * cos(a) - q * sin(a);@@ -422,12 +425,13 @@ fn halation(uv: vec2<f32>, rgb: vec3<f32>, threshold: f32, radius: f32, tint: vevar sum = vec3<f32>(0.0);for (var y: i32 = -2; y <= 2; y++) {for (var x: i32 = -2; x <= 2; x++) {- let s = sample(uv + vec2<f32>(f32(x), f32(y)) * t).rgb;- let bright = smoothstep(threshold, 1.0, luma(s));- sum += s * bright;+ let s = sample_premultiplied(uv + vec2<f32>(f32(x), f32(y)) * t);+ let bright = smoothstep(threshold, 1.0, luma(s.rgb / max(s.a, 1e-6)));+ sum += s.rgb * bright;}}- let glow = clamp(sum / 25.0 * tint * amount, vec3<f32>(0.0), vec3<f32>(1.0));+ // Light past white glows past white: only the floor is held.+ let glow = max(sum / 25.0 * tint * amount, vec3<f32>(0.0));return screen(rgb, glow);}@@ -471,16 +475,18 @@ fn skin_mask(rgb: vec3<f32>) -> f32 {}/// The layer averaged over a square of taps `radius` pixels across: a-/// bloom, a soft denoise, the blur an unsharp mask subtracts.+/// bloom, a soft denoise, the blur an unsharp mask subtracts. The taps are+/// summed premultiplied, so a transparent pixel's colour never bleeds into+/// the picture beside it, and the average is handed back straight.fn soften(uv: vec2<f32>, radius: f32) -> vec3<f32> {let t = texel() * radius * 0.5;- var sum = vec3<f32>(0.0);+ var sum = vec4<f32>(0.0);for (var y: i32 = -2; y <= 2; y++) {for (var x: i32 = -2; x <= 2; x++) {- sum += sample(uv + vec2<f32>(f32(x), f32(y)) * t).rgb;+ sum += sample_premultiplied(uv + vec2<f32>(f32(x), f32(y)) * t);}}- return sum / 25.0;+ return sum.rgb / max(sum.a, 1e-6);}/// Grain: noise that changes every frame, centred on zero, `amount` as adiff --git a/src/crates/concat-render/src/gpu/tests.rs b/src/crates/concat-render/src/gpu/tests.rsindex 612a3aa6..37f773c1 100644--- a/src/crates/concat-render/src/gpu/tests.rs+++ b/src/crates/concat-render/src/gpu/tests.rs@@ -1113,6 +1113,46 @@ fn every_package_probe_holds() {assert!(failures.is_empty(), "\n{}", failures.join("\n"));}+/// The prelude's hue turn leaves a colour as it was when it turns it by+/// nothing - the identity every HSL band rests on.+#[test]+fn a_hue_turn_of_nothing_is_the_colour_it_was() {+ let Some(mut gpu) = gpu() else { return };+ const TURN: &str = "fn effect(uv: vec2<f32>) -> vec4<f32> { let c = sample(uv); return vec4<f32>(hue_rotate(c.rgb, 0.0), c.a); }";+ let pass = package("test.turn", TURN, "", &[], 1.0);+ for colour in [+ [0.8, 0.05, 0.05, 1.0],+ [0.05, 0.6, 0.1, 1.0],+ [0.1, 0.2, 0.9, 1.0],+ ] {+ let got = gpu+ .probe(std::slice::from_ref(&pass), colour, 8, 0.0)+ .expect("reads back");+ // Half floats through the display encoding and back: a hundredth+ // of a channel, where the turn that was wrong moved one by 0.09.+ assert!(near(got, colour, 0.01), "{colour:?} came back {got:?}");+ }+}++/// Halation's glow is not held at white: a brighter highlight lights the+/// picture around it more.+#[test]+fn halation_glows_brighter_from_light_past_white() {+ let Some(mut gpu) = gpu() else { return };+ const GLOW: &str = "fn effect(uv: vec2<f32>) -> vec4<f32> { let c = sample(uv); return vec4<f32>(halation(uv, vec3<f32>(0.0), 0.5, 4.0, vec3<f32>(1.0), 1.0), c.a); }";+ let pass = package("test.glow", GLOW, "", &[], 1.0);+ let white = gpu+ .probe(std::slice::from_ref(&pass), [1.0, 1.0, 1.0, 1.0], 8, 0.0)+ .expect("reads back");+ let past = gpu+ .probe(&[pass], [4.0, 4.0, 4.0, 1.0], 8, 0.0)+ .expect("reads back");+ assert!(+ past[0] > white[0] * 1.5,+ "white glows {white:?}, four times white {past:?}"+ );+}+/// A format 2 stack hands its light on unclipped: four times the light and/// a quarter of it again is the picture it was, a highlight far above/// white in between.