r/digitalcards • u/grim-golf • 5h ago
I rebuilt how my digital cards shine. Left is the old CSS version, right is the new WebGL2 one
I make GG Collect, a free digital card game, and recently updated how the packs and cards are rendered.
Since the start, the shine was a few colour gradients slid over the picture as it turned. That's cheap and works everywhere, but it knows how far the card has turned and nothing about what's printed on it. So the rainbow washes over the whole card the same way whatever the art is.
The new version is drawn with WebGL2, which runs straight on your phone's or computer's graphics chip. It's now what I reach for first for anything that has to shine or move, and plain CSS stays as the fallback for any device that can't run it, so nobody gets a blank card.
It works out the light for every pixel, from where the lamp is and where your eye is. Three things change:
- The foil reads the card's own art, so it catches on the bright bits (the moon, the gilt frame) and breaks over their edges like real embossed foil.
- Glitter is thousands of tiny flakes, each tipped at its own angle, so they catch the light one at a time as the card moves and go still when it stops.
- The edge of the card is lit on the side facing the lamp, which is most of what makes it feel like an object rather than a picture.
It only draws while the card is moving, so a card lying still costs your phone nothing.
I wrote up the whole rebuild, including the packs, which are now real 3D models built with three.js on top of WebGL2, with demos you can play with in the browser:
https://grim.golf/blog/from-css-to-webgl2-and-threejs
Happy to answer questions. It's free to play at collect.grim.golf. Gold is earned in the game, never bought.



