Date post: | 17-Sep-2018 |
Category: |
Documents |
Upload: | phungtuong |
View: | 218 times |
Download: | 0 times |
Particle Based Simulations Using GPUs
Yalmar Ponce
Claudio Esperança
Outline
• Environment configuration
– Linux, Windows, OSX (if necessary)
• Particles simulation
– Collision detection
• Rigid bodies simulation
– From particles to bodies
– Collision detection
– From bodies to particles
• Soft bodies simulation (similar to rigid bodies)
• SPH
ENVIRONMENT CONFIGURATION
C++ and CUDA
• Currently C++ and CUDA are supported by the most popular operating systems
– Linux
– Windows
– OSX
What is required in Linux?
• Suppose we have a NVIDIA card (ATI must be similar)
– Fedora
• Install gcc compiler (4.8 or later)
• Download driver from NVIDIA
• Run Fedora on runlevel 3
• Install the driver and restart
• Download and install CUDA SDK and ToolKit
• A good source code editor like Geany is recommended
What is required in Windows?
• Similar to Linux but more easy
– Download NVIDIA driver and install it
– Download and install CUDA SDK and Toolkit
– A good source code editor or IDE will be required
• All CUDA samples have Ms Visual Studio Projects
• Therefore, will be necessary to have installed the Ms Visual Studio 2008 or a later version
What about OpenCL?
• Notice that, so far, only OpenCL 1.1 is supported by NVIDIA hardware.
• On Linux, it is required to install the drivers from NVIDIA web page. Other drivers (from yum repositories) have no support for OpenCL
– Check if the libs libOpenCL .so.* have been copied to the correct libs directory
• For Windows there are no problems
FREE PARTICLES SIMULATION
Particles representation
• Particles typically are represented by small spheres with properties:
– Position
– Velocity
– Radius
– Mass
• Ideal for simulating granular materials
Collision Detection
• Particles are represented by small spheres
• Brute force
– n(n-1)/2 O(n2)
• Particles interact in a small region
– Well suited to spatial subdivision methods
• Using an uniform grid
– World is a cubical grid
– Grid cells store particles
– Collision occurs only between particles on neighbor Grid cells (3d-1)
Collision Detection
• Spatial Subdivision
– Uniform Grid
– Collision test only if the objects belong the same cell or adjacent cells
– A particle can be involved in more than one collision
– Cells must be processed in parallel
– NVIDIA CUDA is made for that
Uniform grid
• Particles are mapped onto cells based on their centers
• Cell size = particle diameter
– For equal sized particles, assuming no inter-penetration, up to 4 particles per cell
• Collision test examines a neighborhood of 33 cells
– O(n)
GPU Collision detection
• Sorting (radix sort)
• Grid is updated efficiently using sorting and search
• Supports unlimited number of particles per cell
• 3 stages
– Cell hash for each particle
– Sort particles based on hash, and
– Search sorted list of each cell
GPU Collision detection
GPU Collision detection
GPU Collision detection
Collision response
• Compute forces between collided particles
• Update positions and velocities
Results
RIGID BODIES SIMULATION
Rigid Bodies on GPU
• Introduced by Takahiro Harada
• All operations computed on GPU (FBO-R2Tex)
– Particle dynamics
– Grid generation
– Collision detection
– Momenta computations
– Body dynamics
From bodies to particles
• The goal
– Discretize the mesh body on small boxes and place a particle at each box
From bodies to particles
• There are many methods
– Octree based
• Build an octree for the 3D mesh
• Can be implemented on GPUs
• Query for occupied voxels
– Image based
• Define image resolution
• Suitable for GPU
• Ray casting for getting the ocuppied voxels
From bodies to particles
Ray casting technique
Free particles
But for Rigid Bodies?
• Particles depend on rigid body attributes
– Position and orientation
Collision detection
• Similar to free particles
– First, the particles attributes are computed by using the rigid bodies positions and orientations
– Here, collision detection is done in the same way as free particles, generating repulsion forces
– Finally, these forces are added to compute a total force and total torque.
Momenta computation
• Using the forces and torques compute the linear and angular velocities
• Next, compute the new positions and orientations
Rigid bodies positions
Rigid bodies orientations
Particles positions
Particles velocities
Particles relative positions
Computes particle values
Uniform Grid
Forces on particles
Collision detection
Update the grid
Rigid bodies linear momentum
Rigid bodies linear momentum
Momenta computation
Update rigid bodies positions and orientations
Rigid bodies formulae
• Update particle’s properties
• Compute forces on particles
• Compute forces on bodies
• Momenta computation
• Update rigid bodies’ properties
Results
SOFT BODIES SIMULATION
Motivation
• Soft bodies' simulation opens a huge range of solid objects for many applications like games.
Soft deformations
• Simulate soft bodies deformations in a computationally efficient and plausible way
Simple model
• Shape matching [Muller 05]
– Solids represented by particles
– No conectivity information is needed
• Given n point with positions , which represents a soft body
• Animate these points considering ext forces and it becomes deformed
• At every time step, match the current configuration to the original shape yielding goals
Basic algorithm
Basic algorithm
• Pull the actual points (black) towards the goal positions (red)
Basic algorithm
• It’s like applying a translation and a rotation
• In fact, we need to compute a transformation matrix
f(R,t)
Algorithm
1. Find the optimal transformation matrix in order to compute the goal points.
– This is shape matching
2. Move the particles towards those goal points
Shape matching
• Given and , the original shape points and the actual shape points, respectively.
• Find the rigid transform minimizing
• Optimal is center of mass of the
• Optimal is center of mass of the
Optimal transformation
• Define and
• Minimize
• With optimal linear transform
Optimal transformation
• Extract the rotational part
– can be precomputed
– Get the optimal R from polar decomposition of
– R is the rotation matrix
– S is a symmetric matrix
Extracting R
• R is related with A
• How to find S?
– First, sqrt computation can’t be applied to matrices directly
– Then, we need diagonalize the matrix for computing the matrix sqrt
– D is a diagonal matrix and have the eigenvalues and U have the eigenvectors of the decomposition process (diagonalization)
Matrix diagonalization
• Authors suggests to use Jacobi rotations
jacobi(AtA, v, U);
– 5 - 10 Jacobi rotation should be sufficient
• D is formed by the vector of eigenvalues v
• Finally,
• Note that D is inverted directly
Goal positions
• After R is computed, we can compute goal points for each time step
Integration
• Control stiffness setting by (rigid for = 1)
• So far, only rigid deformations can be achieved
Linear deformations
• Recall that R is the polar decomposition of ( , where )
• Instead of using only R to compute the goal point, also use the matrix A
• Now, objects can get stretched
Quadratic deformations
• Further, quadratic deformations allows for more awesome effects like twisting and bending
Quadratic deformations
• Again, reformulate the equations considering quadratic terms and mixed terms
Objects representation
• Two representations
– Particles for simulation
– Mesh for rendering
From bodies to particles
• Bodies are discretized by placing particles near to mesh faces
– Naive approach
• Place small spheres for all the vertices
• Try to place using negative normals
• Remove those that are very close
Soft body representation
• When bodies have complex geometries
– Particles are used for collision detection and to compute an optimal deformation matrix
– Later, the deformation matrix is applied to all vertices and normals (on faces or vertices)
Original particles positions x0
i
Current particles positions xi
Updated particles positions xi
Update particles with external forces
Uniform Grid
New moved particles positions (model is deformed)
Collision detection for generating forces
Update the grid
Goal positions gi
Integrate
Compute quadratic deformation matrix
Results
SMOOTHED PARTICLES HYDRODYNAMICS (SPH)
Motivation
• Fluids enables to simulate a large variety of natural phenomena
– Smoke
– Fire
– Liquids, etc.
Introduction
• There are two main methods for modeling fluids
– Eulerian
– Lagrangian
• Point based Lagrangian methods yield high performance and easier to implement
– SPH (Smoothed Particles Hydrodynamics)
– Mesh free
Introduction
• In recent years, point based simulations have become increasingly popular
• Some of the main contributors were
– Matthias Müller
– Takahiro Harada
– Simons Green
What is SPH?
• Particle system with inter-particle forces/interactions
– Interactions at infinite distance yield O(n2) computational complexity
– Define interaction cutoff distance
• Less complexity
• Easier to parallelize
• First developed for use in astrophysics
– Simulation of stars / galaxies
What is SPH?
• Different from other fluid simulation methods (FEM)
– Mesh free (does not consider any “surfaces”)
– Interpolation method for particle systems
What is SPH?
• Each particle is affected only by the particles within a limited radius h(cutoff distance)
– Uses a “radial symmetrical smoothing kernel” to define the cutoff
h
Why use SPH?
• Advantages
– Very fast/efficient compared to other fluid simulation methods
– Easy to parallelize
– Guarantees conservation of mass (particles themselves are the mass) if weighted functions are normalized
– Computes pressure from weighted contributions of neighboring particles (instead of solving linear systems of equations)
But …
• Disadvantages
– Still has to reconstruct a surface to render (marching cubes, splatting, etc.)
– Needs a lot of particles for realistic simulation
How to parallelize
• Use a spatial subdivision data structure
– An uniform grid
– Fill/map particles onto the grid
– Only search within a neighborhood
• For each particle, the cell to which belongs and the adjacent cells in a radius must be checked
SPH dynamics
• Compute density and velocity
– Query on a neighborhood of radius h to verify particles which can contribute
h
The equations of SPH
• The particle at location x is computed as a weighted sum of neighboring particles
• In the discretized functions
The equations of SPH
• The governing equations (mass and momentum conservation) are simplified Navier-Stokes
•
•
•
•
•
Particles’ positions Particles’ densities
Uniform Grid
Particles’ densities
Particles’ velocities
Particles’ velocities
Obstacles’ distance function
Particles’ positions
Compute densities
Update velocities
Update the grid
Update positions
Results
SPH rendering
• Based on gaussian smoothing
– Particles are renderized as small spheres
– This is stored as textures for smoothing
– Two buffers are used
• Depth buffer
• Normals buffer
• After the images are smoothed we can apply effects for
– Illumination, shadow, reflection and refraction
• This technique is simple and cheap
EXTENSIONS
Extensions
• Rigid bodies using impulses instead of forces
• Cloth simulation
• Solid-liquid coupling
• Cloth-liquid coupling
Rigid bodies using impulses instead of forces
• Disadvantages for the method using forces
– Representing high resolution objects • A large particles' set could be necessary
Disadvantages
• Collision response behavior looks a bit springy
• Collision between particles OK
– But with obstacles?
Disadvantages
• Interpenetration between objetcs or obstacle-object
– Large forces can carry for interpenetrating objects
– Small particles do not guarantee correct separation or even any separation in some cases
Rigid bodies using impulses
• Is more adequate to generate correct dynamic behavior
• In our prototipe, we use variable sized particles
Rigid bodies using impulses
• Collision detection – Estimates contact points
• Collision response – Apply impulses at contact
points
• Differs from forces approach because impulses are applied sequentially
Algorithm
• Save positions and orientations of objects
• Update obtects’ properties (positions, velocities and orientations)
• Update particles properties (positions and velocities)
• Update the grid
• Detect collision on particles and process them by applying impulses at contact points
– Changing objects properties
• Retrieve the objects’ saved attributes
• Update velocities of the objects
• Detect and process contacts, if still there are, by applying impulses
• Update positions and orientations of objects
Cloth simulation
• Mass-spring approach
• Resolution
– Efficiency vs Performance
Cloth simulation
• Collision detection
– Grid for mapping triangles
– Similar to particles collision detection
• Search on a neighborhood
Solid-liquid coupling
• Collision detection unified
– SPH particles
• computes pressure and viscosity forces
– Solids particles
• computes forces for separating collided objects
Cloth-liquid coupling
• Collision detection uses two grids
– Fine resolution for SPH particles
– Coarse resolution for cloth triangles
• Collision detection is done in two stages
– One for particles, searching on the two grids
– Second for triangles, searching on the two grids too