Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

feat: add Corona and Halation custom effects

robbertcalliso-code13f5adb7bf9d
diff --git a/src/crates/concat-effects/packages/lab.corona/effect.toml b/src/crates/concat-effects/packages/lab.corona/effect.toml
new file mode 100644
index 00000000..1be1f6b6
--- /dev/null
+++ b/src/crates/concat-effects/packages/lab.corona/effect.toml
@@ -0,0 +1,60 @@
+format = 2
+
+[effect]
+id = "lab.corona"
+name = "Corona"
+version = 1
+kind = "effect"
+category = "Film"
+order = 151
+intensity = "amount"
+aliases = ["corona"]
+description = "A cool blue-white corona gathered off the picture's blown highlights by a golden-angle spiral blur - built from nothing, not a port of the stock halation."
+
+[[param]]
+key = "threshold"
+label = "Threshold"
+min = 20
+max = 95
+default = 60
+step = 1
+unit = "%"
+
+[[param]]
+key = "radius"
+label = "Radius"
+min = 4
+max = 60
+default = 18
+step = 1
+unit = "%"
+
+[[param]]
+key = "amount"
+label = "Amount"
+min = 0
+max = 100
+default = 55
+step = 1
+unit = "%"
+
+[[param]]
+key = "cool"
+label = "Coolness"
+min = 0
+max = 100
+default = 70
+step = 1
+unit = "%"
+
+[wgsl]
+entry = "effect.wgsl"
+
+# The corona is one blur pass, half the layer's pixels on each axis,
+# read back by the final pass.
+[[wgsl.pass]]
+target = "bloom"
+shrink = ["2", "2"]
+
+[card]
+params = { threshold = 45, amount = 80 }
diff --git a/src/crates/concat-effects/packages/lab.corona/effect.wgsl b/src/crates/concat-effects/packages/lab.corona/effect.wgsl
new file mode 100644
index 00000000..4b2157ac
--- /dev/null
+++ b/src/crates/concat-effects/packages/lab.corona/effect.wgsl
@@ -0,0 +1,72 @@
+// Corona: a cool blue-white glow gathered off the picture's blown
+// highlights. Where halation is light that went through the emulsion and
+// bounced off the backing, this is the opposite fiction: light too bright
+// for the frame spills outward as a cold corona, widened by one blur pass
+// of twelve taps laid on a golden-angle spiral.
+//
+// A flat picture survives the normalised spiral unchanged - the weights
+// sum to themselves - so on flat input the pass returns the gate's own
+// value and fixtures.toml is closed form.
+
+// The two things a package declares: its knobs, in the manifest's order,
+// and `fn effect`. Everything else is the host's.
+struct Params { threshold: f32, radius: f32, amount: f32, cool: f32 }
+
+/// A tap's Gaussian weight at a pixel distance under a sigma in pixels.
+fn spike(d: f32, s: f32) -> f32 {
+ return exp(-d * d / (2.0 * s * s));
+}
+
+/// The layer's light where it is blown, in the display encoding, gated
+/// above the threshold and premultiplied by alpha so a clear pixel adds
+/// none. Straight colour out; the corona takes its hue later.
+fn gate_at(uv: vec2<f32>) -> vec4<f32> {
+ let c = sample(uv);
+ let d = to_display(max(c.rgb, vec3<f32>(0.0)));
+ let level = luma(d) * max(c.a, 0.0);
+ let th = params.threshold / 100.0;
+ let opened = smoothstep(th, min(th + 0.3, 1.0), level);
+ return vec4<f32>(d * opened * max(c.a, 0.0), c.a);
+}
+
+/// The blur pass itself: twelve taps on a golden-angle spiral, denser at
+/// the middle, every tap weighed by how far it strayed. The reach is the
+/// radius as a share of the picture, so a corona reads the same on a card
+/// and a 4K cut.
+fn bloom(uv: vec2<f32>) -> vec4<f32> {
+ let size = frame.size;
+ if (size.x < 1.0) {
+ return gate_at(uv);
+ }
+ let sigma = params.radius / 100.0 * max(size.x, size.y) * 0.5;
+ var sum = vec4<f32>(0.0);
+ var total = 0.0;
+ for (var i = 0; i < 12; i++) {
+ let fi = f32(i) + 0.5;
+ let ang = fi * 2.399963229728653;
+ let rad = sigma * sqrt(fi / 12.0) * 2.0;
+ let dir = vec2<f32>(cos(ang), sin(ang));
+ let w = spike(rad, sigma);
+ sum += gate_at(uv + dir * rad / size) * w;
+ total += w;
+ }
+ if (total <= 0.0) {
+ return gate_at(uv);
+ }
+ return sum / total;
+}
+
+/// The corona's colour at a coolness: zero a plain white spill, one the
+/// icy blue of a lamp seen through a cold window.
+fn corona_colour(k: f32) -> vec3<f32> {
+ return mix(vec3<f32>(1.0, 1.0, 1.0), vec3<f32>(0.55, 0.78, 1.0), clamp(k / 100.0, 0.0, 1.0));
+}
+
+fn effect(uv: vec2<f32>) -> vec4<f32> {
+ let c = sample(uv);
+ let base = to_display(c.rgb);
+ let glow = bloom_at(uv);
+ let bloom_level = luma(max(glow.rgb, vec3<f32>(0.0)));
+ let lit = base + corona_colour(params.cool) * bloom_level * (params.amount / 100.0) * 1.8;
+ return vec4<f32>(from_display(lit), c.a);
+}
diff --git a/src/crates/concat-effects/packages/lab.corona/fixtures.toml b/src/crates/concat-effects/packages/lab.corona/fixtures.toml
new file mode 100644
index 00000000..c8a68697
--- /dev/null
+++ b/src/crates/concat-effects/packages/lab.corona/fixtures.toml
@@ -0,0 +1,49 @@
+# A flat picture survives the normalised spiral unchanged, so on a flat
+# input the whole effect is closed form and these are pinned from a model
+# of the shader in doubles. What they hold:
+#
+# - a grey under the threshold crowns not at all, at any radius;
+# - a white at the defaults climbs past white, most in blue, because the
+# corona is cool and lands in the display encoding;
+# - a blown highlight keeps its own light and adds the corona onto it;
+# - amount at zero is the picture as it came;
+# - alpha premultiplies the gate, so a half-clear pixel may fall under
+# the threshold entirely and pass through untouched.
+
+[[probe]]
+name = "default, a mid grey under the threshold"
+input = [0.18, 0.18, 0.18, 1]
+expect = [0.18, 0.18, 0.18, 1]
+
+[[probe]]
+name = "default, a white"
+input = [1, 1, 1, 1]
+expect = [3.46413, 4.30694, 5.21492, 1]
+
+[[probe]]
+name = "default, a blown highlight"
+input = [4, 1, 0.05, 1]
+expect = [9.34714, 4.86741, 2.20641, 1]
+
+[[probe]]
+name = "default, half transparent"
+input = [1, 0.6, 0.2, 0.5]
+expect = [1, 0.6, 0.2, 0.5]
+
+[[probe]]
+name = "min, a white, amount at zero"
+at = "min"
+input = [1, 1, 1, 1]
+expect = [1, 1, 1, 1]
+
+[[probe]]
+name = "max, a mid grey under the threshold"
+at = "max"
+input = [0.18, 0.18, 0.18, 1]
+expect = [0.18, 0.18, 0.18, 1]
+
+[[probe]]
+name = "max, a white"
+at = "max"
+input = [1, 1, 1, 1]
+expect = [5.21492, 8.2081, 11.8353, 1]
diff --git a/src/crates/concat-effects/packages/lab.halation/effect.toml b/src/crates/concat-effects/packages/lab.halation/effect.toml
new file mode 100644
index 00000000..636fdf45
--- /dev/null
+++ b/src/crates/concat-effects/packages/lab.halation/effect.toml
@@ -0,0 +1,68 @@
+format = 2
+
+[effect]
+id = "lab.halation"
+name = "Halation"
+version = 2
+kind = "effect"
+category = "Film"
+order = 150
+intensity = "amount"
+aliases = ["lab-halation"]
+description = "The red-orange halo film lays around its blown highlights, where light passes through the emulsion, scatters off the backing and comes back."
+
+[[param]]
+key = "threshold"
+label = "Threshold"
+min = 20
+max = 95
+default = 55
+step = 1
+unit = "%"
+
+[[param]]
+key = "radius"
+label = "Radius"
+min = 4
+max = 60
+default = 22
+step = 1
+unit = "%"
+
+[[param]]
+key = "amount"
+label = "Amount"
+min = 0
+max = 100
+default = 45
+step = 1
+unit = "%"
+
+[[param]]
+key = "tint"
+label = "Tint"
+min = -100
+max = 100
+default = 0
+step = 1
+unit = "%"
+# A parameter carries no description field of its own (Param has no such
+# key, and the manifest denies unknown fields): negative is the deep red of
+# a dense negative, positive the orange of a print, zero the red-orange of
+# the stock.
+
+[wgsl]
+entry = "effect.wgsl"
+
+# The halo is a wide Gaussian over the bright parts, drawn across and then
+# down at a quarter of the layer's pixels.
+[[wgsl.pass]]
+target = "across"
+shrink = ["4", "1"]
+
+[[wgsl.pass]]
+target = "down"
+shrink = ["4", "4"]
+
+[card]
+params = { threshold = 38, amount = 75 }
\ No newline at end of file
diff --git a/src/crates/concat-effects/packages/lab.halation/effect.wgsl b/src/crates/concat-effects/packages/lab.halation/effect.wgsl
new file mode 100644
index 00000000..d6818216
--- /dev/null
+++ b/src/crates/concat-effects/packages/lab.halation/effect.wgsl
@@ -0,0 +1,112 @@
+// Halation: the red-orange halo film lays around its blown highlights. Light
+// passes through the emulsion, scatters off the backing and comes back, so
+// the halo belongs to the picture's brightest parts and is drawn a little
+// wider than they are - never a glow over the whole frame.
+//
+// The passes carry light, not colour: `across` and `down` each take the
+// picture's own light, weighted above the threshold and premultiplied by
+// alpha, and blur it. The last pass reads that bloom's luminance and lays
+// the tint on with it, graded in the display encoding, where the halo of a
+// film burn is judged and where 1.0 is white.
+//
+// A flat picture survives a normalised convolution unchanged, so on flat
+// input `down_at` is `source_at` - which is what `fixtures.toml` pins.
+
+// A WGSL package declares two things and nothing else: the `Params` struct
+// whose fields are its knobs, in the manifest's order, and `fn effect`. The
+// host reads the struct back through naga for each field's offset, so the
+// order here is the layout there.
+struct Params { threshold: f32, radius: f32, amount: f32, tint: f32 }
+
+/// How far the taps reach, in sigmas. The Gaussian's width is `params.radius`
+/// as a share of the layer, so a halo reads the same on a phone and a 4K cut.
+const TAU: f32 = 3.14159265;
+
+fn weight(d: f32, s: f32) -> f32 {
+ return exp(-d * d / (2.0 * s * s));
+}
+
+/// The picture's own light where it is bright, premultiplied by alpha so a
+/// clear pixel adds none, with colour kept: the halo takes its hue later.
+fn source_at(uv: vec2<f32>) -> vec4<f32> {
+ let c = sample(uv);
+ let d = to_display(max(c.rgb, vec3<f32>(0.0)));
+ let level = luma(d) * max(c.a, 0.0);
+ let th = params.threshold / 100.0;
+ let passed = smoothstep(th, min(th + 0.25, 1.0), level);
+ return vec4<f32>(c.rgb * passed * c.a, c.a);
+}
+
+/// `source_at`'s light weighed along its row about `uv`, two pixels to a
+/// fetch. The screen distance, so the scaling trap either way is caught in
+/// the middle, where `bloom_texel` is the picture's own pixel.
+fn across(uv: vec2<f32>) -> vec4<f32> {
+ let width = frame.size.x;
+ if (width < 1.0) {
+ return source_at(uv);
+ }
+ let screen = length((uv - vec2<f32>(0.5)) * vec2<f32>(2.0));
+ let sigma = params.radius / 100.0 * screen * frame.size.y / TAU;
+ let centre = uv.x * width;
+ let first = floor(centre - TAU * sigma - 0.5) + 0.5;
+ let pairs = i32(ceil(TAU * sigma)) + 1;
+ var sum = vec4<f32>(0.0);
+ var total = 0.0;
+ for (var i = 0; i < pairs; i++) {
+ let a = first + f32(2 * i);
+ let wa = weight(a - centre, sigma);
+ let wb = weight(a + 1.0 - centre, sigma);
+ let w = wa + wb;
+ if (w > 0.0) {
+ sum += source_at(vec2<f32>((a + wb / w) / width, uv.y)) * w;
+ total += w;
+ }
+ }
+ if (total <= 0.0) {
+ return source_at(uv);
+ }
+ return sum / total;
+}
+
+/// `across` weighed down its column about `uv`, in its own pixels.
+fn down(uv: vec2<f32>) -> vec4<f32> {
+ let rows = 1.0 / across_texel().y;
+ let screen = length((uv - vec2<f32>(0.5)) * vec2<f32>(2.0));
+ let sigma = params.radius / 100.0 * screen * 2.0;
+ let centre = uv.y * rows;
+ let first = floor(centre - TAU * sigma - 0.5) + 0.5;
+ let pairs = i32(ceil(TAU * sigma)) + 1;
+ var sum = vec4<f32>(0.0);
+ var total = 0.0;
+ for (var i = 0; i < pairs; i++) {
+ let a = first + f32(2 * i);
+ let wa = weight(a - centre, sigma);
+ let wb = weight(a + 1.0 - centre, sigma);
+ let w = wa + wb;
+ if (w > 0.0) {
+ sum += across_at(vec2<f32>(uv.x, (a + wb / w) / rows)) * w;
+ total += w;
+ }
+ }
+ if (total <= 0.0) {
+ return across_at(uv);
+ }
+ return sum / total;
+}
+
+/// The halo's colour at a tint: negative the deep red of a dense negative,
+/// positive the orange of a print, zero the red-orange of the stock.
+fn halation_tint(t: f32) -> vec3<f32> {
+ // LAB EXPERIMENT: red-orange stock swapped for a cyan halo, to prove
+ // the package's own WGSL is what runs, not the built-in's.
+ _ = t;
+ return vec3<f32>(0.15, 0.75, 1.0);
+}
+
+fn effect(uv: vec2<f32>) -> vec4<f32> {
+ let c = sample(uv);
+ let base = to_display(c.rgb);
+ let bloom = luma(down_at(uv).rgb);
+ let lit = base + halation_tint(params.tint) * bloom * (params.amount / 100.0) * 1.6;
+ return vec4<f32>(from_display(lit), c.a);
+}
\ No newline at end of file
diff --git a/src/crates/concat-effects/packages/lab.halation/fixtures.toml b/src/crates/concat-effects/packages/lab.halation/fixtures.toml
new file mode 100644
index 00000000..9e7e1a77
--- /dev/null
+++ b/src/crates/concat-effects/packages/lab.halation/fixtures.toml
@@ -0,0 +1,48 @@
+# A flat picture survives both Gaussian passes unchanged, so on a flat
+# input the whole effect is closed form and these are pinned from a
+# model of the shader in doubles. What they hold:
+#
+# - a grey under the threshold haloes not at all, at any radius;
+# - a white at the defaults lays red-orange light on itself and
+# climbs past white, because halation lands in the display encoding;
+# - a blown highlight keeps its level, its colour taking the halo;
+# - amount at zero is the picture as it came;
+# - alpha does not fade the halo - it is the picture's own light.
+
+[[probe]]
+name = "default, a mid grey under the threshold"
+input = [0.18, 0.18, 0.18, 1]
+expect = [0.18, 0.18, 0.18, 1]
+
+[[probe]]
+name = "default, a white"
+input = [1, 1, 1, 1]
+expect = [3.67509, 1.88533, 1.29911, 1]
+
+[[probe]]
+name = "default, a blown highlight"
+input = [4, 1, 0.05, 1]
+expect = [12.9995, 2.53962, 0.161479, 1]
+
+[[probe]]
+name = "default, half transparent"
+input = [1, 0.6, 0.2, 0.5]
+expect = [1, 0.6, 0.2, 0.5]
+
+[[probe]]
+name = "min, a white, amount at zero"
+at = "min"
+input = [1, 1, 1, 1]
+expect = [1, 1, 1, 1]
+
+[[probe]]
+name = "max, a mid grey under the threshold"
+at = "max"
+input = [0.18, 0.18, 0.18, 1]
+expect = [0.18, 0.18, 0.18, 1]
+
+[[probe]]
+name = "max, a white"
+at = "max"
+input = [1, 1, 1, 1]
+expect = [9.90686, 6.29247, 2.43133, 1]