Directional whip-pan motion-blur cut
I wanted to know if one ElementGL canvas can whip-pan between two live HTML views with 16-tap directional blur, RGB fringe and a damped overshoot spring while keeping buttons and inputs clickable at rest. Tap a cut direction, swipe across the stage or scrub from 0% to 100%.
Show the code Dual drawable views, directional blur shader, spring curve and fallbacks
- Two live scenes inside one drawable canvas.
#wp-scene-a(warm Studio Storyboard) and#wp-scene-b(dark indigo Timeline Sequence) sit inside<canvas id="wp-canvas" content="drawable" layoutsubtree>. - Bell-curve velocity, damped overshoot spring and hit-box sync.
stepWhipCut(..., tMs)drives the overshoot landing,whipBellVelocity()peaks at 50%, andsyncSceneGeometry()moves the settled view into place while parking the other view offstage withinert. - 16-tap directional velocity blur and RGB fringe shader.
WHIP_FRAGsamples both textures across the moving shutter vectoruPanDirwith red and blue channel offsets proportional to velocity andBlur px. - Premultiplied alpha uploads, 2D fallback and context recovery. Sets
UNPACK_PREMULTIPLY_ALPHA_WEBGL = trueon creation and restore, callsstage.begin()beforestage.upload()insidepaint, and falls back to 5-argumentdrawElementImage()or#plain-host.
How it works
Both views live inside one <canvas id="wp-canvas" content="drawable" layoutsubtree> managed by a single ElementGL WebGL 2 context from /lib/element-gl.js. On creation and inside onRestored, the page turns on gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true) so badges and input borders keep clean anti-aliased edges. Inside the paint handler, hasPainted unlocks uploads and stage.begin() sizes the backing buffer before stage.upload() updates whichever scene changed.
During a cut or manual scrub, stepWhipCut(anim, tMs, reducedMotion) drives progress across a 480 ms S-curve with a damped overshoot spring landing (about 2.6% past the stop before rebounding to rest). whipBellVelocity() follows a raised sine bell curve that starts at 0, peaks at 1.0 around 50%, and returns to 0 when settled. In WHIP_FRAG, once velocity times Blur px exceeds 0.15 px, the shader integrates 16 directional taps along uPanDir across both the trailing half of Scene A and the entering half of Scene B while splitting red and blue channels along the pan axis for a subtle velocity fringe. At 0% and 100% rest, it drops to a single direct texture fetch so controls and text stay razor-sharp.
At rest, syncSceneGeometry() calibrates CSS-to-canvas units with geometryUnit(), places the settled scene over the canvas via updateElementGeometry(), moves the hidden scene to OFFSTAGE with inert = true, and flips data-hit-tick to clear Chromium's hit-test cache. The stage disables native drag selection with user-select: none plus a selectstart guard while keeping user-select: text on both title inputs. Idle preview cuts pause on IntersectionObserver, document.hidden, any touch or scrub, and prefers-reduced-motion: reduce. When WebGL 2 isn't available or ?route=2d is set, a 5-argument drawElementImage() pass draws the moving frames; on webglcontextlost, ?route=plain or missing API support, both scenes move 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×893backing store (0.844 MP,6.75 MBinitial,12.18 MBpeak),glPeak = 2,openSnapshots = 0,unaskedReads = 0andwrongDraws = 0. - At
50%midpoint underLeftblur (48 px), trailing edge luminance smeared from255at0%rest down to177on mobile (185at960 pxdesktop) with a1.026overshoot peak fromstepWhipCut(). Reversing axes swapped smear cleanly:LeftgaveH=97vsV=12andUpgaveV=84vsH=12. - Real CDP clicks and text entry hit View A at
0%(Take #1incremented toTake #2;#wp-title-aupdated toSTUDIO REEL · OPENING EDITED) and View B at100%(Marker #1incremented toMarker #2;#wp-title-bupdated toTIMELINE SEQ 04 · WHIP LIVE), and a touch swipe across the timeline track returned cleanly to0%. - With
?route=2d, the 5-argumentdrawElementImage()fallback ran withwrongDraws = 0. With?route=plainor--disable-blink-features=CanvasDrawElement, both scenes moved into#plain-host(inert = false,scrollWidth = 412). Under emulatedprefers-reduced-motion: reduce, idle preview stayed paused and clickingUpsnapped straight to100%withvel = 0%. - Running
/lib/a11y-audit.jsat960×800with tab focus emulation enabled 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 multiply 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.