Scratch-off foil and thermal paper

I wanted to know if an R8 mask texture in one ElementGL canvas can coat a live HTML card in brushed metallic foil, gate pointer hits until you scratch past 35% of a control, and flip to heat-reactive thermal receipt paper. Drag to scratch the foil, or switch to thermal paper and rub to develop the ink.

INSTANT TICKET #8492

Canvas Prize Card

2x BONUS
Claimed 0
Spin 2x
Winner Guest
Card swatch:

0% scratched · 0 of 6 controls open

 

Show the code R8 mask texSubImage2D, anisotropic foil and thermal shaders, CPU hit gating, ElementGL paint
  1. One drawable wrapper holding both cards. Both the prize card and the thermal receipt sit inside one <canvas content="drawable" layoutsubtree>, with covered controls marked by data-gate.
  2. Anisotropic foil and thermal paper fragment shader. Draws brushed metallic streaks, holographic diffraction and torn flake shadows in foil mode, or converts dark DOM luminance into thermal-carbon ink surrounded by warm amber halos in thermal mode.
  3. Selective R8 mask upload. Stamps jagged coin strokes or thermal stylus heat into a 256 by 192 Uint8Array and uploads only the dirty rectangle via gl.texSubImage2D() with UNPACK_ROW_LENGTH.
  4. CPU shadow mask hit-test gating. Measures each control's cleared fraction against the 256 by 192 buffer and keeps pointer-events: none until cleared past 35%, then toggles data-hit-tick to flush Chromium's hit-test cache.
  5. Single ElementGL paint path and 2D fallback. Uploads the live DOM with texElementSubImage2D(), aligns hit geometry with updateElementGeometry(), and falls back to destination-out + 5-argument drawElementImage() or plain HTML.

How it works

I built this experiment around a single ElementGL context from /lib/element-gl.js and a 256 by 192 single-channel Uint8Array uploaded as an R8 WebGL 2 texture. Each pointer stroke updates only the dirty bounding box in that CPU array and calls gl.texSubImage2D() with UNPACK_ROW_LENGTH, UNPACK_SKIP_PIXELS and UNPACK_SKIP_ROWS so no pixels are read back from the GPU.

In scratch-off mode, the fragment shader combines directional brushed streaks, cell-based metallic flake normals, pointer-tilt specular lighting and serrated edge noise to peel back the foil and cast a rim shadow onto the bright HTML card beneath. Switching to thermal paper keeps the same R8 texture as a heat field: holding the stylus down pours heat into the buffer, blooming dark receipt text and borders into carbon black inside warm amber scorch halos while paper areas stay pale and waxy.

Hit-test gating runs straight off the CPU shadow mask. Covered controls start with pointer-events: none and tabIndex = -1 so dragging across a button or input scratches the canvas instead of triggering taps or opening the phone keyboard. Once more than 35% of a control's cached layout box reaches the cleared threshold, the gating pass flips data-gated="open", toggles a data-hit-tick attribute after canvas.updateElementGeometry() to clear Chromium's hit-test cache, and lets taps and typing land inside the scratched window.

Live checks

These wait for a tap so the demo starts with no extra WebGL contexts running. Each check builds a small fixture in the corner of the window and retires it afterwards.

Findings