physically-based simulation on the gpu mark harrisnvidia developer technology
TRANSCRIPT
Physically-Based Physically-Based Simulation on the GPUSimulation on the GPU
Mark Harris NVIDIA Developer Technology
Simulating the worldSimulating 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 MethodsApproximate Methods
• Several approximations for PDEs– Cellular Automata (CA)– Coupled Map Lattice (CML)– Lattice-Boltzmann Methods (LBM)
• I’ll talk briefly about CML
Coupled Map LatticeCoupled 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: BoilingExample: 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 SimulationsPDE 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-DiffusionReaction-Diffusion
• Gray-Scott reaction-diffusion model [Pearson 1993]
• State = two scalar chemical concentrations
• Simple: just Diffusion and Reaction ops
U
tD
u2U UV 2 F(1 U ),
V
tD
v2V UV 2 (F k)V
U, V are chemical concentrations, F, k, Du, Dv are constants
Demo: “Disease”Demo: “Disease”
Fluid DynamicsFluid 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 EquationsNavier-Stokes Equations
• Describe flow of an incompressible fluid
u
t (u)u
1
p 2u f
Advection PressureGradient
Diffusion (viscosity)
External Force
u 0 Velocity is divergence-free
Fluid Simulator DemoFluid Simulator Demo
Cloud Dynamics OverviewCloud Dynamics Overview
• 3 components
– 7 unknowns
• Fluid dynamics
– Motion of the air
• Thermodynamics
– Temperature changes
• Water continuity
– Evaporation, condensation
Water vapor mixing ratio: qv
Liquid water mixing ratio: qc
Velocity:
Pressure: p u (u,v,w)
Potential temperature: (see dissertation)
ThermodynamicsThermodynamics
• Temperature affected by– Heat sources– Advection– Latent heat released / absorbed during condensation /
evaporation
temperature = advection + latent heat release
+ temperature input
Water ContinuityWater 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 DynamicsCloud Dynamics
Simulation AlgorithmSimulation Algorithm
• Advect quantities q, qv, qc 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 AlgorithmSimulation 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 TexturesFlat 3D Textures
Flat 3D TexturesFlat 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
ConclusionConclusion
• GPUs are a capable, efficient, and flexible platform for physically-based visual simulation
• The possibilities are endless!
AcknowledgementsAcknowledgements
• 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 ReferencesSelected 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 ReferencesMore 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 SlidesExtra Slides
3D simulation3D 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 DetailsFluid Simulation Details
Divergence-Free?Divergence-Free?
• In any element of fluid, inward velocity is balanced by outward velocity– No sources or sinks
• Ensures mass / momentum conservation
AlgorithmAlgorithm
• Break it down [Stam 2000]:
– Add forces:
– Advect:
– Diffuse:
– Solve for pressure:
– Subtract pressuregradient:
w1u(x,t) f (x,t)t
2 p w
3
u(x,t t) w3 p
I t2 w3
w2
w2w
1(x w
1t)
AlgorithmAlgorithm
• Break it down [Stam 2000]:
– Add forces: w1u(x,t) f (x,t)t
Add ForcesAdd 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
w1u(x,t) f (x,t)t
AlgorithmAlgorithm
• Break it down [Stam 2000]:
– Add forces:
– Advect:
w1u(x,t) f (x,t)t
w2w
1(x w
1t)
AdvectionAdvection
• 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 - w1t)
– Like tracing particles!– Simple in a fragment program
u(x, t+t)
u(x’, t)
Path of fluid
Trace back in time
w2(x) w
1(x w
1t)
AlgorithmAlgorithm
• Break it down [Stam 2000]:
– Add forces:
– Advect:
– Diffuse:
w1u(x,t) f (x,t)t
I t2 w3
w2
w2w
1(x w
1t)
Viscous DiffusionViscous 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…
I t2 w3
w2
w2
t2w
2
AlgorithmAlgorithm
• Break it down [Stam 2000]:
– Add forces:
– Advect:
– Diffuse:
– Solve for pressure:
w1u(x,t) f (x,t)t
2 p w
3
I t2 w3
w2
w2w
1(x w
1t)
Poisson-Pressure SolutionPoisson-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:
2 p w
3
pi, jn1
1
4p
i1, jn p
i 1, jn p
i, j1n p
i, j 1n 2(w
3) ,
w3
1
2(u3
i1, j u3
i 1, j v3
i, j1 v3
i, j 1) = grid spacing
u, v = components of w3
i, j = grid coordinatesn = solution iteration
AlgorithmAlgorithm
• Break it down [Stam 2000]:
– Add forces:
– Advect:
– Diffuse:
– Solve for pressure:
– Subtract pressure gradient:
w1u(x,t) f (x,t)t
2 p w
3
u(x,t t) w3 p
I t2 w3
w2
w2w
1(x w
1t)
Subtract Pressure GradientSubtract Pressure Gradient
• Last computation of the time step– u is now a divergence-free velocity field
• Very simple fragment program
u(x,t t) w3 p
ui, j
u3i, j
1
2 p
i1, j p
i 1, j ,v
i, jv3
i, j
1
2 p
i, j1 p
i, j 1 = grid spacingi, j = grid coordinatesu, v = components of uu3,v3= components of w3
p = pressure
Fluid Simulator Demo (more)Fluid Simulator Demo (more)
Boundary ConditionsBoundary 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)
p
n0
Cloud DetailsCloud Details
Fluid DynamicsFluid Dynamics
• Incompressible Euler equations
• Same as previous fluid simulation– Viscosity = 0
• Buoyancy term– Temperature, pressure, water changes induce motion
u
t (u)u
1
p B ök f
u 0
Projection StepProjection 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 SolversVectorized Solvers
• Pressure is scalar, texels are RGBA – Pack 4 pressure values in each texel– Process 4x fewer fragments each iteration
Simulation AmortizationSimulation 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 AmortizationSimulation Amortization
• Non-interactive application:– Simulate as fast as possible– Frame rate suffers
20ms
Simulation AmortizationSimulation Amortization
• Interactive frame rate!– Simulation still proceeds pretty fast
10 20ms