Velocity-driven Disney motion smear and squash-stretch
I wanted to know if one ElementGL canvas can stretch, squash and smear a live HTML card from its instantaneous velocity, then snap back to crisp 1:1 text and hit-testing when it stops. Drag and fling the card, press Fling card, or toggle Figure-8 orbit.
Show the code Live drawable card, 2D spring-damper physics, squash-stretch smear shader and hit sync
- Live card inside one drawable canvas.
#ms-cardsits inside<canvas id="ms-canvas" content="drawable" layoutsubtree>with an editable label, palette buttons and+1 Pingcounter. - 2D momentum, spring-damper physics and hit-box sync.
stepCardMotion(state, tMs)bounces softly off stage bounds, couples the figure-8 orbit via a damped spring, and callsupdateElementGeometry()withgeometryUnit()anddata-hit-tick. - Squash-stretch, 16-tap smear and chromatic RGB trail shader.
SMEAR_FRAGwarps coordinates alonguVelwithstretch * squash == 1.0, integrates 16 dithered taps with leading warm and trailing cool fringes, and snaps to 1:1 whenspeed < 0.01. - Premultiplied uploads, 5-arg 2D fallback and context recovery. Turns on
UNPACK_PREMULTIPLY_ALPHA_WEBGL, gatesstage.upload()onpaintafterstage.begin(), and moves the card into#plain-hostonwebglcontextlost.
How it works
One <canvas id="ms-canvas" content="drawable" layoutsubtree> holds #ms-card under a single ElementGL WebGL 2 context from /lib/element-gl.js. Both creation and onRestored turn on gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true) so the rounded borders, colour swatches and text keep clean edges over the dark stage grid. Texture uploads wait for hasPainted = true inside paint after calling stage.begin(), so the backing store matches device pixel ratio before stage.upload() copies the card.
Dragging, flinging, Fling card or Figure-8 orbit drives stepCardMotion(state, tMs) with explicit timestamps. Free flings coast under exponential damping with soft elastic wall rebounds inside the stage margins; Reset centre and Figure-8 orbit pull the card with a 2D spring-damper. Each frame passes the normalised velocity vector uVel to SMEAR_FRAG on a padded local quad so trails never clip at the card border.
Inside SMEAR_FRAG, any frame with speed >= 0.01 computes an area-preserving basis aligned to (vx, vy) (stretch = 1 + 0.24 * min(speed, 2.2), squash = 1 / stretch) and integrates 16 interleaved-gradient-noise taps weighted from the leading edge into the trailing wake, splitting red ahead and blue behind for a chromatic RGB trail. Once speed < 0.01 or Compare crisp 1:1 (no smear) is pressed, the shader takes one direct unpadded texture sample with zero blur. Every position or stretch change updates updateElementGeometry() scaled by geometryUnit() and flips data-hit-tick to clear Chromium's hit-test cache, while IntersectionObserver and document.hidden pause the loop off screen. If WebGL 2 is unavailable or ?route=2d is set, a 5-argument drawElementImage() trail renders instead; on webglcontextlost or ?route=plain, the live card moves into #plain-host as plain HTML.
Live checks
These checks run on isolated fixtures inside testStage() and wait for a tap so opening the page doesn't allocate extra WebGL contexts or move focus.
| Status | Check | Detail |
|---|
Findings
- Measured in
HeadlessChrome/160.0.0.0on 2026-11-27 (412 px wide, DPR 2.625, withCanvasDrawElementenabled): all 6 live checks pass with 0 console errors,scrollWidth === 412, a945×961backing store (0.91 MP,7.27 MBinitial,16.78 MBpeak),glPeak = 2,glActive = 1after checks,removed = 0,openSnapshots = 0,unaskedReads = 0,noSizeDraws = 0andwrongDraws = 0. - Under diagonal velocity
(+1.2, -0.9), area-preserving deformation measuredstretch = 1.45xandsquash = 0.69x(product1.00), while trailing wake luminance jumped from13at rest (and13perpendicular) to124on mobile (141at960 pxdesktop), with separated trailing bluergb(86, 125, 162)and leading redrgb(78, 7, 14)chromatic fringes. Turning onCompare crisp 1:1 (no smear)returned trailing edge luminance to13immediately while the card kept moving along the figure-8 path. - Deterministic
stepCardMotion(state, tMs)coasted across5wall bounces (peak speed2.37) tovel = 0inside stage bounds, sprang cleanly back to centre(66, 91), and snapped in one step under reduced motion. Real CDP clicks and text input hit+1 Ping(1 ping), switched palette tocobalt, appended text inside#ms-title-input, and clicked+1 Pingagain at its displaced post-fling settle(70, 145)(2 pings). - With
?route=2d, the 5-argumentdrawElementImage()trail ran at1621 px/s(1.53x/0.65x) withnoSizeDraws = 0andwrongDraws = 0. With?route=plainor--disable-blink-features=CanvasDrawElement,#ms-cardmoved into#plain-host(scrollWidth = 412). Under emulatedprefers-reduced-motion: reduce,Figure-8 orbitstayed off andFling cardstepped with0 px/sand zero smear. - Running
/lib/a11y-audit.jsat960×800with focus emulation passed 9 checks (calm,blank,dom,hit,ghost,focus6/6,names6/6,sharp,motion) with 0 failures and 1 warning (zoom, becauseElementGL.#syncSize()doesn't scale backing pixels bycurrentCSSZoom). npm run check:jank,node tools/draw-size/audit.mjs, real Chrome 159 on Android hardware andsocial.jpgcapture are not verified yet.