Datamosh and RGB block-slice glitch cut
I wanted to know if one ElementGL WebGL 2 canvas could run NLE-style datamosh, horizontal sync tear and RGB chroma-shatter cuts between two live HTML panels while keeping buttons, toggles and editable inputs working. Press Trigger cut to B, scrub the cut slider or drag across the stage to smear macroblocks across both views.
Starting canvas…
Show the code dual-scene canvas markup, ping-pong smear FBO, transition envelope, hit sync and 2D slice fallback
- Two live panels in one drawable canvas. Both
#gc-scene-a(Editorial Broadcast Feed) and#gc-scene-b(Telemetry Node Console) sit directly inside<canvas content="drawable" layoutsubtree>. - Explicit timestamp envelope.
triggerCutEnvelope()andstepCutEnvelope(env, tMs)drive cut progress and glitch bell decay from explicit millisecond timestamps. - Ping-pong smear and three glitch shaders.
SMEAR_FRAGadvects frozen macroblocks along motion vectors andCOMPOSITE_FRAGswitches between Block datamosh, Scan tear, Chroma shatter and a reduced-motion geometric wipe. - Ping-pong FBO pipeline with clean unbind. Draws pass 1 into the back smear FBO, unbinds with
gl.bindFramebuffer(gl.FRAMEBUFFER, null)before compositing to screen, and finishes withgl.bindVertexArray(null). - Paint gating and selective uploads. Waits for
hasPainted = true, runsstage.begin()beforestage.upload()and skips re-uploading unchanged scenes during shader frames. - Active scene hit-box calibration. Routes
updateElementGeometry()andgeometryUnit()to the dominant view, marks the hidden viewinertoffstage and togglesdataset.hitTick. - Five-argument 2D slice and plain-HTML fallbacks. Draws horizontal slice cuts via 5-argument
drawElementImage()without WebGL 2, or moves both views into#plain-hoston context loss.
How it works
Both live panels stay mounted inside one <canvas content="drawable" layoutsubtree> driven by a single ElementGL WebGL 2 context from /lib/element-gl.js. I set gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true) on creation and inside onRestored, wait for hasPainted = true inside the paint handler and call stage.begin() before calling stage.upload() on whichever scene changed.
During each transition or pointer drag, GlitchPipeline runs two passes. Pass 1 writes into one of two ping-pong RGBA8 FBOs, advecting stale tiles from View A along simulated P-frame motion vectors and pointer velocity. Before drawing pass 2 onto the canvas, it calls gl.bindFramebuffer(gl.FRAMEBUFFER, null), composites View A, View B and the smear buffer for the chosen preset (Block datamosh, Scan tear or Chroma shatter), and calls gl.bindVertexArray(null) when done. Under prefers-reduced-motion or the Reduced motion toggle, strobing and RGB flashes drop out in favour of a crisp stepped geometric wipe.
Dragging on the canvas injects pointer velocity into the shader while a selectstart guard keeps text selection off the panels outside #gc-a-input and #gc-b-input. Once a cut crosses 50%, syncSceneGeometry() switches inert and moves the inactive scene offstage via updateElementGeometry() calibrated with geometryUnit() and dataset.hitTick, so clicks and typing only land on the active view. An IntersectionObserver and document.hidden check pause the animation loop off screen.
Live checks
These checks wait for a tap so the page opens with one WebGL context running. Each check creates its own fixture on testStage() and retires it afterwards.
| Result | Experiment | Detail |
|---|
Findings
Measured in headless Chrome 160.0.8188.0 canary on 2026-11-27 (412 px DPR 2.625 and 960 px DPR 2, SwiftShader WebGL), plus a fallback check with --disable-blink-features=CanvasDrawElement and emulated prefers-reduced-motion: reduce. Chrome 159 on Android, Chromium 157 and npm run check:jank stay not verified.
- One
ElementGLcontext and ping-pong smear FBO stay within mobile budget: on 412 px at 2.625 DPR, the stage runs at948×1036 px(0.98 MP,7.86 MBat rest,8.52 MBpeak after tap checks settle), unbinds the FBO (FRAMEBUFFER_BINDING === null) before compositing to screen and unbinds the VAO afterwards withgl.getError() === 0. - Mid-cut macroblock displacement and RGB channel split are distinct across presets: at
tMs = 390(p = 0.50),Block datamoshaltered43/45sampled tiles compared with0%rest,Chroma shattermeasured199max|R - B|channel spread across a vertical edge, andScan teardiffered fromBlock datamoshon41/45sampled points. - Active scene hit boxes swap cleanly across the 50% midpoint: pairing
inertwith offstageupdateElementGeometry()and toggleddataset.hitTickkeptelementsFromPoint()and clicks landing on#gc-a-cue-btnand#gc-a-inputat0%, then on#gc-b-flush-btnand#gc-b-inputat100%, with0accidental text selection during pointer drags. - Reduced motion and fallbacks work without errors: emulated
prefers-reduced-motion: reducechecks the toggle automatically and switches mid-cut output to a clean geometric wipe (29/45pixel delta vs datamosh). Syntheticwebglcontextlost/webglcontextrestoredevents rescue both panels into#plain-hostand restore GL cleanly, the 5-argumentdrawElementImage()2D slice helper passes with0wrong-size draws, and disabling the API puts both views in plain HTML atscrollWidth === 412. - Not verified: real GPU frame timing, touch drag feel and soft keyboard behaviour on Chrome 159 for Android, plus Playwright
npm run check:jank -- /glitch-cut/in Chromium 157.