Skip to content

Commit e2bb7da

Browse files
vanceingallsclaude
andauthored
feat(core): auto motion blur draws with the filter tier (#7288)
* feat(core): auto motion blur draws with the filter tier Capture stays available as data-motion-blur-tier="capture". auto now draws with the filter tier (reasonCode tier-auto), so the capture-only defects leave the default path. Removes the translation-only hand-off and its Discovery field, adds a filter arm to the differential, and updates the check, guide, skill and Blur panel label. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * docs(core): measured cost and known limits of the filter tier, the new auto default spacex-launch (77 movers) takes 2.9x the CPU of no blur on the filter tier and 1.7x on capture; say so, and list the filter tier's measured limits (sweep D, E, F, I, O, B). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * docs(core): word the filter tier's cost and limits as measured, not as mechanism Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * docs(core): do not say every filter-tier limit is pinned by a sweep test Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * test(engine): split the blur differential so each file fits the flake gate's 120 s run The filter arm moves to its own file and skips fixtures that already draw with the filter tier; inside cases get their own file; a fixture's blur-off page is opened once per file. Shared helpers live in __fixtures__/motionBlur/differentialPage.ts. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
1 parent 4bee04e commit e2bb7da

21 files changed

Lines changed: 405 additions & 330 deletions

‎docs/guides/motion-blur.mdx‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ That is all. The same attribute drives the browser editor preview and `hyperfram
3131
| `data-motion-blur-phase` | centred | When the shutter opens, in degrees of a frame, -360 to 360. The window starts at `t + phase / 360 / fps` and lasts `shutter / 360 / fps`. `0` opens on the frame, so the smear trails ahead of it; unset centres it, the same as minus half the shutter. Matches After Effects' Shutter Phase. |
3232
| `data-motion-blur-samples` | at least 32 | A fixed number of samples per frame, 2–64. Left unset, each mover gets at least 32, and about one per 2 px of smear when that is more, so a fast move never shows steps. |
3333
| `data-motion-blur-events` | off | `on` runs timeline callbacks (`onUpdate` and similar) while blur looks for movers, and at each sample when a callback changes an element's inline style or its box. Needed when the motion is set from a callback, such as a `render(t)` function, which blur cannot otherwise see. |
34-
| `data-motion-blur-tier` | `auto` | `capture` or `filter` forces one of the two ways blur is drawn (below). |
34+
| `data-motion-blur-tier` | `auto` | `auto` and `filter` draw with the filter tier; `capture` asks for the capture tier (below). |
3535

3636
## In the browser editor
3737

@@ -43,15 +43,19 @@ Elements that move quickly in 2D: position, scale and rotation changes from GSAP
4343

4444
## Two ways it is drawn
4545

46-
**Capture** copies each mover out of the page with Chrome's [HTML in Canvas](/guides/html-in-canvas) API and redraws it along its path. It draws turns and zooms truthfully: a spinning tile smears along its arc and its centre stays sharp, and a zoom streaks outward.
46+
**Filter** puts an SVG filter on each mover: copies of the element along its path, averaged, and softened along the motion. It is what `data-motion-blur-tier="auto"` (the default) draws with. It works in any Chrome and over a WebGL canvas. On a four-whip test it cost about what a render without blur costs; on two real films it cost more than capture (see Cost and limits). Turns and zooms are only softened, not streaked.
4747

48-
**Filter** puts an SVG filter on each mover: copies of the element along its path, averaged, and softened along the motion. It works in any Chrome, over a WebGL canvas, and costs about what a render without blur costs. Turns and zooms are only softened, not streaked.
48+
**Capture** is opt-in with `data-motion-blur-tier="capture"`. It copies each mover out of the page with Chrome's [HTML in Canvas](/guides/html-in-canvas) API and redraws it along its path. It draws turns and zooms truthfully: a spinning tile smears along its arc and its centre stays sharp, and a zoom streaks outward. It has limits of its own, listed here (the filter tier's are listed under Cost and limits, and a few, such as `backdrop-filter`, apply to both), so ask for it only for a film whose spins and zooms need the streak:
4949

50-
With `data-motion-blur-tier="auto"` (the default), blur uses the filter tier when every mover only translates and capture when anything turns or scales, because for translation the two look the same and the filter tier is much cheaper.
50+
- Anything in front of a mover is lost: a static panel, an overlay or a title card over a moving element is drawn behind its smear.
51+
- `mix-blend-mode` and `backdrop-filter` on a mover or its ancestor are not applied.
52+
- A CSS selector that reaches the root through its parent, such as `body > #root > .m`, stops matching once capture wraps the root.
53+
- A mover sliding into an `overflow: hidden` or clipped card drags the clip edge along, two overlapping movers carry each other's pixels, and content past the frame edge leaves a thin band.
54+
- In preview, the first frame after every play shows black for a moment.
5155

5256
Capture needs a browser with HTML in Canvas. Chrome 157 and 158 builds exposed it without a flag in headless and Chrome-for-Testing builds; whether stable Chrome does is unverified. Chrome 155 and earlier need `chrome://flags/#html-in-canvas`.
5357

54-
Blur uses the filter tier instead of capture when capture cannot run:
58+
A page that asks for capture gets the filter tier instead when capture cannot run:
5559

5660
| Found in the composition | Why capture cannot draw it |
5761
| --- | --- |
@@ -75,17 +79,24 @@ npx hyperframes check
7579

7680
| Finding | Severity | Meaning |
7781
| --- | --- | --- |
78-
| `motion_blur_filter_fallback` | info | Capture could not run, so the filter tier draws. The message names the cause and how to get capture back. |
82+
| `motion_blur_filter_fallback` | info | The page asked for capture, which could not run, so the filter tier draws. The message names the cause. |
7983
| `motion_blur_no_movers` | info | Blur is on but nothing moves fast enough to blur. If the motion is set from a callback, add `data-motion-blur-events="on"`. |
80-
| `motion_blur_unverified` | info | The check browser cannot run capture, so it drew with the filter tier. Render once to see capture. |
84+
| `motion_blur_unverified` | info | The page asks for capture and the check browser cannot run it, so it drew with the filter tier. Render once to see capture. |
8185

8286
In the page, `window.__hfMotionBlur.report()` returns `state`, `tier`, `reason`, `reasonCode` and `movers`. A render logs one line per session with the tier, and a session-end line when any frames fell back to sharp (`failedFrames > 0`).
8387

8488
## Cost and limits
8589

86-
- **Render time.** On an 8 s test composition with four whips, a render took 9.8 s with capture, 5.2–5.4 s with the filter tier and 5.3–5.9 s with no blur (two runs each, including startup). Capture adds a second paint per blurred frame; the filter tier adds almost nothing.
87-
- **Editing.** With capture the root is wrapped only while playing or rendering; paused, it is plain DOM, so click-to-select works. The filter tier never wraps anything.
90+
- **Render time.** It varies by film. On an 8 s test composition with four whips, a render took 9.8 s with capture, 5.2–5.4 s with the filter tier and 5.3–5.9 s with no blur (two runs each, including startup). On two real 1080p films the filter tier cost more than capture, measured as CPU seconds of the whole render (wall time was too noisy on a loaded machine): `spacex-launch` (77 movers, 39.5 s) took 547–552 CPU s with the filter tier, 302–320 with capture and 184–193 with no blur (three runs each, 2.9 times no blur); `k3-promo` (106 movers, 16.5 s) took 236, 205 and 117 (one run per arm, 2.0 times no blur). The two films do not order by mover count, and the cause of the difference was not isolated. The filter tier draws each mover as at least 32 offset copies per frame; capture adds a second paint per blurred frame.
91+
- **Editing.** The filter tier never wraps anything. With capture the root is wrapped only while playing or rendering; paused, it is plain DOM, so click-to-select works.
8892
- **Capture only.** Blurred preview can run at half the frame rate on heavy compositions, and a `<video>` drawn through the capture looks about 2–3% darker in the browser editor preview than in normal playback. Renders are not affected.
89-
- **Preview and render.** A browser without HTML in Canvas previews with the filter tier. A render then uses capture where the composition needs it, so a spin or zoom looks softer in that preview than in the render. Force one tier with `data-motion-blur-tier` for an exact match.
93+
- **Preview and render.** `auto` draws the same way in both. A page that asks for capture previews with the filter tier in a browser without HTML in Canvas, so a spin or zoom looks softer there than in the render.
9094
- **Worker count.** Output is not bit-identical between worker counts (around 60 dB PSNR), about the size of the difference chunking already causes.
9195
- **Not handled.** Pose errors under CSS `zoom`, `position: fixed` and `foreignObject`; a very short Web Animations API animation that falls between scan samples; a large see-through mover (a full-frame translucent sweep), which is left sharp while its fast children still blur. With capture, a mover is drawn above the static content, so a static element that should cover a mover does not.
96+
- **Limits of the filter tier** (the default), as measured on one-pattern test compositions:
97+
- `::before` or `::after` content outside the mover's box is cut off.
98+
- A mover's own `clip-path` or mask gets hard edges: the smear is clipped to the shape it has at that frame.
99+
- A `position: fixed` child of a mover that moves via `left` jumps, because the filter makes the mover its containing block.
100+
- A `:last-child` selector on the root's children also matches the `<svg>` the tier adds to the root (`nth-last-*` works the same way but was not measured).
101+
- A visibility toggle inside the shutter window is drawn at full strength instead of half.
102+
- `backdrop-filter` on a mover differs from the 32-sample oracle in the sweep (the backdrop only).

‎packages/cli/src/docs/motion-blur.md‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ Fast-moving elements get a shutter smear along their path. It is opt-in: nothing
99
- `data-motion-blur-phase` — when the shutter opens, in degrees of a frame, -360 to 360: 0 opens on the frame (default: centred on the frame, which is minus half the shutter)
1010
- `data-motion-blur-samples` — samples per frame, 2-64 (default: at least 32, sized to the smear)
1111
- `data-motion-blur-events` — `on` runs timeline callbacks while blur looks for movers; needed when motion is set from a `render(t)` callback
12-
- `data-motion-blur-tier` — `auto` (default), `capture` or `filter`
12+
- `data-motion-blur-tier` — `auto` (default, draws with `filter`), `filter` or `capture`
1313

1414
The same attributes drive the browser editor preview and `hyperframes render`.
1515

1616
## Two ways it is drawn
1717

18-
- `capture` redraws each mover along its path, so turns and zooms smear truthfully. Needs a browser with HTML in Canvas.
19-
- `filter` puts an SVG filter on each mover. Works in any Chrome and costs little; turns and zooms are only softened.
20-
21-
`auto` uses `filter` when every mover only translates and `capture` when anything turns or scales.
18+
- `filter` puts an SVG filter on each mover. Works in any Chrome; cost varies by film (one with 77 movers took about 2.9 times the CPU of no blur and 1.75 times `capture`'s; the cause was not isolated); turns and zooms are only softened. `auto` draws with it. It cuts off `::before`/`::after` content outside a mover's box, gives a mover's own `clip-path` or mask hard edges, makes a `position: fixed` child of a mover that moves via `left` jump, lets a `:last-child` selector match the `<svg>` it adds to the root, draws a visibility toggle inside the shutter at full strength, and differs from the oracle for `backdrop-filter` on a mover.
19+
- `capture` is opt-in. It redraws each mover along its path, so turns and zooms streak truthfully. Needs a browser with HTML in Canvas. It loses anything drawn in front of a mover, ignores `mix-blend-mode` on movers, and breaks selectors that reach the root through its parent.
2220

2321
## Check and render
2422

‎packages/cli/src/utils/checkMotionBlur.test.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,33 @@ describe("motionBlurDrafts", () => {
6767
expect(motionBlurDrafts(filter("accelerated-canvas", 0))[0]?.code).toBe(
6868
"motion_blur_no_movers",
6969
);
70-
expect(motionBlurDrafts(filter("translation-only"))).toEqual([]);
7170
expect(motionBlurDrafts(filter("tier-attribute"))).toEqual([]);
7271
});
7372

73+
it("reports nothing when auto draws with the filter tier, wherever the check browser runs", () => {
74+
const auto: MotionBlurProbe = {
75+
state: "on",
76+
tier: "filter",
77+
reason: 'auto draws with the filter tier; data-motion-blur-tier="capture" streaks turns',
78+
reasonCode: "tier-auto",
79+
movers: 3,
80+
};
81+
expect(motionBlurDrafts(auto)).toEqual([]);
82+
});
83+
84+
it("still informs when capture was forced and the check browser cannot run it", () => {
85+
const forced: MotionBlurProbe = {
86+
state: "on",
87+
tier: "filter",
88+
reason: "html-in-canvas (drawElementImage) is unavailable in this browser",
89+
reasonCode: "unsupported-browser",
90+
movers: 3,
91+
};
92+
expect(motionBlurDrafts(forced)).toMatchObject([
93+
{ code: "motion_blur_unverified", severity: "info" },
94+
]);
95+
});
96+
7497
it("only informs, once, when the browser cannot run html-in-canvas", () => {
7598
const drafts = motionBlurDrafts(off("unsupported-browser", "html-in-canvas is unavailable"));
7699
expect(drafts).toHaveLength(1);

‎packages/cli/src/utils/checkMotionBlur.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const OFF_HINTS: Record<string, string> = {
3232
"nested-capture-canvas":
3333
"remove the inner <canvas layoutsubtree> / content=drawable, or drop motion blur",
3434
};
35-
const CHOSEN = new Set(["translation-only", "tier-attribute"]);
35+
const CHOSEN = new Set(["tier-auto", "tier-attribute"]);
3636
const GENERIC_OFF_HINT = "remove what the reason names, or drop data-motion-blur";
3737

3838
const ASKED = 'data-motion-blur="on" is set but';

‎packages/core/src/runtime/captureMotionBlur/discover.test.ts‎

Lines changed: 1 addition & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
1+
import { afterEach, describe, expect, it, vi } from "vitest";
22
import { discoverMovers } from "./discover";
33

44
// jsdom lays nothing out: each element's rect follows the x its fake timeline writes.
@@ -303,97 +303,3 @@ describe("discoverMovers", () => {
303303
expect(discoverMovers({ scene, durationSeconds: 1, fps: 30, seek }).movers).toEqual([fast]);
304304
});
305305
});
306-
307-
describe("discoverMovers translationOnly", () => {
308-
// jsdom resolves no transforms: give computed style the inline matrix, as Chrome's would be.
309-
beforeEach(() => {
310-
const real = window.getComputedStyle.bind(window);
311-
vi.spyOn(window, "getComputedStyle").mockImplementation((el: Element) => {
312-
const cs = real(el);
313-
return new Proxy(cs, {
314-
get: (target, key) => {
315-
if (key === "transform")
316-
return el instanceof HTMLElement ? el.style.transform || "none" : "none";
317-
const value = Reflect.get(target, key);
318-
return typeof value === "function" ? value.bind(target) : value;
319-
},
320-
});
321-
});
322-
});
323-
afterEach(() => vi.restoreAllMocks());
324-
325-
// The box follows the matrix's x, or `left` when it has no transform.
326-
function mover(parent: Element, size = 10): HTMLElement {
327-
const el = document.createElement("div");
328-
parent.append(el);
329-
el.getBoundingClientRect = () => {
330-
const m = /matrix\(([^)]*)\)/.exec(el.style.transform);
331-
const x = m ? Number(m[1]?.split(",")[4]) : parseFloat(el.style.left) || 0;
332-
return {
333-
left: x,
334-
top: 0,
335-
right: x + size,
336-
bottom: size,
337-
width: size,
338-
height: size,
339-
} as DOMRect;
340-
};
341-
return el;
342-
}
343-
const scan = (scene: HTMLElement, seek: (t: number) => void) => {
344-
seek(0);
345-
return discoverMovers({ scene, durationSeconds: 1, fps: 30, seek });
346-
};
347-
348-
it("is true when movers only translate, with their own transform", () => {
349-
const scene = document.createElement("div");
350-
const el = mover(scene);
351-
const found = scan(scene, (t) => {
352-
el.style.transform = `matrix(1, 0, 0, 1, ${300 * t}, 0)`;
353-
});
354-
expect(found.movers).toEqual([el]);
355-
expect(found.translationOnly).toBe(true);
356-
});
357-
358-
it("is still true under a parent that scales by a constant", () => {
359-
const scene = document.createElement("div");
360-
const wrapper = document.createElement("div");
361-
wrapper.style.transform = "matrix(1.5, 0, 0, 1.5, 0, 0)";
362-
scene.append(wrapper);
363-
const el = mover(wrapper);
364-
const found = scan(scene, (t) => {
365-
el.style.transform = `matrix(1, 0, 0, 1, ${300 * t}, 0)`;
366-
});
367-
expect(found.translationOnly).toBe(true);
368-
});
369-
370-
it("is false when a mover turns or scales while it moves", () => {
371-
for (const linear of ["rotate", "scale"]) {
372-
const scene = document.createElement("div");
373-
const el = mover(scene);
374-
const found = scan(scene, (t) => {
375-
const a = linear === "scale" ? 1 + t : Math.cos(t);
376-
const b = linear === "scale" ? 0 : Math.sin(t);
377-
el.style.transform = `matrix(${a}, ${b}, ${-b}, ${a}, ${300 * t}, 0)`;
378-
});
379-
expect(found.movers).toEqual([el]);
380-
expect(found.translationOnly).toBe(false);
381-
}
382-
});
383-
384-
it("is false when a mover is moved without a transform, which a filter would re-stack", () => {
385-
const scene = document.createElement("div");
386-
const el = mover(scene);
387-
const found = scan(scene, (t) => {
388-
el.style.left = `${300 * t}px`;
389-
});
390-
expect(found.movers).toEqual([el]);
391-
expect(found.translationOnly).toBe(false);
392-
});
393-
394-
it("is false when nothing moves", () => {
395-
const scene = document.createElement("div");
396-
mover(scene);
397-
expect(scan(scene, () => {}).translationOnly).toBe(false);
398-
});
399-
});

‎packages/core/src/runtime/captureMotionBlur/discover.ts‎

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import { isHtmlElement } from "../domRealm";
1111
import { inkPad } from "./ink";
12-
import { individualIs3d, parseTransform } from "./pose";
12+
import { individualIs3d } from "./pose";
1313

1414
/** Under this peak speed (px per frame) a smear is invisible, so the element stays sharp. */
1515
const MIN_SPEED = 2;
@@ -47,7 +47,6 @@ export interface Discovery {
4747
dynamic: Set<Element>;
4848
/** Px each mover's ink reaches past its box (shadows, glows), the largest seen. */
4949
pads: Map<HTMLElement, number>;
50-
translationOnly: boolean;
5150
}
5251

5352
// The whole inline style in one read; opacity or colour tweens only cost a rect check.
@@ -76,22 +75,6 @@ function in3d(el: Element, scene: Element): boolean {
7675
return false;
7776
}
7877

79-
function linearSignature(el: Element, scene: Element): string {
80-
const parts: string[] = [];
81-
for (let n: Element | null = el; n && n !== scene; n = n.parentElement) {
82-
const cs = getComputedStyle(n);
83-
const m = parseTransform(cs.transform);
84-
parts.push(m ? [m.a, m.b, m.c, m.d].map((v) => v.toFixed(3)).join(",") : "1,0,0,1");
85-
parts.push(cs.rotate ?? "none", cs.scale ?? "none");
86-
}
87-
return parts.join("|");
88-
}
89-
90-
function hasOwnContext(el: Element): boolean {
91-
const cs = getComputedStyle(el);
92-
return cs.transform !== "none" || (cs.translate ?? "none") !== "none";
93-
}
94-
9578
/** Elements a CSS animation or WAAPI animation moves (no inline style to diff). */
9679
function pageAnimated(scene: Element): Set<HTMLElement> {
9780
const out = new Set<HTMLElement>();
@@ -203,15 +186,8 @@ export function discoverMovers({
203186
const fast = new Set<HTMLElement>();
204187
const threeD = new Set<HTMLElement>();
205188
const pads = new Map<HTMLElement, number>();
206-
const signatures = new Map<HTMLElement, string>();
207-
const notPlain = new Set<HTMLElement>();
208189
const measure = (el: HTMLElement): void => {
209190
pads.set(el, Math.max(pads.get(el) ?? 0, inkPad(el)));
210-
const sig = linearSignature(el, scene);
211-
const first = signatures.get(el);
212-
if (first === undefined) signatures.set(el, sig);
213-
else if (first !== sig) notPlain.add(el);
214-
if (!hasOwnContext(el)) notPlain.add(el);
215191
};
216192
const seeThrough = new Set<HTMLElement>();
217193
const alphaCache = new Map<Bitmap, boolean>();
@@ -270,8 +246,7 @@ export function discoverMovers({
270246
(el) => fast.has(el) && !threeD.has(el) && !seeThrough.has(el) && !optedOut(el, scene),
271247
);
272248
const movers = candidates.filter((el) => !candidates.some((o) => o !== el && o.contains(el)));
273-
const translationOnly = movers.length > 0 && movers.every((el) => !notPlain.has(el));
274-
return { movers, dynamic, pads, translationOnly };
249+
return { movers, dynamic, pads };
275250
}
276251

277252
export interface ScanOptions extends Omit<DiscoverOptions, "seek"> {

0 commit comments

Comments
 (0)