Leaf Me Alone! – a leaf blower game with 7,200 simulated leaves (three.js, ~230 KB, mobile)

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_button: 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 computeVertexNormals every 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...of with 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, and postprocessing (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!

6 Likes

amazing. AAA

1 Like

Hey, This is actually Fun

1 Like

Thank you :heart:

Happy to hear that. Thank you :heart:

Computing the pile normals straight from the grid instead of calling computeVertexNormals every few frames is a nice catch, and darkening the buried leaves is a clever bit of fake AO for almost no cost. The note about non-inlined functions boxing doubles is going in my own notes too.

Curious about the waking side: when the blower cone sweeps across a resting area, do you test every resting leaf against the cone each frame, or do you use the 0.3 m pile grid to only wake leaves in cells the cone touches? With 7,200 leaves I’d guess the grid lookup is what keeps it cheap on phones, but I’d love to hear how you split it.

1 Like

Thanks! Honest answer: no grid. Every step, every leaf gets tested against each active blower cone. It stays cheap because:

  • The cone test is written inline over typed arrays, so there are no function calls and no boxing.
  • The first check is one dot product: “is this leaf behind the nozzle or past its reach?” That throws out most leaves right away.
  • A resting leaf only wakes when the air beats a friction threshold that grows with its pile’s height. That’s why piles peel off layer by layer.

The 0.3 m grid is only used for height lookups. The loop has to visit every resting leaf anyway to keep it on the pile surface, so culling by cell wouldn’t save the loop. It would just add bookkeeping. If I push the leaf count higher, I’ll try your idea next: mark the cells the cone touches and skip the force math elsewhere.

2 Likes

Makes sense. If the loop already touches every resting leaf to keep it on the pile, a grid would just be extra bookkeeping. The early dot-product reject plus friction that grows with pile height is a nice way to get that layer-by-layer peel. Thanks for explaining it.

1 Like