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.

Puffy · no field yet

Stick it anywhere

A cartoon cat face with whiskers, cut out on a transparent background

Starting the ElementGL jump flood...

Show the code sticker markup, jump flood, sticker shader, hit sync
  1. 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.
  2. 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.
  3. 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.
  4. Size and hit sync. Copies the canvas box into --card-w and --card-h, then calls updateElementGeometry() 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