Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

Keep the storyboard animatic smooth under a film look

Claudea4b0563d3b70
diff --git a/client/src/components/media/FilmLookFrame.jsx b/client/src/components/media/FilmLookFrame.jsx
index f9a466452b..5d902839e5 100644
--- a/client/src/components/media/FilmLookFrame.jsx
+++ b/client/src/components/media/FilmLookFrame.jsx
@@ -1,18 +1,27 @@
import { useEffect, useId, useRef, useState } from 'react';
-import { filmLookFilterMarkup, isFilmLookNeutral, normalizeFilmLook } from '../../lib/filmLook.js';
+import { filmLookFilterMarkup, filmLookMotionLayers, isFilmLookNeutral, normalizeFilmLook } from '../../lib/filmLook.js';
// Before the box is measured (and in a test DOM that never lays out), radii
// scale to a nominal preview width rather than to nothing.
const NOMINAL = { width: 1280, height: 720 };
/**
- * Children seen through a film look, live: the same SVG filter the render and
- * the gallery bake use, sized to this box so every radius reads as it will at
- * full size. `frame` is the song frame; it re-seeds the grain and drift so the
- * texture moves the way the finished render's does. A neutral look renders the
- * children untouched.
+ * Children seen through a film look, live, sized to this box so every radius
+ * reads as it will at full size. `frame` is the song frame; it re-seeds the
+ * grain and drives the weave, flicker and leak drift the way the render's frame
+ * does. Two renderings of the same look:
+ *
+ * - paused (`playing` false): the exact SVG filter the render and the gallery
+ * bake use, over the whole box — one evaluation per frame shown;
+ * - playing: `filmLookMotionLayers`, CSS filter functions and blended overlay
+ * layers the compositor runs per video frame for free, because a browser
+ * re-runs an SVG filter chain over every decoded frame and the full look
+ * stalled a phone's playback after #11215. The glows, fringing and split tone
+ * wait for the pause.
+ *
+ * A neutral look renders the children untouched.
*/
-export default function FilmLookFrame({ look, frame = 0, className = '', children }) {
+export default function FilmLookFrame({ look, frame = 0, playing = false, className = '', children }) {
const ref = useRef(null);
const [size, setSize] = useState(NOMINAL);
const filterId = `portos-film-look-${useId().replace(/[^A-Za-z0-9_-]/g, '')}`;
@@ -28,11 +37,41 @@ export default function FilmLookFrame({ look, frame = 0, className = '', childre
observer.observe(box);
return () => observer.disconnect();
}, [active]);
- const built = active ? filmLookFilterMarkup(settings, { frame, width: size.width, height: size.height, id: filterId }) : null;
+ if (!active) return <div ref={ref} className={`relative ${className}`}>{children}</div>;
+ if (!playing) {
+ const built = filmLookFilterMarkup(settings, { frame, width: size.width, height: size.height, id: filterId });
+ return (
+ <div ref={ref} className={`relative ${className}`} style={built.active ? { filter: built.css } : undefined} data-film-look={built.active ? 'exact' : undefined}>
+ {built.active && <div aria-hidden="true" dangerouslySetInnerHTML={{ __html: built.svg }} />}
+ {children}
+ </div>
+ );
+ }
+ const motion = filmLookMotionLayers(settings, { frame, width: size.width, height: size.height });
return (
- <div ref={ref} className={`relative ${className}`} style={built?.active ? { filter: built.css } : undefined} data-film-look={built?.active ? 'on' : undefined}>
- {built?.active && <div aria-hidden="true" dangerouslySetInnerHTML={{ __html: built.svg }} />}
- {children}
+ <div ref={ref} className={`relative overflow-hidden ${className}`} data-film-look="motion">
+ <div className="absolute inset-0" style={{ filter: motion.filter || undefined, transform: motion.transform || undefined }} data-film-look-layer="picture">{children}</div>
+ {motion.overlays.map((layer) => (
+ <div
+ key={layer.key}
+ aria-hidden="true"
+ data-film-look-layer={layer.key}
+ className={`pointer-events-none absolute ${layer.kind === 'tile' ? 'left-0 top-0 h-[200%] w-[200%]' : 'inset-0'}`}
+ style={{
+ opacity: layer.opacity,
+ mixBlendMode: layer.blend,
+ ...(layer.kind === 'flat' ? { backgroundColor: layer.color } : {}),
+ ...(layer.kind === 'gradient' ? { backgroundImage: layer.gradient } : {}),
+ ...(layer.kind === 'tile' ? {
+ backgroundImage: `url("${layer.image}")`,
+ backgroundSize: `${layer.size[0]}px ${layer.size[1]}px`,
+ backgroundRepeat: 'repeat',
+ // Half the oversized tile layer is spare on each axis: the shift slides it compositor-side.
+ transform: `translate(${-layer.shift[0] * 50}%, ${-layer.shift[1] * 50}%)`,
+ } : {}),
+ }}
+ />
+ ))}
</div>
);
}
diff --git a/client/src/components/musicVideo/StoryboardAnimatic.jsx b/client/src/components/musicVideo/StoryboardAnimatic.jsx
index 7760ee5db6..c081fb88be 100644
--- a/client/src/components/musicVideo/StoryboardAnimatic.jsx
+++ b/client/src/components/musicVideo/StoryboardAnimatic.jsx
@@ -1,7 +1,8 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import FilmLookFrame from '../media/FilmLookFrame.jsx';
+import { safeReadStorage, safeWriteStorage } from '../../lib/safeStorage.js';
import { isFilmLookNeutral } from '../../lib/filmLook.js';
-import { Captions } from 'lucide-react';
+import { Captions, Film } from 'lucide-react';
import { formatDurationSec } from '../../utils/formatters.js';
import { getMusicVideoLyricOverlayPreview } from '../../services/apiMusicVideo.js';
import { playthroughVersion } from './CompositionPreviewPlayer.jsx';
@@ -165,6 +166,8 @@ export function clipTimeAt(scene, t, clipSec = null) {
const CLIP_PRELOAD_SHOTS = 2;
// The song frame the film look's grain and drift follow; footage renders run at 24 fps.
const ANIMATIC_FPS = 24;
+// Remembers, per viewer, that the animatic plays without the project's film look.
+const ANIMATIC_LOOK_KEY = 'portos-mv-animatic-look';
/**
* A shot's selected video clip, muted under the master song and kept in step
@@ -235,6 +238,12 @@ export default function StoryboardAnimatic({ project, audioUrl, seekRequest, col
const applied = useRef(null);
const [time, setTime] = useState(0);
const [lyricsOn, setLyricsOn] = useState(true);
+ // The look is the render's; a viewer whose phone struggles can watch without it.
+ const [lookOn, setLookOn] = useState(() => safeReadStorage(ANIMATIC_LOOK_KEY) !== 'off');
+ // While the song plays the look is the light playback version; paused, the exact render filter.
+ const [playing, setPlaying] = useState(false);
+ const lookAvailable = !isFilmLookNeutral(project.filmLook);
+ const toggleLook = () => setLookOn((on) => { safeWriteStorage(ANIMATIC_LOOK_KEY, on ? 'off' : 'on'); return !on; });
const scenes = project.scenes || [];
const lyricsAvailable = hasTimedLyrics(project);
const { overlay, failed } = useLyricOverlay({ project, enabled: lyricsAvailable && lyricsOn, audioRef, time });
@@ -265,7 +274,7 @@ export default function StoryboardAnimatic({ project, audioUrl, seekRequest, col
<div className={`space-y-2 ${collapsed ? 'max-xl:hidden' : ''}`}>
<figure aria-label="Storyboard animatic" className="relative aspect-video w-full overflow-hidden rounded border border-port-border bg-black">
{/* The project's film look, as the final render applies it over the whole picture, lyrics included. */}
- <FilmLookFrame look={project.filmLook} frame={Math.round(time * ANIMATIC_FPS)} className="h-full w-full">
+ <FilmLookFrame look={lookOn ? project.filmLook : null} frame={Math.round(time * ANIMATIC_FPS)} playing={playing} className="h-full w-full">
{shot?.referenceImageId ? (
<img src={`/data/images/${shot.referenceImageId}`} alt="" className="h-full w-full object-contain" />
) : cardInFrame && !shot?.videoHistoryId ? (
@@ -286,7 +295,6 @@ export default function StoryboardAnimatic({ project, audioUrl, seekRequest, col
<div className="flex flex-wrap items-center gap-x-2 gap-y-1">
<ShotStepper scenes={timed} time={time} onSeek={seekTo} keys />
<span className="tabular-nums">{formatDurationSec(shot.startSec)}</span>
- {!isFilmLookNeutral(project.filmLook) && <span className="text-port-accent">Film look</span>}
</div>
)}
{!cardInFrame && shot && !shot.referenceImageId && !shot.videoHistoryId && (
@@ -296,6 +304,17 @@ export default function StoryboardAnimatic({ project, audioUrl, seekRequest, col
)}
{lyricsOn && failed && <p className="text-port-error">The lyrics could not be drawn over the animatic.</p>}
</div>
+ {lookAvailable && (
+ <button
+ type="button"
+ onClick={toggleLook}
+ aria-pressed={lookOn}
+ title={lookOn ? 'Showing the project film look: a light version while playing, the exact render look when paused. Tap to watch without it.' : 'Film look hidden in the animatic; the render still applies it'}
+ className={`flex min-h-[44px] shrink-0 items-center gap-1 rounded border px-2 text-xs sm:min-h-0 sm:py-1 ${lookOn ? 'border-port-accent text-port-accent' : 'border-port-border text-port-text-muted'}`}
+ >
+ <Film size={14} aria-hidden="true" /> Film look
+ </button>
+ )}
{lyricsAvailable && (
<button
type="button"
@@ -315,6 +334,9 @@ export default function StoryboardAnimatic({ project, audioUrl, seekRequest, col
aria-label="Song for the storyboard animatic"
onTimeUpdate={(e) => setTime(e.currentTarget.currentTime)}
onSeeked={(e) => setTime(e.currentTarget.currentTime)}
+ onPlay={() => setPlaying(true)}
+ onPause={() => setPlaying(false)}
+ onEnded={() => setPlaying(false)}
className="w-full"
/>
</div>
diff --git a/client/src/components/musicVideo/StoryboardAnimatic.test.jsx b/client/src/components/musicVideo/StoryboardAnimatic.test.jsx
index cf6ada8a64..eaef09a93d 100644
--- a/client/src/components/musicVideo/StoryboardAnimatic.test.jsx
+++ b/client/src/components/musicVideo/StoryboardAnimatic.test.jsx
@@ -145,25 +145,49 @@ describe('StoryboardAnimatic clips', () => {
});
describe('StoryboardAnimatic film look', () => {
- // Uniquely catches the animatic showing footage without the look the final render will apply.
- it('shows the project film look over the whole picture on the song frame, and nothing without one', () => {
- const look = { preset: 'super8', grain: 0.5, halation: 0.4 };
+ // Uniquely catches the animatic showing footage without the look the final render will apply,
+ // and an SVG filter over the PLAYING picture (re-run per video frame, it stalled a phone after #11215).
+ it('shows the exact look when paused, a light compositor-only look while playing, and nothing without one', () => {
+ const look = { preset: 'super8', defocus: 0.2, grain: 0.5, halation: 0.4, vignette: 0.3 };
const { container, rerender } = render(<StoryboardAnimatic project={{ id: 'p', scenes, filmLook: look }} audioUrl="/song.mp3" />);
- const frame = container.querySelector('figure [data-film-look="on"]');
- expect(frame).toBeTruthy();
- expect(frame.style.filter).toMatch(/^url\(#portos-film-look-/);
- expect(frame.querySelector('svg filter')).toBeTruthy();
- expect(screen.getByText('Film look')).toBeTruthy();
- const before = frame.querySelector('svg').innerHTML;
const audio = screen.getByLabelText('Song for the storyboard animatic');
+ // Paused: the render's filter over the whole box.
+ const exact = container.querySelector('figure [data-film-look="exact"]');
+ expect(exact).toBeTruthy();
+ expect(exact.style.filter).toMatch(/^url\(#portos-film-look-/);
+ expect(exact.querySelector('svg filter feTurbulence')).toBeTruthy();
+ // Playing: no SVG filter anywhere in the picture; CSS functions on it and tiles over it.
+ fireEvent.play(audio);
+ const motion = container.querySelector('figure [data-film-look="motion"]');
+ expect(motion).toBeTruthy();
+ expect(motion.querySelector('svg')).toBeNull();
+ const picture = motion.querySelector('[data-film-look-layer="picture"]');
+ expect(picture.style.filter).toMatch(/^blur\(/);
+ expect(picture.style.filter).not.toContain('url(');
+ const grain = motion.querySelector('[data-film-look-layer="grain"]');
+ expect(grain.style.mixBlendMode).toBe('overlay');
+ expect(grain.style.opacity).toBe('0.5');
+ expect(motion.querySelector('[data-film-look-layer="vignette"]')).toBeTruthy();
+ const shiftBefore = grain.style.transform;
Object.defineProperty(audio, 'currentTime', { value: 12, configurable: true });
fireEvent.timeUpdate(audio);
- // The picture sits inside the filtered box, and the grain re-seeds on the new song frame.
- const after = container.querySelector('figure [data-film-look="on"]');
+ // The picture sits inside the filtered box, and the grain tile shifts on the new song frame.
+ const after = container.querySelector('figure [data-film-look="motion"]');
expect(after.querySelector('img').getAttribute('src')).toBe('/data/images/frame-b.png');
- expect(after.querySelector('svg').innerHTML).not.toBe(before);
+ expect(after.querySelector('[data-film-look-layer="grain"]').style.transform).not.toBe(shiftBefore);
+ fireEvent.pause(audio);
+ expect(container.querySelector('figure [data-film-look="exact"]')).toBeTruthy();
+ // The viewer can watch without the look; the choice is remembered.
+ const toggle = screen.getByRole('button', { name: 'Film look' });
+ expect(toggle.getAttribute('aria-pressed')).toBe('true');
+ fireEvent.click(toggle);
+ expect(container.querySelector('[data-film-look]')).toBeNull();
+ expect(toggle.getAttribute('aria-pressed')).toBe('false');
+ expect(globalThis.localStorage.getItem('portos-mv-animatic-look')).toBe('off');
+ fireEvent.click(toggle);
+ expect(container.querySelector('figure [data-film-look="exact"]')).toBeTruthy();
rerender(<StoryboardAnimatic project={{ id: 'p', scenes, filmLook: null }} audioUrl="/song.mp3" />);
expect(container.querySelector('[data-film-look]')).toBeNull();
- expect(screen.queryByText('Film look')).toBeNull();
+ expect(screen.queryByRole('button', { name: 'Film look' })).toBeNull();
});
});
diff --git a/client/src/lib/README.md b/client/src/lib/README.md
index d831e4ce90..330bfc0db8 100644
--- a/client/src/lib/README.md
+++ b/client/src/lib/README.md
@@ -314,5 +314,5 @@ grep -i "what you want to do" client/src/lib/README.md
| `navPresentation.js` | Sidebar icon presentation and section ordering, separate from the Layout React refresh boundary. |
| `musicVideoGrade.js` | Shared Music Video grade preset and grain bounds for the composition controls. |
-| `filmLook.js` | Shared film look controls, presets, normalizer, prompt vocabulary and the SVG filter markup the editor previews with (server `lib/filmLook.js`). |
+| `filmLook.js` | Shared film look controls, presets, normalizer, prompt vocabulary, the SVG filter markup the editor previews with and the playback-time motion layers (server `lib/filmLook.js`). |
| `musicVideoNarrativeEvents.js` | Named narrative event kinds, absolute onset/word/frame resolution and deterministic silence/reactive state for composition documents. |
diff --git a/client/src/lib/filmLook.js b/client/src/lib/filmLook.js
index 6dcbe9cd97..570ebb15f6 100644
--- a/client/src/lib/filmLook.js
+++ b/client/src/lib/filmLook.js
@@ -11,4 +11,5 @@ export {
describeFilmLook,
filmLookControl,
filmLookFilterMarkup,
+ filmLookMotionLayers,
} from '../../../server/lib/filmLook.js';
diff --git a/docs/HTML_COMPOSITIONS.md b/docs/HTML_COMPOSITIONS.md
index 13f47efc06..ca1ebb86da 100644
--- a/docs/HTML_COMPOSITIONS.md
+++ b/docs/HTML_COMPOSITIONS.md
@@ -313,6 +313,16 @@ what the preview shows and what the render bakes:
cancel aborts it.
- **The storyboard animatic** (the docked preview for footage projects) shows
the look live over the whole picture, lyrics included, on the song frame.
+ Paused, that is the exact filter; **while the song plays** it is the light
+ playback version (`filmLookMotionLayers`, `FilmLookFrame.jsx`): a browser
+ re-runs an SVG filter chain over every decoded video frame, and the full
+ look took a phone's animatic from 30 fps to under 1 after #11215. The playback
+ version is compositor-only: CSS filter functions for focus, tone and
+ saturation, the gate weave as a transform, and the cast, grain, tape bands,
+ vignette and leak as blended overlays (the noise rasterized once as tiles
+ and shifted per song frame). The glows, fringing and split tone wait for the
+ pause. The **Film look** button under the animatic turns the preview look
+ off for that viewer (remembered on the device); the render still applies it.
The filter is an SVG `<filter>` applied to the document root (or to the
`<img>` for a still). Radii and offsets scale with the filtered element's
diff --git a/server/lib/README.md b/server/lib/README.md
index e75a0cfb72..685d6bb197 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -856,7 +856,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `musicVideoActionContract.js` | Versioned shot intent shape/timing validation and clip-relative frame/motion prompt compilation, shared by treatment and the board. |
| `sheetPointers.js` | Browser-safe persisted character-sheet layout: `LEGACY_SHEET_VARIANT_ID`, `readSheetPointer`, `listSheetPointers`, identity-preserving `applySheetPointerToCharacter`, and default-variant browser adapter `applySheetPointer`. |
| `musicVideoGrade.js` | Opt-in Music Video grade presets, bounded normalization, and shared song-timed RGB curves with deterministic grain for composed and document encodes. |
-| `filmLook.js` | The film look: `FILM_LOOK_CONTROLS` (sliders, colors, toggles with their photography terms and prompt words), `FILM_LOOK_PRESETS`, `normalizeFilmLook`, `isFilmLookNeutral`, `describeFilmLook` (the look as prompt vocabulary), `filmLookFilterMarkup` (the one SVG filter the live preview, the document render and gallery bakes apply, frame-seeded) and `filmLookRuntimeSource` (the page script that applies and re-seeds it per seek). Browser-safe. |
+| `filmLook.js` | The film look: `FILM_LOOK_CONTROLS` (sliders, colors, toggles with their photography terms and prompt words), `FILM_LOOK_PRESETS`, `normalizeFilmLook`, `isFilmLookNeutral`, `describeFilmLook` (the look as prompt vocabulary), `filmLookFilterMarkup` (the one SVG filter the live preview, the document render and gallery bakes apply, frame-seeded), `filmLookMotionLayers` (the same look as CSS filter functions plus blended overlays a playing video can afford) and `filmLookRuntimeSource` (the page script that applies and re-seeds it per seek). Browser-safe. |
| `filmLookValidation.js` | `filmLookSchema` / `filmLookBakeSchema`: the Zod shape of a film look, derived from `FILM_LOOK_CONTROLS`. |
| `musicVideoTitleCard.js` | The MTV-style opening title card (song, artist, year over the opener): `normalizeTitleCard`, `titleCardVisible`, `titleCardPrefill` (a new card's text and a window ending before the first sung line), and `titleCardRuntimeSource` (the page script the live preview and the document render install to draw it per seek, with its fade and title-safe layout). Browser-safe. |
| `musicVideoDependencies.js` | Versioned take/evidence provenance, dependency comparisons and bounded selective-repair previews. |
diff --git a/server/lib/filmLook.js b/server/lib/filmLook.js
index cff2b5dc02..f99a97d03c 100644
--- a/server/lib/filmLook.js
+++ b/server/lib/filmLook.js
@@ -363,6 +363,103 @@ export function filmLookFilterMarkup(look, { frame = 0, width = 1920, height = 1
};
}
+const FILM_LOOK_TILE_PX = 256;
+const svgDataUrl = (markup) => `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" ${markup}</svg>`)}`;
+const frameHash = (seed) => {
+ let x = Math.imul(seed + 0x9e3779b9, 0x85ebca6b) >>> 0;
+ x ^= x >>> 13; x = Math.imul(x, 0xc2b2ae35) >>> 0; x ^= x >>> 16;
+ return (x >>> 0) / 4294967296;
+};
+const hexColor = (value, fallback) => (typeof value === 'string' && /^#[0-9a-f]{6}$/i.test(value) ? value : fallback);
+
+/**
+ * The look as a PLAYING picture can afford it: no SVG filter, which a browser
+ * re-runs over every decoded video frame (the full chain drops a phone's
+ * animatic from 30 fps to under 1 after #11215), only what the
+ * compositor does for free. The focus, tone and saturation become CSS filter
+ * functions on the box holding the picture (`filter`, with the gate weave as
+ * its `transform`), and the cast, grain, tape bands, vignette and leak become
+ * blended `overlays` in the render's order, each a flat color, a gradient or a
+ * tile rasterized once (`image`) and shifted per song frame (`shift`, [0, 1)).
+ * The glows, the fringing and the split tone have no cheap stand-in and are
+ * left to the exact filter the paused picture shows. Returns null for a
+ * neutral look.
+ */
+export function filmLookMotionLayers(look, { frame = 0, width = 1920, height = 1080 } = {}) {
+ const settings = normalizeFilmLook(look);
+ if (!settings || isFilmLookNeutral(settings)) return null;
+ const v = (key) => (Number.isFinite(settings[key]) ? settings[key] : 0);
+ const n = (value) => Number(value.toFixed(4));
+ const w = Math.max(1, width);
+ const h = Math.max(1, height);
+ const f = Math.max(0, Math.floor(frame));
+ const filter = [];
+ const defocus = v('defocus');
+ if (defocus > 0) filter.push(`blur(${n(Math.pow(defocus, 1.5) * 0.014 * w)}px)`);
+ // The render's per-channel transfer v' = slope·v + intercept, as brightness(b) then
+ // contrast(k): k·b·v + (1 − k)/2, so k = 1 − 2·intercept and b = slope / k.
+ const exposure = v('exposure'); const contrast = v('contrast'); const fade = v('fade'); const flicker = v('flicker');
+ if (exposure || contrast || fade || flicker) {
+ const e = Math.pow(2, exposure) * (1 + flicker * 0.12 * (frameHash(f) * 2 - 1));
+ const c = 1 + contrast * 0.8;
+ const s = 1 - 0.28 * fade;
+ const slope = e * c * s;
+ const intercept = s * ((1 - c) / 2) + 0.2 * fade;
+ const k = Math.max(0.05, 1 - 2 * intercept);
+ filter.push(`brightness(${n(slope / k)})`, `contrast(${n(k)})`);
+ }
+ const saturation = v('saturation');
+ if (saturation) filter.push(`saturate(${n(Math.max(0, 1 + saturation))})`);
+ const weave = v('weave');
+ const transform = weave > 0
+ ? `translate(${n(weave * 0.004 * w * (Math.sin(f * 0.37) + 0.6 * Math.sin(f * 1.13)) / 1.6)}px, ${n(weave * 0.004 * h * (Math.cos(f * 0.29) + 0.6 * Math.sin(f * 0.91)) / 1.6)}px)`
+ : null;
+
+ const overlays = [];
+ const flat = (key, color, opacity, blend) => overlays.push({ key, kind: 'flat', color, opacity: n(opacity), blend });
+ // Warmth and tint are per-channel scales in the render; a soft-light wash leans the picture the same way.
+ const warmth = v('warmth');
+ if (warmth) flat('warmth', warmth > 0 ? '#ff9a3c' : '#3c9aff', Math.min(1, Math.abs(warmth) * 0.9), 'soft-light');
+ const tint = v('tint');
+ if (tint) flat('tint', tint > 0 ? '#ff3cff' : '#3cff3c', Math.min(1, Math.abs(tint) * 0.6), 'soft-light');
+ const cast = v('cast');
+ if (cast > 0) flat('cast', hexColor(settings.castColor, '#b9c04a'), cast, 'soft-light');
+ const mono = '1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1';
+ const color = '1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1';
+ const grain = v('grain');
+ if (grain > 0) {
+ const size = Number.isFinite(settings.grainSize) ? settings.grainSize : 0.35;
+ const baseFrequency = Math.min(1.5, (0.95 - 0.7 * size) * (1920 / w));
+ const tile = FILM_LOOK_TILE_PX;
+ overlays.push({
+ key: 'grain', kind: 'tile', size: [tile, tile], opacity: n(grain), blend: 'overlay', shift: [n(frameHash(f)), n(frameHash(f + 1))],
+ image: svgDataUrl(`width="${tile}" height="${tile}"><filter id="g" x="0" y="0" width="100%" height="100%" color-interpolation-filters="sRGB"><feTurbulence type="fractalNoise" baseFrequency="${n(baseFrequency)}" numOctaves="2" seed="7" stitchTiles="stitch"/><feColorMatrix type="matrix" values="${settings.grainColor === true ? color : mono}"/></filter><rect width="${tile}" height="${tile}" filter="url(#g)"/>`),
+ });
+ }
+ const tape = v('tapeNoise');
+ if (tape > 0) {
+ const tileW = Math.round(w);
+ const tileH = 128;
+ overlays.push({
+ key: 'tape', kind: 'tile', size: [tileW, tileH], opacity: n(0.8 * tape), blend: 'soft-light', shift: [0, n(frameHash(f * 7))],
+ image: svgDataUrl(`width="${tileW}" height="${tileH}"><filter id="t" x="0" y="0" width="100%" height="100%" color-interpolation-filters="sRGB"><feTurbulence type="fractalNoise" baseFrequency="${n(0.0015 * (1920 / w))} ${n(0.45 * (1080 / h))}" numOctaves="1" seed="11" stitchTiles="stitch"/><feColorMatrix type="matrix" values="${mono}"/></filter><rect width="${tileW}" height="${tileH}" filter="url(#t)"/>`),
+ });
+ }
+ const vignette = v('vignette');
+ if (vignette > 0) {
+ overlays.push({ key: 'vignette', kind: 'gradient', opacity: 1, blend: 'normal',
+ gradient: `radial-gradient(ellipse at center, rgba(0,0,0,0) ${Math.round(58 - 22 * vignette)}%, rgba(0,0,0,${n(vignette)}) 100%)` });
+ }
+ const leak = v('leak');
+ if (leak > 0) {
+ const drift = 0.62 + 0.18 * Math.sin(f * 0.011) + 0.05 * Math.sin(f * 0.047);
+ const breathe = 0.75 + 0.25 * Math.sin(f * 0.023 + 1);
+ overlays.push({ key: 'leak', kind: 'gradient', opacity: n(Math.min(1, leak * breathe)), blend: 'screen',
+ gradient: `radial-gradient(ellipse 40% 140% at ${n((drift + 0.15) * 100)}% 50%, ${hexColor(settings.leakColor, '#ff7a2a')} 0%, rgba(0,0,0,0) 70%)` });
+ }
+ return { filter: filter.join(' ') || null, transform, overlays };
+}
+
/**
* A browser script that applies a look to the page it runs in, re-seeding it
* for every song frame: installed in the composition live preview and in the
diff --git a/server/lib/filmLook.test.js b/server/lib/filmLook.test.js
index 9a9b5d0466..e49392fa02 100644
--- a/server/lib/filmLook.test.js
+++ b/server/lib/filmLook.test.js
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
import {
- FILM_LOOK_CONTROLS, FILM_LOOK_PRESETS, describeFilmLook, filmLookFilterMarkup, filmLookPreset, filmLookRuntimeSource,
+ FILM_LOOK_CONTROLS, FILM_LOOK_PRESETS, describeFilmLook, filmLookFilterMarkup, filmLookMotionLayers, filmLookPreset, filmLookRuntimeSource,
isFilmLookNeutral, normalizeFilmLook,
} from './filmLook.js';
import { filmLookSchema } from './filmLookValidation.js';
@@ -95,3 +95,45 @@ describe('film look runtime', () => {
expect(filmLookRuntimeSource(null)).toContain('let look = null;');
});
});
+
+describe('film look motion layers', () => {
+ // Uniquely catches an SVG filter coming back into the playing picture (a browser re-runs it over
+ // every decoded video frame: 30 fps → under 1 on a phone after #11215) and the stages leaving the render's order.
+ it('turns the look into CSS filter functions and blended overlays, with the noise as tiles shifted per frame', () => {
+ const look = normalizeFilmLook({ defocus: 0.3, halation: 0.4, contrast: -0.2, fade: 0.3, saturation: 0.15, warmth: 0.2, cast: 0.2, castColor: '#b9c04a', grain: 0.6, grainSize: 0.5, tapeNoise: 0.5, vignette: 0.4, leak: 0.3, weave: 0.5 });
+ const motion = filmLookMotionLayers(look, { frame: 12, width: 390, height: 219 });
+ expect(motion.filter).toMatch(/^blur\([\d.]+px\) brightness\([\d.]+\) contrast\([\d.]+\) saturate\(1\.15\)$/);
+ expect(motion.filter).not.toContain('url(');
+ expect(motion.transform).toMatch(/^translate\(-?[\d.]+px, -?[\d.]+px\)$/);
+ expect(motion.overlays.map((layer) => [layer.key, layer.kind, layer.blend])).toEqual([
+ ['warmth', 'flat', 'soft-light'], ['cast', 'flat', 'soft-light'], ['grain', 'tile', 'overlay'], ['tape', 'tile', 'soft-light'], ['vignette', 'gradient', 'normal'], ['leak', 'gradient', 'screen'],
+ ]);
+ const grain = motion.overlays.find((layer) => layer.key === 'grain');
+ expect(grain).toMatchObject({ opacity: 0.6, size: [256, 256] });
+ expect(decodeURIComponent(grain.image)).toContain('<feTurbulence type="fractalNoise"');
+ expect(decodeURIComponent(grain.image)).toContain('stitchTiles="stitch"');
+ expect(motion.overlays.find((layer) => layer.key === 'cast')).toMatchObject({ color: '#b9c04a', opacity: 0.2 });
+ expect(motion.overlays.find((layer) => layer.key === 'tape')).toMatchObject({ opacity: 0.4, size: [390, 128] });
+ expect(motion.overlays.find((layer) => layer.key === 'vignette').gradient).toContain('rgba(0,0,0,0.4) 100%');
+ // The tone transfer matches the render's: brightness(b) then contrast(k) = slope·v + intercept.
+ const [, b, k] = /brightness\(([\d.]+)\) contrast\(([\d.]+)\)/.exec(motion.filter).map(Number);
+ const c = 1 - 0.2 * 0.8; const s = 1 - 0.28 * 0.3;
+ expect(b * k).toBeCloseTo(c * s, 3);
+ expect((1 - k) / 2).toBeCloseTo(s * ((1 - c) / 2) + 0.2 * 0.3, 3);
+ // Frames shift the tiles and drift the leak; the tile images stay the same, so they rasterize once.
+ const next = filmLookMotionLayers(look, { frame: 13, width: 390, height: 219 });
+ const grainNext = next.overlays.find((layer) => layer.key === 'grain');
+ expect(grainNext.shift).not.toEqual(grain.shift);
+ expect(grainNext.image).toBe(grain.image);
+ expect(next.transform).not.toBe(motion.transform);
+ expect(filmLookMotionLayers(look, { frame: 12, width: 390, height: 219 })).toEqual(motion);
+ });
+
+ it('carries only what a look uses, and is null for a neutral one', () => {
+ const flat = filmLookMotionLayers({ saturation: -0.4 }, {});
+ expect(flat).toEqual({ filter: 'saturate(0.6)', transform: null, overlays: [] });
+ expect(filmLookMotionLayers({ grain: 0.3 }, {}).filter).toBeNull();
+ expect(filmLookMotionLayers(filmLookPreset('none'), {})).toBeNull();
+ expect(filmLookMotionLayers(null)).toBeNull();
+ });
+});