VHS tape tracking and head-switching noise
I wanted to know if an ElementGL WebGL 2 shader can put analog helical-scan VHS artefacts across a live VCR deck (tracking shear, bottom 7% head-switching jitter, YIQ chroma smear, dropout snow and fast-forward scan streaks) while the transport buttons, channel switcher and tape label input stay clickable. Type into the tape label, switch channels or turn the tracking slider toward zero to lock the signal.
Starting canvas…
Show the code drawable VCR deck markup, YIQ chroma smear shader, upload gating and hit-box sync
- One live VCR deck inside one canvas. The tape counter, editable label input, channel buttons, transport row and bottom head-switching strip live inside a single
<canvas content="drawable" layoutsubtree>. - Helical-scan VHS fragment shader. Separates luminance (Y) from horizontally delayed and low-pass smeared chrominance (I/Q), shifts the tracking tear band from
uTracking, adds FF/REW and Pause streaks, and shreds the bottom 7% head-switching band. - Upload gating and draw order. Waits for
hasPainted = trueinside'paint', callsstage.begin()beforestage.upload(deckEl), and reuses the cached GPU texture on pure shader frames. - Hit-box calibration. Measures
geometryUnit()and togglesdataset.hitTickafterupdateElementGeometry()so clicks and typing stay aligned over the degraded deck. - 2D and plain-HTML fallbacks. Falls back to five-argument
drawElementImage()with light scanlines when WebGL 2 is absent, or moves#vhs-deckinto plain HTML on context loss.
How it works
Real VHS decks split luminance (Y) at around 3 MHz from colour-under chrominance (I/Q) downconverted to 629 kHz, so bright text stays sharp while saturated colours lag and smear sideways. I placed the full VCR player card inside one <canvas content="drawable" layoutsubtree> and drove it with a single ElementGL WebGL 2 context from /lib/element-gl.js, with UNPACK_PREMULTIPLY_ALPHA_WEBGL turned on at context creation and on restore.
Inside the paint handler, the script waits for the first paint record (hasPainted = true), calls stage.begin() before stage.upload(deckEl) so the backing store is sized past 300 by 150 first, and skips re-uploading with gl.texElementSubImage2D() unless a DOM node inside the deck changed. The fragment shader (VHS_FRAG) converts the uploaded pixels to YIQ, leaves luminance sharp along each displaced scanline, smears I and Q horizontally leftward in source space so colours bleed right across the SMPTE bars and buttons, moves a white-noise tracking tear bar according to uTracking (clearing it within ±0.04 of zero), and tears the bottom 7% (vUv.y > 0.928) for rotary head-switching jitter.
All clickable controls (the tape label <input>, channel buttons and transport row) sit above the bottom 7% switching band and stay aligned via canvas.updateElementGeometry() scaled by geometryUnit() plus a toggled dataset.hitTick attribute. An IntersectionObserver and document.hidden check stop the animation loop when the deck is off screen or in a background tab, and enabling Reduced motion freezes jitter, pause tremble and dropout snow into a static calibration frame.
Live checks
These checks wait for a tap so the page opens with only one WebGL context running. Each check builds its own isolated 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). Chrome 159 on Android, Chromium 157 and npm run check:jank stay not verified.
- YIQ chroma separation holds text crisp while colours bleed: converting premultiplied uploads to YIQ lets luminance stay sharp along each displaced scanline while low-pass filtered I/Q delayed leftward in UV bleeds
144red 4 CSS pixels past a sharp red/black edge (compared with[8,10,16,255]in Clean signal). - Tracking tear clears cleanly near zero: sweeping the tracking band at
uTracking = 0.32changed 58 of 153 sampled pixels on 412 px (59 on desktop) across a white calibration bar, whileuTracking = 0.0cleared all 58 back to zero difference. - Premultiplied alpha and upload order: setting
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true)at creation and inonRestored, gating uploads onhasPainted = trueinsidepaintand callingstage.begin()beforestage.upload(deckEl)keeps first-frame textures sized at full HiDPI resolution (948×1183 px,1.12 MP,8.97 MBon 412 px). - Controls stay clickable above the bottom 7% switching band: placing the calibration footer in
vUv.y > 0.928keeps the bottom head-switching tear out of the button rows whileupdateElementGeometry()scaled bygeometryUnit()plus toggleddataset.hitTickpasseselementsFromPoint()checks on the label<input>, channel button and PLAY button. - Reduced motion and fallbacks: under emulated
prefers-reduced-motion: reduce, the deck drops to 2 static calibration uploads with zero rAF loop churn; with--disable-blink-features=CanvasDrawElement, the VCR deck moves into plain HTML at 412 px with zero horizontal overflow and zero console errors. - Not verified: real GPU frame timing, touch keyboard focus inside
#vhs-labeland memory pressure on Chrome 159 for Android, plus Playwrightnpm run check:jank -- /vhs-tracking/in Chromium 157.