General Purpose GPU computing (GPGPU) uses the massively parallel architecture of graphics processing units—originally designed to render millions of pixels simultaneously—for scientific and engineering simulations. A modern GPU contains thousands of simple shader cores that execute the same instruction on different data in parallel (SIMD: Single Instruction, Multiple Data), making it ideal for simulations where many identical independent calculations are performed, such as updating thousands of particles under the same physical laws simultaneously.
Traditional CPU simulation of N particles requires O(N²) force calculations per timestep for direct all-pairs interactions, limiting practical N to thousands. GPUs accelerate this by computing all pair forces in parallel blocks, achieving 100–1000× speedup for particle simulations. WebGL compute shaders and WebGPU allow this parallelism in-browser: particle positions and velocities are stored in GPU textures, and a single shader pass updates all particles simultaneously without CPU-GPU data transfer bottlenecks. Applications include fluid dynamics (SPH), molecular dynamics, crowd simulation, and real-time visual effects.
This simulator runs thousands to millions of particles simultaneously on your GPU, with each particle experiencing gravity, inter-particle forces, or flow-field steering computed entirely on GPU. You can observe the quadratic vs. linear scaling as N increases, toggle different interaction models, and see how GPU parallelism makes interactive simulation of complex systems feasible in a web browser—demonstrating the architecture underlying modern scientific computing, machine learning, and game physics engines.
Why are GPUs so much faster than CPUs for particle simulations?
CPUs are optimized for low-latency sequential computation: a modern CPU has 8–32 cores, each capable of executing complex instruction sequences with branch prediction, out-of-order execution, and large caches. GPUs have thousands of simpler cores optimized for high-throughput parallel computation, sacrificing individual core speed for massive parallelism. A particle simulation updates each particle independently (same equations, different data), which maps perfectly onto GPU parallelism—all particles update simultaneously. For N=1,000,000 particles, a GPU computing 10,000 particles per clock cycle needs 100 passes; a CPU doing them sequentially needs 1,000,000 passes.
How does a compute shader work?
A compute shader is a GPU program that runs N independent instances (work items) simultaneously, each identified by a unique index. For particle simulation, the compute shader is dispatched with N work items—one per particle. Each work item reads the particle's current position and velocity from a GPU buffer (stored in GPU VRAM), computes forces from neighboring particles or fields, updates velocity and position using an integration scheme (e.g., Verlet or Euler), and writes the result back to the buffer. In the next animation frame, the rendering shader reads these updated positions to draw the particles, while the compute shader is already computing the next timestep.
What is the difference between WebGL and WebGPU for particle simulation?
WebGL (based on OpenGL ES 2.0/3.0) was designed for rendering and adapts graphics pipeline stages for GPGPU—storing particle data in textures and using fragment shaders to process them. This is somewhat indirect and has limitations (no explicit compute stage, limited memory access patterns). WebGPU is a newer API (available in Chrome/Firefox since 2023) with native compute shader support, more flexible memory access, better debugging tools, and closer alignment with modern GPU capabilities (like Vulkan and Metal). WebGPU enables more efficient GPGPU workloads in-browser, achieving performance closer to native applications.
Direct all-pairs force computation scales as O(N²)—infeasible for large N even on GPU. Spatial acceleration structures reduce this: uniform grids assign particles to grid cells, so each particle only interacts with particles in neighboring cells (O(N) total interactions for short-range forces). GPU-optimized grids use parallel radix sort to sort particles by cell index into a compact array, then use a cell index buffer to quickly find which particles occupy each cell. This reduces the simulation to O(N log N) for sorting and O(N·k) for force computation (where k is the typical number of neighbors), enabling simulations of millions of particles in real time.
GPU particle simulations are essential across science: molecular dynamics simulations of protein folding use GPUs to simulate millions of atoms with pairwise Lennard-Jones and electrostatic forces, enabling microsecond-timescale biomolecular dynamics (AMBER, NAMD, GROMACS). Smoothed Particle Hydrodynamics (SPH) simulates fluid flow on GPUs for visual effects in films and games. N-body astrophysical simulations model galaxy formation and dark matter clustering. Weather and climate models use GPU-accelerated particle transport for aerosol and chemical species. Machine learning training is itself a massive GPU-accelerated matrix (particle-like) parallel computation.