Skip to content

Fork patch: Preview motion blur filter copies - #12

Draft
ocboogie wants to merge 1 commit into
mainfrom
patch/preview-motion-blur-filter-copies
Draft

ocboogie wants to merge 1 commit into
mainfrom
patch/preview-motion-blur-filter-copies

Conversation

@ocboogie

@ocboogie ocboogie commented Nov 5, 2026

Copy link
Copy Markdown

🤖 AI agent: Arcade fork patch. Do not merge.

This draft shows patch/preview-motion-blur-filter-copies against main, the upstream mirror, so the patch has one page for its diff, its revisions and its reason. Arcade's /hyperframes-update rebases the branch onto main and cherry-picks it onto arcade; this PR is not part of that flow. When a rebuild changes the patch, its git range-diff against the previous sync/<date>/preview-motion-blur-filter-copies tag is posted as a comment.

Why

The runtime's filter tier draws motion blur as 32 SVG offset copies of every moving element, and each copy is a full-size filter pass. With dozens of movers, live playback in Chrome without html-in-canvas drops frames. The patch uses fewer copies only while the page plays:

  • Live playback (preview) draws 8 copies per mover; engine-mode seeks (renders) keep 32.
  • The existing softening along the motion closes the gaps between copies, so 8 copies show no visible stepping at native resolution. The streak is about 9% shorter.
  • A page that plays and then renders rebuilds each mover's filter in place, so the render still gets 32.

Checked locally on Chrome with an 82-mover scene: dropped frames fall from 15.7% to 0.1% with GPU, and from 25.4% to 2.3% without.

Upstream

Kept local. Upstream hard-codes 32 copies for both playback and render, and latest (0.9.17) still does.

Drop when

Upstream lets the preview filter tier use fewer copies than renders.

Arcade

Tracked in Arcade's issue tracker.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Edit accuracy: accurate 271 (base branch 271), smooth 202 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

@valeriangalliat
valeriangalliat force-pushed the patch/preview-motion-blur-filter-copies branch from 17e2c6e to 69fa232 Compare November 10, 2026 18:00
@valeriangalliat

Copy link
Copy Markdown
Collaborator

🤖 AI agent: sync/2026-11-10: rebased onto upstream cda84222a (just past v0.9.30). Conflict in filterTier.ts: upstream reworked the readMoverFrames call. The one changed argument (taps) is re-applied on upstream's version.

1:  17e2c6eac ! 1:  69fa23201 perf(core): draw live-playback filter-tier motion blur with 8 copies
    @@ Commit message
         renders rebuilds each mover's filter in place.
     
      ## packages/core/src/runtime/captureMotionBlur/filterTier.ts ##
    -@@ packages/core/src/runtime/captureMotionBlur/filterTier.ts: import { createPoseReader } from "./pose";
    +@@ packages/core/src/runtime/captureMotionBlur/filterTier.ts: import type { MotionBlurFingerprint } from "../../motionBlurFingerprint";
      import type { CaptureMotionBlurHost, Config, Report, Tier } from "./tier";
      
      const NS = "http://www.w3.org/2000/svg";
    @@ packages/core/src/runtime/captureMotionBlur/filterTier.ts: export function creat
            defs.setAttribute("width", "0");
     @@ packages/core/src/runtime/captureMotionBlur/filterTier.ts: export function createFilterTier(
            node(defs, "defs", {});
    -       root.append(defs);
    +       document.documentElement.append(defs);
          }
     -    layer = buildLayer(defs.querySelector("defs") ?? defs, layers.size, el);
     +    const id = old ? old.filter.id : `${FILTER_ID}-${layers.size}`;
    @@ packages/core/src/runtime/captureMotionBlur/filterTier.ts: export function creat
          const base = strip(el) || layer.css;
          el.style.filter = base ? `${base} ${layer.url}` : layer.url;
     @@ packages/core/src/runtime/captureMotionBlur/filterTier.ts: export function createFilterTier(
    -       t,
    -       reads: engineMode ? RENDER_READS : PREVIEW_READS,
    -       shutterSeconds: config.shutterDeg / 360 / host.fps,
    --      taps: COPIES,
    -+      taps: engineMode ? RENDER_COPIES : PREVIEW_COPIES,
    -       frameW: width,
    -       frameH: height,
    -     });
    +         t,
    +         reads: engineMode ? RENDER_READS : PREVIEW_READS,
    +         ...shutterTimes(config.shutterDeg, config.phaseDeg, host.fps),
    +-        taps: COPIES,
    ++        taps: engineMode ? RENDER_COPIES : PREVIEW_COPIES,
    +         frameW: width,
    +         scene: root,
    +         frameH: height,
     
      ## packages/core/src/runtime/captureMotionBlur/index.test.ts ##
     @@ packages/core/src/runtime/captureMotionBlur/index.test.ts: describe("filter fallback", () => {

@Pentiado
Pentiado force-pushed the patch/preview-motion-blur-filter-copies branch 2 times, most recently from 86c0cf1 to 859fe3d Compare November 16, 2026 20:34
@Pentiado

Copy link
Copy Markdown

🤖 AI agent: sync/2026-11-16b: rewritten on upstream main 778a00564 (v0.9.58 plus later upstream commits, including heygen-com#7550), not rebased.

Upstream #7547 (first released in v0.9.36) is a partial upstream fix. Preview now draws fewer copies than renders, but only when the host sends a preview quality level: 32 at Full, 16 at 1/2, 8 at 1/4 and below. Arcade's player sends no level, so with upstream's code alone its preview would draw 32 copies again.

The patch now sits on upstream's code and reuses its in-place filter rebuild:

  • Live playback draws 8 copies at every preview quality level. Engine-mode seeks (renders) keep 32.
  • The tier advertises no lighter blur levels to the host (FILTER_LIGHTER_LEVELS is empty), because a lower level is no lighter for blur.
  • Upstream's preview-quality test now expects 8 copies at every level, and the Full-quality preview test expects 8.

New drop condition: Arcade's player drives HyperFrames preview quality. Then upstream heygen-com#7547 covers this case and the patch can go.

Range-diff, paired with --creation-factor=100 because the commit was rewritten:

1:  69fa23201 ! 1:  859fe3dd5 perf(core): draw live-playback filter-tier motion blur with 8 copies
    @@
      ## Metadata ##
    -Author: ocboogie <boogie@mikulec.com>
    +Author: Pawel Wszola <wszola.p@gmail.com>
     
      ## Commit message ##
    -    perf(core): draw live-playback filter-tier motion blur with 8 copies
    +    perf(core): draw live-playback filter-tier motion blur with 8 copies at every preview quality
     
    -    The filter tier stacks 32 offset copies of every moving element, and each
    -    copy is a full-size filter pass. With dozens of movers, live playback in
    -    Chrome without html-in-canvas drops frames (one 82-mover scene: 16% with GPU,
    -    25% without). Eight copies, with the existing softening of 0.35x the step
    -    between copies, show no stepping at native resolution and drop 0.1% / 2.3%
    -    on the same scene.
    +    The filter tier stacks offset copies of every moving element, and each copy
    +    is a full-size filter pass. Preview already draws fewer copies below Full
    +    quality, but only when the host sends a preview quality level. A host that
    +    never does (an embed of the plain player) draws 32 copies in live playback,
    +    and with dozens of movers that drops frames (one 82-mover scene: 16% with
    +    GPU, 25% without; 0.1% / 2.3% with 8 copies).
     
    -    Renders (engine-mode seeks) keep 32 copies. A page that plays and then
    -    renders rebuilds each mover's filter in place.
    +    Live playback now draws 8 copies at every preview quality level, and renders
    +    (engine-mode seeks) keep 32. A lower level is no lighter for blur any more,
    +    so the tier advertises no lighter levels to the host.
     
      ## packages/core/src/runtime/captureMotionBlur/filterTier.ts ##
    -@@ packages/core/src/runtime/captureMotionBlur/filterTier.ts: import type { MotionBlurFingerprint } from "../../motionBlurFingerprint";
    - import type { CaptureMotionBlurHost, Config, Report, Tier } from "./tier";
    - 
    +@@ packages/core/src/runtime/captureMotionBlur/filterTier.ts: import type { CaptureMotionBlurHost, Config, Report, Tier } from "./tier";
      const NS = "http://www.w3.org/2000/svg";
    --/** Copies per mover; the softening along the motion closes the steps between them. */
    --const COPIES = 32;
    + /** Copies per mover; the softening along the motion closes the steps between them. */
    + const COPIES = 32;
    +-export const FILTER_LIGHTER_LEVELS = [0.5, 0.25] as const;
    +-const previewCopiesAt = (level: number): number => (level >= 1 ? COPIES : level >= 0.5 ? 16 : 8);
    +-let previewCopies = COPIES;
     +/**
    -+ * Copies per mover; the softening along the motion closes the steps between them. Each copy is a
    -+ * full-size pass over the mover, so live playback takes fewer: with many movers, 32 drop frames.
    -+ * Powers of two, so the pairwise average weighs every copy alike.
    ++ * Live playback draws 8 copies at every preview quality: each copy is a full-size pass over the
    ++ * mover, so with many movers 32 drop frames, even at Full. No lower level is lighter, so none is
    ++ * advertised.
     + */
    -+const RENDER_COPIES = 32;
     +const PREVIEW_COPIES = 8;
    ++export const FILTER_LIGHTER_LEVELS: readonly number[] = [];
    + 
    +-export function setFilterPreviewQuality(level: number): void {
    +-  if (level > 0) previewCopies = previewCopiesAt(level);
    +-}
    ++/** Preview quality leaves the copy count alone: playback always draws PREVIEW_COPIES. */
    ++export function setFilterPreviewQuality(_level: number): void {}
      const PREVIEW_READS = 4;
      const RENDER_READS = 8;
      const FILTER_ID = "hf-mb";
    -@@ packages/core/src/runtime/captureMotionBlur/filterTier.ts: function node<K extends keyof SVGElementTagNameMap>(
    -   return el;
    - }
    - 
    --/** 32 offset copies, averaged in pairs so 8-bit filter buffers do not band, then softened. */
    --function buildLayer(defs: SVGDefsElement, index: number, el: HTMLElement): Layer {
    --  const id = `${FILTER_ID}-${index}`;
    -+/** Offset copies, averaged in pairs so 8-bit filter buffers do not band, then softened. */
    -+function buildLayer(defs: SVGDefsElement, id: string, el: HTMLElement, copies: number): Layer {
    -   const filter = node(defs, "filter", {
    -     id,
    -     "color-interpolation-filters": "sRGB",
    -     filterUnits: "userSpaceOnUse",
    -   });
    --  const offsets = Array.from({ length: COPIES }, (_, k) =>
    -+  const offsets = Array.from({ length: copies }, (_, k) =>
    -     node(filter, "feOffset", { in: "SourceGraphic", result: `s${k}` }),
    -   );
    -   let level = offsets.map((_, k) => `s${k}`);
    -@@ packages/core/src/runtime/captureMotionBlur/filterTier.ts: export function createFilterTier(
    -     for (const el of [...styled]) drop(el);
    -   }
    - 
    --  function layerOf(el: HTMLElement): Layer {
    --    let layer = layers.get(el);
    --    if (layer) return layer;
    -+  /** The mover's filter, rebuilt in place if a render and playback share the page. */
    -+  function layerOf(el: HTMLElement, copies: number): Layer {
    -+    const old = layers.get(el);
    -+    if (old?.offsets.length === copies) return old;
    -+    old?.filter.remove();
    -     if (!defs) {
    -       defs = document.createElementNS(NS, "svg");
    -       defs.setAttribute("width", "0");
    -@@ packages/core/src/runtime/captureMotionBlur/filterTier.ts: export function createFilterTier(
    -       node(defs, "defs", {});
    -       document.documentElement.append(defs);
    -     }
    --    layer = buildLayer(defs.querySelector("defs") ?? defs, layers.size, el);
    -+    const id = old ? old.filter.id : `${FILTER_ID}-${layers.size}`;
    -+    const layer = buildLayer(defs.querySelector("defs") ?? defs, id, el, copies);
    -     layers.set(el, layer);
    -     return layer;
    -   }
    - 
    -   function show(el: HTMLElement, plan: FilterPlan): void {
    --    const layer = layerOf(el);
    -+    const layer = layerOf(el, plan.offsets.length);
    -     aim(layer, plan);
    -     const base = strip(el) || layer.css;
    -     el.style.filter = base ? `${base} ${layer.url}` : layer.url;
     @@ packages/core/src/runtime/captureMotionBlur/filterTier.ts: export function createFilterTier(
              t,
              reads: engineMode ? RENDER_READS : PREVIEW_READS,
              ...shutterTimes(config.shutterDeg, config.phaseDeg, host.fps),
    --        taps: COPIES,
    -+        taps: engineMode ? RENDER_COPIES : PREVIEW_COPIES,
    +-        taps: engineMode ? COPIES : previewCopies,
    ++        taps: engineMode ? COPIES : PREVIEW_COPIES,
              frameW: width,
              scene: root,
              frameH: height,
    @@ packages/core/src/runtime/captureMotionBlur/index.test.ts: describe("filter fall
          expect(document.querySelectorAll("feGaussianBlur")).toHaveLength(1);
        });
      
    -+  it("draws a render with 32 copies, and rebuilds the filter in place after playback", () => {
    -+    const { el, h } = movingHost();
    -+    initCaptureMotionBlur(h);
    -+    void paintCaptureMotionBlur(0.5, PLAY);
    -+    expect(document.querySelectorAll("#hf-mb-0 feOffset")).toHaveLength(8);
    -+    void paintCaptureMotionBlur(0.5, { engineMode: true });
    -+    expect(el.style.filter).toMatch(/url\("?#hf-mb-0"?\)/);
    +-  it("draws fewer copies in preview below Full, and the full 32 in a render", () => {
    ++  it("draws 8 copies in preview at every quality, and the full 32 in a render", () => {
    +     const { el, h } = movingHost(CAPTURE);
    +     initCaptureMotionBlur(h);
    +-    expect(motionBlurLighterLevels()).toEqual([]);
    +     setMotionBlurPreviewQuality(0.5);
    +     void paintCaptureMotionBlur(0.5, PLAY);
    +-    expect(document.querySelectorAll("feOffset")).toHaveLength(16);
    +-    expect(motionBlurLighterLevels()).toEqual([0.5, 0.25]);
    ++    expect(document.querySelectorAll("feOffset")).toHaveLength(8);
    ++    expect(motionBlurLighterLevels()).toEqual([]);
    +     setMotionBlurPreviewQuality(0.125);
    +     void paintCaptureMotionBlur(0.6, PLAY);
    +     expect(document.querySelectorAll("feOffset")).toHaveLength(8);
    +     expect(el.style.filter).toMatch(/url\("?#hf-mb-0"?\)/);
    +     void paintCaptureMotionBlur(0.5, { engineMode: true });
    +-    expect(document.querySelectorAll("feOffset")).toHaveLength(32);
     +    expect(document.querySelectorAll("filter")).toHaveLength(1);
     +    expect(document.querySelectorAll("#hf-mb-0 feOffset")).toHaveLength(32);
     +    expect(document.querySelectorAll("#hf-mb-0 feComposite")).toHaveLength(31);
    -+  });
    -+
    +   });
    + 
        it("stays off when the renderer turned blur off", () => {
    -     win.__HF_PAGE_MOTION_BLUR_OFF__ = "hdr-render";
    -     const { el, h } = movingHost();

…at every preview quality

The filter tier stacks offset copies of every moving element, and each copy
is a full-size filter pass. Preview already draws fewer copies below Full
quality, but only when the host sends a preview quality level. A host that
never does (an embed of the plain player) draws 32 copies in live playback,
and with dozens of movers that drops frames (one 82-mover scene: 16% with
GPU, 25% without; 0.1% / 2.3% with 8 copies).

Live playback now draws 8 copies at every preview quality level, and renders
(engine-mode seeks) keep 32. A lower level is no lighter for blur any more,
so the tier advertises no lighter levels to the host.
@valeriangalliat
valeriangalliat force-pushed the patch/preview-motion-blur-filter-copies branch from 859fe3d to 586cb51 Compare November 25, 2026 00:56

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants