Live-sticker finishes on real elements
I wanted to know if an ElementGL shader can turn a live <button>, a <label> chip, a transparent <img> and an <h2> into iOS-style stickers by jump-flooding a distance field from the card's own alpha, then inflating it into a lit pillow, while every control keeps working. Move over the card, tap the button or the chip, or pick a finish.
Starting the ElementGL jump flood...
Show the code sticker markup, jump flood, sticker shader, hit sync
- Live elements in a sticker zone. A heading, a button with an
<output>, a checkbox chip and an SVG<img>sit in the zone whose alpha becomes stickers. The finish radios sit below it and stay flat. - Jump flood on the ElementGL context. A seed pass sorts each texel of the uploaded card into sticker or background, and seven jump passes (32 down to 1, plus one) spread the nearest seed of each kind through two RGBA16UI framebuffers. It runs only when the card is uploaded again.
- Border, pillow and finishes. The distance to the nearest seeds gives the die-cut border and a pillow height whose slope is the surface normal, lit with Blinn-Phong for Puffy, left flat for Outline, screened into CMYK dots for Comic and tinted with tilt-driven foil for Shiny.
- Size and hit sync. Copies the canvas box into
--card-wand--card-h, then callsupdateElementGeometry()only when the unit or buffer size changes.
How it works
The idea is Apple's iOS 17 Live Stickers, which lift a subject out of a photo and offer Outline, Comic, Puffy and Shiny finishes. Puffy inflates the sticker from its own outline. That needs a distance field from the shape's alpha, and CSS has no route from an element's alpha to a surface normal. Here the shape is a set of live elements on a transparent card in one ElementGL WebGL 2 canvas.
When the card is uploaded with texElementSubImage2D(), a seed pass marks each texel as sticker (alpha over 0.5 inside the sticker zone) or background, storing its own coordinate in an integer texture. Seven jump-flood passes then carry the nearest sticker seed and the nearest background seed to every texel. I start the flood at a step of 32 rather than half the card, because the border, pillow and shadow never need more than 64 px of reach. Hover, a tap on the button or a tick in the chip repaints the card, which uploads it again and floods again.
Each frame the sticker shader reads the seeds of the four texels around a pixel, which gives a smooth distance to the outline, adds a border of 9 to 12 px, and turns the distance into a pillow height. My first normals used the direction to the single nearest seed, which snaps from grid point to grid point and drew fibrous streaks around curved letters, so the slope now comes from central differences of that smooth distance 2.2 px either side. Puffy lights it with a point light that follows the pointer. Outline draws the border flat with a cut line. Comic screens the colours into cyan, magenta and yellow dots at three angles with solid black. Shiny shifts a rainbow foil, a glare band and sparkles with pointer or phone tilt.
The card is a direct child of <canvas layoutsubtree>, so I size it with left: 0; top: 0 and a width and height copied from the canvas box rather than inset: 0. The finish radios sit outside the sticker zone, and the shader puts them back on top with mix(bg, tex.rgb, tex.a) because the uploaded texture has straight alpha.
Live checks
These checks wait for a tap so the page keeps one WebGL context until asked. The shader checks run on their own small fixtures and give their canvases back afterwards. The control and hit checks run against the card on this page.
Findings
- Measured in Chrome Canary
161.0.8200.0on 2026-12-04 at412x915(DPR2.625, SwiftShader WebGL): all 10 live checks passed with zero JS errors, zero lost contexts, zero open snapshots and no horizontal overflow on a924x1202canvas (1.11 MP,8.5 MB). The same 10 passed at1280x900. - The jump flood (a seed pass and 7 jumps in two
RGBA16UIframebuffers on the ElementGL context) matched the exact distance to a100x60box within0.21 px, mean0.037 px, over29220texels, with no texel left without a seed inside 50 px. - With the light at the top left, Puffy's border measured luma
229on the left and107on the right, with a highlight of255; moving the light to the right swapped them (101and241). Comic raised the luma spread inside a blue box from45to237, and Shiny raised border chroma from4.0to61.8. - Ticking the live Like chip repainted the card, which uploaded it again and ran a new flood. The Shiny radio, the Stuck button and the Like checkbox hit at their drawn centres with
0.00,0.06and0.06 pxof vertical offset, and the card measured458pxagainst a458pxcanvas. - Normals from the direction to the single nearest seed drew fibrous streaks around curved letters, because seeds sit on grid points. Central differences of the smooth four-texel distance removed them.