WebGPU Cloth Simulation 01 - Project & Research Planning

Research Question

What are the technological challenges and solutions in developing an accurate and widely accessible virtual fitting technology that can adapt to diverse body types and garments?


Notable Challenges

- Accurate Body Measurement and Modeling for diverse body types.

- Simulating the physical behavior of different fabrics under various conditions is computationally intensive and requires detailed physical models.

- Real-time virtual fitting demands highly optimized algorithms and significant computational resources.

- The lack of standardization in how digital garments are shared across platforms and virtual fitting solution.

- Ensuring the technology performs well across a range of devices is difficult.



Preliminary Research

    - Real-time Cloth Physical Simulation Techniques

    - Collision Detection & Response Techniques

    - Web-based Multi-Threading & Parallel Processing


1. Existing Cloth Simulation Techniques




    - Particle System

Cloth is discretized into a set of particles. These particles are often arranged in a grid-like pattern, corresponding to the vertices of the cloth mesh. Forces (e.g., gravity, wind) are applied to particles, and constraints (e.g., distance constraints to maintain the cloth's structure, bending constraints for stiffness) are defined to simulate the physical properties of the fabric.

The system's state is updated over time by numerically integrating the forces acting on each particle, adjusting their velocities and positions to simulate movement and deformation. Collision Handling: Interactions with external objects and self-collisions within the cloth are detected and resolved to prevent particles from penetrating other objects or each other.


    - Mass-Spring System

The vertices of the mesh representing the object are treated as point masses. These masses are subject to forces like gravity, external forces (e.g., wind), and forces exerted by the springs. The edges between the masses act as springs with properties such as stiffness and damping. The springs can be configured to simulate various material properties, including stretch resistance, shear resistance, and bending resistance.

At each step of the simulation, the forces on each mass are computed based on the spring forces and any external forces. The positions and velocities of the masses are then updated using numerical integration methods (e.g., Euler integration, Verlet integration).


    - Finite Element Method (FEM)

The FEM divides a complex problem into many smaller, simpler parts called finite elements. The domain is typically a physical structure, and the elements are often triangles (in 2D) or tetrahedra (in 3D), although other shapes can be used. For each element, the method formulates a local problem. Then, it approximates the field variables using simple functions that vary over each element, such as linear or quadratic polynomials. The local problems are then assembled into a global system of equations that models the entire problem. Boundary conditions are applied to the global system to reflect the physical constraints of the problem. The global system of equations is solved, typically using numerical techniques like matrix solvers, to find the approximate solution to the original problem.


    - Position-Based Dynamics (PBD)

The system's state is defined in terms of positions and potentially velocities of particles or vertices representing the object. Constraints are defined to represent the physical properties of the system, such as rigidity, elasticity, volume preservation, and collision avoidance. The positions of particles are iteratively adjusted to satisfy these constraints. This process may involve projecting the current state onto a set of feasible states that comply with the constraints. The positions are updated based on the solved constraints, and velocities may be derived from the position changes to handle dynamic effects and damping.


    - Discrete Differential Geometry (DDG)

The continuous surfaces of the cloth are represented using discrete elements (e.g., triangles in a mesh). This discretization allows the simulation to approximate complex geometries and deformations. DDG techniques are used to calculate discrete equivalents of continuous geometric properties, such as discrete curvature. These properties influence how the cloth bends and folds, contributing to its realistic behavior. The physical behavior of the cloth, influenced by its geometric properties, is simulated by applying forces and constraints. DDG provides the framework to incorporate these geometric considerations directly into the simulation algorithms.


    - Extended Position-Based Dynamics (XPBD)

XPBD introduces compliance parameters to the constraints, which control the 'give' or elasticity of the constraint. This addition enables the simulation of materials that exhibit a range of stiffness properties, from very soft and elastic to almost rigid, within the same framework. XPBD utilizes Lagrange multipliers in its constraint resolution scheme, which helps in maintaining stable simulations even under large time steps or when dealing with highly stiff materials. By addressing some of the numerical stability issues inherent in the original PBD approach, especially when simulating stiff materials, XPBD provides a more robust framework for simulating a wide variety of physical behaviors.


    - Machine Learning-based Model

    a. Data-Driven Simulations: Machine Learning models for soft body simulations are trained on datasets comprising observations of real or high-fidelity simulated fabric behaviors. These models learn the underlying physics and deformation characteristics of materials from the data.

    b. Neural Networks and Deep Learning: Deep learning models, particularly those involving neural networks, are commonly used due to their ability to handle high-dimensional data and learn complex mappings between inputs (e.g., forces, initial states) and outputs (e.g., subsequent deformations).

    c. Generalization and Prediction: Once trained, these models can generalize to new scenarios not seen during training, predicting the material's response to various forces and interactions efficiently.

Examples: 

 Deep Cloth: https://www.liuyebin.com/DeepCloth/files/paper.pdf

Learning-Based Animation of Clothing for Virtual Try-On: https://arxiv.org/pdf/1903.07190.pdf



2. Collision Detection Techniques




    - Broad Phase & Narrow Phase Collision Detection

The goal of the Broad Phase is to quickly identify pairs of objects that might be colliding. It's about eliminating as many object pairs as possible from further checks, focusing on pairs that are definitely not colliding due to their spatial separation. This phase doesn't check for actual collisions; instead, it narrows down the number of potential collision pairs through various algorithms:

        AABB (Axis-Aligned Bounding Boxes)

        - Spatial Partitioning

        - Sweep and Prune

After potential collisions are identified in the Broad Phase, the Narrow Phase involves detailed checks between these potential pairs to determine if a collision actually occurs and to calculate the collision response. This phase is computationally more intensive, hence performed on a smaller set of object pairs.

        - GJK (Gilbert-Johnson-Keerthi) Algorithm

        - EPA (Expanding Polytope Algorithm)

        - SAT (Separating Axis Theorem)


    - Hierarchical Collision Detection

Particles are grouped hierarchically under bounding volumes. Start collision detection from the top of the hierarchy and drill down, allowing for early dismissal of non-colliding particles or sections of the fabric

    - Continuous Collision Detection (CCD)

For the rigid body, use CCD to accurately detect collisions with high-speed movement, ensuring that no collision is missed between simulation steps. This is crucial for avoiding scenarios where the rigid body might pass through the fabric due to fast motion.

    - Temporal Coherence

Leverages the fact that physical systems change gradually over time, meaning the set of colliding objects doesn't change dramatically between simulation steps. This allows reusing results from previous steps to speed up current calculations.

    - Level of Detail (LoD)

For distant interactions or less critical collision checks, use a lower level of detail for the fabric's physical model, simplifying the number of particles or constraints considered during the collision detection process.

    - Gauss-Seidel (PGS) method

For the fabric, optimize the constraint solver that maintains the soft body's shape and volume during interactions. Techniques such as Projected Gauss-Seidel can be efficient for solving constraints iteratively without requiring the computation of a global system matrix.

    - Impulse-based Methods

Utilize impulse-based methods to calculate the collision response for the rigid body, which can handle complex interactions efficiently without requiring the full resolution of forces at each timestep.


3. Multi-Threading & Parallel Processing



    a. CPU Multi-Threading Tools

        - Web Worker

    b. GPU Parallel Processing Tools

        - WebGPU



Potential Projects

1. Algorithm Optimization Methods

    - Simulation Techniques Testing

    - Muti-Threading & Parallel Processing Techniques Testing

    - Step 1: Divide the Workload

Divide your simulation space into segments or use a workload-based approach where each worker is responsible for a subset of the physics bodies. This division can be spatial or functional.

    - Step 2: Implement Multiple Workers

Create several Web Worker scripts that each handle a portion of the physics simulation. You'll need to establish a protocol for how these workers communicate with the main thread and potentially with each other.

    - Step 3: Main Thread to Workers Communication

The main thread initializes workers and distributes the workload among them. It sends updates about physics bodies that might move between workers' domains and handles the collection and aggregation of simulation results.

    - Step 4: Worker to Worker Communication

In some cases, you might need direct communication between workers, especially for handling interactions between objects that are on the edge of their assigned segments. This can be done by establishing a messaging system where workers can send and receive updates from their neighboring workers.

    - Step 5: Aggregating Results

The main thread collects results from all workers, consolidates them, and updates the visual representation accordingly. This includes updating positions, rotations, and any other relevant properties of the objects in the scene.

    - Collision Detection Techniques Testing


2. Fabric Behavior Simulation Models

    - Simulation Techniques Testing

    - Model Development

    - Fabric Types: Select a range of fabrics with differing characteristics (e.g., cotton, silk, denim, leather) to model.

    - Physical Properties: Define the key physical properties to simulate (e.g., elasticity, weight, friction, drape).

    - Environmental Conditions: Identify the environmental conditions to simulate (e.g., wind, humidity, movement).















Comments