Hi everyone! I made a small autumn game where every leaf on the lawn is simulated and you clean up the yard with a leaf blower.
Play (free, desktop and mobile): Leaf Me Alone!: Play free online | Glowbit Games
You walk behind the leaves and blow them onto a tarp, fight a leaf war with the grumpy neighbour (his hat flies off if you blow him), keep the dog from diving into your pile, and at the end of every yard you cannonball into the pile you built.
Some technical bits
- Leaves: up to 7,200 per yard, all in one
InstancedMesh(a slightly cupped plane with a 4×2 canvas-painted leaf atlas, chosen with an instanced attribute). The simulation is plain TypeScript on the CPU. Each leaf is resting, moving, floating on the pond, or still in a tree. Resting leaves cost almost nothing until air or a foot reaches them. - Piles: leaves are binned into a 0.3 m grid that gives a smoothed height field. Leaves rest inside the pile volume (the buried ones are darker, a cheap kind of AO), steep edges slump, and a litter-textured height-field mesh follows the grid. I compute its normals straight from the grid, because
computeVertexNormalsevery few frames was showing up in the allocation profile. - The blower: a cone of air that is strongest at the nozzle and fades with distance. The same cone is sent to the grass shader as uniforms, so the blades bend away from the air.
- Grass: about 100k instanced blades with wind sway and blower bending in the vertex shader (
MeshLambertMaterial+onBeforeCompile). - Trees: recursive branches merged into one geometry per tree, plus crowns of alpha-tested leaf-cluster cards with fake outward normals. Leaves pile up thickest under trees, so the player is often under one. A crown that blocks the line of sight to the player fades with a 4×4 Bayer dither, and there is a small cutout around the character.
- Performance: the hot leaf loop has to stay allocation-free. Replacing
for...ofwith indexed loops and inlining the air test (non-inlined functions returning doubles were boxing them) cut the GC churn by about 5×. Static yard meshes are merged per material at load, which took a yard from about 500 to about 200 draw calls including the shadow pass. Quality drops automatically (DPR, MSAA, leaf count, grass density) if the frame rate falls. - Look:
Sky, a sky-based PMREM environment, one shadow-casting sun that follows the camera, andpostprocessing(bloom, ACES, vignette). Six weather presets: golden hour, morning, sunset, dusk with string lights, overcast and a rainstorm. - No assets: every texture (leaves, grass, bark, siding, shingles, brick, a woven tarp, flannel…) is painted on canvases at load. All the sound is Web Audio: a two-stroke engine for the blower, rustling leaves and a Karplus-Strong guitar tune. The whole game is about 230 KB gzipped.
Stack: three.js r186, TypeScript, Vite, postprocessing.
I’d love feedback, especially on how it runs on your phone and whether the leaves feel right!
