Frost and arc form controls
I wanted to know if one ElementGL fragment shader can grow crystalline frost around ticked checkboxes and crackle branching electric arcs along range sliders, reading each control's rectangle from offsetLeft and offsetTop, while the native form underneath keeps working by touch, mouse and keyboard. Tick a box or drag a slider.
Starting the ElementGL frost and arc shader...
Show the code control rectangles, frost and arc shader, hit sync
- A real form inside the drawable canvas. Three native checkboxes, two native range inputs with
<output>readouts and two buttons, on a transparent card sized withleft,top,widthandheight. - Control rectangles from layout. Walks
offsetLeftandoffsetTopup to the card to get each chip and track in untransformed card pixels, then passes them as uniforms. - Frost halos and branching arcs. A rounded-rectangle distance field with Voronoi facets and dendrite spikes for frost, and a jittered polyline with three branches from the track start to the thumb for each arc.
- Size and hit sync. Copies the canvas box into
--card-wand--card-h, then callsupdateElementGeometry()only when the unit or buffer size changes.
How it works
The idea comes from Opera's HTML-in-canvas demos, which have checkboxes that frost when ticked and controls that crackle with electricity. I put both on one form in one ElementGL WebGL 2 canvas. The form's background is transparent, so the premultiplied texture alpha separates the controls from the effect behind them.
Each frame the page reads every chip and slider track with offsetLeft and offsetTop, which ignore transforms, and hands up to three frost rectangles and two track rectangles to the shader. Frost is drawn behind the controls and grows outwards from the ticked chip. Arcs are added on top of the texture so they cross the native track, with their length set by the slider value and a brief surge each time the slider moves.
The card is a direct child of <canvas layoutsubtree>. I size it with left: 0; top: 0 and a width and height copied from the canvas box rather than inset: 0, because Blink gives an inset: 0 child its content height there, which stretches the drawn card and moves taps away from the controls.
Live checks
These checks wait for a tap so the page keeps one WebGL context until asked. The shader checks run on their own small fixtures and give their canvases back afterwards. The hit check runs against the form on this page.
Findings
- Measured in Chrome Canary
161.0.8200.0on 2026-12-04 at412x915(DPR2.625, SwiftShader WebGL): all 9 live checks passed with zero JS errors, zero lost contexts, zero open snapshots and no horizontal overflow on a924x1223canvas (1.13 MP,8.6 MB). - Frost around a ticked
120x40rectangle raised luma on a ring 6 px outside it from18to119. Arcs stopped at the thumb: at charge 0.4 there were33bright columns before it and0past it, and83at charge 0.9. - The card measured
466pxagainst a466pxcanvas, andelementsFromPoint()found Thaw all, the bottom control, at its top, centre and bottom with0.00pxvertical offset. Two frames atuClock=0matched in all910928bytes. - The arc envelope
pow(sin(PI * a), 0.6)was NaN at the thumb, where float32sin(3.1415927)is slightly negative. SwiftShader hid it, but a hardware GPU drew white vertical lines. Across 41 clock values the tallest bright column run was138.0 pxbeforemax(..., 0.0)and13.0 pxafter. - Reading
MediaQueryList.matchesevery frame stopped Chrome sending itschangeevent (my listener counted0, a fresh one1). The page now reads it once and follows the event.