Liquid storage meters and draining digits
I wanted to see if semantic HTML <meter> storage bars and large live <output> quota numerals can serve directly as fluid-filled glass vessels in one WebGL 2 fragment shader. Move the quota slider, press Clear cache or Refill, or drag across the glass dashboard to slosh the layered liquids.
Starting...
Show the code drawable storage card, fluid glass shader, slosh physics, geometry sync and 2D fallback
- Live storage dashboard inside one canvas. Semantic
<meter>bars, an<input type="range">slider, action buttons and a bold<output>readout share onedrawablecontainer. - Luminance-masked liquid glass fragment shader. Detects the bright tank, semantic
<meter>tracks and<output>numerals fromtexElementSubImage2D(), refracts etched tank labels and layers sloshing coloured bands. - Damped drain and slosh physics. Integrates target fill levels, angular tilt velocity and wave energy, settling to sleep when idle or snapping immediately under
prefers-reduced-motion: reduce. - Hit-test calibration with
updateElementGeometry(). Measures sub-element UV boxes, scales the card transform bygeometryUnit()and flipsdataset.hitTick. - Five-argument
drawElementImage()2D and plain HTML fallbacks. Draws wave-clipped layers over the 2D card picture or moves the live DOM card into plain HTML on context loss.
How it works
This experiment rebuilds Alim Joldaspayev's Liquid Storage (original post) alongside Noman Ijaz's Usage Limit Drain (original post) inside one <canvas content="drawable" layoutsubtree> backed by a single ElementGL WebGL 2 context from /lib/element-gl.js. Everything inside #storage-card stays live HTML: four semantic <meter> elements for Apps, Media, Cache and System, an <input type="range"> slider, two buttons and a bold <output> quota readout.
On each paint event, stage.begin() sizes the backing store before stage.upload(cardEl) uploads the card with gl.texElementSubImage2D(). The fragment shader reads DOM luminance directly from uTex inside the measured boxes of the vertical tank, the four <meter> bars and #quota-digits. Outside those vessel regions, the shader outputs uTex untouched so every label, slider thumb and button border stays sharp.
Inside the tank silhouette (lum > 0.28), four stacked fluid bands rise from System at the bottom through Apps and Media to Cache at the top. Each boundary carries a three-harmonic wave surface tilted by uTilt, a bright capillary meniscus rim, buoyant bubbles and chromatic RGB refraction of the etched 128 GB capacity labels painted in #768fb8 behind the tank. Inside #quota-digits, four-tap luminance gradients form glass tube edges around each numeral so the empty upper portion stays readable even when the liquid drains to 15%.
Clearing cache, dragging the slider or swiping horizontally across the card kicks angular velocity and wave energy in a damped oscillator. Once levels and tilt settle (or when the stage scrolls off screen via IntersectionObserver or the tab hides), the animation loop stops completely. Hit boxes stay aligned through updateElementGeometry() scaled by geometryUnit(), with a five-argument drawElementImage() 2D path and a plain HTML fallback if the context is lost.
Live checks
Each check builds an isolated fixture on testStage() without touching the dashboard above. Press Run to run them in this browser.
Findings
- Not verified in a live browser yet: syntax, graphics rules and writing checks run first, followed by headless Chrome 160 Canary at 412 px (DPR 2.625) and desktop.
- Using mid-bright
#768fb8capacity labels inside an#eff6fftank silhouette keeps both above the0.28mask threshold while giving the shader enough luminance contrast (0.55vs0.96) to refract the DOM labels chromatically underneath the coloured fluid. - Keeping
#quota-digitson a tight0.80line-height lets the shader align0%to the numeral baseline and100%to the cap height without clipping drained states near15%. - Skipping pointer capture when a gesture starts on
inputorbuttonleaves native slider drags and button taps uninterrupted while horizontal swipes across the glass tank tilt the fluid.