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.
Show the code sdRoundBox SDF morph shader, spring bounds, ElementGL paint and hit-test handoff
- Two drawable subtrees in one canvas. The 2×2 grid
#mc-gridand expanded sheet#mc-detailsit inside one<canvas content="drawable" layoutsubtree>, withinerthiding whichever subtree is inactive. - 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. - Deterministic spring interpolation and box bounds. Integrates morph progress with
stepMorphSpring()using elapsedtMsand playback speed, or snaps to target whenprefers-reduced-motion: reduceis active. - Gated single-context paint and geometry sync. Gates
stage.upload()onhasPaintedinsidepaintafterstage.begin(), and updatesupdateElementGeometry()with cachedgeometryUnit()plusdataset.hitTick. - 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-hoston 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
- Measured in headless Chrome 160 Canary (2026-11-27) at
412×915(2.625DPR) and1024×900(1DPR): oneElementGLcanvas uploads both#mc-gridand#mc-detailviatexElementSubImage2D()withgl.getError() === 0, runs at1.04 MP(8.3 MBlive,0lost contexts,0open snapshots,0unasked readbacks), and keepsscrollWidth === 412and load CLS at0. - Sampling
uTexinside the selected slot rectangle with 9 discrete taps produced visible text echoes at 35% morph. Generating mipmaps (gl.generateMipmap()withLINEAR_MIPMAP_LINEAR) and switching to 16 golden-angle GaussiantextureLod()taps (peaking at7.5 pxmid-morph and dropping to LOD 0 at both endpoints) melts the card into the sheet cleanly while keeping settled text sharp. - Syncing
inertandupdateElementGeometry()with a cachedgeometryUnit()calibrated once on#mc-grid(plusdataset.hitTicktoggles) keeps card buttons clickable at0%, moves focus cleanly across the50%threshold, and routes clicks to#mc-detailaction pills,#mc-note-inputandCollapseat100%. - All 6 live checks passed in Chrome 160 Canary under WebGL 2 and under
?route=2d(5-argumentdrawElementImage()rounded-rect clip morph withdraws.wrong === 0), and disabling the API moved both subtrees into#plain-hostwith working card expansion and note input. - Not verified on real hardware: Chrome 159 on Android (
412 pxwide,2.625DPR touch morph feel, soft keyboard focus on#mc-note-input, real GPU frame rate) andnpm run check:jank -- /morph-container/(Playwright isn't installed here).