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.

00.00s
Type here to bend letters in time

Scroll this column to stretch lines in time

Every pixel in this panel is uploaded into a single ElementGL WebGL 2 context via texElementSubImage2D() and copied on the GPU into the next slice of a 64-layer TEXTURE_2D_ARRAY with copyTexSubImage3D().

In vertical slit-scan mode, the top edge shows the current frame while the bottom edge shows one second in the past. Scrolling downward stretches tall glyphs; scrolling upward compresses them into tight bands.

Switch to radial ripple to watch waves spread from the centre, diagonal ribbon to shear time across the controls, or time-freeze brush to paint an R8 delay mask directly on the canvas.

Because no captureElementImage() snapshots are kept open, window.__gfx.snapshots.open stays at zero even after thousands of frames.

 

Show the code TEXTURE_2D_ARRAY GPU ring buffer, copyTexSubImage3D, slit-scan shader and R8 freeze brush
  1. One drawable panel in one canvas. The live input, animated bars, buttons and scrollable article sit inside one <canvas content="drawable" layoutsubtree>.
  2. Zero-snapshot GPU ring buffer. Allocates one 64-layer TEXTURE_2D_ARRAY inside a VRAM cap (24 MB on narrow screens, 32 MB on wide screens) and copies each frame on the GPU with blitFramebuffer() and copyTexSubImage3D().
  3. Space-time fragment shader. Computes a per-pixel delay from vertical position, radial distance, diagonal shear or the painted R8 mask, then interpolates between adjacent ring slices.
  4. 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 with updateElementGeometry().
  5. Time-freeze brush mask. Paints delay values into a 128 by 128 Uint8Array and uploads it to an R8 texture with texSubImage2D() 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