Foil cards and world-locked dithering

I wanted to see if one live HTML playing card could switch smoothly between Balatro-style Foil, Holographic, Polychrome and Negative shaders, plus Return of the Obra Dinn 3D sphere-locked 1-bit dithering, without losing clickable controls when tilted. Drag the card to tilt it in 3D, type into its title box, tap the chip and mult counters, then switch to Obra Dinn mode and toggle between Screen-space and Sphere-locked to watch why the 3D view sphere stops dither swimming.

A♠ FOIL · +50 CHIPS
200 pts
NO. 057 · GOLD SEAL A♠

Drag card to tilt in 3D · pointer updates reflections

Obra Dinn 1-bit:
Initialising ElementGL WebGL 2 shader stage...
Show the code card markup, 5 optical shaders, 3D view-sphere dithering, spring tilt and hit sync
  1. The live playing card inside one drawable canvas. The editable title <input>, counter buttons, suit toggle, seal toggle and shaded SVG medallion sit inside one <canvas content="drawable" layoutsubtree>.
  2. Toroidal 32x32 blue-noise generator. Ulichney's void-and-cluster pass builds a tileable rank table once on startup and uploads it to texture unit 1.
  3. Five optical editions in one WebGL 2 fragment shader. Switching uEdition swaps between anisotropic Foil, prismatic Holographic scan-bars, thin-film Polychrome iridescence, solarized Negative edges and Obra Dinn 1-bit dithering without recompiling.
  4. 3D view-sphere angular grid vs screen-space coordinates. Quantizing equirectangular angles from normalize(rayDir) keeps Bayer 8x8 plus blue-noise dots anchored to the card in 3D space instead of sliding across gl_FragCoord.xy.
  5. 3D perspective projection, spring physics and hit testing. One DOMMatrix drives WebGL clip space and canvas.updateElementGeometry() scaled by geometryUnit(), toggling dataset.hitTick when the pose moves.
  6. 2D drawElementImage() fallback and plain-HTML recovery. Falls back to 5-argument drawElementImage() if WebGL 2 is absent, or moves #collector-card into plain HTML if the context is lost.

How it works

CSS mix-blend-mode and static gradients can approximate a sheen over flat DOM nodes, though they can't drive anisotropic diffraction gratings from a 3D surface normal or re-index an ordered dither matrix onto a 3D sphere. Here one ElementGL WebGL 2 context uploads #collector-card via gl.texElementSubImage2D() whenever the input, counters, suit or seal change, then draws the card as a single perspective-tilted quad.

Switching editions sets a uniform integer uEdition instead of recompiling shaders, so Foil, Holographic, Polychrome, Negative and Obra Dinn 1-bit switch in zero milliseconds. Foil modulates an anisotropic brushed-metal specular lobe along embossed borders; Holographic sweeps prismatic cosine diffraction bars across the surface; Polychrome evaluates a thin-film optical path difference with a Fresnel rim boost; Negative inverts into a darkroom plate with Sobel-like emerald and magenta edge halos.

In Obra Dinn 1-bit mode, I wanted to show directly why Lucas Pope projected his dither pattern onto a 3D sphere instead of flat screen coordinates. In Screen-space mode, the 8x8 ordered Bayer plus 32x32 blue-noise threshold is sampled at gl_FragCoord.xy, so tilting or orbiting the card drags its shaded gradients across a stationary screen door. In Sphere-locked mode, each fragment constructs a 3D unit vector rayDir = normalize(vec3(localPx, -uSphereRadius)), converts it to equirectangular angles (theta, phi), and quantizes those angular coordinates to select the Bayer and blue-noise cell before outputting strictly two binary colours (such as #333319 and #e5ffff).

To keep the card clickable and typeable while tilted, the same 3D perspective DOMMatrix passed to WebGL clip space (with clip Z zeroed so near and far planes never clip) is scaled by geometryUnit(canvas, cardEl, cardW) from /lib/surface.js and passed to canvas.updateElementGeometry(). Whenever the rounded pose key changes, cardEl.dataset.hitTick toggles so Chromium clears its hit-test cache, and under prefers-reduced-motion: reduce spring release snaps instantaneously without running an animation loop.

Live checks

These checks wait for a tap so the page opens with one GPU context. Each check runs on its own isolated fixture on the test stage and retires its canvas when finished.

Findings

Not verified in a live browser yet. Run the checks above in Chromium with #canvas-draw-element enabled to measure this device.