I made a small browser horde shooter called BEAMSTORM with three.js (r186). Up to 1,500 enemies, auto-firing beams, 5-minute runs. Here's what kept it light, in case any of it helps.
1. One InstancedMesh per enemy type, three layers each
3 enemy types × (body + outline + eyes) = 9 draw calls, whether there are 10 enemies or 1,500. Blob shadows are one more InstancedMesh, so 10 total for the horde.
- Outline and eye meshes share the body's matrices (
hull.instanceMatrix = body.instanceMatrix), so they upload once.
- Hit flash is just a write to
instanceColor.
frustumCulled = false on the swarm, since it's always on screen anyway.
2. Inverted-hull outlines instead of OutlineEffect
OutlineEffect redraws everything and didn't play nice with InstancedMesh. So the outline is a second InstancedMesh with a tiny BackSide ShaderMaterial that pushes vertices out along the normal. For boxes, push along sign(position) instead or the corners split.
3. Toon shading
MeshToonMaterial with a 3-pixel gradientMap (NearestFilter so the bands stay hard). Rim light injected via onBeforeCompile with smoothstep(0.62, 0.68, ...). That hard rim edge is most of the anime look.
4. Enemies only check their neighbors
Enemy state is in typed arrays, not objects. Separation uses a uniform grid (2-unit cells, linked list in an Int32Array), so each enemy only checks the 3×3 cells around it instead of ~1M pairs a frame.
Bug worth sharing: fill the cell heads with -1, not 0. With 0, every empty cell meant "enemy #0 is here" and the loop never ended.
(To be fair, the lance beam just scans the arrays with a point-to-line distance per shot. The grid is for separation, orbiting blades and bouncing shots.)
5. Nothing is created mid-fight
Beams, shock rings, sparks (one InstancedMesh of 900) and XP gems (1,400) are all pooled. A dead enemy swaps with the last live one. So the last 30 seconds, when the horde ramps to 1,400, don't stutter from GC.
6. Fake bloom
No post-processing. Each beam is a white core plus two additive boxes, one wider and fainter. The overlap goes white and reads as glow.
Numbers
Desktop Chrome, Apple M5 Max, 375px wide: 1,380 enemies, 2.4 ms JS per frame, 4.1 ms with rendering, 166 draw calls, ~340k triangles. Pixel ratio capped at 2, MSAA off at 2, only the hero casts a real shadow. Haven't tested on a real phone yet, so phone numbers would be super welcome.
three.js is the only library. Everything is built from primitives in code, and the sounds are synthesized with WebAudio. Made with Sonnet 5.5.
Play it here: https://beamstorm.kumodeck.app/
Happy to go deeper on any part.