# Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology.

## Presentation on theme: "Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology."— Presentation transcript:

Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology

Simulating the world Simulate a wide variety of phenomena on GPUs –Anything we can describe with discrete PDEs or approximations of PDEs –I will talk about boiling, reaction-diffusion, fluids, and clouds

Approximate Methods Several approximations for PDEs –Cellular Automata (CA) –Coupled Map Lattice (CML) –Lattice-Boltzmann Methods (LBM) I’ll talk briefly about CML

Coupled Map Lattice Mapping: –Continuous state  lattice nodes Coupling: –Nodes interact with each other to produce new state according to specified rules Extension of CA: –Continuous state at cells instead of discrete

Example: Boiling State = Temperature Three operations: –Diffusion, buoyancy, & latent heat Based on [Yanagita 1992] 3D Simulation –Stack of 2D texture slices –Sample from neighboring slices DEMO

PDE Simulations Floating-point GPUs open up new possibilities –Less Ad Hoc methods: real PDEs –Must be able to discretize in space and time I’ll discuss three examples: –Reaction-Diffusion –Fluid Dynamics –Cloud Dynamics

Reaction-Diffusion Gray-Scott reaction-diffusion model [Pearson 1993] State = two scalar chemical concentrations Simple: just Diffusion and Reaction ops U, V are chemical concentrations, F, k, D u, D v are constants

Demo: “Disease”

Fluid Dynamics Solution of Navier-Stokes flow eqs. –Stable for arbitrary time steps Means you can run it fast! –[Stam 1999], [Fedkiw et al. 2001] Can be implemented on latest GPUs –Quite a bit more complex than R-D or boiling See “Fast Fluid Dynamics Simulation on the GPU” –Harris, GPU Gems, 2004

Navier-Stokes Equations Describe flow of an incompressible fluid Advection Pressure Gradient Diffusion (viscosity) External Force Velocity is divergence-free

Fluid Simulator Demo

Cloud Dynamics Overview 3 components –7 unknowns Fluid dynamics –Motion of the air Thermodynamics –Temperature changes Water continuity –Evaporation, condensation Water vapor mixing ratio: q v Liquid water mixing ratio: q c Velocity: Pressure: p Potential temperature:  (see dissertation)

Thermodynamics Temperature affected by –Heat sources –Advection –Latent heat released / absorbed during condensation / evaporation  temperature = advection + latent heat release + temperature input

Water Continuity Water is conserved –Condensation balances Evaporation –  H2O vapor = -  H2O liquid –  = Phase changes + advection Liquid water is what is rendered –Convert water field to a “density” texture

Cloud Dynamics

Simulation Algorithm Advect quantities q, q v, q c and u –Similar to [Stam, 1999] Compute and apply accelerations –Buoyancy Compute condensation, evaporation, and temperature changes Enforce momentum conservation –Otherwise velocity dissipates, loses “swirls” –Projection step of “Stable Fluids” [Stam, 1999]

Simulation Algorithm Most steps are simple –Most use one fragment program, one pass –Programs come directly from equations Tricky parts: –Staggered grid discretization See dissertation (harris, 2003) –Stable Fluids projection step Vectorized solver (see earlier talks) –Boundary conditions (Static Branch Resolution – earlier talks) –3D Simulation

Flat 3D Textures

Advantages –One texture update per operation –Better use of GPU parallelism –Non-power-of-two Textures –Quick simulation preview Disadvantage –Must compute texture offsets

Conclusion GPUs are a capable, efficient, and flexible platform for physically-based visual simulation The possibilities are endless!

Acknowledgements Fellow UNC Students –Bill Baxter, Greg Coombe, Thorsten Scheuermann Anselmo Lastra and other UNC Faculty Sponsors: –NVIDIA Corporation –US National Institutes of Health –US Office of Naval Research –US Department of Energy ASCI program –US National Science Foundation

Selected References Chorin, A.J., Marsden, J.E. A Mathematical Introduction to Fluid Mechanics. 3rd ed. Springer. New York, 1993 Fedkiw, R., Stam, J. and Jensen, H.W. Visual Simulation of Smoke. In Proceedings of SIGGRAPH 2001, ACM Press / ACM SIGGRAPH. 2001. Harris, M., Coombe, G., Scheuermann, T., and Lastra, A. Physically-Based Visual Simulation on Graphics Hardware.. Proc. 2002 SIGGRAPH / Eurographics Workshop on Graphics Hardware 2002. Harris, Baxter, Scheuermann, Lastra. Simulation of Cloud Dynamics on Graphics Hardware. Proc. Graphics Hardware 2003. Harris, M. Real-Time Cloud Simulation and Rendering. Ph.D. Dissertation. http://www.markmark.net/dissertation Kaneko, K. (ed.), Theory and applications of coupled map lattices. Wiley, 1993. Nishimori, H. and Ouchi, N. Formation of Ripple Patterns and Dunes by Wind-Blown Sand. Physical Review Letters, 71 1. 197-200. 1993. Pearson, J.E. Complex Patterns in a Simple System. Science, 261. 189-192. 1993. Stam, J. Stable Fluids. In Proceedings of SIGGRAPH 1999, ACM Press / ACM SIGGRAPH, 121-128. 1999. Turk, G. Generating Textures on Arbitrary Surfaces Using Reaction-Diffusion. In Proceedings of SIGGRAPH 1991, ACM Press / ACM SIGGRAPH, 289-298. 1991. Witkin, A. and Kass, M. Reaction-Diffusion Textures. In Proceedings of SIGGRAPH 1991, ACM Press / ACM SIGGRAPH, 299-308. 1991.

More References Gomez, M. Interactive Simulation of Water Surfaces. in Game Programming Gems. Charles River Media, 2000. p 187. Lengyel, E. Mathematics for 3D Game Programming & Computer Graphics. Charles River Media, 2002. Chapter 12, p 327. James, G. Operations for Hardware-Accelerated Procedural Texture Animation. in Game Programming Gems II. Charles River Media, 2001. p 497. Strzodka, R. Virtual 16 Bit Precise Operations on RGBA8 Textures. Proceedings VMV 2002, 2002 Strzodka, R., Rumpf, M. Using Graphics Cards for Quantized FEM Computations. In Proceedings VIIP 2001, 2001. Yanagita, T. Phenomenology of boiling: A coupled map lattice model. Chaos, 2 3. 343-350. 1992. Yanagita, T. and Kaneko, K. Coupled map lattice model for convection. Physics Letters A, 175. 415-420. 1993. Yanagita, T. and Kaneko, K. Modeling and Characterization of Cloud Dynamics. Physical Review Letters, 78 22. 4297-4300. 1997

Extra Slides

3D simulation Lattice is now 3D –3D texture or stack of 2D textures –Or tile slices onto a large 2D texture Neighbor sampling is 3D –Texels in nearby slices –If it’s a 3D texture, just perturb the r texture coordinate to get slice neighbors –Otherwise bind neighbor slice textures

Fluid Simulation Details

Divergence-Free? In any element of fluid, inward velocity is balanced by outward velocity –No sources or sinks Ensures mass / momentum conservation

Algorithm Break it down [Stam 2000]: –Add forces: –Advect: –Diffuse: –Solve for pressure: –Subtract pressure gradient:

Algorithm Break it down [Stam 2000]: –Add forces:

Add Forces Scale force by time step, add to velocity In demo, we just “splat” –Color of splat encodes direction and strength of force (determined by mouse motion) –Simple fragment program adds gaussian splat to velocity texture

Algorithm Break it down [Stam 2000]: –Add forces: –Advect:

Advection Advection: quantities in a fluid are carried along by its velocity Want velocity at position x at new time t +  t Follow velocity field back in time from x : (x - w1  t) –Like tracing particles! –Simple in a fragment program u(x, t+  t) u(x’, t) Path of fluid Trace back in time

Algorithm Break it down [Stam 2000]: –Add forces: –Advect: –Diffuse:

Viscous Diffusion Viscous fluid exerts drag on itself –Causes diffusion of velocity Implicit, discrete form of –Explicit form is unstable Solution is just like the next step –Simpler to explain the next step…

Algorithm Break it down [Stam 2000]: –Add forces: –Advect: –Diffuse: –Solve for pressure:

Poisson-Pressure Solution Poisson Equation –Discretize, solve using iterative solver (relaxation) –Jacobi, Gauss-Seidel, Multigrid, etc. Jacobi easy on GPU, the rest are trickier Demo uses Jacobi iteration (15-20 iters.) –Boils down to repeated evaluation of:  = grid spacing u, v = components of w 3 i, j = grid coordinates n = solution iteration

Algorithm Break it down [Stam 2000]: –Add forces: –Advect: –Diffuse: –Solve for pressure: –Subtract pressure gradient:

Subtract Pressure Gradient Last computation of the time step –u is now a divergence-free velocity field Very simple fragment program  = grid spacing i, j = grid coordinates u, v = components of u u3,v3 = components of w 3 p = pressure

Fluid Simulator Demo (more)

Boundary Conditions Various types of BCs –No-slip, free-slip, outflow, inflow, periodic, etc. Demo uses “no-slip” velocity BCs –V = 0 at boundaries. Pressure: pure Neumann BCs –Have to set them each iteration of solver –p (boundary) = p (nearest non-boundary neighbor)

Cloud Details

Fluid Dynamics Incompressible Euler equations Same as previous fluid simulation –Viscosity = 0 Buoyancy term –Temperature, pressure, water changes induce motion

Projection Step Enforces divergence-free velocity –Iterative solution of Poisson-pressure eq. Poisson solver options –Conjugate Gradient –Multigrid –Fast Fourier Transform –Jacobi, Red-Black Gauss Seidel

Vectorized Solvers Pressure is scalar, texels are RGBA –Pack 4 pressure values in each texel –Process 4x fewer fragments each iteration

Simulation Amortization Simulation takes ~200 ms per step –64x64x64 volume, GeForce FX 5900 Ultra But simulation time step represents 3s of actual time –On the order of visual change in real clouds –So, faster than real time, but low frame rate

Simulation Amortization Non-interactive application: –Simulate as fast as possible –Frame rate suffers 20ms

Simulation Amortization Interactive frame rate! –Simulation still proceeds pretty fast 10 20ms

Similar presentations