Performance Comparison of Vertex Block Descent and Position Based Dynamics Algorithms Using Cloth Simulation in Unity
Abstract
:1. Introduction
2. Related Works
2.1. Cloth Simulation
2.2. Position-Based Dynamics
2.2.1. Key Characteristics of Position-Based Dynamics
- Position-Based Approach: The PBD algorithm enforces physical constraints by directly adjusting the positions of objects, rather than utilizing a force-based approach. This allows for physical simulation to be achieved through direct positional modifications.
- Stability: PBD prevents excessive energy accumulation due to external forces by directly correcting position values without the need for velocity calculations. This approach effectively reduces instability in the system.
- Efficiency: The PBD algorithm is notably efficient, especially in collision handling. At each time step, collision constraints are introduced to prevent object penetration. Bender [36] demonstrated that in scenarios involving self-collision, such as cloth movement and overlap, PBD ensures real-time performance, compared to traditional force-based methods.
2.2.2. Key Formula of Position-Based Dynamics Algorithm
- Update location to meet constraintsThe position of the object in the PBD algorithm is updated according to the following equation:
- Distance constraintThe distance constraint between the two vertices and is defined as
2.3. Vertex Block Descent
2.3.1. Key Characteristics of Vertex Block Descent
- Block Coordinate Descent: This method performs vertex-level parallel computation, independently calculating and updating each node of the mesh to maximize parallelism. In particular, mesh coloring techniques are employed to minimize task handling bottlenecks, thereby improving computational efficiency.
- Stability: VBD ensures high stability even under large time steps, making it well suited for real-time simulations. This stability is particularly advantageous when computational resources are constrained, enabling robust results without compromising accuracy.
- Efficiency: By using a localized linear system, VBD achieves relatively low computational cost, thus demonstrating high efficiency in its calculations.
- Optimization for Large-Scale Simulations: The VBD algorithm is adept at handling common optimization challenges inherent in large-scale simulations. It can efficiently manage complex physical interactions, such as object-to-object collisions and self-collisions, even in scenarios involving a substantial number of nodes.
2.3.2. Key Formula of Vertex Block Descent Algorithm
- Minimize global energyThe purpose of the VBD algorithm is to minimize the energy of the entire system. is defined as follows:
- Minimize local energyThe VBD algorithm locally minimizes the energy for each vertex . The local energy of each vertex is defined as
- Update the vertex locationTo update the position of each vertex, we define a linear system using the Hessian matrix and Newton’s method:
2.4. Unity Engine
3. Method
3.1. Position-Based Dynamics Progression
Algorithm 1: Position-Based Dynamics for Cloth Simulation |
1: Initialize cloth mesh, rest positions, and parameters |
2: For each time step: |
3: PredictPositions() |
4: // PBD core loop |
5: For iteration = 1 to solverIterations: |
6: SolveDistanceConstraints() |
7: SolveBendingConstraints() |
8: UpdateVelocitiesAndPositions() |
9: HandleExternalCollisions() |
10: HandleSelfCollisions() |
11: Function PredictPositions(): |
12: For each vertex v: |
13: If v is not pinned: |
14: v.predictedPosition = v.position + timeStep * v.velocity + gravity * timeStep^2 / 2 |
15: Function SolveDistanceConstraints(): |
16: For each edge (v1, v2): |
17: restLength = initialLength(v1, v2) |
18: currentVector = v2.predictedPosition - v1.predictedPosition |
19: currentLength = length(currentVector) |
20: correction = (currentLength - restLength) * currentVector / currentLength |
21: If v1 is not pinned: |
22: v1.predictedPosition += 0.5 * stiffness * correction |
23: If v2 is not pinned: |
24: v2.predictedPosition -= 0.5 * stiffness * correction |
25: Function SolveBendingConstraints(): |
26: For each triangle pair (t1, t2): |
27: Calculate dihedral angle |
28: Calculate bending force |
29: Apply force to vertices of t1 and t2 |
30: Function UpdateVelocitiesAndPositions(): |
31: For each vertex v: |
32: If v is not pinned: |
33: v.velocity = (v.predictedPosition - v.position) / timeStep |
34: v.velocity *= (1 - damping) |
35: v.position = v.predictedPosition |
36: Function HandleExternalCollisions(): |
37: For each vertex v: |
38: If v collides with external object: |
39: Move v to collision surface |
40: Update v.velocity (reflect or absorb) |
41: Function HandleSelfCollisions(): |
42: For each vertex pair (v1, v2): |
43: If distance(v1, v2) < collisionThreshold: |
44: Separate v1 and v2 |
45: Update velocities of v1 and v2 |
- Prediction of Vertex Positions: The algorithm first predicts the subsequent position of each vertex by factoring in its current position, velocity, and gravitational forces. This prediction accounts for the time step, ensuring that pinned vertices remain fixed.
- Constraint Resolution: Physical constraints on the cloth are resolved through multiple iterations. The two primary constraints are the distance constraint and the bending constraint. The distance constraint prevents overstretching or compression by maintaining the original distance between connected vertices, with the stiffness parameter controlling the cloth’s stretch and crumple response. The bending constraint, which manages the extent of bending, is addressed by calculating the angle between adjacent triangles.
- Velocity and Position Update: The new velocity and position of each vertex are then updated based on the predicted positions. A damping parameter is applied in this stage to simulate kinetic energy loss, allowing for the cloth to naturally come to rest, rather than moving indefinitely.
- Collision Handling: Two types of collisions are managed: external collisions (between the cloth and another object) and self-collisions (within the cloth itself). For external collisions, the impacted vertex is repositioned on the collision surface, and its velocity is appropriately adjusted. For self-collisions, when different parts of the cloth come too close, the collision is detected, and the vertices are separated accordingly.
3.2. Vertex Block Descent Progression
Algorithm 2: Vertex Block Descent for Cloth Simulation |
1: Initialize cloth mesh, rest positions, and parameters |
2: For each time step: |
3: AdaptiveInitialization() |
4: // VBD core loop |
5: For iteration = 1 to maxIterations: |
6: For each color in vertexColors: |
7: For each vertex v with current color: |
8: If v is not pinned: |
9: constraint_energy = ComputeConstraintEnergy(v) |
10: hessian = ComputeLocalHessian(v) |
11: deltaX = Solve(hessian, force) |
12: v.position += deltaX |
13: HandleExternalCollisions() |
14: HandleSelfCollisions() |
15: ApplyVelocityUpdate() |
16: Function AdaptiveInitialization(): |
17: For each vertex v: 25 Estimate acceleration |
18: v.predicted_position = v.position + timeStep * v.velocity + estimated_acceleration * timeStep^2 / 2 |
19: Function ComputeConstraintEnergy(v): |
20: energy = ComputeInertiaEnergy(v) |
21: For each neighbor n of v: |
22: energy += ComputeSpringEnergy(v, n) |
23: Return energy |
24: Function ComputeLocalHessian(v): |
25: Compute Hessian matrix based on local deformation |
26: Function Solve(hessian, gradient): |
27: Return hessian^(-1) * gradient |
28: Function HandleExternalCollisions(): |
29: Detect and resolve collisions for each vertex |
30: Function HandleSelfCollisions(): |
31: For each vertex v: |
32: For each other vertex u: |
33: If distance(v, u) < collisionThreshold: |
34: Apply repulsion force between v and u |
35: Update v.position and u.position |
36: // Optional: Continuous Collision Detection (CCD) |
37: For each edge e1: |
38: For each edge e2: |
39: If e1 and e2 intersect: |
40: Resolve edge–edge collision |
- Mesh Initialization: The algorithm initializes the cloth mesh, setting up the initial positions of each vertex and defining necessary parameters, such as stiffness and damping factors.
- Adaptive Initialization: At each time step, the algorithm starts with Adaptive Initialization, where it estimates the acceleration of each vertex, and predicts its next position. This is calculated by integrating the velocity and the estimated acceleration over the time step, with the following formula:v.predicted_position = v.position + timeStep × v.velocity + estimated_acceleration × timeStep2/2
- Iterative Optimization: The algorithm then enters the core iterative loop, which runs for a specified maximum number of iterations. Within each iteration, the vertices are processed based on their assigned color group, where vertices in each color can be optimized independently. This vertex-coloring technique groups vertices to allow for parallel processing. For each vertex v in the current color group:
- Compute Constraint Energy: The algorithm calculates the constraint energy for the vertex, which includes both the inertial energy and the spring energy relative to neighboring vertices. The spring energy helps maintain the original distances between connected vertices, preventing excessive stretching or compression.
- Compute Local Hessian Matrix: The local Hessian matrix is then calculated to capture the local deformable of the vertex. This matrix helps in solving for the position update by approximating the local stiffness of the vertex.
- Solve for Position Update: Using the Hessian and the energy gradient, a linear system is solved to compute the position variation Δx, which is then applied to the position of the vertex.
- Velocity and Damping Update: After all iterations, the algorithm updates the velocity of each vertex based on the changes in position, applying a damping factor to simulate energy loss. This damping allows for the cloth to settle into a resting state, preventing perpetual motion.
- Collision Handling: After updating the positions within each iteration, collision handling takes place:
- External Collisions: For each vertex, collisions with external objects are detected and resolved by repositioning the vertex onto the collision surface, adjusting its velocity accordingly.
- Self-Collisions: For internal cloth collisions, the algorithm checks the distance between vertices. If two vertices come closer than a set collision threshold, a repulsive force is applied to separate them. Edge-to-edge collisions are also managed using Continuous Collision Detection (CCD) to resolve intersections between edges within the cloth.
4. Results
4.1. Hanging Cloth Simulation
4.2. Object-to-Object Collision Cloth Simulation
4.3. Self-Collision Cloth Simulation
4.4. Guidelines for Maintaining Real-Time Performance
5. Discussion
6. Conclusions and Future Works
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Conflicts of Interest
References
- Lloyd, B.; Székely, G.; Harders, M. Identification of spring parameters for deformable object simulation. IEEE Trans. Vis. Comput. Graph. 2007, 13, 1081–1094. [Google Scholar] [CrossRef]
- Ding, W.L.; Zhu, X.J.; Xu, B.; Xu, Y.; Chen, K.; Wan, Z.X. The interactive modeling method of virtual city scene based on building codes. KSII Trans. Internet Inf. Syst. TIIS 2021, 15, 74–89. [Google Scholar]
- Wang, Z.; Han, K.; Tiwari, P. Digital Twin Simulation of Connected and Automated Vehicles with the Unity Game Engine. In Proceedings of the 2021 IEEE 1st International Conference on Digital Twins and Parallel Intelligence (DTPI), Beijing, China, 15 July–15 August 2021; pp. 1–4. [Google Scholar]
- Lee, D.H.; Kim, D.M.; Joo, J.M.; Joo, J.W.; Choi, S.H. A unity-based simulator for tsunami evacuation with devs agent model and cellular automata. J. Korea Multimed. Soc. 2020, 23, 772–783. [Google Scholar]
- Baraff, D.; Witkin, A. Large Steps in Cloth Simulation. In Seminal Graphics Papers: Pushing the Boundaries; Association for Computing Machinery: New York, NY, US, 2023; Volume 2, pp. 767–778. [Google Scholar]
- Liang, J.; Lin, M.; Koltun, V. Differentiable cloth simulation for inverse problems. Adv. Neural Inf. Process. Syst. 2019, 32, 772–781. [Google Scholar]
- Lee, Y.; Yoon, S.E.; Oh, S.; Kim, D.; Choi, S. Multi-Resolution Cloth Simulation. In Computer Graphics Forum; Blackwell Publishing Ltd.: Oxford, UK, 2010; pp. 2225–2232. [Google Scholar]
- Volino, P.; Thalmann, N.M. Implementing Fast Cloth Simulation with Collision Response. In Proceedings of the Computer Graphics International 2000, Geneva, Switzerland, 19–24 June 2000; pp. 257–266. [Google Scholar]
- Müller, M.; Heidelberger, B.; Hennix, M.; Ratcliff, J. Position based dynamics. J. Vis. Commun. Image Represent. 2007, 18, 109–118. [Google Scholar] [CrossRef]
- Terzopoulos, D.; Platt, J.; Barr, A.; Fleischer, K. Elastically Deformable Models. In Proceedings of the 14th Annual Conference on Computer Graphics and Interactive Techniques, Anaheim, CA, US, 27–31 July 1987; pp. 205–214. [Google Scholar]
- Terzopoulos, D.; Fleischer, K. Deformable models. Vis. Comput. 1988, 4, 306–331. [Google Scholar] [CrossRef]
- Desbrun, M.; Schröder, P.; Barr, A. Interactive Animation of Structured Deformable Objects. Graph. Interface 1999, 99, 10. [Google Scholar]
- Jaramillo, A.; Prieto, F.; Boulanger, P. Deformable part inspection using a spring–mass system. Comput.-Aided Des. 2013, 45, 1128–1137. [Google Scholar] [CrossRef]
- Reddy, J.N. An Introduction to the Finite Element Method; McGraw Hill: New York, NY, USA, 1993. [Google Scholar]
- Nikishkov, G.P. Introduction to the Finite Element Method; University of Aizu: Aizuwakamatsu, Japan, 2004; pp. 1–70. [Google Scholar]
- Aziz, A.K. The Mathematical Foundations of the Finite Element Method with Applications to Partial Differential Equations; Academic Press: Cambridge, MA, USA, 2014. [Google Scholar]
- Zeller, C. Cloth Simulation on the Gpu. In ACM SIGGRAPH 2005 Sketches; Association for Computing Machinery: New York, NY, US, 2005. [Google Scholar]
- Wang, H. A chebyshev semi-iterative approach for accelerating projective and position-based dynamics. ACM Trans. Graph. 2015, 34, 246. [Google Scholar] [CrossRef]
- Deul, C.; Charrier, P.; Bender, J. Position-based rigid-body dynamics. Comput. Animat. Virtual Worlds 2016, 27, 103–112. [Google Scholar] [CrossRef]
- Gast, T.F.; Schroeder, C.; Stomakhin, A.; Jiang, C.; Teran, J.M. Optimization integrator for large time steps. IEEE Trans. Vis. Comput. Graph. 2015, 21, 1103–1115. [Google Scholar] [CrossRef] [PubMed]
- Wang, J.; Shi, R.; Zheng, W.; Xie, W.; Kao, D.; Liang, H.N. Effect of frame rate on user experience, performance, and simulator sickness in virtual reality. IEEE Trans. Vis. Comput. Graph. 2023, 29, 2478–2488. [Google Scholar] [CrossRef]
- Claypool, K.T.; Claypool, M. On frame rate and player performance in first person shooter games. Multimed. Syst. 2007, 13, 3–17. [Google Scholar] [CrossRef]
- Chen, J.Y.; Thropp, J.E. Review of low frame rate effects on human performance. IEEE Trans. Syst. Man Cybern. Part A Syst. Hum. 2007, 37, 1063–1076. [Google Scholar] [CrossRef]
- James, D.L.; Pai, D.K. Artdefo: Accurate Real Time Deformable Objects. In Proceedings of the 26th Annual Conference on Computer Graphics and Interactive Techniques, Los Angeles, CA, USA, 8–13 August 1999; pp. 65–72. [Google Scholar]
- Brown, J.; Sorkin, S.; Bruyns, C.; Latombe, J.C.; Montgomery, K.; Stephanides, M. Real-Time Simulation of Deformable Objects: Tools and Application. In Proceedings of the Computer Animation 2001 Fourteenth Conference on Computer Animation (Cat. No. 01TH8596), Seoul, Republic of Korea, 7–8 November 2001; pp. 228–258. [Google Scholar]
- Berenson, D. Manipulation of Deformable Objects Without Modeling and Simulating Deformation. In Proceedings of the 2013 IEEE/RSJ International Conference on Intelligent Robots and Systems, Tokyo, Japan, 3–7 November 2013; pp. 4525–4532. [Google Scholar]
- Oshita, M.; Makinouchi, A. Real-Time Cloth Simulation with Sparse Particles and Curved Faces. In Proceedings of the Computer Animation 2001 Fourteenth Conference on Computer Animation (Cat. No. 01TH8596), Seoul, Republic of Korea, 7–8 November 2001; pp. 220–227. [Google Scholar]
- Mohammed, M.; Al-Sharify, T.; Kolivand, H. Real-time cloth simulation on virtual human character using enhanced position based dynamic framework technique. Baghdad Sci. J. 2020, 17, 1294. [Google Scholar]
- Va, H.; Choi, M.H.; Hong, M. Real-time cloth simulation using compute shader in Unity3D for AR/VR contents. Appl. Sci. 2021, 11, 8255. [Google Scholar] [CrossRef]
- Provot, X. Deformation Constraints in a Mass-Spring Model to Describe Rigid Cloth Behaviour. In Graphics Interface; Canadian Information Processing Society: Mississauga, ON, Canada, 1995; p. 147. [Google Scholar]
- Sin, F.S.; Schroeder, D.; Barbič, J. Vega: Non-Linear FEM Deformable Object Simulator. In Computer Graphics Forum; Blackwell Publishing Ltd.: Oxford, UK, 2013; pp. 36–48. [Google Scholar]
- Bender, J.; Erleben, K.; Trinkle, J. Interactive simulation of rigid body dynamics in computer graphics. Comput. Graph. Forum 2014, 33, 246–270. [Google Scholar] [CrossRef]
- Jakobson, T. Advanced character physics. Game Dev. Conf. 2001, 3, 383–401. [Google Scholar]
- Macklin, M.; Müller, M.; Chentanez, N. XPBD: Position-Based Simulation of Compliant Constrained Dynamics. In Proceedings of the 9th International Conference on Motion in Games, Lisbon, Portugal, 1–4 November 2016; pp. 49–54. [Google Scholar]
- Chen, A.H.; Liu, Z.; Yang, Y.; Yuksel, C. Vertex Block Descent. ACM Trans. Graph. 2024, 43, 1–16. [Google Scholar] [CrossRef]
- Bender, J.; Müller, M.; Macklin, M. A Survey on Position Based Dynamics. In Proceedings of the European Association for Computer Graphics: Tutorials, Lyon, France, 8–12 May 2017; pp. 1–31. [Google Scholar]
- Xu, Y.; Kim, E.; Lee, K.; Ki, J.; Lee, B. Using physX simulation fire model of backdraft in unity 3D game engine. Int. J. Multimed. Ubiquitous Eng. 2014, 9, 243–252. [Google Scholar] [CrossRef]
- Mohan, D.M.; Zhong, Y.; Smith, J.; Ehrampoosh, A.; Shirinzadeh, B. Soft-Tissue Deformation Model for Virtual Reality-Based Surgery Training Using Unity3D. In Proceedings of the 2024 IEEE 18th International Conference on Advanced Motion Control (AMC), Hsinchu, Taiwan, 25–27 March 2024; pp. 1–6. [Google Scholar]
- Lee, S.; Koo, A.; Jhung, J. Moskit: Motion Sickness Analysis Platform for VR Games. In Proceedings of the 2017 IEEE International Conference on Consumer Electronics (ICCE), Las Vegas, NV, USA, 7–11 January 2017; pp. 17–18. [Google Scholar]
Algorithm | Advantages | Disadvantages |
---|---|---|
Mass-Spring System |
|
|
FEM |
|
|
PBD |
|
|
VBD |
|
|
Name | Specification |
---|---|
CPU | Intel i7-13700, 2.1 GHz |
GPU | Nvidia GeForce RTX 4070 Ti, 12 GB VRAM |
Memory | 64 GB |
Dev Tool | Unity 2022.3.30f1 |
Hanging | 8 × 8 Nodes | 64 × 64 Nodes | 128 × 128 Nodes |
---|---|---|---|
VBD | 490.3 fps | 202.8 fps | 75.2 fps |
PBD | 489.1 fps | 132.3 fps | 41.4 fps |
Comparison | 0.20% | 53.0% | 82.9% |
Object Collision | 8 × 8 Nodes | 32 × 32 Nodes | 64 × 64 Nodes |
---|---|---|---|
VBD | 425.4 fps | 171.1 fps | 58.3 fps |
PBD | 398.7 fps | 141.5 fps | 44.3 fps |
Comparison | 6.7% | 21.2% | 31.1% |
Self-Collision | 8 × 8 Nodes | 16 × 16 Nodes | 32 × 32 Nodes |
---|---|---|---|
VBD | 338.2 fps | 83.1 fps | 7.4 fps |
PBD | 312.3 fps | 77.7 fps | 6.8 fps |
Comparison | 8.3% | 7.8% | 8.8% |
Node × Node (Total Nodes) | fps | |
---|---|---|
Hanging | ||
VBD | 120 × 120 (14,400) | 30.1 |
PBD | 93 × 93 (8649) | 30.6 |
Object-to-object collision | ||
VBD | 92 × 92 (8464) | 30.2 |
PBD | 80 × 80 (6400) | 30.1 |
Self-collision | ||
VBD | 23 × 23(529) | 30.1 |
PBD | 21 × 21(441) | 31.5 |
Time Step | 0.01 s | 0.02 s |
---|---|---|
VBD | 100–101.5% | 100–101.8% |
PBD | 100–101.1% | 100–107.4% |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2024 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Ma, J.; Sung, N.-J.; Choi, M.-H.; Hong, M. Performance Comparison of Vertex Block Descent and Position Based Dynamics Algorithms Using Cloth Simulation in Unity. Appl. Sci. 2024, 14, 11072. https://doi.org/10.3390/app142311072
Ma J, Sung N-J, Choi M-H, Hong M. Performance Comparison of Vertex Block Descent and Position Based Dynamics Algorithms Using Cloth Simulation in Unity. Applied Sciences. 2024; 14(23):11072. https://doi.org/10.3390/app142311072
Chicago/Turabian StyleMa, Jun, Nak-Jun Sung, Min-Hyung Choi, and Min Hong. 2024. "Performance Comparison of Vertex Block Descent and Position Based Dynamics Algorithms Using Cloth Simulation in Unity" Applied Sciences 14, no. 23: 11072. https://doi.org/10.3390/app142311072
APA StyleMa, J., Sung, N.-J., Choi, M.-H., & Hong, M. (2024). Performance Comparison of Vertex Block Descent and Position Based Dynamics Algorithms Using Cloth Simulation in Unity. Applied Sciences, 14(23), 11072. https://doi.org/10.3390/app142311072