The 3D version runs the same Muller (2003) SPH equations on particles free to move in x, y and z inside a cube, rendered with instanced spheres and an orbit camera. This 2D version is a genuinely separate simulation: particles carry only (x, y), every kernel below is the planar (2D-normalized) form of the same math, and the neighbour search is a 2D spatial hash instead of a 3D one โ so the constants, the density field and the resulting flow behaviour (how it pools on a floor, sloshes between two walls and splashes when dragged) are all different from a flattened 3D scene.
rho_i = sum_j W_poly6(r_ij, h), W_poly6 = 4/(pi h^8) * (h^2 - r^2)^3
p_i = k * (rho_i - rho_0)
a_i = (-grad p + mu * lap v) / rho_i + g
grad W_spiky = -30/(pi h^5) * (h - r)^2 * r_hat
lap W_visc = 40/(pi h^5) * (h - r)
- Density and forces are recomputed every substep from a 2D uniform grid hash of neighbours within radius h โ an O(N) build, O(Nยทk) force pass, same complexity class as the 3D version but on a 2D lattice.
- Dragging the mouse adds a real radial force to every particle inside the cursor's influence radius, on top of gravity, pressure and viscosity โ it is summed into the same acceleration used by the SPH integrator, not a separate cosmetic effect.
- Colour still encodes local pressure (blue โ cyan โ green โ red), so a shockwave from the Wave button or a drag is visible rippling through the liquid exactly as in the 3D tank.