Skip to content

Feature idea: feed a shader with an SVG subtree rendered in the same frame (multi-pass in one video) #210

Open

Description

@mrsarac

Motivation

I recreated @mnowakdesign's tracking-HUD look (the same one you posted) with a camera that films the screen: perspective tilt, depth of field focused on the tracked glyph, LED grid, bloom, chromatic aberration, per-scene palette, all in one SkSL pass.

The shader needs the flat screen as its input, so today it takes two fframes projects:

  1. flat renders the terminal + tracker at 3840×2160 to an mp4 (crf 8).
  2. lens reads it with get_synced_video_frame(..).into_image() and binds it as iChannel0.

That works (thanks for the video-frames-in-shaders support), but it costs a 4K h264 round trip per frame (disk, decode, compression artefacts under 3× magnification), two binaries, and a shared crate just so both passes agree on the timeline.

Idea

Let a shader take an SVG subtree of the same frame as a child image, rendered offscreen first:

let screen = fframes::svgr!(<g>{terminal}{tracker}</g>);
let layer = self.lens.draw(&frame, ShaderUniforms::new()
    .layer("iChannel0", screen, 3840, 2160)   // rendered offscreen, bound as `uniform shader`
    .float("uZoom", zoom));
fframes::svgr!(<image href={layer.href()} width="1920" height="1080" />)

On Skia this could stay on the GPU: draw the subtree into an offscreen surface and bind its image snapshot as the child shader, with no CPU readback. On the CPU backend it could fall back to rasterizing the subtree. Is this something you'd want in fframes? I can help with the API, an example or tests.

Example (C)

The project is at https://github.com/mrsarac/ff-tracking (MIT): 6 s, 12 scenes, a two-pass render plus a synthesized sound track (~40 s end to end on an M3 Pro). If it's useful, I can contribute a trimmed version as examples/screen-camera, now as a two-pass example or later as the single-pass demo of the feature above. Video: https://x.com/0xsarac/status/2108515856544317489

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions