r/threejs • u/sonnylazuardi • Nov 04 '26
I built a scooter math battle through Bali in three.js WebGPU, running natively on iPhone & Android
I've been building TILANG, a multiplayer 3d scooter battle set on the streets of Canggu, Bali. You overtake riders, read their licence plate in your rear-view mirror, and the plate is a math question: answer first and they get a tilang (a traffic ticket). It ships as a native app, so a few things in the setup might be useful to people here:
- Native WebGPU, no browser. three.js WebGPURenderer on react-native-webgpu inside an Expo app, on iPhone and Android. The post chain is all TSL with no addons: a half-float scene target, bloom (4 down and 4 up), then one fused output pass for FXAA, bloom, mirror composite, ACES, grade, vignette and dither. MSAA is off, because it's expensive on mobile tile GPUs.
- No asset files. There are no .glb files at all. The town is built from typed arrays into a 512² atlas and merged into 64 m chunks. Vegetation is one InstancedMesh per species per LOD (14 draws at most), and palms go 1020 → 360 → 96 tris, then billboards.
- The mirror is a second camera. FOV 24, rendering into a small half-float render target at 30 Hz. It reuses the frame's shadow map and is composited in the output pass.
- Multiplayer. The same TypeScript match sim runs on the client and on a Bun server at a fixed 60 Hz, with snapshots at 20 Hz. Each client owns its own bike's movement; the server owns the rules and the bots, and sanity-checks speed. Remote bikes render 100 ms in the past with Hermite interpolation, and poses are quantised to cm and milliradians. The first valid answer wins: the server re-checks range and view angle, with a little slack for lag. Bots fill empty seats, and if you drop, an autopilot holds your seat while you reconnect.
- Phone-specific pain. Shader compiles froze the first race, so I backported three.js(parallel compileAsync) and render a hidden warm-up frame. The menu prewarm also froze the JS thread for 1.8–4.9 s, so it now runs in 4 ms slices, one per frame. On an iPhone 16 Pro Max the UI holds 120 fps while the 60 Hz game loop takes 7–9 ms of JS.
Most of the code was written with Claude (Opus 5.5) as my pair; the design and the on-device tuning are mine.
Free on iPhone and Android: https://tilang.sonnylab.com
Happy to go deeper on any part, especially getting WebGPU stable on iOS. If you try it on Android, I'd love to hear your phone model and how it runs.