Search Unity

[RELEASED] Cloth Dynamics

Discussion in 'Assets and Asset Store' started by Nexusmaster, Dec 9, 2020.

  1. Jahvan

    Jahvan

    Joined:
    Feb 1, 2017
    Posts:
    7
    Is it possible to use the HDRP silk shader with this or to set up something similar?
     
  2. xiaoxiaoxh124

    xiaoxiaoxh124

    Joined:
    Aug 11, 2020
    Posts:
    5
    Hi, I want to manipulate clothes(i.e. folding or flatting a T-shirt) with hands on a table-top scene. I mainly care about the physics simulation rather than the rendering quality.
    I have a few questions:
    1. If I turn on self-collision, can it run at real-time on a RTX 3090 GPU with cloth mesh that contains ~10K vertices?
    2. Does it support multi-GPU? If I have multiple GPU, will it run faster?
    3. Can I add or remove pin constraint dynamically at runtime? For example, I want to attach one vertex of the cloth to my hand mesh when the hand touches the cloth, and releases the attachment when needed.
    4. Does it support VR in the latest version?

    I already bought Obi Cloth, but it is too slow to support our need. If Cloth Dynamics is efficient enough and have these properties, I will definitely buy it!
     
  3. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    Hi, should be possible, try to use the cloth subgraph and link the outputs to vertex, normal and tangent input.
     
  4. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    1. Yes, should be no problem with 10k cloth, see the latest demo on the asset store, there is a scene with 2 cloth objects using self collision.
    2. I didn't test it. You can test it by downloading the demo or one of the free github Unity sources, that use compute shaders.
    3. You can add constraints to your scene and turn them off and on during runtime. Currently they get cached in a list to the CD component at the start.
    4. VR should work, but i didn't try it. Cloth Dynamics does not use any camera effects that affect stereo view, however you might need to turn off the cloth frustum culling or increase the bbox. Both options can be set in the gpu cloth dynamics inspector. Maybe the Projection Mask does not work in VR, but it sounds like, that you don't need it.
    If it doesn't work for you, you can get a refund!
     
    Last edited: Sep 7, 2021
  5. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    I checked the FightSceneHD, it has 105.696 triangles in total, one T-Shirt has 34.668 and the Trousers 18.180 triangles. The total cloth vertex count of this scene is 55.682.
     
    Last edited: Sep 7, 2021
  6. Jahvan

    Jahvan

    Joined:
    Feb 1, 2017
    Posts:
    7
    Hi again. So after buying and playing around with this asset, I can definitely say that I'm pleased with it. There's just a few things holding me back from using it in my project, and it mostly comes down to the fact that my character mesh can change drastically during runtime. (Think character creator with body sliders and such)

    The main issues I'm facing are:

    1. My character shader already uses every vertex color for specific things. I'd like to do the same with my clothing shader, but this would conflict with the weighted cloth blending functionality, no? Would it be possible to add the option of using a texture instead of vertex colors for that kind of thing?

    2. The collidable surface of a skinned mesh updates accordingly for bones, but blend shapes have no effect. Or am I missing something?

    3. Vertex positions for my character mesh can change during runtime, but updating the mesh itself has no effect on the collisions. Makes sense since you'd normally only need to get the vertex positions once. Is there some way I can apply changes to the vertices used for collision or would that break everything?

    If these problems are more than trivial to solve then don't mind me - just figured I'd ask.
     
  7. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    Thanks for your support!
    1. Yes, I want to fix this anyway, best would be if the shader graph supports vertex IDs. Maybe with Unity 2021 beta, which version are you using btw.?
    2. You are right, currently there is a lack of blend shape support. I will have a look how hard it is to add this.
    3. This sounds more tricky, but it is possible to apply, are you using CPU or GPU vertex modifications?

    Most of these issues can be fixed, when I add the new Unity 2021 Vertex Buffer, so if you want to work with the Unity beta version, you can soon use this.
    https://docs.unity3d.com/2021.2/Doc...ence/SkinnedMeshRenderer.GetVertexBuffer.html
    I already started with it, there are just some transformation issues that will take so time to fix, but I think it's possible.
     
  8. Jahvan

    Jahvan

    Joined:
    Feb 1, 2017
    Posts:
    7
    Sounds good! I'm already on the beta version and can upgrade as necessary. The vertex modifications take place on the CPU. If it ends up being possible to update the collision vertices, then I can similarly apply blend shapes on the CPU for now
     
  9. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    Update: Currently there is an issue with the NeighbourCheck and Self Collision system, I will try to fix this asap. Sorry about that, it must have been sneaked in when I did some changes. For now just turn off "Use Neighbour Check".
     
  10. Boopnetic

    Boopnetic

    Joined:
    Jul 31, 2018
    Posts:
    2
    Hey there- I'm interested in buying Cloth Dynamics but have some DAZ questions.

    1) You selected a dforce dress in the unity workflow video. Do you have to have dforce applied to clothing for Cloth Dynamics to work?
    2) In the unity workflow video. You imported the model into blender instead of directly into Unity3D using the DaztoUnity bridge. Is the blender step absolutely required? (wMagicaCloth this isn't required)
     
  11. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    Hi, the video just showed my personal workflow, but you can do it completely different, Cloth Dynamics just needs a mesh, you basically can use any mesh as a cloth mesh, however the results will differ, normally I recommend a uniform mesh, where all edges have the same distances. e.g. Marvelous Designer.
    I never tried DazToUnity, because with the Diffeomorphic Blender plugin I have many options to edit the mesh, also in Blender I can decimate the mesh to make it more low poly.
     
  12. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    Hi, I finally found the bug which caused a slowdown with self collision (and NeighbourCheck).
    I will upload a new version with the fix today! Sorry for the delay!
     
  13. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    So, I sent the latest version 1.6.7 to the asset store! Will be soon available!
    Please DELETE the old ClothDynamics/Resources Folder before updating!
    Thanks!
     
  14. xiaoxiaoxh124

    xiaoxiaoxh124

    Joined:
    Aug 11, 2020
    Posts:
    5
    Hi! Does this plugin support self-friction? For example, if I try to fold clothes, are there some kind of friction forces between the cloth's own particles?
     
  15. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    You can use the static friction slider for mesh collision. There is also a friction component, which works with primitive objects. The dynamic friction slider affects the primitive collisions globally.
     
  16. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    The new version 1.6.7 is now online, please update!
     
  17. regddfgdf

    regddfgdf

    Joined:
    Feb 25, 2020
    Posts:
    2
    Hello! Does Cloth Dynamics support scaling object with cloth at runtime?
     
  18. mahna3411

    mahna3411

    Joined:
    Dec 11, 2018
    Posts:
    39
    hi ,
    I bought this package that I can use it on all systems, but I get the Platform error does not support compute shaders,
    Does this package only work on systems that support compute shaders?
     
  19. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    Hi, sorry but you could have read the description on the asset store:
    "
    Description
    Cloth Dynamics is a fast and advanced particle-based physics system mostly running on the GPU with compute shaders.
    Additional compatibility information
    NO WebGL support !!!
    "
    Currently WebGL is the only "platform" I know that doesn't support all compute shaders (and also old mobile phones..)

    Which platform are you using?

    Send me an email please with your invoice no. and I can give you a refund.
     
    Last edited: Sep 30, 2021
    mahna3411 likes this.
  20. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    At the moment it does not work out of the box, I will add this feature to my TODO list.
     
  21. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    Thank you everyone for been so patient the last weeks, I was very busy, but now I will try to finish the user requests and update the documentation! I think it makes more sense to finish the new features first and then update the docs.
     
    Last edited: Sep 30, 2021
  22. mahna3411

    mahna3411

    Joined:
    Dec 11, 2018
    Posts:
    39




    I got this asset for a friend of mine. If you repay it, thank you very much,
    I'm sorry I did not see the description of compute shaders
    I wanted to use it on all Android phones, but only a limited number of Android devices support compute shaders.

    And I did not find your email to send the invoice
     
  23. SpencerIO

    SpencerIO

    Joined:
    Oct 8, 2013
    Posts:
    6
    @Nexusmaster, I've been publishing the cloth dynamics examples to mobile and I haven't seen a scene that will work without some kind of issue out of the box. I am publishing to iPhone 12 Pro. For example the AnimeCharacter scene, the dress is flowing but the top is not on the character. The DressNoPC scene, the dress just explodes. Are there any examples you would say run well on iOS?
     
  24. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    Hi, yes there are currently not many examples that work on mobile, I will add a mobile example scene, that is a good idea! What I tried is the AnimeCharacter, but I just used the skirt as a cloth object and turned off the "Collision Finder".
    Here is a quick test, sorry the settings are not perfect, need to fix the skin overlapping via projection mask:


    (This gif video looks kind of slow, but normally this runs faster, I think this is from the avi to gif conversion.)
     
    Last edited: Oct 6, 2021
  25. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    Tomorrow, I will update the new changes,
    today I had to release my first steam page:
    https://store.steampowered.com/app/1773990/Power_Pushout/




    This is my first game using Cloth Dynamics, this game will also be released on mobile later.

    I have a deal for anyone how wants to support me and my products:
    When 'Power Pushout' comes out and you write a review about it in the first week, you can get Cloth Dynamics or my next new asset for free! (After verifying your steam username.)

    I can't say much about the new asset yet, but it will be similar to some new features of UE5.

    Btw.: It also helps if you add Power Pushout to your Wishlist and follow it, so I get more awareness from the steam bot/ai system, which will give the product more visibility. I will do the same for your game if anyone needs the support! I also offer to write reviews for other game devs, we need to work together!
     
    Last edited: Oct 6, 2021
  26. tiggaxxx

    tiggaxxx

    Joined:
    Jan 13, 2020
    Posts:
    18
    I have this project which is kinda a character creator, where the base mesh has blend shapes and the character is animated, somehow like posing. And i want the clothes to have realtime simulation. I have tried other cloth simulators but they dont really do what i want, the collisions between the character mesh and the cloth is never perfect.

    Will this asset work well for this situation? And will it work on WebGL?
     
  27. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    Hi, it should work well, in the last version I added a projection mask feature, so even when cloth will overlap with the body in some fast movement situations, now the "mask" will hide the body underneath.

    I also added a new feature, which will be available in the next version, which will be soon on the asset store:
    upload_2021-10-8_16-44-2.png
    GPU Blend Shapes, before you could only use the character body without blend shapes, but now with this new script you can also use Blendshapes as if it would be the normal skinned mesh blendshapes.

    However, I currently can't support WebGL, because of the memory limits it has. Maybe at some point I will support it, but now it's not possible.

    Thanks for asking! Have a nice day!
     
    Last edited: Oct 8, 2021
    tiggaxxx and victorkin11 like this.
  28. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224

    :D Something is not right here but I can't tell, I think, the vertices just get the bones rotation but not the bones translation, very weird... testing 2021 beta -> skin.GetVertexBuffer();

    Edit: Ok, I found the solution: I need to transform the vertex buffer data with the skinned root object! But it only works if the skinned mesh has the correct root bone object applied... this can be tricky, e.g. the Kyle model had a different root bone as default than the original root bone. o_O

    Anyone who wants to try it out:

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class TransferGPUSkin : MonoBehaviour
    7. {
    8.     Vector3[] verts;
    9.     public Transform _rootBone;
    10.  
    11.     void Update()
    12.     {
    13.         var skin = this.GetComponent<SkinnedMeshRenderer>();
    14.         skin.vertexBufferTarget |= GraphicsBuffer.Target.Raw;
    15.         var vertexBuffer = skin.GetVertexBuffer();
    16.  
    17.         if (vertexBuffer != null && vertexBuffer.IsValid())
    18.         {
    19.             byte[] data = new byte[vertexBuffer.count * (skin.sharedMesh.GetVertexBufferStride(0))];
    20.             vertexBuffer.GetData(data);
    21.  
    22.             int stride = skin.sharedMesh.GetVertexBufferStride(0);
    23.  
    24.             int length = data.Length / stride;
    25.             if (verts == null) verts = new Vector3[length];
    26.             for (int i = 0; i < length; i++)
    27.             {
    28.                 int dataStep = i * stride;
    29.  
    30.                 for (int n = 0; n < 3; n++)
    31.                 {
    32.                     int floatStep = dataStep + n * 4;
    33.                     verts[i][n] = BitConverter.ToSingle(new byte[] { data[floatStep], data[floatStep + 1], data[floatStep + 2], data[floatStep + 3] });
    34.                 }
    35.  
    36.                if(_rootBone!=null){
    37.                  verts[i] = _rootBone.localRotation * verts[i];
    38.                  verts[i] += _rootBone.localPosition;
    39.                }
    40.             }
    41.         }
    42.     }
    43.  
    44.     private void OnDrawGizmos()
    45.     {
    46.         if (verts != null)
    47.         {
    48.             for (int i = 0; i < verts.Length; i++)
    49.             {
    50.                 Gizmos.DrawWireCube(this.transform.TransformPoint(verts[i]), Vector3.one * 0.001f);
    51.             }
    52.         }
    53.     }
    54. }
    55.  
     
    Last edited: Oct 8, 2021
    SunnySunshine likes this.
  29. DriesVrBase

    DriesVrBase

    Joined:
    Mar 24, 2020
    Posts:
    39
    Hi,
    When I start my game my texture goes missing? It's always a white cloth? How can I fix this?

    Kind regards,
    Dries
     
  30. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    Hi Dries, sorry, this part is still missing in the docs, I will update them with the next version. CD needs to replace the cloth material shader, so that is why it might change your texture. You can select the cloth shader for your material before hitting play and it won't change the texture. Just have a look which shader it uses by selecting the cloth and unroll the material inspector. If you know which shader it uses you can apply this one before you start the Play mode. You can also create a custom shader, but this needs to be a shader with the name "Cloth" in it, so it won't get replaced.

    The same happens with the Body material, if you are using mesh collision. You also need to check the shader. They have a "Skinning" in their shader name.

    Hope this helps,
    All the best,
    Chris
     
    DriesVrBase likes this.
  31. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    224
    I finished the work with the GPU VertexBuffer, just making the Docs on monday and it's done. :)
     
    SunnySunshine likes this.
unityunity