Position-Based Dynamics Analysis and Implementation Miles Macklin - - PowerPoint PPT Presentation

position based dynamics
SMART_READER_LITE
LIVE PREVIEW

Position-Based Dynamics Analysis and Implementation Miles Macklin - - PowerPoint PPT Presentation

Position-Based Dynamics Analysis and Implementation Miles Macklin Analysis Position-Based Dynamics Very stable Highly damped Example Continuous Equations of Motion Newtons second law Will consider forces which we can


slide-1
SLIDE 1

Position-Based Dynamics

Analysis and Implementation

Miles Macklin

slide-2
SLIDE 2

Analysis

slide-3
SLIDE 3

Position-Based Dynamics

  • Very stable
  • Highly damped
  • Example
slide-4
SLIDE 4

Continuous Equations of Motion

  • Newton’s second law
  • Will consider forces which we can derive

from an energy potential E(x)

  • Our path: start with implicit Euler and

transform it into PBD

  • Why implicit Euler? Also highly stable,

damped.

M¨ x = f(x)

slide-5
SLIDE 5
  • Implicit Euler:



 


  • Equivalent to:



 


  • Forces evaluated at end of the time-step
  • Implicit, position-level, time-discretization of Newton’s equations

Implicit Euler Integration

vn+1 = vn + ∆tM−1f(xn+1) xn+1 = xn + ∆tvn+1

M ✓xn+1 − 2xn + xn−1 ∆t2 ◆ = f(xn+1)

slide-6
SLIDE 6
  • Discrete equations of motion
  • Are the first order optimality

conditions for a non-linear minimization

  • [Goldenthal et al. 2007]


[Liu et al. 2013]

Variational Implicit Euler

M(xn+1 − 2xn + xn−1) = ∆t2f(xn+1)

˜ x = 2xn − xn−1 + M−1fext = xn + ∆tvn + M−1fext

argmin 1

2(xn+1 − ˜ x)T M(xn+1 − ˜ x) − ∆t2E(xn+1)

slide-7
SLIDE 7
  • In the limit of infinite

stiffness we obtain a constrained minimization


Variational Implicit Euler

E → ∞

argmin subject to

1 2(xn+1 − ˜ x)T M(xn+1 − ˜ x) C(xn+1) = 0

argmin

1 2(xn+1 − ˜ x)T M(xn+1 − ˜ x) − ∆t2E(xn+1)

slide-8
SLIDE 8

˜ x

x∗

C(x) = 0

x1 x2

xn

Geometric Interpretation

  • Variational form gives a “step

and project” interpretation for implicit Euler

  • PBD performs approximate

projection

argmin subject to

1 2(xn+1 − ˜ x)T M(xn+1 − ˜ x) C(xn+1) = 0

slide-9
SLIDE 9

Solving

  • Implicit time discretization

produces a non-linear system of equations

  • How do we solve such a

system?

  • Newton’s method

g(xi, λi) = 0 h(xi, λi) = 0

M(xn+1 ˜ x) ∆t2rC(xn+1)T λ = 0 C(xn+1) = 0

Discrete constrained equations of motion Non-Linear System

slide-10
SLIDE 10

Approximate Newton Step

First approximation:


  • M = K + O(dt^2)
  • Common Quasi-Newton

simplification


Second approximation:


  • Assume g = 0
  • True for first iteration
  • Typically remains small

Full Newton System Approximate System

 K rCT rC  ∆x ∆λ

  • =

 g(xi, λi) h(xi, λi)

M rCT rC  ∆x ∆λ

  • =

 h(xi, λi)

rC(xi)M−1rC(xi)T ⇤ ∆λ = C(xi)

PBD System

(Schur Complement)

slide-11
SLIDE 11

Variational Interpretation of Approximate Projection

Implicit Euler PBD (each iteration)

˜ x

x∗

C(x) = 0

x1 x2

xn

1 2(x − xi)T M(x − xi) C(x) = 0

1 2(x − ˜ x)T M(x − ˜ x) C(x) = 0

argmin subject to argmin subject to

slide-12
SLIDE 12

Problems

  • To arrive at PBD we had to assume infinitely stiff energy potentials
  • This means PBD converges to an infinitely stiff solution regardless
  • f stiffness coefficient
  • Stiffness dependent on iteration count and time-step
  • No concept of total constraint force
  • Fully implicit -> severe energy dissipation
slide-13
SLIDE 13

Iteration Count Dependent Stiffness

160 ITERATIONS 20 ITERATIONS

slide-14
SLIDE 14

PBD Extensions

  • Projective Dynamics [Bouaziz et al. 2014]
  • XPBD [Macklin et al. 2016]
  • Second order PBD
slide-15
SLIDE 15

XPBD

  • Instead of assuming infinite stiffness,

allow constraints to be compliant

  • Leads to a modified / regularized

non-linear system

  • Direct correspondence to engineering

stiffness (Young’s modulus)

  • Compliance is simply inverse stiffness
  • [Servin et al. 2006]

α = k−1

Potential Compliance

E = 1 2CT (xn+1)α−1C(xn+1)

slide-16
SLIDE 16

XPBD Newton Step

  • Take Schur complement
  • f approximate system

with respect to M

  • Obtain PBD or Fast

Projection form

  • [Goldenthal et al 2007]

Schur complement Modified Newton System

 M rCT rC ˜ α  ∆x ∆λ

  • =

 h(xi, λi)

rC(xi)M−1rC(xi)T + ˜ α ⇤ ∆λ = C(xi) ˜ αλi

slide-17
SLIDE 17

XPBD Gauss-Seidel Update

  • View PBD “scaling fator” s

as incremental Lagrange multiplier

  • Additional compliance terms
  • Must store Lagrange

multiplier for each constraint

  • PBD solves the infinite

stiffness case

PBD XPBD

sj = Cj(xi) rCjM−1rCT

j

∆λj = Cj(xi) ˜ αjλij rCjM−1rCT

j + ˜

αj

slide-18
SLIDE 18

XPBD Algorithm

  • Only two differences from

PBD:

  • Lagrange multiplier

calculation (include compliance terms)

  • Lagrange multiplier update

(store instead of discard)

slide-19
SLIDE 19

RESULTS

  • Contact / friction
slide-20
SLIDE 20

XPBD - FEM

  • Generalizes to arbitrary

constitutive models

  • Treat strain as vector of

constraints

  • Compliance matrix is inverse

stiffness

Ctri(x) = ✏tri =   ✏x ✏y ✏xy   αtri = K−1 =   λ + 2µ λ λ λ + 2µ 2µ  

−1

Etri = V 1 2✏T K✏

Compliance Matrix Constraint Vector Elastic Energy Potential

slide-21
SLIDE 21

RESULTS

  • Contact / friction
slide-22
SLIDE 22
slide-23
SLIDE 23

Results - XPBD vs Implicit Euler

  • Compare solver output to a

non-linear Newton method

  • Close agreement for primal

and dual variables

slide-24
SLIDE 24
  • First order backward Euler (BDF1):



 
 


  • Second order backward Euler (BDF2)

Second Order Implicit Euler

vn+1 = vn + ∆tM−1f(xn+1) xn+1 = xn + ∆tvn+1

vn+1 = 4 3vn − 1 3vn−1 + 2 3∆tM−1f(xn+1) xn+1 = 4 3xn − 1 3xn−1 + 2 3∆tvn+1

slide-25
SLIDE 25
  • First order velocity update:
  • Second order velocity update:

Second Order PBD

vn+1 = 1 ∆t 3 2xn+1 − 2xn + 1 2xn−1

  • .

˜ x = xn + ∆tvn + ∆t2M−1fext

vn+1 = 1 ∆t ⇥ xn+1 − xn⇤

˜ x =4 3xn − 1 3xn−1 + 8 9∆tvn − 2 9∆tvn−1 + 4 9∆t2M−1fext

  • First order prediction:
  • Second order prediction:
  • See [English 08]
slide-26
SLIDE 26

Second Order PBD

First Order Second Order

slide-27
SLIDE 27

Second Order PBD

First Order Second Order

slide-28
SLIDE 28

Second Order PBD

First Order Second Order

slide-29
SLIDE 29

Second Order PBD

  • Significantly less damping
  • Positions stay closer to constraint manifold
  • Requires fewer constraint iterations!
  • Non-smooth events (contact) need special handling
slide-30
SLIDE 30

Implementation

slide-31
SLIDE 31

Parallel PBD

  • Gauss-Seidel inherently serial
  • Parallel options:
  • Graph coloring methods
  • Jacobi methods
  • Hybrid methods
slide-32
SLIDE 32
  • Break constraint graph into independent sets
  • Solve the constraints in a set in parallel
  • “Batched” Gauss-Seidel
  • Requires synchronization between each set
  • Size of sets decreases -> poor utilisation

Graph Coloring Methods

3 Color Graph

slide-33
SLIDE 33

Jacobi Methods

  • Process each constraint or particle in parallel
  • Sum up contributions on each particle

Particle-centric approach (gather) Constraint-centric approach (scatter)

foreach particle (in parallel) { foreach constraint { calculate constraint error update delta } } foreach constraint (in parallel) { calculate constraint error foreach particle { update delta (atomically) } }

slide-34
SLIDE 34
  • Problem: system matrix can be indefinite, Jacobi will not

converge, e.g.: for redundant constraints (cf. figure)

  • Regularized Jacobi iteration via averaging [Bridson et al. 02]
  • Sum all constraint deltas together and divide by constraint

count for that particle
 


  • Successive-over relaxation by user parameter omega [0,2]:

Jacobi Methods

xi xi + 1 ni X

ni

λjrCj

xi xi + ω ni X

ni

λjrCj

slide-35
SLIDE 35

Parallel Methods Comparison

Method Advantages Disadvantages Batched Gauss-Seidel Good Convergence Very Robust Graph Coloring Synchronization Jacobi Trivial Parallelism Slow Convergence Less Robust

slide-36
SLIDE 36

Hybrid Parallel Methods

  • Best of both worlds
  • Perform graph-coloring
  • Upper limit on number of colors
  • Process everything else with Jacobi
  • [Fratarcangeli & Pellacini 2015]
slide-37
SLIDE 37

Solver Framework

slide-38
SLIDE 38
  • Simplifies collision detection
  • Two-way interaction of all object types:

  • Cloth
  • Deformables
  • Fluids
  • Rigid Bodies
  • Fits well on the GPU

Unified Solver

Everything is a set of particles connected by constraints

slide-39
SLIDE 39

Examples

  • Show some neat examples of what we can do with Flex that would

not be possible in other frameworks

  • Smoke / Cloth
  • Water / Buoyancy
slide-40
SLIDE 40
slide-41
SLIDE 41
slide-42
SLIDE 42

Particles

  • Velocity stored explicitly
  • Phase-ID used to control collision

filtering

  • Global radius
  • SOA layout

struct Particle { float pos[3]; float vel[3]; float invMass; int phase; };

slide-43
SLIDE 43

Constraints

  • Constraint types:
  • Distance (clothing)
  • Shape (rigids, plastics)
  • Density (fluids)
  • Volume (inflatables)
  • Contact (non-penetration)
  • Combine constraints
  • Melting, phase-changes
  • Stiff cloth, bent metal
slide-44
SLIDE 44

Contact and Friction

slide-45
SLIDE 45

Collision Detection Between Particles

  • All dynamics represented as particles
  • Kinematic objects represented as

meshes

  • Two types of collision detection:
  • Particle-Particle
  • Particle-Mesh

Ccontact = n · x − r ≥ 0

Ccontact = |xi − xj| − 2r ≥ 0

slide-46
SLIDE 46

Collision Detection Between Particles

  • Particle-Particle
  • Tiled uniform grid
  • Fixed maximum radius
  • Built using cub::DeviceRadixSort
  • Re-order particle data according to cell

index to improve memory locality

  • CUDA Particles Sample [Green 07]

r

slide-47
SLIDE 47

Collision Detection Against Shapes

  • Particle-Convex
  • 2D hash-grid
  • Built on GPU

  • Particle-Triangle Mesh
  • 3D hash-grid
  • Rasterized in CUDA
  • Lollipop test (CCD)

Triangle Collision (TOI) Convex Collision (MTD)

slide-48
SLIDE 48

Friction

  • Friction in PBD traditionally applied using a velocity

filter

  • Replace with a position-level frictional constraint
  • Approximate Coulomb friction using penetration

depth to limit constraint lambda

  • Generates convincing particle piling
  • [Francu 2017]

Cfriction = |(x − x0) ⊥ n|

slide-49
SLIDE 49

Granular Materials

  • Collections of hard spheres
  • Treat friction during constraint solve
slide-50
SLIDE 50

Rigid Bodies

slide-51
SLIDE 51

Rigid Bodies

  • Convert mesh->SDF
  • Place particles in interior
  • Add shape-matching constraint
  • Store SDF dist + gradient on

particles

Rest Configuration Deformed State Best Rigid Rotation/ Translation

slide-52
SLIDE 52
slide-53
SLIDE 53

Plastic Deformation

  • Detect when deformation exceeds a

threshold

  • Simply change rest-configuration of

particles

  • Adjust visual mesh (linear skinning)
slide-54
SLIDE 54

Shape matching on the GPU

  • Shape matching requires computing centre of mass and the moment matrix for

particles:
 
 


  • Large summations, not immediately parallel friendly
  • Optimized using two parallel cub::BlockReduce calls
  • O(N) -> O(logN) (18ms -> 0.6ms)
  • 1 block per-rigid shape (64 threads, heuristic, irregular workload problem)
  • Polar decomposition still single threaded

A = X

i

mi(xi − c)(¯ xi − ¯ c)T c = X

i

mixi/ X

i

mi

slide-55
SLIDE 55

Robust and Simple Polar Decomposition

  • Shape matching requires a polar

decomposition

  • Can be done through SVD /

Eigenvalue decomposition

  • Complex code, ill-posed for indefinite

systems

  • Simple algorithm given in [Müller et al

2016]

  • Robustly handles inversion through

temporal coherence

slide-56
SLIDE 56
slide-57
SLIDE 57

Generalised Coordinate Rigid Bodies

  • Particle:
  • Rigid body:
  • Rotation is parameterized by exponential map
  • Example, ball joint:



 


  • [Deul et al. 2014]
slide-58
SLIDE 58

Generalized Rigid Body Constraint Gradients

  • Split gradient into a constraint part and connector part
  • Particle:



 


  • Rigid Body:
slide-59
SLIDE 59

Generalised Position-Based Solver

  • Linearization of constraint (rigid bodies):
  • Computation of Lagrange multiplier:
  • Correction vectors:

[∆xT , ∆ϕT ] = M−1rCT λ

[rCM−1rCT ]∆λ = C(xi, ϕi)

C(x + ∆x, ϕ + ∆ϕ) ⇡ C(x, ϕ) + rC(∆xT , ∆ϕT )

slide-60
SLIDE 60

Results

slide-61
SLIDE 61

Fluids

slide-62
SLIDE 62

Density Constraint

  • Density via SPH kernels
  • Unilateral constraint
  • Cohesion from [Akinci13]

Cdensity = ρi ρ0 − 1 ≤ 0

slide-63
SLIDE 63
slide-64
SLIDE 64

Surface Tension Constraint

  • Adapted surface tension model of [Akinci et al. 2013] to PBD
  • Attempts to minimize curvature

θ

Ctension = ¯ xij · ¯ ni = cos(θ)

slide-65
SLIDE 65
slide-66
SLIDE 66

Two-Way Rigid Fluid Coupling

  • Mostly automatic
  • Include all particles in fluid

density estimation

  • Treat fluid->solid particle

interactions as if both particles solid

slide-67
SLIDE 67
slide-68
SLIDE 68

Cloth

  • Graph of distance + tether constraints
  • Self-collision / inter-collision automatically handled
slide-69
SLIDE 69

Cloth - Forces

  • Basic aerodynamic model
  • Treat each triangle as a thin airfoil to generate lift + drag
  • Flexible enough to model paper planes

¯ n

¯ vwind

¯ flift ¯ fdrag

¯ vtri

slide-70
SLIDE 70
slide-71
SLIDE 71

Ropes

  • Build ropes from distance + bending

constraints

  • Fit Catmull-Rom spline to points
  • Torsion possible [Umetani 14]
slide-72
SLIDE 72
slide-73
SLIDE 73

Examples

slide-74
SLIDE 74
slide-75
SLIDE 75
slide-76
SLIDE 76
slide-77
SLIDE 77
slide-78
SLIDE 78

Limitations and Future Work

  • Representing smooth surfaces problematic
  • Want parallel and robust collision of simplices
  • Hierarchical representation (multi-scale particles)
  • Convergence for parallel solver / accelerated methods [Mazhar 2015]
slide-79
SLIDE 79

Resources

  • PBD available as an open source library:


https://github.com/InteractiveComputerGraphics/PositionBasedDynamics

  • Already supports many constraints: point-point, point-edge, point-

triangle and edge-edge distance constraints, dihedral bending constraint, isometric bending, volume constraint, shape matching, FEM- based PBD (2D & 3D), strain-based dynamics (2D & 3D).

  • Simple interface: just one class with static methods.
  • MIT License
  • Demos for usage
slide-80
SLIDE 80

Conclusion

  • Position-Based Methods are:
  • Fast, stable and simple to implement,
  • Provide a high level of control,
  • Can simulate deformable solids (1D, 2D,

3D), multi-body systems, fluids and granular materials,

  • Can be viewed as an approximation of

implicit methods

slide-81
SLIDE 81

Questions?

slide-82
SLIDE 82

References

  • English, Elliot, and Robert Bridson. "Animating developable surfaces using

nonconforming elements." ACM Transactions on Graphics (TOG). Vol. 27. No. 3. ACM, 2008.

  • Goldenthal, Rony, et al. "Efficient simulation of inextensible cloth." ACM Transactions
  • n Graphics (TOG) 26.3 (2007): 49.
  • Bouaziz, Sofien, et al. "Projective dynamics: fusing constraint projections for fast

simulation." ACM Transactions on Graphics (TOG) 33.4 (2014): 154.

  • Bridson, Robert, Ronald Fedkiw, and John Anderson. "Robust treatment of collisions,

contact and friction for cloth animation." ACM Transactions on Graphics (ToG). Vol. 21.

  • No. 3. ACM, 2002.
  • Stam, Jos. "Nucleus: Towards a unified dynamics solver for computer graphics."

Computer-Aided Design and Computer Graphics, 2009. CAD/Graphics' 09. 11th IEEE International Conference on. IEEE, 2009.

  • Green, Simon. "Cuda particles." nVidia Whitepaper 2.3.2 (2008): 1.
  • Guendelman, Eran, Robert Bridson, and Ronald Fedkiw. "Nonconvex rigid bodies with

stacking." ACM Transactions on Graphics (TOG). Vol. 22. No. 3. ACM, 2003.

  • Servin, M., Lacoursiere, C., & Melin, N. (2006, November). Interactive simulation of

elastic deformable materials. In SIGRAD 2006. The Annual SIGRAD Conference; Special Theme: Computer Games (No. 019). Linköping University Electronic Press.

  • Provot, Xavier. "Deformation constraints in a mass-spring model to describe rigid cloth

behaviour." Graphics interface. Canadian Information Processing Society, 1995.

  • Fratarcangeli, M., and F

. Pellacini. "Scalable Partitioning for Parallel Position Based Dynamics." EUROGRAPHICS. Vol. 34. No. 2. 2015.

  • Liu, Tiantian, et al. "Fast simulation of mass-spring systems." ACM Transactions on

Graphics (TOG) 32.6 (2013): 214.

  • Akinci, Nadir, Gizem Akinci, and Matthias Teschner. "Versatile surface tension and

adhesion for SPH fluids." ACM Transactions on Graphics (TOG) 32.6 (2013): 182.

  • Ryckaert, Jean-Paul, Giovanni Ciccotti, and Herman JC Berendsen. "Numerical

integration of the cartesian equations of motion of a system with constraints: molecular dynamics of n-alkanes." Journal of Computational Physics 23.3 (1977): 327-341.

  • Umetani, Nobuyuki, Ryan Schmidt, and Jos Stam. "Position-based elastic rods." ACM

SIGGRAPH 2014 Talks. ACM, 2014.

  • Müller, M., Bender, J., Chentanez, N., & Macklin, M. (2016, October). A robust method

to extract the rotational part of deformations. In Proceedings of the 9th International Conference on Motion in Games (pp. 55-60). ACM.

  • Bender, Jan, et al. "Position-based simulation of continuous materials." Computers &

Graphics 44 (2014): 1-10.

  • Unified Simulation of Rigid and Flexible Bodies Using Position Based Dynamics -

VRIPHYS 2017