Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Add GPU color grading controls

Bittid1870801f375
diff --git a/src-tauri/src/project/commands/clips.rs b/src-tauri/src/project/commands/clips.rs
index 7d1fe9a..fe7a44c 100644
--- a/src-tauri/src/project/commands/clips.rs
+++ b/src-tauri/src/project/commands/clips.rs
@@ -152,6 +152,9 @@ pub(super) fn apply(
blur: None,
color_correction: None,
vignette: None,
+ creative: None,
+ curves: None,
+ color_wheels: None,
lut: None,
transition: None,
});
diff --git a/src-tauri/src/project/timeline.rs b/src-tauri/src/project/timeline.rs
index 5275e42..d3ae0c6 100644
--- a/src-tauri/src/project/timeline.rs
+++ b/src-tauri/src/project/timeline.rs
@@ -46,10 +46,16 @@ pub(crate) struct TimelineClip {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) color_correction: Option<ClipColorCorrection>,
#[serde(default, skip_serializing_if = "Option::is_none")]
- pub(crate) vignette: Option<ClipAmount>,
+ pub(crate) vignette: Option<ClipVignette>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) lut: Option<ClipLut>,
#[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) creative: Option<ClipCreative>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) curves: Option<ClipCurves>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) color_wheels: Option<ClipColorWheels>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) transition: Option<ClipTransition>,
}
@@ -100,6 +106,18 @@ pub(crate) struct ClipBlur {
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub(crate) struct ClipColorCorrection {
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) temperature: Option<f64>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) tint: Option<f64>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) highlights: Option<f64>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) shadows: Option<f64>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) whites: Option<f64>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) blacks: Option<f64>,
pub(crate) exposure: f64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) brightness: Option<f64>,
@@ -144,3 +162,72 @@ pub(crate) struct ClipTransition {
pub(crate) fn default_clip_status() -> String {
"approved".into()
}
+
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub(crate) struct ClipVignette {
+ pub(crate) amount: f64,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) midpoint: Option<f64>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) roundness: Option<f64>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) feather: Option<f64>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) enabled: Option<bool>,
+}
+
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub(crate) struct ClipCreative {
+ pub(crate) look: String,
+ pub(crate) intensity: f64,
+ pub(crate) faded_film: f64,
+ pub(crate) sharpen: f64,
+ pub(crate) vibrance: f64,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) enabled: Option<bool>,
+}
+
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub(crate) struct ClipCurves {
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) rgb: Option<Vec<[f64; 2]>>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) red: Option<Vec<[f64; 2]>>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) green: Option<Vec<[f64; 2]>>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) blue: Option<Vec<[f64; 2]>>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) hue_vs_sat: Option<Vec<[f64; 2]>>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) hue_vs_hue: Option<Vec<[f64; 2]>>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) hue_vs_luma: Option<Vec<[f64; 2]>>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) luma_vs_sat: Option<Vec<[f64; 2]>>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) sat_vs_sat: Option<Vec<[f64; 2]>>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) enabled: Option<bool>,
+}
+
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub(crate) struct ClipWheel {
+ pub(crate) x: f64,
+ pub(crate) y: f64,
+ pub(crate) lightness: f64,
+}
+
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub(crate) struct ClipColorWheels {
+ pub(crate) shadows: ClipWheel,
+ pub(crate) midtones: ClipWheel,
+ pub(crate) highlights: ClipWheel,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) enabled: Option<bool>,
+}
diff --git a/src-tauri/src/project/validation/timeline.rs b/src-tauri/src/project/validation/timeline.rs
index a2beddd..5140563 100644
--- a/src-tauri/src/project/validation/timeline.rs
+++ b/src-tauri/src/project/validation/timeline.rs
@@ -74,9 +74,13 @@ pub(super) fn validate(config: &mut ProjectConfig) -> Result<(), String> {
|| clip
.vignette
.as_ref()
- .is_some_and(|v| !within(v.amount, 0.0, 100.0))
+ .is_some_and(|v| !within(v.amount, -100.0, 100.0)
+ || v.midpoint.is_some_and(|n| !within(n, 0.0, 100.0))
+ || v.roundness.is_some_and(|n| !within(n, -100.0, 100.0))
+ || v.feather.is_some_and(|n| !within(n, 0.0, 100.0)))
|| clip.color_correction.as_ref().is_some_and(|v| {
- !within(v.exposure, -4.0, 4.0)
+ [v.temperature, v.tint, v.highlights, v.shadows, v.whites, v.blacks].iter().flatten().any(|n| !within(*n, -100.0, 100.0))
+ || !within(v.exposure, -4.0, 4.0)
|| v.brightness.is_some_and(|value| !within(value, -100.0, 100.0))
|| !within(v.contrast, -100.0, 100.0)
|| !within(v.saturation, 0.0, 200.0)
@@ -84,6 +88,35 @@ pub(super) fn validate(config: &mut ProjectConfig) -> Result<(), String> {
{
return Err(format!("Clip '{}' has invalid video effects.", clip.id));
}
+ if let Some(v) = &clip.creative {
+ if !matches!(v.look.as_str(), "None" | "Teal & Orange" | "Warm Film" | "Cool Blue" | "Bleach Bypass" | "Faded Matte" | "Monochrome" | "Golden Hour" | "Night")
+ || !within(v.intensity, 0.0, 100.0) || !within(v.faded_film, 0.0, 100.0)
+ || !within(v.sharpen, 0.0, 200.0) || !within(v.vibrance, -100.0, 100.0) {
+ return Err(format!("Clip '{}' has invalid Creative settings.", clip.id));
+ }
+ }
+ if let Some(v) = &clip.color_wheels {
+ for wheel in [&v.shadows, &v.midtones, &v.highlights] {
+ if !within(wheel.x, -1.0, 1.0) || !within(wheel.y, -1.0, 1.0)
+ || wheel.x.hypot(wheel.y) > 1.000001 || !within(wheel.lightness, -100.0, 100.0) {
+ return Err(format!("Clip '{}' has invalid Color Wheels settings.", clip.id));
+ }
+ }
+ }
+ if let Some(v) = &clip.curves {
+ for (curve, hue) in [(&v.rgb, false), (&v.red, false), (&v.green, false), (&v.blue, false),
+ (&v.hue_vs_sat, true), (&v.hue_vs_hue, true), (&v.hue_vs_luma, true), (&v.luma_vs_sat, false), (&v.sat_vs_sat, false)] {
+ if let Some(points) = curve {
+ if !(2..=32).contains(&points.len())
+ || points.iter().flatten().any(|n| !within(*n, 0.0, 1.0))
+ || points[0][0] != 0.0 || points[points.len() - 1][0] != 1.0
+ || points.windows(2).any(|p| p[1][0] - p[0][0] < 0.001)
+ || (hue && points[0][1] != points[points.len() - 1][1]) {
+ return Err(format!("Clip '{}' has invalid Curves settings.", clip.id));
+ }
+ }
+ }
+ }
if let Some(lut) = &clip.lut {
if !within(lut.intensity, 0.0, 100.0) {
return Err(format!("Clip '{}' has invalid LUT intensity.", clip.id));
diff --git a/src/components/workspace/ClipEffects.test.tsx b/src/components/workspace/ClipEffects.test.tsx
index 6bdd923..d30e1ae 100644
--- a/src/components/workspace/ClipEffects.test.tsx
+++ b/src/components/workspace/ClipEffects.test.tsx
@@ -3,7 +3,7 @@ import { act, cleanup, fireEvent, render, screen, within, waitFor } from "@testi
import { useState } from "react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { timelineClipSchema, type TimelineClip } from "../../lib/project";
-import { parseCube } from "../../lib/effectSettings";
+import { DEFAULT_CREATIVE, DEFAULT_WHEELS, parseCube } from "../../lib/effectSettings";
import { ClipEffects } from "./ClipEffects";
vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));
@@ -54,8 +54,11 @@ describe("clip effects", () => {
{ name: "Chroma key", patch: { chromaKey: { color: "#123456", tolerance: 43 } } },
{ name: "Sharpen", patch: { sharpen: { amount: 125 } } },
{ name: "Gaussian blur", patch: { blur: { radius: 8.5 } } },
- { name: "Colour correction", patch: { colorCorrection: { exposure: -1.2, brightness: 35, contrast: 20, saturation: 75 } } },
+ { name: "Basic Corrections", patch: { colorCorrection: { exposure: -1.2, brightness: 35, contrast: 20, saturation: 75 } } },
{ name: "Vignette", patch: { vignette: { amount: 75 } } },
+ { name: "Creative", patch: { creative: { ...DEFAULT_CREATIVE, look: "Night", intensity: 45 } } },
+ { name: "Curves", patch: { curves: { rgb: [[0, 0], [.4, .6], [1, 1]], enabled: false } } },
+ { name: "Color Wheels", patch: { colorWheels: { ...DEFAULT_WHEELS, shadows: { x: .2, y: -.4, lightness: 10 } } } },
{ name: "3D LUT", patch: { lut: { intensity: 45, table: parseCube(CUBE, "identity.cube") } } },
] satisfies { name: string; patch: Partial<TimelineClip> }[])("copies $name settings to another clip as one independent edit", ({ name, patch }) => {
const onChange = vi.fn();
@@ -148,7 +151,7 @@ describe("clip effects", () => {
it("adds, edits and removes effects independently", () => {
render(<Harness />);
- for (const name of ["Sharpen", "Gaussian blur", "Colour correction", "Vignette"]) add(name);
+ for (const name of ["Sharpen", "Gaussian blur", "Basic Corrections", "Vignette"]) add(name);
fireEvent.change(screen.getByLabelText("Sharpen amount"), { target: { value: "120" } });
fireEvent.change(screen.getByLabelText("Blur radius"), { target: { value: "6.5" } });
fireEvent.change(screen.getByLabelText("Exposure"), { target: { value: "-1.2" } });
@@ -178,6 +181,62 @@ describe("clip effects", () => {
expect(screen.queryByLabelText("Vignette amount")).toBeNull();
});
+ it("edits new basic, Creative and vignette controls", () => {
+ render(<Harness />);
+ for (const name of ["Basic Corrections", "Creative", "Vignette"]) add(name);
+ for (const label of ["Temperature", "Tint", "Highlights", "Shadows", "Whites", "Blacks"]) {
+ fireEvent.change(screen.getByLabelText(label), { target: { value: "25" } });
+ expect(saved().colorCorrection[label.toLowerCase()]).toBe(25);
+ }
+ fireEvent.keyDown(screen.getByRole("combobox", { name: "Creative look" }), { key: "End" });
+ expect(saved().creative.look).toBe("Night");
+ for (const [label, key] of [["Creative intensity", "intensity"], ["Faded film", "fadedFilm"], ["Creative sharpen", "sharpen"], ["Vibrance", "vibrance"]]) {
+ fireEvent.change(screen.getByLabelText(label), { target: { value: "30" } });
+ expect(saved().creative[key]).toBe(30);
+ }
+ for (const key of ["amount", "midpoint", "roundness", "feather"]) {
+ fireEvent.change(screen.getByLabelText(`Vignette ${key}`), { target: { value: "20" } });
+ expect(saved().vignette[key]).toBe(20);
+ }
+ fireEvent.click(screen.getByRole("checkbox", { name: "Creative on" }));
+ fireEvent.click(screen.getByRole("button", { name: "Reset Creative" }));
+ expect(saved().creative).toEqual({ ...DEFAULT_CREATIVE, enabled: false });
+ });
+
+ it("adds, moves, removes and resets curve points with keyboard and numeric controls", () => {
+ render(<Harness />); add("Curves");
+ fireEvent.click(screen.getByRole("button", { name: "Add point" }));
+ expect(saved().curves.rgb).toEqual([[0, 0], [.5, .5], [1, 1]]);
+ fireEvent.change(screen.getByLabelText("Curve point output"), { target: { value: "75" } });
+ expect(saved().curves.rgb[1]).toEqual([.5, .75]);
+ fireEvent.keyDown(screen.getByRole("slider", { name: "RGB point 2" }), { key: "ArrowLeft", shiftKey: true });
+ expect(saved().curves.rgb[1]).toEqual([.4, .75]);
+ fireEvent.click(screen.getByRole("button", { name: "Remove point" }));
+ expect(saved().curves.rgb).toEqual([[0, 0], [1, 1]]);
+ const combo = screen.getByRole("combobox", { name: "Curve channel" });
+ for (let i = 0; i < 4; i++) fireEvent.keyDown(combo, { key: "ArrowDown" });
+ fireEvent.change(screen.getByLabelText("Curve point output"), { target: { value: "70" } });
+ expect(saved().curves.hueVsSat).toEqual([[0, .7], [1, .7]]);
+ fireEvent.click(screen.getByRole("button", { name: "Reset curve" }));
+ expect(saved().curves.hueVsSat).toEqual([[0, .5], [1, .5]]);
+ });
+
+ it("edits each wheel independently and prevents locked wheel and curve changes", () => {
+ const view = render(<Harness />); add("Color Wheels");
+ for (const name of ["Shadows", "Midtones", "Highlights"]) {
+ fireEvent.keyDown(screen.getByRole("slider", { name: `${name} color` }), { key: "ArrowRight", shiftKey: true });
+ fireEvent.change(screen.getByLabelText(`${name} lightness`), { target: { value: "-25" } });
+ expect(saved().colorWheels[name.toLowerCase()]).toEqual({ x: .1, y: 0, lightness: -25 });
+ }
+ fireEvent.keyDown(screen.getByRole("slider", { name: "Shadows color" }), { key: "Home" });
+ expect(saved().colorWheels.shadows).toEqual({ x: 0, y: 0, lightness: -25 });
+ const clip = saved(); view.unmount(); const change = vi.fn();
+ render(<ClipEffects clip={{ ...clip, curves: {} }} disabled onChange={change} />);
+ fireEvent.keyDown(screen.getByRole("slider", { name: "Shadows color" }), { key: "ArrowRight" });
+ fireEvent.keyDown(screen.getByRole("slider", { name: "RGB point 1" }), { key: "ArrowUp" });
+ expect(change).not.toHaveBeenCalled();
+ });
+
it("describes each effect in a tooltip rather than a second line", () => {
render(<Harness />);
fireEvent.click(screen.getByRole("button", { name: "Add effect" }));
diff --git a/src/components/workspace/ClipEffects.tsx b/src/components/workspace/ClipEffects.tsx
index 2861705..0c51b7f 100644
--- a/src/components/workspace/ClipEffects.tsx
+++ b/src/components/workspace/ClipEffects.tsx
@@ -1,13 +1,15 @@
import { Add16, ChevronDown12, Copy16, FolderOpen14, More14, Paste16, Reset14, Reset16 } from "../ui/icons";
import { useEffect, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
import { DEFAULT_CLIP_CHROMA_KEY, DEFAULT_CLIP_LOOK, type TimelineClip } from "../../lib/project";
-import { isEffectOn, parseCube } from "../../lib/effectSettings";
+import { CREATIVE_LOOKS, DEFAULT_CREATIVE, DEFAULT_WHEELS, isEffectOn, parseCube } from "../../lib/effectSettings";
import { readLutFile } from "../../lib/exportPipeline";
import { inTauri, pickFile } from "../../lib/nativeShell";
import { Checkbox, ComboBox, Flyout, PropRow, Slider, tooltipProps, useContextMenu } from "../ui";
+import { CurveEditor } from "./CurveEditor";
+import { GradingWheel } from "./GradingWheel";
import { ColorSwatch } from "./ColorPicker";
-type EffectId = "look" | "transition" | "chromaKey" | "sharpen" | "blur" | "colorCorrection" | "vignette" | "lut";
+type EffectId = "look" | "transition" | "chromaKey" | "sharpen" | "blur" | "colorCorrection" | "vignette" | "lut" | "creative" | "curves" | "colorWheels";
// Keep copied settings across clip selections and inspector remounts, like the
// image-node clipboard. Snapshots include bypass and embedded LUT data.
let effectClipboard: { id: EffectId; settings: NonNullable<TimelineClip[EffectId]> } | null = null;
@@ -153,22 +155,68 @@ const EFFECTS: readonly EffectDefinition[] = [
editor: ({ clip, update, disabled }) => <Param label="Radius" ariaLabel="Blur radius" value={clip.blur!.radius} max={24} step={0.5} suffix=" px" defaultValue={4} disabled={disabled} onChange={(radius) => update({ blur: { ...clip.blur!, radius } })} />,
},
{
- id: "colorCorrection", name: "Colour correction", description: "Adjust exposure, brightness, contrast and saturation",
+ id: "colorCorrection", name: "Basic Corrections", description: "White balance, exposure, tonal ranges and saturation",
defaults: { colorCorrection: { exposure: 0, brightness: 0, contrast: 0, saturation: 100 } },
editor: ({ clip, update, disabled }) => {
const color = clip.colorCorrection!;
return <>
+ {(["temperature", "tint"] as const).map((key) => <Param key={key} label={key[0].toUpperCase() + key.slice(1)} value={color[key] ?? 0} min={-100} defaultValue={0} disabled={disabled} onChange={(value) => update({ colorCorrection: { ...color, [key]: value } })} />) }
<Param label="Exposure" value={color.exposure} min={-4} max={4} step={0.1} suffix=" stops" defaultValue={0} disabled={disabled} onChange={(exposure) => update({ colorCorrection: { ...color, exposure } })} />
<Param label="Brightness" value={color.brightness ?? 0} min={-100} defaultValue={0} disabled={disabled} onChange={(brightness) => update({ colorCorrection: { ...color, brightness } })} />
<Param label="Contrast" value={color.contrast} min={-100} defaultValue={0} disabled={disabled} onChange={(contrast) => update({ colorCorrection: { ...color, contrast } })} />
+ {(["highlights", "shadows", "whites", "blacks"] as const).map((key) => <Param key={key} label={key[0].toUpperCase() + key.slice(1)} value={color[key] ?? 0} min={-100} defaultValue={0} disabled={disabled} onChange={(value) => update({ colorCorrection: { ...color, [key]: value } })} />)}
<Param label="Saturation" value={color.saturation} max={200} defaultValue={100} disabled={disabled} onChange={(saturation) => update({ colorCorrection: { ...color, saturation } })} />
</>;
},
},
{
- id: "vignette", name: "Vignette", description: "Darken the edges of the picture",
+ id: "creative", name: "Creative", description: "Eight built-in looks, faded film, sharpening and vibrance",
+ defaults: { creative: DEFAULT_CREATIVE },
+ editor: ({ clip, update, disabled }) => {
+ const creative = clip.creative!;
+ return <>
+ <PropRow label="Look"><ComboBox aria-label="Creative look" value={creative.look} disabled={disabled} options={CREATIVE_LOOKS.map((look) => ({ value: look, label: look }))}
+ onChange={(look) => update({ creative: { ...creative, look } })} /></PropRow>
+ <Param label="Intensity" ariaLabel="Creative intensity" value={creative.intensity} defaultValue={100} disabled={disabled} onChange={(intensity) => update({ creative: { ...creative, intensity } })} />
+ <Param label="Faded film" value={creative.fadedFilm} defaultValue={0} disabled={disabled} onChange={(fadedFilm) => update({ creative: { ...creative, fadedFilm } })} />
+ <Param label="Sharpen" ariaLabel="Creative sharpen" value={creative.sharpen} max={200} defaultValue={0} disabled={disabled} onChange={(sharpen) => update({ creative: { ...creative, sharpen } })} />
+ <Param label="Vibrance" value={creative.vibrance} min={-100} defaultValue={0} disabled={disabled} onChange={(vibrance) => update({ creative: { ...creative, vibrance } })} />
+ </>;
+ },
+ },
+ {
+ id: "curves", name: "Curves", description: "RGB and hue, saturation and luma curves",
+ defaults: { curves: {} },
+ editor: ({ clip, update, disabled }) => <CurveEditor key={clip.id} value={clip.curves!} disabled={disabled} onChange={(curves) => update({ curves })} />,
+ },
+ {
+ id: "colorWheels", name: "Color Wheels", description: "Tint and lightness for shadows, midtones and highlights",
+ defaults: { colorWheels: DEFAULT_WHEELS },
+ editor: ({ clip, update, disabled }) => {
+ const wheels = clip.colorWheels!;
+ return <>{(["shadows", "midtones", "highlights"] as const).map((key) => {
+ const label = key[0].toUpperCase() + key.slice(1), wheel = wheels[key];
+ return <div className="grading-wheel-section" key={key}>
+ <div className="grading-wheel-section__heading"><span>{label}</span><button type="button" className="clip-effect__action" aria-label={`Reset ${label} wheel`} disabled={disabled}
+ onClick={() => update({ colorWheels: { ...wheels, [key]: { x: 0, y: 0, lightness: 0 } } })}><Reset14 /></button></div>
+ <GradingWheel label={label} x={wheel.x} y={wheel.y} disabled={disabled} onChange={(x, y) => update({ colorWheels: { ...wheels, [key]: { ...wheel, x, y } } })} />
+ <Param label="Lightness" ariaLabel={`${label} lightness`} value={wheel.lightness} min={-100} defaultValue={0} disabled={disabled} onChange={(lightness) => update({ colorWheels: { ...wheels, [key]: { ...wheel, lightness } } })} />
+ </div>;
+ })}</>;
+ },
+ },
+ {
+ id: "vignette", name: "Vignette", description: "Shape and soften dark or light edges",
defaults: { vignette: { amount: 35 } },
- editor: ({ clip, update, disabled }) => <Param label="Amount" ariaLabel="Vignette amount" value={clip.vignette!.amount} defaultValue={35} disabled={disabled} onChange={(amount) => update({ vignette: { ...clip.vignette!, amount } })} />,
+ editor: ({ clip, update, disabled }) => {
+ const vignette = clip.vignette!;
+ return <>
+ <Param label="Amount" ariaLabel="Vignette amount" value={vignette.amount} min={-100} defaultValue={35} disabled={disabled} onChange={(amount) => update({ vignette: { ...vignette, amount } })} />
+ <Param label="Midpoint" ariaLabel="Vignette midpoint" value={vignette.midpoint ?? 50} defaultValue={50} disabled={disabled} onChange={(midpoint) => update({ vignette: { ...vignette, midpoint } })} />
+ <Param label="Roundness" ariaLabel="Vignette roundness" value={vignette.roundness ?? 0} min={-100} defaultValue={0} disabled={disabled} onChange={(roundness) => update({ vignette: { ...vignette, roundness } })} />
+ <Param label="Feather" ariaLabel="Vignette feather" value={vignette.feather ?? 100} defaultValue={100} disabled={disabled} onChange={(feather) => update({ vignette: { ...vignette, feather } })} />
+ </>;
+ },
},
{
id: "lut", name: "3D LUT", description: "Apply a colour look from a .cube file",
diff --git a/src/components/workspace/CurveEditor.tsx b/src/components/workspace/CurveEditor.tsx
new file mode 100644
index 0000000..52161ea
--- /dev/null
+++ b/src/components/workspace/CurveEditor.tsx
@@ -0,0 +1,81 @@
+import { useId, useRef, useState, type PointerEvent } from "react";
+import { ComboBox } from "../ui";
+import { curveEvaluator } from "../../lib/colorCurves";
+import { CURVE_CHANNELS, defaultCurve, type CurveChannel, type CurvePoint, type VideoEffects } from "../../lib/effectSettings";
+
+const LABELS: Record<CurveChannel, string> = { rgb: "RGB", red: "Red", green: "Green", blue: "Blue", hueVsSat: "Hue vs saturation", hueVsHue: "Hue vs hue", hueVsLuma: "Hue vs luma", lumaVsSat: "Luma vs saturation", satVsSat: "Saturation vs saturation" };
+const clamp = (v: number, lo = 0, hi = 1) => Math.max(lo, Math.min(hi, v));
+
+export function CurveEditor({ value, disabled, onChange }: { value: NonNullable<VideoEffects["curves"]>; disabled: boolean; onChange: (value: NonNullable<VideoEffects["curves"]>) => void }) {
+ const [channel, setChannel] = useState<CurveChannel>("rgb");
+ const [selected, setSelected] = useState(0);
+ const drag = useRef<number | null>(null);
+ const svg = useRef<SVGSVGElement>(null);
+ const hint = useId();
+ const points = value[channel] ?? defaultCurve(channel);
+ const latest = useRef(points); latest.current = points;
+ const index = Math.min(selected, points.length - 1);
+ const periodic = channel.startsWith("hue");
+ const evaluate = curveEvaluator(points, periodic);
+ const commit = (next: CurvePoint[]) => { if (!disabled) { latest.current = next; onChange({ ...value, [channel]: next }); } };
+ const move = (i: number, x: number, y: number) => {
+ const next = latest.current.map((p) => [...p] as CurvePoint);
+ const last = next.length - 1;
+ next[i] = [i === 0 ? 0 : i === last ? 1 : clamp(x, next[i - 1][0] + .002, next[i + 1][0] - .002), clamp(y)];
+ if (periodic && (i === 0 || i === last)) next[i === 0 ? last : 0][1] = next[i][1];
+ commit(next);
+ };
+ const position = (event: PointerEvent<SVGSVGElement>): CurvePoint => {
+ const rect = event.currentTarget.getBoundingClientRect();
+ return [clamp((event.clientX - rect.left) / rect.width), clamp(1 - (event.clientY - rect.top) / rect.height)];
+ };
+ const addPoint = (x: number, y: number) => {
+ if (disabled || points.length >= 32 || points.some((p) => Math.abs(p[0] - x) < .004)) return;
+ const next = [...points, [x, y] as CurvePoint].sort((a, b) => a[0] - b[0]);
+ setSelected(next.findIndex((p) => p[0] === x)); commit(next);
+ };
+ const remove = () => { if (index > 0 && index < points.length - 1) { commit(points.filter((_, i) => i !== index)); setSelected(index - 1); } };
+ return <div className="grading-curves">
+ <ComboBox aria-label="Curve channel" value={channel} disabled={disabled} options={CURVE_CHANNELS.map((c) => ({ value: c, label: LABELS[c] }))}
+ onChange={(c) => { setChannel(c); setSelected(0); drag.current = null; }} />
+ <svg ref={svg} className={`grading-curves__graph grading-curves__graph--${channel}`} viewBox="0 0 256 256" aria-label={`${LABELS[channel]} curve`} aria-describedby={hint}
+ onPointerDown={(e) => {
+ if (disabled || e.button !== 0) return;
+ const [x, y] = position(e);
+ const nearest = points.findIndex((p) => Math.hypot(p[0] - x, p[1] - y) < .045);
+ if (nearest >= 0) { setSelected(nearest); drag.current = nearest; e.currentTarget.setPointerCapture(e.pointerId); }
+ else addPoint(x, y);
+ }}
+ onPointerMove={(e) => { if (drag.current !== null && !disabled) move(drag.current, ...position(e)); }}
+ onPointerUp={() => { drag.current = null; }} onPointerCancel={() => { drag.current = null; }} onLostPointerCapture={() => { drag.current = null; }}>
+ {[64, 128, 192].map((n) => <path key={n} className="grading-curves__grid" d={`M ${n} 0 V 256 M 0 ${n} H 256`} />)}
+ <path className="grading-curves__baseline" d={CURVE_CHANNELS.indexOf(channel) < 4 ? "M 0 256 L 256 0" : "M 0 128 H 256"} />
+ <path className="grading-curves__line" d={Array.from({ length: 257 }, (_, i) => `${i ? "L" : "M"} ${i} ${(1 - evaluate(i / 256)) * 256}`).join(" ")} />
+ {points.map(([x, y], i) => <circle key={i} cx={x * 256} cy={(1 - y) * 256} r={i === index ? 5 : 4} className={i === index ? "grading-curves__point grading-curves__point--selected" : "grading-curves__point"}
+ role="slider" tabIndex={disabled ? -1 : 0} aria-disabled={disabled} aria-label={`${LABELS[channel]} point ${i + 1}`} aria-valuemin={0} aria-valuemax={100} aria-valuenow={Math.round(y * 100)} aria-valuetext={`Input ${Math.round(x * 100)}, output ${Math.round(y * 100)}`}
+ onFocus={() => setSelected(i)} onKeyDown={(e) => {
+ if (disabled) return;
+ const step = e.shiftKey ? .1 : .01;
+ if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(e.key)) {
+ e.preventDefault(); e.stopPropagation();
+ move(i, x + (e.key === "ArrowLeft" ? -step : e.key === "ArrowRight" ? step : 0), y + (e.key === "ArrowUp" ? step : e.key === "ArrowDown" ? -step : 0));
+ } else if (e.key === "Delete" || e.key === "Backspace") { e.preventDefault(); e.stopPropagation(); remove(); }
+ }} />)}
+ </svg>
+ <div className="grading-curves__coordinates">
+ <label>Input <input aria-label="Curve point input" type="number" min={0} max={100} step={1} value={+(points[index][0] * 100).toFixed(1)} disabled={disabled || index === 0 || index === points.length - 1}
+ onChange={(e) => { if (Number.isFinite(e.target.valueAsNumber)) move(index, e.target.valueAsNumber / 100, points[index][1]); }} /></label>
+ <label>Output <input aria-label="Curve point output" type="number" min={0} max={100} step={1} value={+(points[index][1] * 100).toFixed(1)} disabled={disabled}
+ onChange={(e) => { if (Number.isFinite(e.target.valueAsNumber)) move(index, points[index][0], e.target.valueAsNumber / 100); }} /></label>
+ </div>
+ <div className="grading-curves__actions">
+ <button type="button" className="secondary-button" disabled={disabled || points.length >= 32} onClick={() => {
+ let gap = 0; for (let i = 1; i < points.length - 1; i++) if (points[i + 1][0] - points[i][0] > points[gap + 1][0] - points[gap][0]) gap = i;
+ const x = (points[gap][0] + points[gap + 1][0]) / 2; addPoint(x, evaluate(x));
+ }}>Add point</button>
+ <button type="button" className="secondary-button" disabled={disabled || index === 0 || index === points.length - 1} onClick={remove}>Remove point</button>
+ <button type="button" className="secondary-button" disabled={disabled} onClick={() => { commit(defaultCurve(channel)); setSelected(0); }}>Reset curve</button>
+ </div>
+ <p id={hint} className="clip-effect__note">Click to add a point; drag to shape the curve. Arrow keys move a focused point. Delete removes it.</p>
+ </div>;
+}
diff --git a/src/components/workspace/GradingWheel.tsx b/src/components/workspace/GradingWheel.tsx
new file mode 100644
index 0000000..4e50351
--- /dev/null
+++ b/src/components/workspace/GradingWheel.tsx
@@ -0,0 +1,29 @@
+import { useRef, type PointerEvent } from "react";
+
+export function GradingWheel({ label, x, y, disabled, onChange }: { label: string; x: number; y: number; disabled: boolean; onChange: (x: number, y: number) => void }) {
+ const dragging = useRef(false);
+ const set = (nextX: number, nextY: number) => {
+ if (disabled) return;
+ const radius = Math.max(1, Math.hypot(nextX, nextY));
+ onChange(nextX / radius, nextY / radius);
+ };
+ const point = (event: PointerEvent<HTMLDivElement>) => {
+ const bounds = event.currentTarget.getBoundingClientRect();
+ set((event.clientX - bounds.left) / bounds.width * 2 - 1, 1 - (event.clientY - bounds.top) / bounds.height * 2);
+ };
+ return <div className="grading-wheel" role="slider" tabIndex={disabled ? -1 : 0} aria-disabled={disabled} aria-label={`${label} color`} aria-valuemin={0} aria-valuemax={100} aria-valuenow={Math.round(Math.hypot(x, y) * 100)}
+ aria-valuetext={`Horizontal ${Math.round(x * 100)}, vertical ${Math.round(y * 100)}`} title="Drag to tint. Arrow keys adjust; Home resets color."
+ onPointerDown={(event) => { if (disabled || event.button !== 0) return; dragging.current = true; event.currentTarget.setPointerCapture(event.pointerId); event.currentTarget.focus(); point(event); }}
+ onPointerMove={(event) => { if (dragging.current) point(event); }} onPointerUp={() => { dragging.current = false; }} onPointerCancel={() => { dragging.current = false; }} onLostPointerCapture={() => { dragging.current = false; }}
+ onDoubleClick={() => set(0, 0)} onKeyDown={(e) => {
+ const step = e.shiftKey ? .1 : .02;
+ if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home"].includes(e.key)) {
+ e.preventDefault(); e.stopPropagation();
+ if (e.key === "Home") set(0, 0);
+ else set(x + (e.key === "ArrowLeft" ? -step : e.key === "ArrowRight" ? step : 0), y + (e.key === "ArrowUp" ? step : e.key === "ArrowDown" ? -step : 0));
+ }
+ }}>
+ <span className="grading-wheel__center" />
+ <span className="grading-wheel__handle" style={{ left: `${(x + 1) * 50}%`, top: `${(1 - y) * 50}%` }} />
+ </div>;
+}
diff --git a/src/lib/colorCurves.test.ts b/src/lib/colorCurves.test.ts
new file mode 100644
index 0000000..c2fb197
--- /dev/null
+++ b/src/lib/colorCurves.test.ts
@@ -0,0 +1,73 @@
+import { describe, expect, it } from "vitest";
+import { compileCurves, curveEvaluator, CURVE_SAMPLES } from "./colorCurves";
+import { CREATIVE_LOOKS, DEFAULT_CREATIVE, DEFAULT_WHEELS, activeVideoEffects, curveSchema, effectSchemas, type CurvePoint } from "./effectSettings";
+import { timelineClipSchema } from "./project";
+import { clipVisualSettings } from "./export";
+
+describe("shape-preserving curves", () => {
+ it.each<CurvePoint[][]>([
+ [[[0, 0], [.1, .8], [.8, .81], [1, 1]]],
+ [[[0, 1], [.25, .8], [.4, .1], [1, 0]]],
+ [[[0, .2], [.2, .9], [.5, .9], [.8, .1], [1, .5]]],
+ [[[0, 0], [.002, .9], [.99, .91], [1, 1]]],
+ ])("passes through control points without overshooting any segment", (points) => {
+ const evaluate = curveEvaluator(points);
+ points.forEach(([x, y]) => expect(evaluate(x)).toBeCloseTo(y, 10));
+ for (let i = 0; i < points.length - 1; i++) {
+ const [x, y] = points[i], [endX, endY] = points[i + 1];
+ for (let step = 0; step <= 100; step++) {
+ const value = evaluate(x + (endX - x) * step / 100);
+ expect(value).toBeGreaterThanOrEqual(Math.min(y, endY) - 1e-10);
+ expect(value).toBeLessThanOrEqual(Math.max(y, endY) + 1e-10);
+ }
+ }
+ });
+ it("keeps the hue seam continuous with matching endpoint tangents", () => {
+ const f = curveEvaluator([[0, .6], [.2, .9], [.8, .1], [1, .6]], true);
+ expect(f(0)).toBe(f(1));
+ expect((f(.000001) - f(0)) / .000001).toBeCloseTo(0, 3);
+ expect((f(1) - f(.999999)) / .000001).toBeCloseTo(0, 3);
+ });
+ it("keeps neutral curves inactive and compiles only changed channel flags", () => {
+ expect(compileCurves({}).mask).toBe(0);
+ const compiled = compileCurves({ red: [[0, .1], [1, .9]], hueVsSat: [[0, .3], [1, .3]] });
+ expect(compiled.mask).toBe((1 << 1) | (1 << 4));
+ expect(compiled.values.length).toBe(9 * CURVE_SAMPLES);
+ expect(compiled.values[CURVE_SAMPLES]).toBeCloseTo(.1);
+ expect(compiled.values[2 * CURVE_SAMPLES - 1]).toBeCloseTo(.9);
+ expect(compiled.values[4 * CURVE_SAMPLES + 500]).toBeCloseTo(.3);
+ });
+ it.each([[], [[0, 0]], [[0, 0], [0, 1]], [[0, 0], [.5, 1], [.4, 0], [1, 1]], [[0, 0], [1, NaN]], [[.1, 0], [1, 1]], [[0, 0], [1, 1.1]]])("rejects malformed curve data", (points) => {
+ expect(curveSchema.safeParse(points).success).toBe(false);
+ });
+});
+
+describe("grading persistence and export", () => {
+ const base = { id: "clip", assetId: "asset", trackId: "video", label: "Graded", startMs: 0, durationMs: 1000 };
+ it("round trips every new setting into the shared export plan", () => {
+ const settings = {
+ colorCorrection: { exposure: 1, contrast: 20, saturation: 80, temperature: 25, tint: -15, highlights: -20, shadows: 30, whites: 10, blacks: -10 },
+ creative: { ...DEFAULT_CREATIVE, look: "Warm Film", intensity: 65, fadedFilm: 10, sharpen: 35, vibrance: -15 },
+ curves: { rgb: [[0, 0], [.5, .7], [1, 1]], hueVsHue: [[0, .5], [.2, .8], [1, .5]] },
+ colorWheels: { ...DEFAULT_WHEELS, midtones: { x: .3, y: -.4, lightness: 10 } },
+ vignette: { amount: -30, midpoint: 20, roundness: -15, feather: 65 },
+ };
+ const clip = timelineClipSchema.parse(JSON.parse(JSON.stringify({ ...base, ...settings })));
+ expect(clipVisualSettings(clip)).toMatchObject(settings);
+ expect(CREATIVE_LOOKS.filter((look) => look !== "None")).toHaveLength(8);
+ for (const key of ["creative", "curves", "colorWheels"] as const) {
+ const off = { ...clip, [key]: { ...clip[key], enabled: false } };
+ expect(activeVideoEffects(off)[key]).toBeNull();
+ expect(off[key]).toMatchObject(settings[key]);
+ }
+ });
+ it("validates new controls including hue seams and wheel radius", () => {
+ expect(effectSchemas.creative.safeParse({ ...DEFAULT_CREATIVE, look: "unknown" }).success).toBe(false);
+ expect(effectSchemas.colorWheels.safeParse({ ...DEFAULT_WHEELS, shadows: { x: 1, y: 1, lightness: 0 } }).success).toBe(false);
+ expect(effectSchemas.curves.safeParse({ hueVsHue: [[0, .1], [1, .9]] }).success).toBe(false);
+ for (const field of ["temperature", "tint", "highlights", "shadows", "whites", "blacks"]) {
+ expect(effectSchemas.colorCorrection.safeParse({ exposure: 0, contrast: 0, saturation: 100, [field]: 101 }).success).toBe(false);
+ }
+ expect(effectSchemas.vignette.safeParse({ amount: 0, feather: -1 }).success).toBe(false);
+ });
+});
diff --git a/src/lib/colorCurves.ts b/src/lib/colorCurves.ts
new file mode 100644
index 0000000..c184e00
--- /dev/null
+++ b/src/lib/colorCurves.ts
@@ -0,0 +1,41 @@
+import { CURVE_CHANNELS, defaultCurve, type CurvePoint, type VideoEffects } from "./effectSettings";
+
+export const CURVE_SAMPLES = 1024;
+
+/** Shape-preserving cubic Hermite interpolation. Flat spans and local extrema
+ * have zero tangents; the Fritsch–Carlson limiter prevents segment overshoot. */
+export function curveEvaluator(points: readonly CurvePoint[], periodic = false): (x: number) => number {
+ const slopes = points.slice(1).map((p, i) => (p[1] - points[i][1]) / (p[0] - points[i][0]));
+ const tangents = points.map((_, i) => i === 0 ? slopes[0] : i === points.length - 1 ? slopes[i - 1]
+ : slopes[i - 1] * slopes[i] <= 0 ? 0 : (slopes[i - 1] + slopes[i]) / 2);
+ // Equal endpoint values and tangents make the red hue seam continuous.
+ if (periodic) tangents[0] = tangents[tangents.length - 1] = 0;
+ slopes.forEach((slope, i) => {
+ if (slope === 0) { tangents[i] = tangents[i + 1] = 0; return; }
+ const length = Math.hypot(tangents[i] / slope, tangents[i + 1] / slope);
+ if (length > 3) { tangents[i] *= 3 / length; tangents[i + 1] *= 3 / length; }
+ });
+ return (x) => {
+ if (x <= points[0][0]) return points[0][1];
+ if (x >= points[points.length - 1][0]) return points[points.length - 1][1];
+ let i = 0;
+ while (points[i + 1][0] < x) i++;
+ const [x0, y0] = points[i], [x1, y1] = points[i + 1];
+ const width = x1 - x0, t = (x - x0) / width, t2 = t * t, t3 = t2 * t;
+ return (2 * t3 - 3 * t2 + 1) * y0 + (t3 - 2 * t2 + t) * width * tangents[i]
+ + (3 * t2 - 2 * t3) * y1 + (t3 - t2) * width * tangents[i + 1];
+ };
+}
+
+/** Only control data crosses to the GPU, never picture pixels. */
+export function compileCurves(curves: VideoEffects["curves"]): { values: Float32Array; mask: number } {
+ const values = new Float32Array(CURVE_CHANNELS.length * CURVE_SAMPLES);
+ let mask = 0;
+ CURVE_CHANNELS.forEach((channel, index) => {
+ const points = curves?.[channel] ?? defaultCurve(channel);
+ if (points.some(([x, y]) => Math.abs(y - (index < 4 ? x : 0.5)) > 1e-7)) mask |= 1 << index;
+ const evaluate = curveEvaluator(points, channel.startsWith("hue"));
+ for (let i = 0; i < CURVE_SAMPLES; i++) values[index * CURVE_SAMPLES + i] = evaluate(i / (CURVE_SAMPLES - 1));
+ });
+ return { values, mask };
+}
diff --git a/src/lib/colorGradingShader.ts b/src/lib/colorGradingShader.ts
new file mode 100644
index 0000000..6f8a185
--- /dev/null
+++ b/src/lib/colorGradingShader.ts
@@ -0,0 +1,74 @@
+// Procedural looks adapted from FilmCraft, copyright 2026 The FilmCraft
+// contributors (MIT). See public/licenses/filmcraft.txt.
+export const COLOR_GRADING_WGSL = /* wgsl */ `
+@group(0) @binding(4) var<storage, read> curves: array<f32>;
+fn luma(c: vec3f) -> f32 { return dot(c, vec3f(.2126, .7152, .0722)); }
+fn sCurve(c: vec3f, k: f32) -> vec3f {
+ let x = clamp(c, vec3f(0.), vec3f(1.));
+ return mix(x, x * x * (3. - 2. * x), k);
+}
+fn creativeLook(c: vec3f) -> vec3f {
+ let l = luma(c);
+ switch u32(params.creative.x) {
+ case 1u: { return sCurve(c + vec3f(0., .08, .1) * (1. - l) + vec3f(.1, .04, -.06) * l, .35); }
+ case 2u: { return mix(c * vec3f(1.06, 1., .9) + vec3f(.02, .01, 0.), vec3f(l), .15) * .94 + .04; }
+ case 3u: { return sCurve(c * vec3f(.9, .98, 1.1) + vec3f(0., 0., .02), .2); }
+ case 4u: { return sCurve(mix(c, vec3f(l), .55), .6); }
+ case 5u: { return mix(c, vec3f(l), .25) * .84 + .08; }
+ case 6u: { return sCurve(vec3f(l), .3); }
+ case 7u: { return sCurve(c * vec3f(1.1, 1.02, .82) + vec3f(.03, .01, 0.), .15); }
+ case 8u: { return c * vec3f(.75, .85, 1.15) * .8; }
+ default: { return c; }
+ }
+}
+fn curve(channel: u32, x: f32) -> f32 {
+ let p = clamp(x, 0., 1.) * 1023.;
+ let i = u32(p);
+ return mix(curves[channel * 1024u + i], curves[channel * 1024u + min(i + 1u, 1023u)], fract(p));
+}
+fn hasCurve(channel: u32) -> bool { return (u32(params.tonal.w) & (1u << channel)) != 0u; }
+fn rgbToHsl(c: vec3f) -> vec3f {
+ let hi = max(c.r, max(c.g, c.b)); let lo = min(c.r, min(c.g, c.b));
+ let d = hi - lo; let l = (hi + lo) * .5;
+ if (d < .000001) { return vec3f(0., 0., l); }
+ var h = (c.g - c.b) / d;
+ if (hi == c.g) { h = (c.b - c.r) / d + 2.; }
+ else if (hi == c.b) { h = (c.r - c.g) / d + 4.; }
+ return vec3f(fract(h / 6. + 1.), d / max(1. - abs(2. * l - 1.), .000001), l);
+}
+fn hslToRgb(h: vec3f) -> vec3f {
+ let c = (1. - abs(2. * h.z - 1.)) * h.y;
+ let rgb = clamp(abs(fract(h.x + vec3f(0., 2./3., 1./3.)) * 6. - 3.) - 1., vec3f(0.), vec3f(1.));
+ return (rgb - .5) * c + h.z;
+}
+fn applyCurves(input: vec3f) -> vec3f {
+ var c = input;
+ if (hasCurve(0u)) { c = vec3f(curve(0u, c.r), curve(0u, c.g), curve(0u, c.b)); }
+ if (hasCurve(1u)) { c.r = curve(1u, c.r); }
+ if (hasCurve(2u)) { c.g = curve(2u, c.g); }
+ if (hasCurve(3u)) { c.b = curve(3u, c.b); }
+ if ((u32(params.tonal.w) & 496u) != 0u) {
+ var h = rgbToHsl(clamp(c, vec3f(0.), vec3f(1.)));
+ let original = h;
+ if (hasCurve(5u)) { h.x = fract(h.x + curve(5u, original.x) - .5 + 1.); }
+ if (hasCurve(4u)) { h.y *= curve(4u, original.x) * 2.; }
+ if (hasCurve(7u)) { h.y *= curve(7u, original.z) * 2.; }
+ if (hasCurve(8u)) { h.y *= curve(8u, original.y) * 2.; }
+ if (hasCurve(6u)) { h.z += (curve(6u, original.x) - .5) * .5; }
+ c = hslToRgb(vec3f(h.x, clamp(h.yz, vec2f(0.), vec2f(1.))));
+ }
+ return c;
+}
+fn wheelOffset(w: vec4f) -> vec3f {
+ // Cosine colour directions: red at right, green at upper left, blue below.
+ return vec3f(w.x, -.5 * w.x + .8660254 * w.y, -.5 * w.x - .8660254 * w.y);
+}
+fn applyWheels(c: vec3f) -> vec3f {
+ let l = clamp(luma(c), 0., 1.);
+ let shadows = (1. - l) * (1. - l); let highlights = l * l;
+ let midtones = 1. - shadows - highlights;
+ var v = c + (wheelOffset(params.shadows) + params.shadows.z) * .3 * shadows;
+ v += (wheelOffset(params.midtones) + params.midtones.z) * .3 * midtones;
+ return v * (1. + (wheelOffset(params.highlights) + params.highlights.z) * .5 * highlights);
+}
+`;
diff --git a/src/lib/effectSettings.test.ts b/src/lib/effectSettings.test.ts
index 77e4dfa..a0c5503 100644
--- a/src/lib/effectSettings.test.ts
+++ b/src/lib/effectSettings.test.ts
@@ -86,7 +86,7 @@ describe("effect bypass", () => {
it("drops bypassed effects from what renders", () => {
const effects = { sharpen: { amount: 40, enabled: false }, blur: { radius: 3 }, lut: { intensity: 50, enabled: false } };
- expect(activeVideoEffects(effects)).toEqual({ sharpen: null, blur: { radius: 3 }, colorCorrection: null, vignette: null, lut: null });
+ expect(activeVideoEffects(effects)).toEqual({ sharpen: null, blur: { radius: 3 }, colorCorrection: null, creative: null, curves: null, colorWheels: null, vignette: null, lut: null });
expect(hasVideoEffects(effects)).toBe(true);
expect(hasVideoEffects({ sharpen: { amount: 40, enabled: false } })).toBe(false);
});
diff --git a/src/lib/effectSettings.ts b/src/lib/effectSettings.ts
index 5ce8c9b..1db2659 100644
--- a/src/lib/effectSettings.ts
+++ b/src/lib/effectSettings.ts
@@ -24,17 +24,45 @@ export const effectEnabledSchema = z.boolean().nullish();
export const isEffectOn = <T extends { enabled?: boolean | null }>(effect: T | null | undefined): effect is T =>
effect !== null && effect !== undefined && effect.enabled !== false;
+const percent = z.number().finite().min(0).max(100);
+const signedPercent = z.number().finite().min(-100).max(100);
+const unit = z.number().finite().min(0).max(1);
+export const curveSchema = z.array(z.tuple([unit, unit])).min(2).max(32).superRefine((points, context) => {
+ if (points[0][0] !== 0 || points[points.length - 1][0] !== 1 || points.some((p, i) => i > 0 && p[0] - points[i - 1][0] < 0.001)) {
+ context.addIssue({ code: "custom", message: "Curves need endpoints at 0 and 1 and increasing inputs at least 0.001 apart." });
+ }
+});
+const hueCurveSchema = curveSchema.refine((p) => p[0][1] === p[p.length - 1][1], "Hue curve endpoints must match.");
+export const CREATIVE_LOOKS = ["None", "Teal & Orange", "Warm Film", "Cool Blue", "Bleach Bypass", "Faded Matte", "Monochrome", "Golden Hour", "Night"] as const;
+export const CURVE_CHANNELS = ["rgb", "red", "green", "blue", "hueVsSat", "hueVsHue", "hueVsLuma", "lumaVsSat", "satVsSat"] as const;
+export type CurveChannel = typeof CURVE_CHANNELS[number];
+export type CurvePoint = [number, number];
+export const defaultCurve = (channel: CurveChannel): CurvePoint[] => channel === "rgb" || channel === "red" || channel === "green" || channel === "blue" ? [[0, 0], [1, 1]] : [[0, 0.5], [1, 0.5]];
+const wheelSchema = z.object({ x: z.number().finite().min(-1).max(1), y: z.number().finite().min(-1).max(1), lightness: signedPercent })
+ .refine((v) => Math.hypot(v.x, v.y) <= 1.000001, "Wheel position must be inside the wheel.");
+export const DEFAULT_CREATIVE = { look: "None", intensity: 100, fadedFilm: 0, sharpen: 0, vibrance: 0 } as const;
+export const DEFAULT_WHEELS = { shadows: { x: 0, y: 0, lightness: 0 }, midtones: { x: 0, y: 0, lightness: 0 }, highlights: { x: 0, y: 0, lightness: 0 } };
+
export const effectSchemas = {
sharpen: z.object({ amount: z.number().finite().min(0).max(200), enabled: effectEnabledSchema }).nullish(),
blur: z.object({ radius: z.number().finite().min(0).max(24), enabled: effectEnabledSchema }).nullish(),
colorCorrection: z.object({
+ temperature: signedPercent.nullish(), tint: signedPercent.nullish(),
+ highlights: signedPercent.nullish(), shadows: signedPercent.nullish(), whites: signedPercent.nullish(), blacks: signedPercent.nullish(),
exposure: z.number().finite().min(-4).max(4),
brightness: z.number().finite().min(-100).max(100).nullish(),
contrast: z.number().finite().min(-100).max(100),
saturation: z.number().finite().min(0).max(200),
enabled: effectEnabledSchema,
}).nullish(),
- vignette: z.object({ amount: z.number().finite().min(0).max(100), enabled: effectEnabledSchema }).nullish(),
+ creative: z.object({ look: z.enum(CREATIVE_LOOKS), intensity: percent, fadedFilm: percent, sharpen: z.number().finite().min(0).max(200), vibrance: signedPercent, enabled: effectEnabledSchema }).nullish(),
+ curves: z.object({
+ rgb: curveSchema.nullish(), red: curveSchema.nullish(), green: curveSchema.nullish(), blue: curveSchema.nullish(),
+ hueVsSat: hueCurveSchema.nullish(), hueVsHue: hueCurveSchema.nullish(), hueVsLuma: hueCurveSchema.nullish(),
+ lumaVsSat: curveSchema.nullish(), satVsSat: curveSchema.nullish(), enabled: effectEnabledSchema,
+ }).nullish(),
+ colorWheels: z.object({ shadows: wheelSchema, midtones: wheelSchema, highlights: wheelSchema, enabled: effectEnabledSchema }).nullish(),
+ vignette: z.object({ amount: signedPercent, midpoint: percent.nullish(), roundness: signedPercent.nullish(), feather: percent.nullish(), enabled: effectEnabledSchema }).nullish(),
lut: z.object({ intensity: z.number().finite().min(0).max(100), table: lutTableSchema.nullish(), enabled: effectEnabledSchema }).nullish(),
};
export type VideoEffects = z.infer<z.ZodObject<typeof effectSchemas>>;
@@ -46,12 +74,15 @@ export const activeVideoEffects = (effects: VideoEffects): VideoEffects => ({
sharpen: isEffectOn(effects.sharpen) ? effects.sharpen : null,
blur: isEffectOn(effects.blur) ? effects.blur : null,
colorCorrection: isEffectOn(effects.colorCorrection) ? effects.colorCorrection : null,
+ creative: isEffectOn(effects.creative) ? effects.creative : null,
+ curves: isEffectOn(effects.curves) ? effects.curves : null,
+ colorWheels: isEffectOn(effects.colorWheels) ? effects.colorWheels : null,
vignette: isEffectOn(effects.vignette) ? effects.vignette : null,
lut: isEffectOn(effects.lut) ? effects.lut : null,
});
export const hasVideoEffects = (effects: VideoEffects): boolean =>
- isEffectOn(effects.sharpen) || isEffectOn(effects.blur) || isEffectOn(effects.colorCorrection) || isEffectOn(effects.vignette) || isEffectOn(effects.lut);
+ Object.keys(effectSchemas).some((key) => isEffectOn(effects[key as keyof VideoEffects]));
export const MAX_LUT_FILE_BYTES = 16 * 1024 * 1024;
diff --git a/src/lib/videoEffectsGpu.ts b/src/lib/videoEffectsGpu.ts
index 4f86c17..45386a7 100644
--- a/src/lib/videoEffectsGpu.ts
+++ b/src/lib/videoEffectsGpu.ts
@@ -1,6 +1,8 @@
/// <reference types="@webgpu/types" />
import { keyColor, KEY_FEATHER, RGB_DISTANCE_SCALE } from "./chromaKey";
-import type { VideoEffects, LutTable } from "./effectSettings";
+import { activeVideoEffects, CREATIVE_LOOKS, type VideoEffects, type LutTable } from "./effectSettings";
+import { compileCurves, CURVE_SAMPLES } from "./colorCurves";
+import { COLOR_GRADING_WGSL } from "./colorGradingShader";
import type { ClipChromaKey } from "./project";
export type GpuEffects = VideoEffects & { chromaKey?: ClipChromaKey | null; look?: { temperature: number } | null };
@@ -21,6 +23,13 @@ struct Params {
domainMin: vec4f,
domainMax: vec4f,
blur: vec4f,
+ balance: vec4f,
+ tonal: vec4f,
+ creative: vec4f,
+ vignette: vec4f,
+ shadows: vec4f,
+ midtones: vec4f,
+ highlights: vec4f,
};
@group(0) @binding(0) var<uniform> params: Params;
@group(0) @binding(2) var linearSampler: sampler;
@@ -55,7 +64,7 @@ const BLUR = VERTEX + PARAMS + TEXTURE + /* wgsl */ `
return total / weights;
}
`;
-const FINISH = VERTEX + PARAMS + TEXTURE + /* wgsl */ `
+const FINISH = VERTEX + PARAMS + TEXTURE + COLOR_GRADING_WGSL + /* wgsl */ `
@group(0) @binding(3) var<storage, read> lut: array<f32>;
fn lookup(p: vec3u) -> vec3f {
let size = u32(params.detail.y);
@@ -88,13 +97,35 @@ fn straight(color: vec4f) -> vec3f { return color.rgb / max(color.a, .00001); }
rgb += (rgb - straight(neighbors)) * params.detail.x;
}
rgb *= exp2(params.grade.x);
+ rgb *= vec3f(1. + .35 * params.balance.x, 1. - .3 * params.balance.y, 1. - .35 * params.balance.x);
rgb += vec3f(params.domainMax.w);
+ let black = -params.tonal.y * .15;
+ let white = 1. - params.tonal.x * .15;
+ rgb = (rgb - black) / max(white - black, .001);
+ let toneLuma = luma(rgb);
+ let tone = clamp(toneLuma, 0., 1.);
+ let lift = params.balance.w * .35 * pow(1. - tone, 3.) + params.balance.z * .35 * pow(tone, 3.);
+ if (abs(lift) > .000001) {
+ if (toneLuma > .00001) { rgb *= max(toneLuma + lift, 0.) / toneLuma; }
+ else { rgb += max(lift, 0.); }
+ }
rgb = (rgb - vec3f(.5)) * params.grade.y + vec3f(.5);
- let luma = dot(rgb, vec3f(.2126, .7152, .0722));
- rgb = mix(vec3f(luma), rgb, params.grade.z);
+ rgb = mix(vec3f(luma(rgb)), rgb, params.grade.z);
+ if (params.creative.x > 0. && params.creative.y > 0.) { rgb = mix(rgb, creativeLook(rgb), params.creative.y); }
+ rgb = rgb * (1. - .25 * params.creative.z) + .12 * params.creative.z;
+ let chroma = clamp(max(rgb.r, max(rgb.g, rgb.b)) - min(rgb.r, min(rgb.g, rgb.b)), 0., 1.);
+ rgb = mix(vec3f(luma(rgb)), rgb, 1. + params.tonal.z * (1. - chroma));
+ rgb = applyWheels(applyCurves(rgb));
if (params.detail.y >= 2. && params.detail.z > 0.) { rgb = mix(rgb, applyLut(rgb), params.detail.z); }
- let distanceFromCenter = length((uv - vec2f(.5)) * 1.41421356);
- rgb *= 1. - params.grade.w * smoothstep(.3, 1., distanceFromCenter);
+ var position = abs((uv - vec2f(.5)) * 1.41421356);
+ let aspect = f32(textureDimensions(picture).x) / f32(textureDimensions(picture).y);
+ position *= mix(vec2f(1.), vec2f(max(aspect, 1.), max(1. / aspect, 1.)), max(params.vignette.y, 0.));
+ let power = 2. + max(-params.vignette.y, 0.) * 6.;
+ let distanceFromCenter = pow(pow(position.x, power) + pow(position.y, power), 1. / power);
+ let start = params.vignette.x * .6;
+ let edge = smoothstep(start, start + max(params.vignette.z * .7, .001), distanceFromCenter);
+ if (params.grade.w >= 0.) { rgb *= 1. - params.grade.w * edge; }
+ else { rgb += (1. - rgb) * -params.grade.w * edge; }
rgb += vec3f(params.domainMin.w * .1, 0., -params.domainMin.w * .1);
return vec4f(clamp(rgb, vec3f(0.), vec3f(1.)) * sampled.a, sampled.a);
}
@@ -122,13 +153,24 @@ export function createVideoEffectsProcessor(device: GPUDevice) {
const blurPipeline = pipeline(device, BLUR, "rgba16float");
const finishPipeline = pipeline(device, FINISH, "rgba16float");
const sampler = device.createSampler({ minFilter: "linear", magFilter: "linear" });
- const uniforms = Array.from({ length: 3 }, () => device.createBuffer({ size: 96, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }));
+ const uniforms = Array.from({ length: 3 }, () => device.createBuffer({ size: 208, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }));
+ const curveBuffer = device.createBuffer({ size: 9 * CURVE_SAMPLES * 4, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST });
+ let curveKey: string | undefined;
+ let curveMask = 0;
const emptyLut = device.createBuffer({ size: 12, usage: GPUBufferUsage.STORAGE });
const luts: { table: LutTable; buffer: GPUBuffer }[] = [];
let textures: GPUTexture[] = [];
let dimensions = "";
return {
render(frame: VideoFrame, effects: GpuEffects): GPUTexture {
+ effects = { ...effects, ...activeVideoEffects(effects) };
+ const nextCurveKey = JSON.stringify(effects.curves ?? null);
+ if (nextCurveKey !== curveKey) {
+ const compiled = compileCurves(effects.curves);
+ device.queue.writeBuffer(curveBuffer, 0, compiled.values);
+ curveMask = compiled.mask;
+ curveKey = nextCurveKey;
+ }
const width = frame.displayWidth, height = frame.displayHeight;
if (dimensions !== `${width}x${height}`) {
textures.forEach((texture) => texture.destroy());
@@ -153,10 +195,18 @@ export function createVideoEffectsProcessor(device: GPUDevice) {
const data = new Float32Array([
...(effects.chromaKey ? keyColor(effects.chromaKey.color) : [0, 0, 0]), (effects.chromaKey?.tolerance ?? 0) / 100,
grade?.exposure ?? 0, 1 + (grade?.contrast ?? 0) / 100, (grade?.saturation ?? 100) / 100, (effects.vignette?.amount ?? 0) / 100,
- (effects.sharpen?.amount ?? 0) / 100, table?.size ?? 0, (effects.lut?.intensity ?? 0) / 100, effects.chromaKey ? 1 : 0,
+ ((effects.sharpen?.amount ?? 0) + (effects.creative?.sharpen ?? 0)) / 100, table?.size ?? 0, (effects.lut?.intensity ?? 0) / 100, effects.chromaKey ? 1 : 0,
// Pack temperature and brightness into the unused domain vector lanes.
...(table?.domainMin ?? [0, 0, 0]), (effects.look?.temperature ?? 0) / 100, ...(table?.domainMax ?? [1, 1, 1]), (grade?.brightness ?? 0) / 100,
effects.blur?.radius ?? 0, 0, 0, 0,
+ (grade?.temperature ?? 0) / 100, (grade?.tint ?? 0) / 100, (grade?.highlights ?? 0) / 100, (grade?.shadows ?? 0) / 100,
+ (grade?.whites ?? 0) / 100, (grade?.blacks ?? 0) / 100, (effects.creative?.vibrance ?? 0) / 100, curveMask,
+ CREATIVE_LOOKS.indexOf(effects.creative?.look ?? "None"), (effects.creative?.intensity ?? 0) / 100, (effects.creative?.fadedFilm ?? 0) / 100, 0,
+ (effects.vignette?.midpoint ?? 50) / 100, (effects.vignette?.roundness ?? 0) / 100, (effects.vignette?.feather ?? 100) / 100, 0,
+ ...(["shadows", "midtones", "highlights"] as const).flatMap((name) => {
+ const wheel = effects.colorWheels?.[name];
+ return [wheel?.x ?? 0, wheel?.y ?? 0, (wheel?.lightness ?? 0) / 100, 0];
+ }),
]);
device.queue.writeBuffer(uniforms[0], 0, data);
const encoder = device.createCommandEncoder();
@@ -164,7 +214,7 @@ export function createVideoEffectsProcessor(device: GPUDevice) {
const entries: GPUBindGroupEntry[] = [
{ binding: 0, resource: { buffer: uniform } }, { binding: 1, resource: source }, { binding: 2, resource: sampler },
];
- if (lut) entries.push({ binding: 3, resource: { buffer: lut } });
+ if (lut) entries.push({ binding: 3, resource: { buffer: lut } }, { binding: 4, resource: { buffer: curveBuffer } });
const group = device.createBindGroup({ layout: renderPipeline.getBindGroupLayout(0), entries });
const render = encoder.beginRenderPass({ colorAttachments: [{ view: target.createView(), loadOp: "clear", storeOp: "store", clearValue: [0, 0, 0, 0] }] });
render.setPipeline(renderPipeline); render.setBindGroup(0, group); render.draw(3); render.end();
@@ -187,6 +237,7 @@ export function createVideoEffectsProcessor(device: GPUDevice) {
uniforms.forEach((buffer) => buffer.destroy());
luts.forEach(({ buffer }) => buffer.destroy());
emptyLut.destroy();
+ curveBuffer.destroy();
},
};
}
diff --git a/src/styles/timeline.css b/src/styles/timeline.css
index dfae7cd..7aa5926 100644
--- a/src/styles/timeline.css
+++ b/src/styles/timeline.css
@@ -1729,3 +1729,26 @@ button.transport-time:hover { background: var(--fill-subtle-hover); }
.program-composited-picture { position: absolute; inset: 0; pointer-events: none; }
.program-layer { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.program-picture > video, .program-picture > img, .program-keyed-picture { position: absolute; inset: 0; }
+
+/* Grading controls share the inspector's compact sizing. */
+.grading-curves { display: grid; gap: 10px; min-width: 0; }
+.grading-curves__graph { width: calc(100% - 12px); margin: 6px; aspect-ratio: 1; overflow: visible; touch-action: none; background: var(--fill-subtle-hover); border: 1px solid var(--stroke-default); color: var(--text-primary); }
+.grading-curves__grid { stroke: currentColor; opacity: .12; fill: none; }
+.grading-curves__baseline { stroke: currentColor; opacity: .3; stroke-dasharray: 4 4; fill: none; }
+.grading-curves__line { stroke: currentColor; stroke-width: 2; fill: none; }
+.grading-curves__graph--red { color: #ed7373; }
+.grading-curves__graph--green { color: #73c88f; }
+.grading-curves__graph--blue { color: #81aaff; }
+.grading-curves__point { fill: currentColor; stroke: #222; stroke-width: 1; cursor: grab; }
+.grading-curves__point--selected, .grading-curves__point:focus { stroke: #fff; stroke-width: 2; outline: none; }
+.grading-curves__coordinates, .grading-curves__actions { display: flex; gap: 6px; flex-wrap: wrap; }
+.grading-curves__coordinates label { display: flex; align-items: center; gap: 6px; flex: 1; font-size: 11px; }
+.grading-curves__coordinates input { width: 60px; min-width: 0; }
+.grading-curves__actions .secondary-button { padding: 4px 8px; min-height: 26px; font-size: 11px; }
+.grading-wheel-section { display: grid; gap: 8px; }
+.grading-wheel-section__heading { display: flex; align-items: center; justify-content: space-between; font-size: 12px; }
+.grading-wheel { position: relative; width: 128px; height: 128px; margin: 6px auto; border-radius: 50%; touch-action: none; cursor: crosshair; background: radial-gradient(circle, #999, transparent 70%), conic-gradient(from 90deg, #ff8080, #ff80ff, #8080ff, #80ffff, #80ff80, #ffff80, #ff8080); box-shadow: inset 0 0 0 1px #ffffff40; }
+.grading-wheel:focus-visible { outline: 2px solid var(--text-primary); outline-offset: 3px; }
+.grading-wheel[aria-disabled="true"] { opacity: .4; cursor: default; }
+.grading-wheel__center { position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; border-radius: 50%; background: #555; transform: translate(-50%, -50%); }
+.grading-wheel__handle { position: absolute; width: 10px; height: 10px; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px #222; transform: translate(-50%, -50%); pointer-events: none; }