Gem Slot

Gem Slot is a 5×3 slot machine demo built in Unity 6.1 URP: four cut-gem symbols with a hand-written gem shader with silhouette glow, and a win presentation that escalates from a small pulse to a screen-wide Mega celebration.

One full cycle: no win, Small, Medium, Big, then Mega

Gem shader

All four gems under the same environment — the colour comes from each gem’s own LUT

The gem is one forward pass in hand-written HLSL. All colour comes from a per-gem 2D LUT indexed by the brightness of a single grayscale cubemap, so one environment serves every gem, and the four materials are variants of one parent.

  • Reflection over interior — Schlick Fresnel blends the reflected environment over the refracted interior, each with its own roughness and contrast.
  • Faceted interior — a shard normal map bends the refraction direction, and a parallax offset gives the shards depth.
  • Glints — per-shard specular pushes further along the LUT with an HDR boost, so glints bloom in the gem’s own colour.
  • Animatable — brightness, saturation and reflection are exposed as material values the Animator can key.

Silhouette glow

Originally, I wanted to make the silhouette glow with a bloom pass. However, it makes the gem body super bright, and the outline is still not thick enough. I also tried adding an inflated mesh, but its width changes as the gem rotates. Finally, I decided to add a glow card behind the gem that recalculates its silhouette every frame.

To do that, I need the gem’s silhouette on screen every frame. This is done by projecting the gem’s vertices to the screen and finding their 2D convex hull using Andrew’s monotone chain algorithm. Afterwards, a camera-facing card is fitted to the silhouette. The card shader then fades by each pixel’s distance to the hull.

Gem and its silhouette mask Left: the gem with its glow card off. Right: the convex hull of its projected vertices, the shape the glow fades from

The hull card costs one small hull per gem on the CPU plus the card’s fill, and exposes a glowBoost value the Animator can key.

Win animation and VFX

Win Trigger VFX
Small 3 in a row Scale pulse, interior boost, sparkle
Medium 4 in a row Scale pulse, interior boost, sparkle, rotation
Big 5 in a row Scale pulse, interior boost, sparkle, rotation, shockwave rings, star streaks, counter-rotating rays, backdrop glow
Mega 5 in a row on all 3 rows Scale pulse, interior boost, sparkle, rotation, shockwave rings, star streaks, counter-rotating rays, backdrop glow, Mega celebration

Small — 3 in a row

Medium — 4 in a row

Big — 5 in a row

Win state machine One hub: WinTier routes Default to Lose, Win 3, Win 4 or Win 5, and the higher tiers fall through to a looping state

  • Animator-driven — the win logic sets one int, WinTier, per gem. The animator takes WinTier and decides what animation to play.
  • State Design — each win state contains a one-shot intro, and the higher tiers add a looping hold so the win lingers until the next spin.
  • Interrupts — one Any State → Default transition with no blend snaps every symbol to rest on the next spin, from any state.

Mega celebration breakdown

The Mega celebration runs on its own Animator through four states — intro, rain, land, then a looping hold.

Mega celebration state machine A straight chain, one Animator of its own: Idle into Mega Intro, Rain, Land, then Hold

  • Intro (0.9 s) — the screen dims, the god rays scale in, MEGA pops followed by WIN, and a burst of gems fires out as the amount appears at $0.
  • Rain (5 s) — gems rain from the top of the screen while the amount counts up and the banner wiggles.
  • Land (0.4 s) — the count lands on its final value with a punch on the amount and a bump on the banner.
  • Hold (loops) — the banner breathes gently with occasional text wiggle, the banner gems keep spinning. The next spin returns every state to idle.

To avoid visual clutter, I wanted the winning gems to drop their streaks and glitter but keep spinning.

Originally, I just switched them to a separate Celebrate state, but that ended up restarting the rotation, so every gem snapped back to 0°. Therefore, I added a second override Animator layer that keys only the effects it switches off, so the base loop keeps the backdrop and rotation running uninterrupted. The layer at full weight then held stale values and blocked the reset on the next spin, so it’s weighted in only while celebrating.