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.

1 frosted · 64% arc
Cryo relay · bay 4 64 kV
-12.6 °C

Tick a loop to frost it. Drag a slider to charge its arc.

Coolant loops

Starting the ElementGL frost and arc shader...

Show the code control rectangles, frost and arc shader, hit sync
  1. 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 with left, top, width and height.
  2. Control rectangles from layout. Walks offsetLeft and offsetTop up to the card to get each chip and track in untransformed card pixels, then passes them as uniforms.
  3. 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.
  4. Size and hit sync. Copies the canvas box into --card-w and --card-h, then calls updateElementGeometry() 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