Simulating Non-Newtonian Fluids in Video Games

Simulating non-Newtonian fluids such as cornstarch slurry (oobleck) in real-time game development requires balancing physical accuracy with rigid frame-rate constraints. Unlike standard fluids, these shear-thickening materials transition from liquid to solid states under stress, forcing developers to look beyond traditional Navier-Stokes implementations. Game engineers achieve this interactive behavior through specialized physics models like modified Smoothed Particle Hydrodynamics (SPH), Material Point Methods (MPM), and Position Based Dynamics (PBD), combined with dynamic viscosity functions executed entirely on GPU compute shaders.

Understanding the Target Physics

In traditional Newtonian fluids (like water), viscosity remains constant regardless of the shear stress applied. Cornstarch slurry is a dilatant, or shear-thickening fluid:

  • At low shear rates, particles suspended in the liquid remain separated by thin layers of fluid, allowing them to slide past one another smoothly.
  • Under rapid impact or high shear stress, the liquid layer is squeezed out, causing frictional particle-particle contact and temporary inter-particle jamming that acts like a solid.

Engineers must calculate local strain rates dynamically per frame to determine whether the fluid particles should flow, deform elastically, or resist displacement entirely.

Primary Simulation Frameworks

1. Smoothed Particle Hydrodynamics (SPH)

SPH is a Lagrangian (particle-based) method commonly used for fluid simulations in games. To handle shear-thickening behavior:

  • Constitutive Viscosity Models: Engineers apply non-Newtonian formulas like the Ostwald-de Waele power-law model or the Cross model. The kinematic viscosity (\(\nu\)) becomes a function of the local strain rate tensor (\(\dot{\gamma}\)).
  • Stress Tensors: High strain rates scale up artificial viscosity and bulk stiffness forces between neighboring particles, temporarily restricting relative velocity.

2. Material Point Method (MPM)

MPM has become the industry standard for complex phase-changing matter due to its ability to seamlessly handle elastoplasticity, fracture, and fluid flow:

  • Hybrid Approach: Particles store physical properties (mass, velocity, deformation gradient), while a background Eulerian grid computes gradients and solves momentum equations.
  • Yield Criteria: Engineers implement custom Drucker-Prager or friction-based yield surfaces. When the shear stress exceeds a threshold, the material transitions from a Navier-Stokes fluid solve to an elastoplastic solid solve.

3. Position Based Dynamics (PBD) and XPBD

For games where performance and unconditional numerical stability outweigh absolute physical accuracy, Position Based Dynamics is preferred:

  • Instead of integrating forces and velocities, PBD directly projects geometric position constraints.
  • Shear-thickening is simulated by modulating distance and shape-matching constraints based on collision velocity. Fast impacts trigger rigid shape-matching constraints to prevent penetration, while slow interactions loosen constraints to permit standard fluid relaxation.

Real-Time Optimization Techniques

Interactive games must maintain a minimum of 60 frames per second, leaving only a few milliseconds for physics updates. Engineers employ several optimization pipelines:

  • GPU Compute Shaders: Modern implementations offload neighbor searches and integration steps directly to the GPU. Spatial hashing algorithms partition particles into uniform grids, enabling parallel processing across thousands of GPU threads.
  • Decoupled Physics and Rendering: The simulation typically runs on a coarse resolution of tens of thousands of particles. For visual output, engineers use screen-space fluid rendering (SSFR) or marching cubes algorithms, applying blur filters and normal smoothing on the depth buffer to make the coarse particle simulation appear as a smooth, continuous surface.
  • Dynamic Substepping: When high-velocity impacts occur, the physics engine triggers adaptive substepping—running multiple micro-steps within a single frame for the affected region to prevent explosive instability without degrading global performance.