技术改变命运,技术成就未来

(模拟)布料仿真的基本方法

本文禁止转载
B站:Heskey0


布料仿真的两大类方法:

1. Mass-Spring Damper Model

Pros:

  • It is derived from natural tendency and is easier to implement

Cons:

  • The model is not derived from theory or observations which makes it less accurate.
  • It has too much of coupling among the springs.
  • Setting spring constant values to obtain desired effect is difficult

2. Elasticity-Model

By considering the surface of the cloth and integrating all the energy functions a more accurate model was designed called Elasticity Model which includes the following properties:

  • There exists a resistance in triangles and edges while making changes to their size. So energy is required if we want to compress or expand them.
  • Bending is resisted by the edges. So energy is required if two adjacent faces needs to be bent.
  • Deformation is resisted by triangle. So energy is required in deforming or shearing a triangle.

Chapter 1. 中科大

2021年(第九届)中国科学技术大学《计算机图形学前沿》暑期课程_哔哩哔哩_bilibili

1.1 An overview of the cloth simulation

Cloth simulation in known to be slow:

  • Dynamics Solver (40% of the total cost)
    • High resolution
    • High nonlinearity: 布料抗拉伸却易弯曲
    • High stiffness
  • Collision Handling (60% of the total cost)
    • Collision detection
    • Collision response

1.1.1 时间积分

Backward Euler Integration/ implicit Euler:

xt+Δt=xt+Δtvt+Δtvt+Δt=vt+ΔtM1f(xt+Δt)

可推出:

xt+Δt=xt+Δtvt+Δt2M1f(xt+Δt)vt+Δt=vt+1Δt(xt+Δtxt)

上式等价于一个优化问题(对下面的F(X)求导即可证明):

重新构建一个Nonlinear optimization:(也可以构建关于 vt+Δt 的优化问题)

xt+Δt=argminxF(x)

where: (加号左边是kinetic energy,右边是potential energy)

F(x)=12Δt2(xx¯)TM(xx¯)+E(x)

and

x¯=xt+Δtvt

1.1.2 Collision Handing

discrete collision handling:

  • 只保证每一个状态都处于安全状态
  • 不保证是否发生碰撞

碰撞是一个约束:

xt+Δt=argminxF(x)s.t.xt+ΔtΩ

where:

  • Ω: intersection-free region

continuous collision handling:

xt+Δt=argminxF(x)s.t.sxt+(1s)xt+ΔtΩ,s[0,1]

1.2.1 非线性优化的套路

非线性优化的solver,通常是满足以下形式:

An iterative nonlinear solver typically has the form: (with certain acceleration methods)

x(k+1)=xkα(k+1)(A(k+1))1F(xk)x

where:

  • step size: α
  • matrix: A
  • gradient: F(xk)/x

1.2.2 Newton-Raphson

Newton-Raphson中,A 是一个Hessian matrix:

A(k+1)=2F(xk)x2

Pros (优点):

  • 2rd-order convergence rate. (单位时间内,error=error/2)

Cons (缺点):

  • How to solve A1 或者说 A1f ?

    • Direct, Iterative (PCG)
  • It can fail to converge if x is far from the solution

    • small step size
    • Hessian must be enforced to be positive define
      • 很多迭代法要求矩阵是positive define的

Newton-Raphson方法的应用:

Papers:

  • (1996) Large step on cloth simulation: 只用了一次Newton iteration

Marvelous Designer (mostly CPU, has GPU)

  • 一次Newton iteration solved by limited PCG iterations

1.2.3 Gradient Descent

Gradient Descent中,A 是一个identity matrix:

A(k+1)=I

Pros:

  • Very GPU friendly
  • Very simple

Cons:

  • 1st-order convergence rate (收敛很慢)
  • No simulator uses this as it is.

1.2.4 Projective Dynamics

Projective Dynamics中,A 是一个Constant smoothing matrix:

A(k+1)=C

Pros:

  • Fast on CPUs, since C can be pre-factorized. (在CPU上对 C 做预分解)
  • Fast convergence in the first few iterations
    • Intuitively, the use of C quickly smooths out some low-frequency errors.

Cons:

  • Not GPU-friendly
    • 矩阵的inverse,通常不是sparse matrix。会导致矩阵乘法效率慢
  • 1st-order convergence rate: slow convergence overall. (一开始收敛快,然后像gradient descent一样收敛慢)

1.2.5 Diagonal Hessian

(sig asia 2015)Diagonal Hessian中,A 是一个Hessian matrix的diagonal matrix:

A(k+1)=diag(2F(xk)x2)

Pros:

  • Converges faster than gradient descent
  • GPU friendly

Cons:

  • Still does not converge that fast

有了非线性算法,还需要加速算法,如:

  • (2015) Chebyshev
  • (2015) Nesterov
  • (2018) Anderson
  • (2017) L-BFGS

Only Chebyshev is GPU-friendly. Multiscale acceleration is also effective

1.3.1 Chebyshev

算法:

  • For k=0,...,K

    • x(k+1)=xkα(k+1)(A(k+1))1F(xk)x

    • if k==0 then ω=1

    • if k==1 then ω=2/(2ρ)2

    • if k>1 then ω=4/(4ρ2ω)

    • x(k+1)=ωx(k+1)+(1ω)x(k1)

ρ is the spectral radius, i.e. the estimation of the residual error decreasing rate

For example:

  • 某次迭代,error=error*0.99,则 ρ0.99

推荐套路:

  • CPU:
    • Projective dynamics followed by Newton-Raphson
  • GPU:
    • Chebyshev + Diagonal Hessian
    • Newton-Raphson with PCG

1.4 The remaining topics

1.4.1 Position-Based Dynamics

不去解数学问题:

x(k+1)=xkα(k+1)(A(k+1))1F(xk)x

而是通过直接将两个顶点拉近,修改顶点的位置(非物理)

Pros:

  • No physical quantities
  • Everything on GPU shared memory, fast! (NVcloth)
    • 当顶点少的时候,直接将顶点数据放到shared memory中,访问快

Cons:

  • No physical meaning
  • Not scalable. (Shared memory is only 16kB)
    • vertex多的时候,效率会显著下降

Chapter 2. Games103

1. 建模

1.1 建立弹簧

在三角网格的每个边上都加一根弹簧,然后跨过所有内部边添加弹簧(称任意两个相邻三角形的公共边为内部边,两个相邻三角形组成一个四边形,新添加的弹簧为这个四边形的对角线)来抵抗弯曲

img

边数组(Triple list)的建立:

img

弹簧的建立:

  • 对于三角形边上的弹簧,直接遍历 Edge list,依次添加弹簧即可。

  • 对于跨过内部边的弹簧,查询内部边所在三角形的剩余两个顶点,把它们连接起来即可。

1.2 Spring Hessian

img

为了计算:

H=fx

需要先计算Sprint Hessian:

He=kx01x01T||x01||2+k(1L||x01||)(Ix01x01T||x01||2)

也可以写成:

He=k[IL||x01||(Ix01x01T||x01||2)]

小矩阵 He 组成大矩阵 H,对角线上的 He 要带上负号

2. Simulation by Newton's Method

x(k+1)=xkα(k+1)(2F(xk)x2)1F(xk)x

其中:

F(x)=12Δt2(xx¯)TM(xx¯)+E(x)

where:

x¯=xt+Δtvt

F(x(k))=1Δt2M(x(k)x[0]Δtv[0])f(x(k))

and

2F(xk)x2=1Δt2M+H(x(k))

where:

  • H(x(k)) 就是弹簧系统 E(x) 的Hessian,
    • 弹簧拉伸时,H(x)一定是SPD,2F(xk)x2 一定是SPD,F(x) 只有一个最小值,牛顿法收敛到唯一的解
    • 弹簧压缩时,H(x)可能不是SPD,2F(xk)x2 可能不是SPD

Algorithm:

  1. Initialize

  2. For k=0,...,K

    1. Solve

      (1Δt2M+H(x(k)))Δx=1Δt2M(x(k)x[0]Δtv[0])+f(x(k))

    2. x(k+1)x(k)+Δx

  3. x[1]=x(k+1)

  4. v[1](x[1]x[0])/Δt

where:

  • x[0]: 上一帧位置
  • x[1]: 这一帧位置
  • x(k), x(k+1): 上一次/这一次迭代的位置

large step in cloths simulation中的方法:[游戏物理探秘]理解Large Steps in Cloth Simulation - 知乎

  • 通过backward Euler的推导,得出:

    (IhM1fvh2M1fx)Δv=hM1(f0+hfxv0)

  • 解上面的线性系统 Ax=b.

3. 主流模拟方法

3.1 基于物理的模拟

  1. Mass-spring system

    1. Stretching

    2. Bending Issue

      1. Dihedral angle model
    3. Locking Issue

      1. 本质上,由于自由度缺失,Bending和Stretching不独立
    4. Stiffness Issue

      1. 问题:当stifness大的时候

        1. 显式积分不稳定,需要减小time step

        2. 隐式积分ill-condition,需要增加迭代次数

          • 要解决这些问题,计算量会增大

3.2 非物理的模拟

要满足约束:

ϕ(xi,xj)=||xixj||L=0

L是弹簧的原长

投影的思路:使用投影函数,将不满足约束的顶点投影到约束内

投影的方式:Gauss-Seidel,Jacobi

  1. Position Based Dynamic:弹性由迭代数量,网格精度体现(顶点多,迭代数量多,则布料会显得更有弹性)

    1. 过程:

      1. 先让粒子自由运动
      2. 投影修改粒子的位置,使粒子满足约束
    2. 投影的方式:

      1. Jacobi迭代

      2. GS迭代

    3. 优点:GPU并行

    4. 缺点

      1. 没有物理含义
      2. 顶点多的时候解算很慢,收敛慢
      3. 迭代过多会导致Locking Issue

      解决方案,构建不同分辨率的布料,解算低分辨率的,然后将结果传到高分辨率网格

  2. Strain Limiting(形变约束)

    1. 过程:

      1. 先进行模拟
      2. 投影修改粒子的位置(相当于纠错),使粒子满足约束(把约束放宽)
    2. Spring Strain Limiting(一维的Strain Limiting)

      1. σmin<ϕ(x)<σmax

      2. 或者写成

      3. σmin<1L||xixj||<σmax

      4. (当 σ=1 的时候,就是PBD)

    3. Triangle Area Limiting

      1. 当三角的面积超出了约束范围时,直接对三角形进行缩放使面积满足约束。
  3. Projective Dynamic

    1. 过程:

      1. 先让粒子自由运动

      2. 投影得到新的粒子位置 ,然后用粒子新旧位置更新能量(和原始mass-spring system的力的公式一样)

        E(x)=k2(||xixj||Le)2

      3. 然后依然使用隐式积分

    2. 使用Projective Dynamic,能量的Hessian更简单(常数矩阵)

      f=E=k(||xixj||Le)xixj||xixj||

    3. 优缺点:

      1. 有物理意义
      2. GPU上运行慢
      3. 迭代一开始收敛快,之后收敛慢
  4. Constrained Dynamic

    1. 在隐式积分中引入了对偶变量便于模拟劲度 k 较大的情况

4. Issue

4.1 Locking Issue

Locking Issue: 当Stiffness大时,布料拉不动,也不能弯曲。(比如纸:拉不动,但能弯曲)

解决方法:

  1. 减小弹簧压缩时的弹性系数
  2. 使弹簧可以在一定范围内自由移动,超出范围才开始计算弹力

5. Collision Handling

《GPU Gems 3》Chapter 32

3.1 Collision Culling

Spatial Partitioning/Spatial Hashing(对空间划分)

BVH(对物体划分)

  • self-colision的处理
  • 不易于实现,Not GPU friendly(GPU不易存储树)
  • 更新树时,不需要更新树的结构,只需要更新bounding volumes

3.2 Collision Test

Discrete Collision Detection(DCD)

  • Edge-triangle pairs
  • 只检测某状态是否相交,不能检测穿透

Continuous Collision Detection

  • Vertex-triangle pairs

    • vertex和triangle构成的四面体,面积为0
    • 每个顶点位置都是 t 的一次函数,解一元三次方程(用二分法,3个顶点所以是三次方程)判断四面体面积为0时(即vertex和triangle在同一平面),vertex是否在triangle内
  • Edge-edge pairs

  • 难写,性能消耗大,游戏GPU以单浮点精度为主

碰撞处理:

  • Interior point method

    • 每一次运动后都满足碰撞约束
    • 慢(需要处理所有vertex)
    • Always succeed
  • Impact zone optimization

    • 逃出约束之后,再慢慢纠正
    • 快(只需要处理碰撞的vertex)
    • May not succeed

课后阅读论文:Robust Treatment of Collisions, Contact and Friction for Cloth Animation(TOG SIGGRAPH 2002)

posted @   Heskey0  阅读(1057)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南

本站勉强运行 1191 天 16 小时 09 分 09 秒

喜欢请打赏

扫描二维码打赏

支付宝打赏

点击右上角即可分享
微信分享提示