Shared-element container morph

I wanted to know if one ElementGL WebGL 2 canvas can melt any of four live HTML grid cards into an expanded detail sheet and back into its slot. Tap a card to open it, or scrub Morph.

WAV
Coral Audio 24-bit Field Mix
RAW
Cobalt Lens 35mm Prime Study
MIDI
Emerald Synth FM Poly Patch
PRO
Amber Reel 16mm Film Scan
SLOT 1 / 4 · WAV

Coral Audio

24-bit Field Mix

Stereo room stems recorded through matched ribbon pairs with soft headroom limiting.

48 kHz 24-bit WAV 03:42
Slot: Coral Audio Morph: 0% starting
Show the code sdRoundBox SDF morph shader, spring bounds, ElementGL paint and hit-test handoff
  1. Two drawable subtrees in one canvas. The 2×2 grid #mc-grid and expanded sheet #mc-detail sit inside one <canvas content="drawable" layoutsubtree>, with inert hiding whichever subtree is inactive.
  2. Continuous SDF container mask and cross-blur UV scaling. Evaluates sdRoundBox() from the clicked card bounds to the expanded sheet, scales UVs from the originating slot sub-rectangle to #mc-detail, and adds a Gaussian cross-blur plus ambient drop shadow.
  3. Deterministic spring interpolation and box bounds. Integrates morph progress with stepMorphSpring() using elapsed tMs and playback speed, or snaps to target when prefers-reduced-motion: reduce is active.
  4. Gated single-context paint and geometry sync. Gates stage.upload() on hasPainted inside paint after stage.begin(), and updates updateElementGeometry() with cached geometryUnit() plus dataset.hitTick.
  5. Five-argument 2D clip-morph and plain-HTML fallbacks. Clips a rounded rectangle with 5-argument drawElementImage() when WebGL 2 is absent, and moves both subtrees into #plain-host on context loss.

How it works

Both the 2×2 card grid (#mc-grid) and the expanded detail sheet (#mc-detail) live inside one <canvas content="drawable" layoutsubtree> backed by one ElementGL WebGL 2 context from /lib/element-gl.js. Inside the paint listener, I set hasPainted = true, call stage.begin() first, and then upload whichever subtree changed through gl.texElementSubImage2D() with UNPACK_PREMULTIPLY_ALPHA_WEBGL set to true.

When you tap a card, openCard() copies that slot's theme, counters and saved note into #mc-detail and drives a spring via stepMorphSpring(). The fragment shader measures the clicked card's sub-rectangle inside #mc-grid, interpolates the container centre, size and corner radius from 14 px to 20 px, casts an expanding ambient shadow over a dimmed grid scrim, and evaluates sdRoundBox() while cross-blurring and scaling UV coordinates between the slot texture and #mc-detail. Blur reaches zero at both endpoints so settled text and controls stay crisp.

Because texture shaders don't move Chromium's hit boxes, syncGeometry() calibrates geometryUnit() once per resize on #mc-grid, toggles inert between #mc-grid and #mc-detail across the midpoint, calls canvas.updateElementGeometry(), and flips dataset.hitTick to clear the hit-test cache. An IntersectionObserver and visibilitychange listener pause animation off screen or in hidden tabs, ?route=2d draws a rounded-rect clip morph with 5-argument drawElementImage(), and ?route=plain or webglcontextlost moves both subtrees into #plain-host.

Live checks

These checks run on isolated fixtures on the test stage and leave the demo above untouched. Tap the button below to run them in this browser.

Findings