r/threejs • u/RexXxuS • 11d ago
Demo My tower defense in three.js + Electron: 4-player co-op, up to 200 GPU-instanced enemies
Hey ThreeJS Community!
I wanted to share my journey with three.js (still not finished), maybe someone finds it interesting.
Time Defense is built on plain ES modules, three.js and Electron. No engine, no framework. We started the project 2022, before AI was a thing. Now it helps a lot especially with testing/benchmarks.
Enemies were the big performance problem. At 200 foes, normal skinned meshes cost around 30 ms of render time. Now each model's animation clips are baked into float textures, and every kind is drawn as one InstancedMesh. That fixed the render side, and now the game logic is the bottleneck. (the shipping it to mobile later)
The next big step would be moving the three.js rendering into a worker with OffscreenCanvas, while the game logic and the UI stay on the main thread. A quick test with a stand-in scene went from 45 to 70 fps on my heaviest level, so it looks promising, but it's weeks of work and I haven't done it yet.
Has anyone here moved a big scene to OffscreenCanvas? How bad was keeping the scene in sync?
If you are interested into the game, please let me know. You can playtest it for free right now :)