Finger shadows on a raised control panel
I wanted to know if an ElementGL fragment shader can cone-trace the soft shadow of a hovering finger across a panel of native controls, treating each control's layout box as a raised block, so the pads cast their own shadows and the finger's shadow steps where it crosses them. Move over the panel, hold Alt or Shift and turn the wheel or drag Hover height, and press a pad. A plain wheel still scrolls the page.
Starting the ElementGL finger shadow shader...
Show the code height map from layout boxes, capsule cone trace, hit sync
- A real control panel inside the drawable canvas. Six
<button aria-pressed>pads, a<select>, three checkboxes, two range inputs and two buttons on a transparent form sized withleft,top,widthandheight. - Elevations from layout. Walks
offsetLeftandoffsetTopup to the form for each control, which ignore transforms, and hands the boxes, heights and corner radii to the shader asuElevRects[],uElevH[]anduElevR[]. - Cone-traced capsule and block shadows. Each pixel sits on the height map, then a cone towards the light is tested against the finger capsule (tip to base) and against every raised block nearby.
- Hover height from the pointer. Pointer position sets the tip, the slider and Alt or Shift with the wheel set the hover height (a plain wheel scrolls the page), and pen or touch pressure brings the tip down to the surface below it.
- 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 Romain Guy's Finger Shadows in Compose (source), where an AGSL RuntimeShader models the finger as a capsule and cone-traces the soft shadow it casts on the screen. I moved it into one ElementGL WebGL 2 canvas and gave the surface heights: every control on the panel is a raised block whose box comes from its layout and whose height comes from its role, so pads stand 16 px proud, the select and sliders less, and a latched pad sinks to 4 px.
For each pixel the shader looks up the height of whatever is under it, then sends a cone from that point towards the light. The finger is a capsule from the tip under the pointer to a base up and away towards the hand. Where the cone passes close to the capsule the pixel darkens, and the cone's width at that distance sets the penumbra, so the shadow is sharp and dark at contact and wide and faint high up. The same cone is tested against the raised blocks, so the pads cast short shadows of their own. Because the top of a pad is closer to the finger than the surface around it, the finger's shadow lands in a different place on the pad than beside it and breaks into steps at every edge.
The form 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, because Blink gives an inset: 0 child its content height there, and the stretched texture would move 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 state and hit checks run against the panel 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 a924x1339canvas (1.24 MP,9.4 MB) holding 16 raised controls. The same 9 passed with the same numbers on a hardware GPU (ANGLE Metal, Apple M4 Pro). - The shadow depends on contact. With the tip touching, luma straight under it was
126and the steepest one-pixel step89; with 80 px of air it was226(lit surface219), the darkest point sat76.4 pxfrom the tip and the steepest step was7. - A 16 px box made from a layout rectangle cast its own shadow (luma
116on its shadow side,213on its lit side) and moved the finger shadow that fell on its top:96of1426samples changed by more than 25 against the same box at 0 px, and0with no finger. - The form measured
510pxagainst a510pxcanvas. Reset (the bottom control), the Hover height slider, the Light select and the Hat pad all hit at their drawn centres with at most0.09pxof vertical drift. - My first sphere test was a one-edge cone model, which kept a full black core under the finger at any height (darkest luma
127at 80 px against122at contact in the first run). Capping the blocked share of the cone at the sphere's area,(r / w)², lets the core lighten as the finger lifts (165at 80 px). - The page only draws when something changes. Driving it with a pointer move every frame gave about
19frames a second on SwiftShader and60.5on the M4 Pro at924x1339.