Slit-scan time ribbon
I wanted to know if a WebGL 2 TEXTURE_2D_ARRAY ring buffer can warp live scrolling, typing and CSS animation across 64 frames of history with zero open ElementImage snapshots and no CPU readback. Type in the input, scroll the article or tap the panel buttons to send waves across space and time.
Show the code TEXTURE_2D_ARRAY GPU ring buffer, copyTexSubImage3D, slit-scan shader and R8 freeze brush
- One drawable panel in one canvas. The live input, animated bars, buttons and scrollable article sit inside one
<canvas content="drawable" layoutsubtree>. - Zero-snapshot GPU ring buffer. Allocates one 64-layer
TEXTURE_2D_ARRAYinside a VRAM cap (24 MB on narrow screens, 32 MB on wide screens) and copies each frame on the GPU withblitFramebuffer()andcopyTexSubImage3D(). - Space-time fragment shader. Computes a per-pixel delay from vertical position, radial distance, diagonal shear or the painted
R8mask, then interpolates between adjacent ring slices. - Paint loop and synced hit boxes. Uploads the panel with
ElementGL.upload(), pushes into the ring buffer, draws the time-displaced quad, and keeps controls reachable withupdateElementGeometry(). - Time-freeze brush mask. Paints delay values into a 128 by 128
Uint8Arrayand uploads it to anR8texture withtexSubImage2D()only when you draw.
How it works
In /time-scrubber/, keeping a history of live HTML frames meant storing over a hundred open
ElementImage objects from captureElementImage(). Each open snapshot holds GPU memory until
close() runs, and the site's graphics guard flags pages that leave more than eight open. I built this page
to test whether a fixed-size WebGL 2 TEXTURE_2D_ARRAY ring buffer can store 64 frames of history directly on
the GPU without calling captureElementImage() or reading any pixels back to the CPU.
Everything runs inside one ElementGL context from /lib/element-gl.js. On each captured frame,
stage.upload(panel) calls gl.texElementSubImage2D() to update the live 2D texture at native
resolution. That texture is attached to a READ_FRAMEBUFFER. When the live texture is larger than the ring
buffer's VRAM budget (capped at 24 MB on narrow screens and 32 MB on desktop, with a 512 px maximum side),
gl.blitFramebuffer() downscales it on the GPU into a single-frame scratch framebuffer first. Then
gl.copyTexSubImage3D(gl.TEXTURE_2D_ARRAY, 0, 0, 0, head, 0, 0, w, h) copies the frame straight into slice
head = (head + 1) % 64. No pixels ever cross back to JavaScript.
The fragment shader maps each screen pixel's UV to a fractional frame age using one of four modes: vertical slit-scan,
radial ripple, diagonal ribbon, or a 128 by 128 R8 delay texture painted with your finger or mouse. Where
age is below half a frame, the shader samples the full-resolution live texture directly; older regions interpolate
between two consecutive layers in the TEXTURE_2D_ARRAY so fast motion doesn't step between discrete slices.
After drawing, canvas.updateElementGeometry() syncs the panel's hit box at its unwarped position so typing,
scrolling and button taps still land on the live DOM. An IntersectionObserver pauses capture whenever the
stage scrolls off screen, and pagehide deletes the ring buffer textures and framebuffers.
Live checks
These wait for a tap so the demo starts with no extra WebGL contexts running. Each check builds its own small fixture in the corner of the window and retires it afterwards.
Findings
- A 64-layer
RGBA8TEXTURE_2D_ARRAYbounded to 24 MB on phones and 32 MB on desktop keeps GPU memory predictable while holding about one second of 60 fps history (or three seconds at capture stride 3) and zero openElementImagesnapshots. gl.copyTexSubImage3D()copies pixels 1:1 fromREAD_FRAMEBUFFERand can't rescale on its own. On high-DPI screens,texElementSubImage2D()uploads at device pixels (often over 1,000 px wide), so adding a GPUblitFramebuffer()step into a small scratch framebuffer avoids cropping the element into the capped ring buffer.- Sampling the full-DPR live texture when a pixel's delay is zero and blending into the capped
TEXTURE_2D_ARRAYfor delayed regions keeps unpainted live UI sharp in time-freeze brush mode without tripling ring VRAM. - The time-freeze paint brush needs a mode switch between painting on the canvas (with
pointer-events: noneon the drawable child andtouch-action: noneon the stage) and interacting with the DOM through the painted mask, otherwise dragging selects text or scrolls the article instead of painting. - Not verified yet in a live browser (written 2026-11-26): running all four live checks in headless Chromium 157 and on Chrome 159 on Android (412 px wide, DPR 2.625), verifying
npm run check:jank -- /slit-scan/, and checking real frame rate and context stability while typing and scrolling on a phone.