Holographic foil and brushed-metal sheen
I wanted to see if one ElementGL WebGL 2 canvas could extract micro-relief normals straight from texElementSubImage2D() luminance gradients and sweep holographic prism, brushed titanium and gold-leaf glints across embossed borders and text on a live membership card. Drag the card to tilt it in 3D, click a tier badge, edit the cardholder name or press Activate pass and Copy token.
Show the code card markup, Sobel relief shader, MVP projection, paint upload and 2D fallback
- Live membership card inside one drawable canvas. Clickable tier badges, an editable member name input, an embossed SVG seal and action buttons sit inside one
<canvas content="drawable" layoutsubtree>. - Deterministic tilt and sweep state helper.
stepTiltAndSweep(sim, tMs, reduced)advances spring tilt, auto orbit and directional light sweeps from explicit timestamps or snaps cleanly under reduced motion. - Sobel relief extraction and three optical materials.
FOIL_FRAGreads 3x3 luminance gradients fromtexElementSubImage2D(), tilts local normals by the 3D pose and switches between Hologram prism, Brushed titanium and Gold leaf. - Perspective projection and hit-test calibration.
buildCardMvp()produces matchinguMvpandcssMatrixtransforms, andsyncCardGeometry()calibratesupdateElementGeometry()withgeometryUnit()anddataset.hitTick. - One ElementGL WebGL 2 context with paint-gated uploads. Sets
UNPACK_PREMULTIPLY_ALPHA_WEBGL = trueon creation and restore, callsstage.begin()beforestage.upload()insidepaintand pauses off screen. - Five-argument 2D gradient fallback and plain-HTML recovery. Falls back to 5-argument
drawElementImage()with a 2D foil gradient blend when WebGL 2 is missing, or moves#os-cardinto plain HTML on context loss.
How it works
CSS gradients can layer a static shine over a card, though they don't know where every border hairline, SVG seal stroke or letter stem sits in the rendered bitmap.
Here one ElementGL WebGL 2 context uploads #os-card via gl.texElementSubImage2D() with UNPACK_PREMULTIPLY_ALPHA_WEBGL = true whenever you edit the member name, switch tiers or toggle pass activation.
Inside FOIL_FRAG, each fragment samples a 3x3 neighbourhood around vUv at CSS-pixel spacing, unpremultiplies RGB and runs a Sobel operator over luminance.
Flat obsidian areas produce gradients near zero, so they stay matte.
Hairline borders, SVG crest lines and typography edges produce steep luminance slopes that bend a local surface normal N_local, which is rotated by the card's 3D yaw and pitch before lighting runs.
Three material branches share that extracted normal without recompiling shaders: Hologram prism computes thin-film optical path difference and rainbow diffraction grating lines that shift hue across the card as tilt and pointer angle change; Brushed titanium evaluates Ward and Kajiya-Kay anisotropic highlights perpendicular to horizontal micro-grooves; Gold leaf concentrates warm amber-gold Fresnel and hammered micro-flake specular glints along embossed borders and text.
Dragging on #os-canvas tilts uMvp in perspective while keeping user-select: none and a selectstart guard outside #os-member-input.
syncCardGeometry() scales the same projective DOMMatrix by geometryUnit() from /lib/surface.js, calls canvas.updateElementGeometry() and flips dataset.hitTick so every button and input stays clickable while tilted.
Motion pauses via IntersectionObserver and document.hidden, snaps immediately under prefers-reduced-motion: reduce and falls back to 5-argument drawElementImage() or plain HTML if WebGL 2 is unavailable or lost.
Live checks
These checks wait for a tap so the page opens with one GPU context. Each check builds an isolated fixture on testStage() and retires its canvas when finished.
| Result | Experiment | Detail |
|---|
Findings
Not verified in a live browser yet. Tap Run above in Chromium with #canvas-draw-element enabled to measure this device.
- CSS-pixel Sobel step across DPRs: sampling the 3x3 Sobel neighbourhood at
max(1 / uTexSize, 1.15 / uSize)keeps extracted bezel widths consistent between 1x desktop monitors and 2.625x phone screens. - Paint-gated uploads on one context: gating
stage.upload(cardEl)onhasPainted = trueinsidepaintafter callingstage.begin()prevents stale size or paint-record exceptions during tilt and pointer sweeps. - Input selection inside a draggable canvas: setting
user-select: noneplus aselectstartguard on the canvas while leavinguser-select: texton#os-member-inputstops accidental label drags without blocking text editing. - Not verified: headless Chrome Canary measurements,
npm run check:jank -- /optical-sheen/and real touch tilting on Chrome 159 for Android at 412 px wide.