Giter Site home page Giter Site logo

nixon-voxell / gpuclothsimulationinunity Goto Github PK

View Code? Open in Web Editor NEW
162.0 7.0 14.0 205.87 MB

Trying to replicate what this legend did: https://youtu.be/kCGHXlLR3l8

License: MIT License

C# 88.10% ShaderLab 2.00% HLSL 9.90%
cloth cloth-simulation position-based-dynamics pbd gpu-cloth-simulation gpu-accelerated-library gpu-computing compute-shader compute-shaders

gpuclothsimulationinunity's Introduction

GPU Cloth Simulation For Real-time Application

This repository is still currently under development, so everything is still in testing mode. A lot of things will break, download at your own risk :/

Disclaimer: This project is in a paused state so there won't be more updates. In the future, if there are any changes to this project, I will post an issue update on this repository. Stay tune!

My goal is to replicate what this legend did: https://youtu.be/kCGHXlLR3l8 (A smooth and interactive cloth simulation)

Currently, my cloth simulation uses Postion Based Dynamics and supports:

  • Distance Constraint
  • Bending Constraint
  • Point Triangle Distance Constraint (Self Collision)
  • Aerodynamics (Wind Effect)

Features comming soon:

  • Vivace Gauss Seidel Method for optimization on GPU (random graph coloring)
  • Primitive Shape Collision (Sphere, Box and Capsule)

Check out my YouTube Playlist where I record my journey on how I approach this problem!

Support me on Patreon so that I can allocate more time to work on this project!

How to use?

*Note: The GPU version is not fully developed yet, this tutorial section will not work for the GPU version.

  1. Create a mesh in Blender that you want to simulate.
  2. Use my custom Blender Addon - Blender Mesh to JSON to transform your mesh into PBD form and export it into your Unity's StreamingAssets folder.
  3. Create an empty GameObject in Unity.
  4. Drag and drop CPUClothSimulation.cs or GPUClothSimulation.cs script onto the GameObject. (Check Cloth Configurations for more cloth parameters' information.)
  5. Select the correct JSON file that the Blender Cloth Exporter Tool exports using the button - Select JSON File.
  6. Press the button - Load Data from JSON.
  7. Put in your Front Material and Back Material.
  8. Press Build Mesh to build the mesh that you have modeled in Blender.
  9. Press Create Back Side to build the other side of the mesh.
  10. Press Apply Materials to apply materials on both sides.

Cloth Configurations

These are the similar parameters in both CPU and GPU Cloth Simulation:

Materials

This determines the front material and back material for the cloth.

ClothSimParam

Tweak these parameters to change the behaviour for the cloth.

  1. Gravity: Constant acceleration.
  2. Compression Stiffness: Coefficient for distance constraint when 2 particles are too close together.
  3. Stretch Stiffness: Coefficient for distance constraint when 2 particles are too far away.
  4. Bending Stiffness: Coefficient for bending constraint when 2 neighbor triangles are not at their rest angle.
  5. Thickness: Cloth thickness for all collisions.
  6. Damping: Multiplier of velocity for every simulation to reduce velocity (as air resistance).

Simulation

Tweak these parameters to balance between accuracy and performance.

  1. Iteration Steps: Number of iterations to solve constraints for every simulation.
  2. Delta Time Step: Time pass between 2 simulations.
  3. Start Simulation On Play: Choose if you want to start the simulation once you enter play mode.

License

This project is under MIT License.

gpuclothsimulationinunity's People

Contributors

nixon-voxell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gpuclothsimulationinunity's Issues

Technical doubts about the implementation of PBD cloth based on GPU

Why is it suspended? No maintenance. Is GPU parallel data disordered during collision? Why do you have your own Json format in blender? Is there any problem with the vertex sorting of cloth mesh in the forum of unity? Is it because the algorithm of calculating shader to achieve PBD must be handled in this way?
企业微信截图_a932c948-33fd-4601-b521-5f05a218f4ec
企业微信截图_596899a1-03e8-4274-9771-f49cc763a8f5

Display error of running program unity

企业微信截图_8cca59d1-9d9e-40ee-a0b4-c76889af3c7d

Or display such an error:
`UnassignedReferenceException: The variable clothSolver of GPUClothSimulation has not been assigned.
You probably need to assign the clothSolver variable of the GPUClothSimulation script in the inspector.
GPUClothSimulation.SimulateOneTimeStep () (at Assets/GPUClothSimulation/Scripts/GPUClothSimulation.cs:137)
GPUClothSimulation.Update () (at Assets/GPUClothSimulation/Scripts/GPUClothSimulation.cs:113)

NullReferenceException: Object reference not set to an instance of an object
GPUClothSimulationLegacy.DispatchKernels () (at Assets/GPUClothSimulation/Scripts/GPUClothSimulationLegacy.cs:445)
GPUClothSimulationLegacy.FixedUpdate () (at Assets/GPUClothSimulation/Scripts/GPUClothSimulationLegacy.cs:204)

IndexOutOfRangeException: Index was outside the bounds of the array.
GPUClothSimulation.Start () (at Assets/GPUClothSimulation/Scripts/GPUClothSimulation.cs:97)`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.