Topographic cursor-elevation card
I wanted to know if an ElementGL fragment shader can generate anti-aliased topographic isolines that swell into glowing peaks beneath the pointer and pinned summits while live <output> telemetry, sliders and radio controls stay sharp on top. Move across the card, tap Pin peak, or drag Ridge gain.
Starting ElementGL topographic contour shader...
Show the code central-difference isolines, transparent card composite and hit sync
- Transparent telemetry card over live terrain. Keeps
<output>figures, a range input, biome radios and buttons directly inside the drawable canvas. - Anti-aliased contour isolines and hillshade. Sums fBM terrain, a cursor Gaussian hill and up to four pinned peaks, evaluates screen-space gradient lines and composites premultiplied DOM controls on top.
- Geometry calibration and tap peak pinning. Uses
geometryUnit()withupdateElementGeometry()and updates<output>telemetry cleanly on taps without blocking controls.
How it works
This experiment combines Sunnie Kapar's Topographic Wallet Card and Nico Frey's Moving Mountains inside one ElementGL WebGL 2 canvas.
Inside the canvas, #topo-card uses a transparent background so its premultiplied alpha mask isolates white type, the slider, radio chips and action buttons cleanly from the terrain behind them.
In the fragment shader, terrainHeight() combines two octaves of value noise, a spring-smoothed Gaussian mound following the pointer and up to four pinned peak coordinates passed in uPeaks.
Central finite differences estimate height slope per pixel so major and minor isolines stay crisp without flickering on software or mobile GPUs, lighting elevated ridges with directional hillshade before compositing the uploaded DOM texture on top.
Live checks
These checks wait for a tap so the page keeps one WebGL context until requested. Each check runs inside its own isolated fixture on the test stage and retires its canvas afterwards.
Findings
- Measured in Chrome Canary
161.0.8200.0on 2026-12-04 at412x915(DPR2.625, SwiftShader WebGL): all 7 live checks passed with zero JS errors, zero lost contexts, zero open snapshots and zero horizontal overflow on a924x1139canvas (8.0 MB). - Moving the cursor shifted ridge elevation brightness cleanly (left cursor:
L=133, R=49; right cursor:L=32, R=139), while compositing premultiplied DOM controls over the terrain kept the white foreground readout bar at purergb(255,255,255)after<output>updates. - Both
<input type="range">and<button>hit-tested cleanly, and two consecutive reduced-motion static draws matched pixel-for-pixel atrgb(13,32,24)withgl.getError()=0. - Mouse hits used to land too far up the card. Blink does not stretch an
inset: 0child of<canvas layoutsubtree>to the canvas height, so the card laid out at518x342inside a518x434canvas and the stretched texture drew controls up to92pxbelow their hit boxes. Sizing the card fromcanvas.clientWidthandcanvas.clientHeightthrough--card-wand--card-hfixed it: the card now measures518x434at1280x900and352x434at412x915, and Ridge gain, Pin peak and Reset peaks hit at their drawn centres with no more than0.5pxof vertical drift.