Tap-origin circular optical theme reveal
I wanted to know if one ElementGL WebGL 2 canvas could run a tap-origin circular theme transition across two live HTML panels, with radial lens magnification and RGB dispersion along the expanding ring while buttons and text fields keep working. Tap any Switch theme from here pill or anywhere on the empty stage, or drag the progress slider to inspect the rim.
Starting...
Show the code two drawable surfaces, tap-origin wavefront controller, optical lens shader, geometry sync and 2D clip
- Two full-stage
drawablesurfaces inside one canvas.#or-surface-aand#or-surface-beach hold corner and centre trigger pills, a counter, filter buttons and an editable<input>. - Deterministic
tMswavefront controller and corner-distance math. ComputesmaxCornerDist()so the expanding ring reaches the farthest corner at100%, and steps expansion or collapse from explicit timestamps. - Circular optical mask, radial magnification and RGB dispersion shader. Splits inside and outside textures at
r, bends sample coordinates across the ring width, splits red, green and blue channels, and adds a specular glint. - Radial
updateElementGeometry()hit sync. CalibratesgeometryUnit(), togglesdataset.hitTick, and enables controls inside the circle on Surface B and outside it on Surface A. - Five-argument
drawElementImage()2D radial clip fallback. Clips Surface B inside the expanding circle over Surface A and draws a matching lens rim when WebGL 2 isn't used.
How it works
Both workspaces (#or-surface-a and #or-surface-b) live inside one <canvas content="drawable" layoutsubtree> owned by a single ElementGL WebGL 2 context from /lib/element-gl.js. I set gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true) right after creating the context and again inside onRestored, wait for hasPainted = true inside the paint event, and always call stage.begin() before stage.upload().
When you tap a Switch theme from here pill or anywhere on the empty stage, the script records the normalised coordinate (ox, oy) and computes maxCornerDist(ox, oy) to the farthest canvas corner. At 0%, Surface A is active. At 100%, tapping another trigger promotes the visible theme to Surface A, updates Surface B to the next palette in the cycle (Daylight Paper, Midnight Studio, Forest Ink), waits for the next paint upload so the screen doesn't flash, and expands from 0% at the new tap point.
In ORIGIN_FRAG, pixels inside radius r = progress * maxCornerDist(ox, oy) read from Surface B and pixels outside read from Surface A. Across r ± ringW, a convex dome profile bends texture coordinates radially, offsets red, green and blue lookups along the radial normal for chromatic dispersion, darkens the outer meniscus lip lightly for contrast on bright paper, and adds a specular rim glint. Both .or-surface containers keep pointer-events: none so syncGeometry() can switch inert and pointer-events per control against the current circle radius, while toggling dataset.hitTick clears Chromium's hit-test cache. Playback pauses under IntersectionObserver and document.hidden, falls back to 5-argument drawElementImage() clipping in 2D, and moves both panels into #plain-host if the WebGL context stays lost.
Live checks
Each check builds an isolated fixture on testStage() without touching the demo above. Press Run to test this browser.
Findings
- Measured in headless Chrome 160.0.8188.0 canary (2026-11-27, 412x915 viewport at 2.625 DPR, SwiftShader WebGL, plus 1024x900 at 1 DPR): all 6 live checks pass, the backing store stays at
992x1040(1.032 MP,7.87 MBinitial,8.11 MBpeak across checks),scrollWidth === innerWidth === 412,CLS === 0across viewport height changes,0errors,0lost contexts,0open snapshots and0wrong-argumentdrawElementImage()calls. - Pixel readbacks in
readPixels()confirm corner-anchored wavefront ordering: at42%progress, a top-left origin(0.12, 0.14)drops top-left luminance to16while bottom-right stays at238, and a bottom-right origin(0.88, 0.86)flips those values to238and16(glErr=0). - Along the
50%circular lens circumference (ringW = 20 px),readPixels()measures a specular rim peak of255, inner cyan chromatic dispersion (B - R = 80), outer warm amber dispersion (R - B = 61), and a radial UV displacement delta of159against aringW = 0sharp mask. - Promoting the visible destination theme onto Surface A and setting the next palette onto Surface B inside a gated
paintpass lets the demo cycleDaylight Paper,Midnight StudioandForest Inkacross two live DOM panels with zero intermediate frame flash, whileupdateElementGeometry()keeps controls clickable at0%,50%and100%andselectstartleaves text selection empty outside<input>. - Both
?route=2d(5-argumentdrawElementImage()circular clip,6/6checks passing) and plain HTML (--disable-blink-features=CanvasDrawElement,scrollWidth === 412) run with0errors, and emulatingprefers-reduced-motion: reducechecks#ctl-reducedand snaps waves to100%. - Chrome 159 on Android (touch feel, real GPU shader frame rates and soft keyboard focus inside
#a-inputand#b-input) andnpm run check:jank -- /origin-reveal/(Playwright isn't installed in this environment) stay not verified.