physically-based simulation on the gpu mark harrisnvidia developer technology
TRANSCRIPT
![Page 1: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/1.jpg)
Physically-Based Physically-Based Simulation on the GPUSimulation on the GPU
Mark Harris NVIDIA Developer Technology
![Page 2: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/2.jpg)
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
![Page 3: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/3.jpg)
Approximate MethodsApproximate Methods
• Several approximations for PDEs– Cellular Automata (CA)– Coupled Map Lattice (CML)– Lattice-Boltzmann Methods (LBM)
• I’ll talk briefly about CML
![Page 4: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/4.jpg)
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
![Page 5: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/5.jpg)
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
![Page 6: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/6.jpg)
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
![Page 7: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/7.jpg)
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
![Page 8: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/8.jpg)
Demo: “Disease”Demo: “Disease”
![Page 9: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/9.jpg)
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
![Page 10: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/10.jpg)
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
![Page 11: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/11.jpg)
Fluid Simulator DemoFluid Simulator Demo
![Page 12: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/12.jpg)
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)
![Page 13: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/13.jpg)
ThermodynamicsThermodynamics
• Temperature affected by– Heat sources– Advection– Latent heat released / absorbed during condensation /
evaporation
temperature = advection + latent heat release
+ temperature input
![Page 14: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/14.jpg)
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
![Page 15: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/15.jpg)
Cloud DynamicsCloud Dynamics
![Page 16: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/16.jpg)
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]
![Page 17: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/17.jpg)
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
![Page 18: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/18.jpg)
Flat 3D TexturesFlat 3D Textures
![Page 19: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/19.jpg)
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
![Page 20: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/20.jpg)
ConclusionConclusion
• GPUs are a capable, efficient, and flexible platform for physically-based visual simulation
• The possibilities are endless!
![Page 21: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/21.jpg)
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
![Page 22: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/22.jpg)
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.
![Page 23: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/23.jpg)
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
![Page 24: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/24.jpg)
Extra SlidesExtra Slides
![Page 25: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/25.jpg)
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
![Page 26: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/26.jpg)
Fluid Simulation DetailsFluid Simulation Details
![Page 27: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/27.jpg)
Divergence-Free?Divergence-Free?
• In any element of fluid, inward velocity is balanced by outward velocity– No sources or sinks
• Ensures mass / momentum conservation
![Page 28: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/28.jpg)
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)
![Page 29: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/29.jpg)
AlgorithmAlgorithm
• Break it down [Stam 2000]:
– Add forces: w1u(x,t) f (x,t)t
![Page 30: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/30.jpg)
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
![Page 31: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/31.jpg)
AlgorithmAlgorithm
• Break it down [Stam 2000]:
– Add forces:
– Advect:
w1u(x,t) f (x,t)t
w2w
1(x w
1t)
![Page 32: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/32.jpg)
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)
![Page 33: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/33.jpg)
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)
![Page 34: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/34.jpg)
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
![Page 35: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/35.jpg)
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)
![Page 36: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/36.jpg)
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
![Page 37: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/37.jpg)
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)
![Page 38: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/38.jpg)
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
![Page 39: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/39.jpg)
Fluid Simulator Demo (more)Fluid Simulator Demo (more)
![Page 40: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/40.jpg)
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
![Page 41: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/41.jpg)
Cloud DetailsCloud Details
![Page 42: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/42.jpg)
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
![Page 43: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/43.jpg)
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
![Page 44: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/44.jpg)
Vectorized SolversVectorized Solvers
• Pressure is scalar, texels are RGBA – Pack 4 pressure values in each texel– Process 4x fewer fragments each iteration
![Page 45: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/45.jpg)
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
![Page 46: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/46.jpg)
Simulation AmortizationSimulation Amortization
• Non-interactive application:– Simulate as fast as possible– Frame rate suffers
20ms
![Page 47: Physically-Based Simulation on the GPU Mark HarrisNVIDIA Developer Technology](https://reader036.vdocuments.site/reader036/viewer/2022062404/551b15b855034607418b5532/html5/thumbnails/47.jpg)
Simulation AmortizationSimulation Amortization
• Interactive frame rate!– Simulation still proceeds pretty fast
10 20ms