Sand-racer: real-time sand simulation & terramechanics in WebGPU (three.js r187 + TSL)

Hi everyone! I’ve been building a driving game on living sand – a real-time sand simulation with a physically based truck, all in the browser on three.js’ WebGPURenderer. Built from scratch: custom sand sim, vehicle physics & shaders – no game or physics engine.

What’s simulated

  • A 512 × 512 m sand field at 1 m, with a nested 25 cm field around the vehicle, stepped at 60 Hz
  • Granular behaviour: two angles of repose (34° static, 31° dynamic), a rolling layer after Pouliquen’s flow rule, slip faces that avalanche as grainflow tongues
  • Tyre–sand contact after Bekker–Wong (sinkage) and Mason (traction), on a 240 Hz multibody pickup
  • Two-way coupling: the truck drives on the sand it moved – the sand’s deviation is read back around the vehicle
  • Mass bookkeeping: every litre the tyres displace lands somewhere (books close to ~1 L)
  • Endless procedural dunes up to 36 m, checked against lidar, drawn to the horizon

How it’s built with three.js

  • WebGPURenderer + TSL throughout; the sand step runs as fragment passes on ping-pong render targets
  • Zero sand textures – ripples, grain glints, crust and tracks all come from the simulation state
  • TSL tip: use Loop instead of JS loops – unrolled kernels cost us seconds of compile time
  • One build for desktop and mobile

Video: X post

Demo coming soon – happy to answer questions!

ezgif-instagif (1)

1 Like