Pieces built in code

Churn has no 3D model files. Every king, pawn, halo, and sniper rifle is built in code when the game starts, from the official chess proportions up. Here's why, and how 36 piece variants end up costing 13 draw calls.

Every Churn piece for both sides at every tier, lined up on the board, tier-3 pieces wearing gold halos
All six kinds, both sides, at every tier. None of it was modeled by hand.

Why not just import models?

The obvious route was to download a nice chess set and load it. We tried candidates and measured them. The problem wasn't how they looked; it was everything Churn wanted to do with them. Pieces level up, pick branches that change their silhouette, grow halos, pick up weapons, squash when they land, and lean when they merge. With imported models, every one of those is a new model or a fight with someone else's mesh.

Built in code, those are just transforms of the same description. A skin is one function. An upgrade is one function. An animation is one branch of a shader. And because the game knows which part of the mesh is the head and which is the foot, effects can treat them differently.

Starting from FIDE

The proportions come from FIDE, the international chess federation, whose equipment rules give standard piece heights and say a piece's base should be 40 to 50 percent of its height. With one square at 5.5 cm, that gives Churn's units:

Piece FIDE height Height (squares) Base diameter
King 95 mm 1.727 0.777
Queen 85 mm 1.545 0.695
Bishop 70 mm 1.273 0.586
Knight 60 mm 1.091 0.545
Rook 55 mm 1.000 0.500
Pawn 50 mm 0.909 0.436

Skins can restyle a piece, but the footprint never changes, so every piece sits on its square the same way. A unit test holds every kind to within 3% of these numbers.

Five kinds of part

Every piece is assembled from a handful of shapes:

  • Lathe: a smooth profile curve spun around the vertical axis, like wood on a lathe. It makes the body of every piece.
  • Loft: a series of rounded-square rings swept along a curved spine. It makes the knight's head and neck, plus gun barrels, stocks, and hammer hafts. The helper is about 60 lines.
  • Box, ball, and torus: for the rook's merlons, the queen's coronet, the knight's eyes, and the gold rings of the tier-3 halo.

Any part can repeat around the axis, each copy turned to face outward, so the rook's five merlons and the queen's eight coronet balls are one line each.

Every vertex also records three numbers: which section of the piece it belongs to (foot, stem, collar, head, and so on), whether it's on a gold trim band, and how high up the piece it sits, from 0 to 1. The shader uses those to wobble a head more than a foot, light up the trim as a piece levels, and squash pieces from the bottom up.

Tiers, branches, and weapons are forms

A piece is described as data, then passed through a stack of pure functions called forms: its branch silhouette, the tier-3 halo, its skin, then its equipment, always in that order. The halo, for example, is added into the piece's own geometry, so it hops, squashes, and leans with the piece for free.

Four close-ups of Churn pieces at tiers 1 to 3 for both sides: knights with mounted riders, queens with M60s, rooks with sniper rifles, and stacked checker chiefs with gold crowns and evil grins
Knights with the Lance Charge rider, queens with the M60, rooks with the sniper, and the checker chiefs.

Weapons are the most detailed parts in the game, and they're built from the same few helpers. The rook's sniper has a tapered barrel, a ported gold muzzle brake, a scope with a turret, a bolt with a gold knob, a magazine, a folded bipod, and a stock with a cheek rest. It's all in code, from rough shapes after real silhouettes, with no assets imported.

Building them taught us one lesson the hard way. A loft that runs backwards along its spine winds its triangles inside out and renders as a hollow shell. The first rifle stocks did exactly that, and looked like they had parts missing. Now a test checks that every loft in every weapon winds outward, by computing the signed volume of the mesh.

36 variants, 13 draw calls

Draw calls (how many times the game asks the graphics card to draw something) are usually what limits a browser game, more than triangle counts. Churn draws all pieces of one variant with one instanced mesh: one draw call, however many are on the board. Team color, current animation, and glow are per-instance values, not separate materials.

Measured in a real browser, every combination of six kinds, three tiers, and two sides comes to 13 draw calls: 12 piece variants and the board. Building every variant takes about 95 ms at medium quality.

Level of detail by construction

Quality settings don't swap in cruder models. The same description is just built more or less finely: 12, 20, or 32 segments around each lathe, with profiles simplified to a tolerance that depends on the setting, so points land where the outline bends and straight stretches cost nothing.

The same Churn pieces close up at low quality, with visible facets, and at high quality, smooth
Low quality on the left, high on the right: one description, built two ways.

On low, the budget is 640 triangles a piece, and a full board of 32 pieces is about 13,500. The queen is the one piece that needs more than 500, because her eight-ball coronet costs 616 at low. Dropping it would have saved triangles nobody would miss, and lost the thing that makes her the queen.

Motion in one shader

Every piece shares one material, patched once with a deformation function. Moves, merges, strikes, and deaths are all curves in that function, driven by a single clock:

  • Hop: an arc with a squash on take-off and landing. Knights hop higher, about 1.9 times as high, and rooks, bishops, and queens glide flat along their lines instead.
  • Wobble: a decaying lean, strongest at the top, for merges and promotions.
  • Fall: pieces drop onto the board from 12 units up, squash on impact, and bounce twice. The squash scales with the piece's weight, so heavy pieces land harder and bounce less.
  • Strike and flinch: the attacker rears back as it fires, and the target dips and springs back.
  • Press and release: clicking a piece squashes it and holds; letting go springs it back with an overshoot.

The game only writes a piece's animation data when an event starts a motion, never every frame, and it only renders while something is actually moving. An idle board costs nothing.

And then there are checkers

Churn's PvE rounds send waves of checkers at you, and they're literally checkers: smooth, worn coins with a gold face on top, slanted eyes in a scowl and a grin whose corners turn up. Chiefs are two coins stacked like a crowned king in draughts, with a gold crown. A checker is 252 triangles at low quality, and a chief 636, just under budget.

The first version gave them little caveman bodies on top. They looked like too much geometry and, somehow, cheese. Coins with evil faces turned out funnier.

Held in place by tests

Pieces built from code can drift if nobody's watching, so tests check that every kind matches its height and footprint, stays under the triangle budget, winds outward, and builds cleanly in every skin, branch, and quality combination. The proportions on screen are the proportions in the rulebook, and the tests keep them there.