Dynamic Island metaball capsule
I wanted to know if one WebGL 2 canvas can morph a liquid obsidian Dynamic Island between a compact pill, split twin bubbles and expanded widgets with crisp live HTML controls inside. Switch states below or tap the capsule, drag the twin orb to stretch and pinch off the black neck, edit the track title or start the timer.
Show the code smin SDF shader, spring physics, ElementGL paint and hit-test calibration
- Five drawable panels in one canvas. The compact pill, split pill, draggable orb, media player and timer/call widget sit inside one
<canvas content="drawable" layoutsubtree>, withinerthiding whichever panels are off-stage. - Smooth-union SDF and crisp post-pass DOM compositing. Evaluates cubic
smin(d1, d2, k)for the obsidian silhouette and specular rim, then samples each live panel at 1:1 CSS pixels inside the SDF mask so text stays sharp. - Damped springs and drag-to-pinch. Integrates capsule size and detached orb position with critically damped springs, or snaps immediately when
prefers-reduced-motion: reduceis active. - Single-context paint and geometry sync. Uploads only dirty panels through
ElementGL.upload()(texElementSubImage2D()) and updatesupdateElementGeometry()scaled bygeometryUnit()withdataset.hitTickcache clearing. - Five-argument 2D and plain-HTML fallbacks. Draws the island with explicit 5-argument
drawElementImage()without WebGL 2, and moves panels to plain HTML on context loss.
How it works
Every island widget lives as a drawable child inside one <canvas content="drawable" layoutsubtree> backed by one WebGL 2 context from ElementGL (/lib/element-gl.js). When a state switches, I toggle inert on the inactive panels, move focus cleanly if needed, and push their hit boxes off-stage while uploading only the panels whose DOM actually changed through gl.texElementSubImage2D().
Standard CSS gooey effects blur the DOM layer before thresholding alpha, which softens letter edges and slider hairlines. Here the fragment shader runs two stages in one pass. First it evaluates signed distances d1 for the rounded main capsule and d2 for the satellite orb, combines them with a C2-continuous cubic smooth minimum smin(d1, d2, k), shades the glossy obsidian fill and directional OLED specular rim, and optionally draws the SDF field and neck bridge strength. Only after that mask is fixed does it sample the uploaded DOM textures at 1:1 CSS layout coordinates inside the capsule mask, so text and buttons stay crisp even while the neck stretches.
Dragging the satellite orb updates a spring target clamped inside the dark mobile frame and releases back to the twin resting gap of 8 px. Because WebGL texture draws don't move Chromium's hit boxes, syncGeometry() calibrates the canvas unit once per resize with geometryUnit() from /lib/surface.js, calls canvas.updateElementGeometry() for each active panel and toggles dataset.hitTick to clear the hit-test cache. An IntersectionObserver pauses the animation loop when the stage leaves the screen, and prefers-reduced-motion: reduce removes spring oscillation so state changes jump cleanly.
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 Chrome 160 Canary (2026-11-27):
texElementSubImage2D()uploads unpremultiplied RGBA whenUNPACK_PREMULTIPLY_ALPHA_WEBGLstays at its defaultfalse(for example,rgb(255 255 255 / 0.1)arrived as[255, 255, 255, 26]), which washed translucent white pills out to solid white inside premultiplied shaders. Settinggl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true)at context creation and on restore produces true premultiplied texels ([26, 26, 26, 26]). - Sampling
uTexat 1:1 CSS pixels inside the SDF mask after computingsmin(d1, d2, k)keeps glyphs, track inputs and range sliders sharp across all four states and during morphs without blurring or distorting text. - Setting
touch-action: noneon the draggable orb while keepingtouch-action: pan-yon the outer canvas lets you pull the orb vertically or horizontally to pinch off the liquid neck while vertical swipes on the backdrop still scroll the page. - Sharing one calibrated
geometryUnit()scale across active panels per canvas resize avoids resetting cached measurements when positioning both the primary pill and the satellite orb in the same paint frame.