Cellular colony growth over live HTML
I wanted to know if a ping-pong framebuffer simulation can run on the GPU without pixel readback to grow organic cellular colonies from every tap on a live HTML card, inverting typography, checkboxes and buttons wherever the cells spread while every control stays clickable. Tap anywhere on the card, toggle the checklist, type a new specimen word or switch strain.
Initialising ElementGL WebGL 2 dish...
Show the code drawable specimen card, RGBA8 ping-pong shaders, hit sync and 2D fallback
- One live specimen card inside a drawable canvas. Keeps semantic headings, checkboxes, an editable text
<input>and strain buttons directly in the DOM tree inside<canvas content="drawable" layoutsubtree>. - Top-down simulation and Voronoi composite shaders. Runs an extension-free
RGBA8reaction-diffusion step inSIM_FSusing matching top-down UVs, then draws Voronoi cell walls and inverted palettes overuTexinCOLONY_FRAG. - Dual-buffer ping-pong loop without readback. Swaps two
192×256RGBA8framebuffers directly on the GPU for 200 steps per tap and stops automatically once the wave settles. - Hit-box calibration and coordinate mapping. Calls
updateElementGeometry()scaled bygeometryUnit(), togglesdataset.hitTick, and maps taps on controls to card UVs without swallowing native clicks. - 5-argument 2D and plain-HTML fallbacks. Draws
drawElementImage(cardEl, 0, 0, w, h)withdifference-blended organic blotches on 2D, or moves the card to#plain-hoston context loss.
How it works
This experiment rebuilds sucodee's Colony Card (original post) using HTML-in-canvas.
Instead of cloning text into static canvas layers, the entire specimen card lives inside one <canvas content="drawable" layoutsubtree> managed by a single ElementGL WebGL 2 context.
On the first paint event (and whenever you type, check a box or switch strain), stage.upload(cardEl) uploads the card into an RGBA8 texture with gl.texElementSubImage2D().
Two compact 192×256 RGBA8 framebuffers swap each step on the GPU with zero float-texture extensions and zero pixel readback: red tracks active dividing biomass, green tracks agar nutrient, and blue stores persistent colonised territory.
Both the ping-pong vertex shader and ElementGL use top-down UVs (v = 0 at the top of the DOM card, v = 1 at the bottom), so stepping across the two buffers never flips the image vertically.
During each simulation step, SIM_FS reads the card texture to boost nutrient renewal slightly over dark ink, making colonies creep faster along letters and borders.
COLONY_FRAG then evaluates a device-DPI Voronoi cell field over the smoothed colony territory, inverting dark typography and borders to luminous strain ink, shifting pale card paper to deep bio-ink, and lighting the advancing frontier with a proliferating membrane rim.
Because WebGL draws don't move Chromium's hit boxes, syncCardGeometry() calibrates updateElementGeometry() with geometryUnit() and toggles dataset.hitTick so every checkbox, text field and button stays tappable.
When prefers-reduced-motion: reduce is on, continuous animation pauses and taps stamp static cellular rings instead.
Live checks
These checks wait for a tap so the page opens with one WebGL context. Each check builds an isolated fixture on the test stage and retires its canvas before the next check runs.
Findings
- Measured in headless Chrome 160 Canary (2026-11-27, 412 px viewport at DPR 2.625): all 5 live checks pass (
gl.getError() === 0, top-left UV seed growth, Voronoi ink inversion, andelementsFromPoint()on checkbox, input and button), with backing store at1.14 MP(924x1234) and9.1 MB. - Using standard
RGBA8(UNSIGNED_BYTE) ping-pong buffers avoids float-FBO extension failures on mobile and software renderers, provided everyrunSimPass()unbindsgl.FRAMEBUFFERback tonullbefore the composite pass draws. - Keeping both the simulation quad (
gl_Position = vec4(aPos * 2.0 - 1.0, 0.0, 1.0),vUv = aPos) andElementGL's DOM texture in top-down UV coordinates eliminates per-step Y flips when samplinguTexinside the growth pass. - Listening on
pointerdownwithout callingsetPointerCapture()orpreventDefault()lets every tap on checkboxes, buttons and the specimen word<input>trigger both native DOM interaction and a GPU colony seed at the exact tapped coordinate.