NVIDIA Interacting with Particle Simulation in Maya using CUDA & Maximus Wil Braithwaite NVIDIA Applied Engineering Digital Film
Some particle milestones FX Rendering Physics 1982 - First CG particle FX in StarTrek 2. 2008 - Disney use GPUs to efficiently render particles as sprites. 2009 - ILM use GPU particles for fast rigid-body dynamics in Transformers 2. Images: Star Trek 2 The Wrath of Khan Bolt, Walt Disney Pictures Transformers 2, Paramount Pictures
What are particles? Discrete points with mass, moving in space. Movement is defined by forces and constraints. They have limited state: e.g. Force modifies velocity, and velocity modifies position. Not constrained by a grid: Computation and storage are only used where needed. f p Position Velocity Colour Etc. u u i+1 = u i + f p i+1 = p i + u i+1
Maya classic particles It has support for: Emitters: Omni, Volume, Surface, etc. Surfaces can emit attributes. Collision geometry. Force-fields: Uniform, Radial, Vortex, etc. Particle expressions.
Maya nparticles Nucleus nparticles, ncloth, etc. Allows integration of different kinds of materials (e.g. cloth, fluid) by using a singular physics representation. You can use Maya Fields to influence the behavior of Nucleus objects. nparticle objects use the same emitter objects that are used with Maya classic particles. - Autodesk
Movie nparticles vs. NVIDIA Particles
Motivation for GPU particles Particles are simple and elegant. Easy to implement. They are used extensively in VFX and games. They form the basis of many other complex effects. Highly scalable. Very GPU friendly!...
The GPU in 1½ slides Huge cache Lots of cores multi-core CPU (4 cores) many-core GPU (448 cores) Not representative of scale
Latency-hiding vs. Throughput Cores WAIT stall GO The CPU hides latency by optimizing memory accesses. C M C M C M C M C M C M WAIT GO C M C M C M C M C M C M The GPU hides latency by quickly switching between compute threads. M C Time = Stall = Memory access time = Computation time
Implementation goals Integrate with existing Maya workflow. Be more interactive than current Maya tools. We don t want to slow down the Maya user-experience. Write clean code as we might release it.
Movie CUDA-Accelerated particles
The life-cycle of particles Potentially kill particles.
Particle sort P bid, P pid 10,0 10,2 12,1 16,3 0 1 2 3 B i 0 2 3 0 10 11 12 16 P bid, P pid 10,0 12,1 10,2 16,3 0 1 2 3 P data 0 2 1 3 0 1 2 3
Particle death If particle expires, set death flag. Bucket assignment will put it in deadpool (numbuckets+1 = 25) Sorting will put all dead particles in a contiguous block. P bid, P pid 10,0 10,2 17,3 25,1 0 1 2 3 P data 0 2 3 B i 0 2 3 0 10 11 17 25 0 1 2 3 numparticles
Particle emission Upload emitted data using numparticles. E data 0 2 3 numparticles count += numemitted P data 0 2 3 0 1 2 3 4 5 We use fast host-to-device transfer for a small block of emission data. i.e. page-locked & write-combined host memory.
Collisions - Primitives Geometric primitives. Unitized for faster math. Can be transformed by matrix. Interior or exterior. Collision event types bounce, die, etc.
Collisions Collision response N 2 u N 4 3 P r u P r d d 1 1. Transform particle (P) into unit-space and calculate penetration (d) 2. Determine normal (N) 3. Move particle out of collider (along normal) 4. Update velocity based on collider s friction and restitution coefficients
Collisions image maps Allows more complex objects. Effectively a 2-level BVH. xnormal for map creation. Note artifacts Normals Displacement
Fluid dynamics (in one slide) More interesting than boring particles. Works well on GPUs; it has many data elements. Existing techniques: Eulerian (grid-based) Lagrangian (particle-based) Heightfield (2D / 2.5D grid) Smoothed Particle Hydrodynamics (SPH) water pressure + incompressibility + viscosity + external forces
The life-cycle of particles (with SPH)
Particle SPH pressure
Movie Digital Elevation Model collision
Rendering particles as a fluid Polygonize density field e.g. Marching cubes, etc. Screen-space rendering
Rendering particles Screen-space
Getting data back to Maya We might want to use the particle data inside Maya. Modern NVIDIA GPUs can overlap compute with copy. Quadro and Tesla both have dual-copy engines. We can remove the cost of the data transfer if we allow some latency
Overlapped transfer Frame [f] H - Acquire emission [f] D1 - Upload emission [f-1] DC - Insert emission [f-2] DC - Simulate [f-2] DC - Generate Mesh [f-2] D2 - Download mesh [f-3] Dual-copy engines H - Access mesh [f-4]
NVIDIA Maximus Quadro AND Tesla with 6GB & 448 cores. Benefits of Maximus DCC apps like Maya already use many GPU resources. Share the data between two cards allowing for larger simulations. Multi-GPU is scalability for the future.
Multi-GPU sharing the compute GPU[0] GPU[1] Partition plane Cross-over to other side We already have the framework for this: If particle is beyond partition then kill it and emit on other device. If within threshold then emit as a ghost (i.e. it lives for only one update). Ghost on other side Threshold
Known issues Floating particles Not enough SPH kernel support. Simulation values must be chosen carefully. Only a subset of Maya s force-fields are supported: Reverse engineering is not sufficient. Handling solid boundaries in SPH is an active area of research.
Future enhancements More simulation algorithms: Flocking birds, schooling fish, rigid-bodies More rendering styles: Smoke, Sprites, Instanced geometry Better fluid rendering by using anisotropic kernels. Scriptable events using a virtual-machine. Maya Viewport 2.0 integration.
Conclusions Building CUDA-accelerated particles in Maya is easy. Leverages some of Maya s existing framework. Using techniques like overlapping and multi-gpu can provide even more performance. By using Maximus and simulating on the Tesla card, Maya is still interactive.
Acknowledgments Robert Bridson: Fluid Simulation for Computer Graphics, A K Peters, 2008 Wladimir J Van Der Laan, Simon Green, Miguel Sainz: Screen space fluid rendering with curvature flow - Proceedings of the 2009 symposium on Interactive 3D graphics and games Markus Becker, Matthias Teschner: Weakly compressible SPH for free surface flows Eurographics / ACM SIGGRAPH Symposium on Computer Animation, 2007
Questions? wbraithwaite@nvidia.com