SPH Fluid Boundary Collisions in Game Development

Smoothed-Particle Hydrodynamics (SPH) is a particle-based Lagrangian method widely used in video games to simulate dynamic liquids like water splashes, mud, and breaking waves. Handling collisions between free-surface fluid particles and solid boundaries requires balancing visual plausibility, physical stability, and strict frame-rate budgets. In game development, developers primarily resolve these boundary interactions using repulsive penalty forces, Signed Distance Fields (SDFs), and boundary or ghost particles to prevent fluid leaks while maintaining natural fluid behavior.

The Boundary Challenge in SPH

In standard SPH, fluid properties like density and pressure are calculated by interpolating values from neighboring particles within a specific support radius. Near solid boundaries, this interpolation breaks down because a boundary truncates the kernel sphere, leaving particles with fewer neighbors. This phenomenon, known as kernel deficiency, artificially drops the calculated density, causing fluid particles to stick unnaturally to surfaces or erroneously compress against walls. Resolving boundary collisions requires not only preventing physical penetration but also compensating for this missing neighbor mass.

1. Penalty and Repulsive Forces

The most computationally inexpensive method used in real-time games is the penalty-based approach. When an SPH particle penetrates an obstacle or crosses within a small threshold distance, the physics engine applies an immediate repulsive force directed along the collision normal.

  • Lennard-Jones style potentials: Use a molecular-inspired force curve that gently pushes particles away at a defined distance and increases exponentially as the particle nears the surface.
  • Spring-damper models: Apply Hooke’s law paired with a damping coefficient to push particles back to the surface while absorbing excessive kinetic energy, preventing unnatural bouncing.
  • Friction and restitution: Tangential velocities are dampened to simulate surface roughness (no-slip or free-slip conditions), while normal velocities are clamped or inverted according to a restitution coefficient.

2. Signed Distance Fields (SDFs)

Signed Distance Fields are the industry standard for modern real-time fluid boundaries, particularly for complex static geometry and GPU-accelerated simulations. An SDF stores the shortest distance to a mesh surface in a 3D grid, where negative values represent the interior of the solid, zero represents the boundary, and positive values represent open space.

  • Fast lookups: SPH particles query the SDF texture to instantly retrieve their distance to the nearest wall and the surface normal (the gradient of the field).
  • Continuous collision response: If a particle enters a negative region, the solver projects it directly back to the zero-surface along the normal vector, eliminating collision tunneling even at high velocities.
  • GPU compatibility: SDF lookups are massively parallel operations, fitting naturally into compute-shader-driven fluid pipelines in engines like Unreal Engine and Unity.

3. Boundary and Ghost Particles

To solve the kernel truncation problem rather than just pushing particles away, developers use boundary-particle methods.

  • Static boundary particles: Solid objects are sampled with fixed, non-moving particles. When a fluid particle approaches the wall, the boundary particles contribute to its density computation, generating realistic pressure that naturally pushes the fluid away according to standard fluid equations.
  • Ghost (mirror) particles: When a fluid particle approaches a planar surface, a virtual "ghost" particle is mirrored across the boundary plane with identical density and inverted normal velocity. This completes the kernel support radius dynamically without pre-allocating millions of static boundary particles.

Performance and Stability Optimizations

Game physics engines must prevent particles from tunneling through thin walls while keeping time steps large enough to maintain 60 or 120 frames per second. Game developers frequently use Position Based Fluids (PBF), an SPH variant that resolves density constraints and boundary collisions geometrically rather than via force integration. PBF ensures unconditional stability, allowing developers to enforce boundary limits as hard positional constraints in each solver iteration. Combined with sub-stepping and velocity clamping, this guarantees leak-free boundaries suitable for interactive gameplay.