Galaxy simulation
Real-time N-body galaxy simulation in the browser. Pure WebGPU. Physics and rendering share GPU buffers, and particle state never touches the CPU during the frame loop.
A real-time N-body galaxy simulation that runs entirely in the browser on WebGPU. Physics and rendering share the same GPU buffers, so particle state never round-trips to the CPU during the frame loop. Requires a WebGPU browser (Chrome 113+, Safari 26+).
Gravity is a Barnes-Hut octree, O(N log N), with Morton-sorted particles and bucketed leaves. The tree topology rebuilds asynchronously in a Web Worker while node masses re-sum on the GPU every step, so forces always follow the live state. Dark matter is an analytic Hernquist halo per galaxy, centred on a smoothed track of each galaxy’s central black hole, so colliding galaxies carry their halos and merge properly.
Initial conditions are built for equilibrium: an exponential disk with a sech² vertical profile and a Hernquist bulge, circular velocities from the measured enclosed mass, and velocity dispersion set by Toomre Q with asymmetric drift. About 30% of the disk is gas that cools, settles thin, and converts to new stars where it gets dense; massive stars supernova and hand their mass back to the gas. Stellar evolution is stateless, derived in the render shader from mass and birth time: Kroupa IMF masses, blackbody colours, main sequence to red giant to supernova or white dwarf.
Click any star to select it and keep zooming in. Below a threshold the view crossfades into that star’s procedurally generated solar system: planets, moons, rings, an asteroid belt, deterministic per star and rendered as ray-traced impostor spheres at AU scale, with the live galaxy behind it. Esc or zoom back out returns to the whole galaxy.
Rendering is an HDR (rgba16float) pipeline: instanced sprites vertex-pulled from the physics buffer, dust extinction, H-II emission around hot O stars, a procedural starfield, mip-chain bloom, and AgX tone mapping. The HUD shows fps, N, and total-energy drift.