cloth simulation on the gpuhttp.download.nvidia.com/developer/presentations... · overview • a...
TRANSCRIPT
![Page 1: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/1.jpg)
Cloth Simulation on the GPUCloth Simulation on the GPU
Cyril Zeller
NVIDIA Corporation
![Page 2: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/2.jpg)
OverviewOverview
• A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400, 3400, 1400, 540, GeForce 6 and above)– Takes advantage of the massive parallel
computation horsepower of GPUs
– Geared toward performance and visual realism, not physical accuracy
– Suitable to 3D games and virtual reality systems
![Page 3: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/3.jpg)
OutlineOutline
• Demo
• Algorithm outline
• GPU implementation
![Page 4: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/4.jpg)
DemoDemo
• Available at http://download.developer.nvidia.com/developer/SDK/Individual_Samples/samples.html#Cloth
![Page 5: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/5.jpg)
Cloth as a Set of ParticlesCloth as a Set of Particles
• Each particle is subject to:– A force (gravity, wind, drag, etc.)
– Various constraints:• To maintain overall shape (springs)
• To prevent interpenetration with the environment
• Constraints are resolved by relaxation
• CPU version successfully used in games:Jakobsen, T. “Advanced character physics”, GDC 01
![Page 6: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/6.jpg)
ForceForce
• Verlet integration:P(t + Δt) = P(t) + k (P(t) – P(t - Δt)) + Δt2 F(t)
• Δt: simulation time step
• P(t): particle position
• F(t): force
• k: damping coefficient
• No force applied to fixed or user-moved particles
![Page 7: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/7.jpg)
• Particles are linked by springs:
• A spring is simulated as a distance constraintbetween two particles
Shear springs
Spring ConstraintsSpring Constraints
Structural springs
![Page 8: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/8.jpg)
• A distance constraint between two particles is enforced by moving them away or towards each other:– If both particles are free:
– If one particle is fixed:
Distance ConstraintDistance Constraint
Distance at rest
![Page 9: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/9.jpg)
Collision ConstraintsCollision Constraints
• The environment is defined as a set of collision objects (planes, spheres, boxes, ellipsoids)
• A collision constraint between a particle and a collision object is enforced by moving the particle outside the object:
![Page 10: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/10.jpg)
Algorithm OutlineAlgorithm Outline
• For every simulation time step:– For every particle that isn’t fixed or user-moved:
• Apply force
– For every relaxation step:• For every spring constraint:
– Enforce distance constraint
• For every particle:
– For every collision object:
› If the particle is inside, move it outside
![Page 11: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/11.jpg)
GPU Implementation OverviewGPU Implementation Overview
• The particle positions and normals are stored into floating-point textures
• The CPU never reads back these textures!
• At every frame:– GPU simulation: Update the position and normal
textures
– GPU rendering: Render using vertex texture fetch(available on Shader Model 3.0 and above)
![Page 12: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/12.jpg)
• Two textures are required: Current and New
• Positions get updated through a series of draw calls
• Each draw call is of the form:– Set the appropriate pixel shader
– Set New as the render target
– Draw a quad covering the entire render target
– Swap Current and New
GPU Simulation: Updating the Position TextureGPU Simulation: Updating the Position Texture
Pixelshader
Current
New
![Page 13: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/13.jpg)
GPU Simulation: ForceGPU Simulation: Force
• One draw call
• Verlet integration requires three textures:
Forcepixel
shader
New
Current Old
![Page 14: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/14.jpg)
• Interdependent constraints must be enforced sequentially for the relaxation to converge
• So constraints are divided into 8 groups of independent constraints
• One draw call per group
GPU Simulation: Spring ConstraintsGPU Simulation: Spring Constraints
One draw call Another draw call
![Page 15: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/15.jpg)
• 4 draw calls for the structural springs:
GPU Simulation: Spring ConstraintsGPU Simulation: Spring Constraints
• 4 draw calls for the shear springs:
![Page 16: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/16.jpg)
GPU Simulation: Collision ConstraintsGPU Simulation: Collision Constraints
• One draw call
• The parameters of each collision object (center, dimension) are stored into 1D-textures:– One texture per geometric type
– Textures are necessary for looping through the collision objects since Shader Model 3.0 does not support indexing of constant registers
![Page 17: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/17.jpg)
GPU Simulation: Cloth CuttingGPU Simulation: Cloth Cutting
• In cut mode each mouse motion defines a cutter triangle
• A pixel shader intersects the cutter with each cloth triangle
• The result is read back to the CPU and cut triangles and springs are removed
![Page 18: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/18.jpg)
Cloth with a Generic ShapeCloth with a Generic Shape
• Non-rectangular mesh or mesh with holes:– Create a geometry image from the
mesh [Gu et al. “Geometry Images” Siggraph 02]
– Handle split vertices by:• Enforcing spring constraints attached to
each duplicate
• Averaging the resulting positions before enforcing the collision constraints
![Page 19: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/19.jpg)
PerformancePerformance
• 400 frames per second
• On a GeForce 6800 Ultra
• With:– 100 x 100 particles
– One relaxation step
– Structural and shear springs
![Page 20: Cloth Simulation on the GPUhttp.download.nvidia.com/developer/presentations... · Overview • A method to simulate cloth on any GPU supporting Shader Model 3 (Quadro FX 4500, 4400,](https://reader035.vdocuments.us/reader035/viewer/2022081404/5f03bc297e708231d40a82b5/html5/thumbnails/20.jpg)
Future WorkFuture Work
• Better collision detection
• Self-collision detection
• Simulation level of details