Digital rain over a live HTML terminal
I wanted to see if one ElementGL canvas could cascade glowing green phosphor code rain straight over a live HTML terminal card without blocking edits or clicks. Type into the command line or press Decode signal, Trace route or Lock rain: the shader detects DOM glyph edges from texElementSubImage2D() and lights up the letters and borders where droplets collide.
Starting canvas…
Show the code drawable terminal markup, Sobel edge catch shader, ElementGL upload and hit-box sync
- Live terminal inside one drawable canvas.
#term-panelholds an editable command<input>, three quick-command buttons, a live<output>and four status rows inside one<canvas content="drawable" layoutsubtree>. - Sobel edge detection and 5x7 phosphor rain shader. Samples
uTexacross a 3x3 luminance stencil, renders procedural 5x7 dot-matrix glyphs and flares DOM letter strokes and button rims when falling drop heads cross them. - One ElementGL context with premultiplied uploads. Sets
UNPACK_PREMULTIPLY_ALPHA_WEBGL = trueon creation and restore, gates uploads onhasPaintedand callsstage.begin()beforestage.upload(). - Hit-box calibration with
geometryUnit(). Keeps#term-panelclickable and editable throughupdateElementGeometry()and togglesdataset.hitTickto clear Chromium's hit-test cache. - Five-argument 2D and plain-HTML fallbacks. Draws
#term-panelwith 5-argumentdrawElementImage()and green rain columns in 2D, or moves it into plain HTML if the context is lost.
How it works
The whole terminal card lives as ordinary HTML inside one <canvas content="drawable" layoutsubtree> driven by a single ElementGL WebGL 2 context from /lib/element-gl.js. There's zero CPU pixel readback during animation.
- Premultiplied DOM upload: on creation and inside
onRestored, the context setsgl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true)so crisp anti-aliased text strokes and translucent focus rings upload cleanly throughgl.texElementSubImage2D(). - Edge catching in GLSL: on every fragment,
RAIN_FRAGsamples a 3x3 luminance stencil ofuTex, computes local Sobel gradient magnitude plus local min/max contrast, and isolates character strokes, borders and active button frames without needing a separate edge pass. - Three compositing modes: Phosphor rain overlays cascading 5x7 dot-matrix streams and flares intersected DOM strokes; Ink reveal dims the terminal in CRT shadow until falling columns wipe it into view; Decode trace runs a neon scanner sweep and expands a phosphor ring from whichever button or input triggered the command.
- Live DOM stays interactive: typing in the command line or pressing Decode signal, Trace route or Lock rain fires a
paintevent on#matrix-canvas, re-uploading#term-panelso new text starts catching falling droplets at once whileupdateElementGeometry()scaled bygeometryUnit()keeps hits aligned. - Motion and fallbacks: rain pauses off-screen via
IntersectionObserver, whendocument.hiddenis true, when Lock rain is active or underprefers-reduced-motion: reduce. Without WebGL 2texElementSubImage2D(), a 2D canvas renders five-argumentdrawElementImage()under green phosphor column stripes, and context loss falls back to plain HTML.
Live checks
Each check builds its own isolated fixture on testStage() and retires its canvas when finished. The visible terminal above isn't touched.
| Result | Experiment | Detail |
|---|
Findings
Measured in headless Chrome 160.0.8188.0 canary on 2026-11-27 (412 px mobile emulation at 2.625 DPR, SwiftShader WebGL). Headless Chromium 157, npm run check:jank and Chrome 159 on Android stay not verified.
- Single-pass Sobel edge catch works on one
ElementGLcontext: sampling a CSS-pixel-clamped 3x3 stencil directly onuTexisolated both bright mint typography on dark obsidian and dark glyphs inside the pressedLock rainbutton (Check 1:rainPx=[99,255,183,255],edgePx=[137,255,208,255],gl.getError() === 0across all three blend modes). - Live DOM edits keep hit boxes intact: changing
<input>text re-uploaded#term-panelinside thepaintevent (inputDelta=149), andupdateElementGeometry()scaled bygeometryUnit()landedelementsFromPoint()on both the command input and button. - Sequential fixture retirement keeps WebGL count low: waiting for
context-guard.jsto reclaim each retired fixture before starting the next held peak WebGL contexts to2and removed canvas memory to0 MBat the end of all 6 checks (1.01 MPlive canvas at 412 px @ 2.625 DPR). - Not verified yet: real Android Chrome 159 touch keyboard interaction on
#term-cmd, native GPU frame timing, the 2DdrawElementImage()fallback branch when WebGL 2texElementSubImage2D()is absent, andnpm run check:jank.