Home

Awesome

GPU Cloth Simulation

cloth with force visualizationcloth with diffuse render
titleimagetitleimage

This repository is about GPU based Mass-Spring Simuation in Unity. Based upon Compute Shader, calculates physics in parallel.

This project is a sub project of ReclothSimulation-master, a private repository, some of features are removed in this repo.

Currently Confirmed working on following platforms:

How to use

Create a empty GameObject on hierarchy panel and append ClothSimuation and ClothRenderer scripts on it. Since this simulation calculates with its own system, you'll need special materials and dedicated shaders for rendering. There are two example materials(Face Normal Rendering, Diffuse Rendering).

Attributes

Cloth Simulation

Compute Shaders
attributesdescription
NodeUpdateComputeShadera compute shader which updates forces, positions, velocities, etc.
TriCollisionResponseComputeShadera compute shader which calculates collision with floor
NormalComputeShadera compute shader which calculates all face normals of the cloth model
Attribute of Cloth
attributesdescription
VertexColumnnumbers of nodes in a Column
VertexRownumbers of nodes in a Row
ClothSizeSize of cloth object in Unity world scale
ClothMassMass of cloth object
Looperamount of looping compute shaders per frame, larger number for precise, slower simulation
Constant for Cloth
attributesdescription
SpringKspring force from Hooke's Law
Dampingdamping coefficient for cloth simulation
External Forceexternal forces such as wind, water etc. since it is public member, you can pass from external scripts

Cloth Renderer

attributesdescription
Mata material for Cloth Object.
LightGameObjecta light-type Gameobject, especially for diffuse rendering. Directional light recommended.
MeshTopologywhich element to draw Cloth: currently triangles supported, but you can write your own shader for others.

Caveats

Since the simulation is not pretty stable, certain values for the clothSimulation scripts are recommended:

recommended parameters of Attribute of Cloth

attributesvalues
vertexColumn8 ~ 64
vertexRow8 ~ 64
Looper20 ~ 500, larger values for more stable simulation

recommended parameters of Constant of Cloth

attributesvalues
SpringK10000~ 50000, but for a non-elastic behaving typical cloth, values around 35000 is recommeded
Damping100~200, can be vary by SpringK

recommended parameters of Cloth Renderer

attributesvalues
Matrequires custom shaders, look at the normalShader and DifwithShadows in shader->render directory.
LightGameObjectDirectional Light is highly recommended
MeshTopologyYou can use all of MeshTopology types, but you should write your own shaders. The embedded two shaders use MeshTopology.Triangles.

Performance

Since this project uses Unity engine and GPU computing, it runs on most platforms, even mobile in real-time. But the performance heavily depends on the size of the model's triangles which you want to make it collided

Contact

You can contact Minsang Kim via e-mail(ben399399@gmail.com).

License

This Project is licensed under the MIT License

Copyright (c) 2018 Minsang Kim

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Acknowledge

This work was supported by the National Research Foundation of Korea(NRF) grant funded by the Korea government(Ministry of Science, ICT & Future Planning) (No. 2017R1A2B1005207).