Search Unity

[RELEASED] Cloth Dynamics

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

  1. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    Here is another important tip when you install (import) Cloth Dynamics in Unity:
    - Make sure you installed "Burst" from the Package Manager!
    - Always download ClothDynamics with the right Unity version, meaning:
    If you want CD with 2020 you need to use a higher or the same version as 2020.3.7f1 (see the assetstore page)
    If you download CD with a lower version and later import it with a higher Unity version you will always get the last downloaded version, so make sure you delete the old version, you can find the package here:

    C:\Users\YourName\AppData\Roaming\Unity\Asset Store-5.x\Christian Kahler\ScriptingPhysics\Cloth Dynamics.unitypackage

    You can also download CD with 2020.3.7f1 and then reimport it with an old Unity version, you will always get the 2020 version.

    Hope that helps!
     
    r3ndesigner likes this.
  2. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    Hi everyone, sorry for the delay, I was also on holiday for a week but now I'm back to work and I try to release a new version till the end of the week if everything works out.
     
    r3ndesigner likes this.
  3. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    Hi Faintle2,
    can you please test the following with your AMD GPU, it should work now.

    https://drive.google.com/file/d/1v4avS1AUjcqOjiwfQNpwuUtkzEnmR7Ke/view?usp=sharing

    The Red Dress should be visible and moving with the character (nothing fancy here, just a test setup), I disabled the hair, because it's not necessary for the test.
     
    r3ndesigner likes this.
  4. JonBanana

    JonBanana

    Joined:
    Feb 5, 2014
    Posts:
    85
    Hi,
    I buy this asset and start to make some test and i have a little trouble :
    when i start the simulation the cloth get distance between face.

    What can cause this ?

    thanks
     

    Attached Files:

  5. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    Well, besides "Use Garment Mesh" only Vertex Parameters and the shader are affecting the mesh layout. So in your case I would play with the vertex parameters (not effective during runtime).
    upload_2021-7-14_9-54-35.png

    I don't know which shader you are using but if you are using builtin the ClothSurfaceShader should not cause this.

    Another thing could be your mesh itself, did you test, that your mesh vertices are connected in a 3d model app? Also you could try editing the normals, because if you have hard egdes the vertices get split up on these edges (however "Sew Edge" should fix this, but maybe you have a different scaling). How many Unity units does the height of your character has? E.g. something around 2 should be fine. I also tested different sizes but maybe this could still affect sew edge.

    upload_2021-7-14_9-44-31.png

    If you are using SRP:
    Also make sure that you are not writing with some other script in UV2 because CD needs UV2 to write the vertex ID.
    You can change this in the advanced mode under Vertex Parameters. If you change the UV Id you also have to change it in your cloth shader manually.
    (In shader code UV2 is UV1)

    Btw. I strongly recommend you to reduce the poly count of your character's body! Half the count should still be fine.
     
    Last edited: Jul 14, 2021
  6. JonBanana

    JonBanana

    Joined:
    Feb 5, 2014
    Posts:
    85
    Thank for your fast answer, the "fix double" checkbox fix it :)

    Thank for your advice about polycount :) but i m in specific usecase where the high number of polycount is really important (i'm not making a video game ;))
     
  7. JonBanana

    JonBanana

    Joined:
    Feb 5, 2014
    Posts:
    85
    I ve another question :
    the bones sphere is really great for fast simulation, but in my case i would need a more accurate calculation.

    i d like to use the sphere collider while i m posing the character but when my character is posed i d like to use directly a mesh collider (generated from the body with bakemesh) instead of the sphere , how can i do that ?
     
  8. JonBanana

    JonBanana

    Joined:
    Feb 5, 2014
    Posts:
    85
    Hi again,

    I want create proxy cloth but i dont find how to generate the skin file (ex: MargotDress_MargotDressHQ_skin.bytes)
     
  9. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    This setup should do what you want:
    upload_2021-7-14_15-41-51.png

    Just remove the Prefab skin and a new one will be created, if you don't want to overwrite, rename your proxy mesh. For direct mesh collision use Mesh Objects, "Use Triangle Mesh" will be slower. Self Collision might add jitter effects so be careful with that. Surface Push helps you to get a more stable collision, however the vertices sometimes seem to jump, this is what I want to improve in the next versions.
    You Proxy Mesh should look like this:
    upload_2021-7-14_15-46-27.png
    You can also use a Mesh Renderer but then you need to remove the Skinned mesh renderer!

    Btw. if you want to get a better cloth sim use a "uniform mesh" for your cloth object. (Meaning all egdes have the same length.)

    Here is the example file for your setup:
     

    Attached Files:

    Last edited: Jul 14, 2021
  10. JonBanana

    JonBanana

    Joined:
    Feb 5, 2014
    Posts:
    85
    thank you :)
     
  11. shubhank008

    shubhank008

    Joined:
    Apr 3, 2014
    Posts:
    107
    I have a model which has a single mesh (no separate mesh for clothes), will this still work ?
     
  12. unity_K_nDtRZtMCIVjg

    unity_K_nDtRZtMCIVjg

    Joined:
    Feb 4, 2021
    Posts:
    8
    WebGL supported?
     
  13. xermao

    xermao

    Joined:
    Jun 20, 2018
    Posts:
    1
    After I checked "Use collision finder", the collision still works even if all colliders are removed.
    Does this mean that I only need to check "Use collision finder" and collider generation is worthless?
     
  14. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    You could still use it but you have to paint all vertices that are not cloth red and use a skinned mesh. Also you need a separate collider so you maybe have a invisible skinned body mesh or use spheres / round cones for collision.
     
    Last edited: Jul 20, 2021
  15. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    Use Collision Finder: uses a voxel grid to collide with mesh(es).

    Use Collidable Objects List: uses primitive objects like spheres or round cones to collide with the cloth.

    You can use both together or just one of them.

    Tip of today: Hover over any parameter with your mouse cursor to get more informations.
     
  16. unity_K_nDtRZtMCIVjg

    unity_K_nDtRZtMCIVjg

    Joined:
    Feb 4, 2021
    Posts:
    8
    Nexusmaster, Could you clarify WebGL platform is supported or not? Thanks
     
  17. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    Sorry, currently it is not supported, maybe at some point, but currently I'm focusing on PC, Mac, Linux and Mobile, what is already quite a lot to manage.
     
    Last edited: Jul 20, 2021
    unity_K_nDtRZtMCIVjg likes this.
  18. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365


    New tutorial video: DAZ to Unity.
     
  19. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
  20. JonBanana

    JonBanana

    Joined:
    Feb 5, 2014
    Posts:
    85
  21. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    No, thanks! I still need to verify if it works on an integrated AMD Gpu...
     
  22. FaberVi

    FaberVi

    Joined:
    Nov 11, 2014
    Posts:
    146
    @Nexusmaster I have this problem of white texture in play:

    upload_2021-7-22_10-29-51.png

    Editor:

    upload_2021-7-22_10-30-27.png



    I am using URPs and have already tried clicking on the button to reimport the shaders with no results.
     
  23. victorkin11

    victorkin11

    Joined:
    Apr 20, 2013
    Posts:
    175
    Did you use the CD shader for cloth? or use the CD shader graph to make you custom shader? cloth only work with the shader come from CD.
     
  24. FaberVi

    FaberVi

    Joined:
    Nov 11, 2014
    Posts:
    146
    The material is automatically changed by the Skinning GPU script, so I have no control. The basic material you see in the editor is this:

    upload_2021-7-22_12-53-15.png


    EDIT: I solved, it was enough to set the shader directly. However, this information was missing from the documentation.
     
    Last edited: Jul 22, 2021
  25. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    Sorry, I will update the docs soon... yes you can use any shader that has the "Cloth" name in it and CD will not change it.
     
  26. JonBanana

    JonBanana

    Joined:
    Feb 5, 2014
    Posts:
    85
    I m'using UMA , i m interested :)
     
    Framehacker likes this.
  27. JonBanana

    JonBanana

    Joined:
    Feb 5, 2014
    Posts:
    85
    Hi @Nexusmaster

    I start to made some test on ios ,i got some trouble :
    • the painted vertex were not created on my mac,i have to recreate them (i use git and pull the project,may be some file where missing) , where are store the vertex painting information ?
    • The vertex shader for painting is not working (it appear purple),maybe because of old graphic card, if i replace it manually (directly on temp model) by probuilder/unlitevertexcolor its working well. Is it a place where i can change the default painting shader ?
    • when i build for ios the shader 'URP_Lit_graph_cloth' throw compilation error.
      Code (CSharp):
      1. Shader error in 'Shader Graphs/URP_Lit_Graph_Cloth_Compiled': Couldn't open include file 'Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl'. at line 177 Compiling Vertex program with _ADDITIONAL_LIGHTS_VERTEX Platform defines: UNITY_NO_DXT5nm UNITY_NO_RGBM UNITY_ENABLE_REFLECTION_BUFFERS UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF3 SHADER_API_MOBILE UNITY_HARDWARE_TIER1 UNITY_COLORSPACE_GAMMA UNITY_LIGHTMAP_DLDR_ENCODING Disabled keywords: DOTS_INSTANCING_ON _SCREEN_SPACE_OCCLUSION LIGHTMAP_ON DIRLIGHTMAP_COMBINED _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _ADDITIONAL_LIGHTS _ADDITIONAL_OFF _ADDITIONAL_LIGHT_SHADOWS _SHADOWS_SOFT LIGHTMAP_SHADOW_MIXING SHADOWS_SHADOWMASK INSTANCING_ON FOG_LINEAR FOG_EXP FOG_EXP2 USE_BUFFERS UNITY_ENABLE_NATIVE_SHADOW_LOOKUPS UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_PBS_USE_BRDF2 UNITY_NO_FULL_STANDARD_SHADER UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_LIGHTMAP_RGBM_ENCODING UNITY_LIGHTMAP_FULL_HDR UNITY_VIRTUAL_TEXTURING UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_ASTC_NORMALMAP_ENCODING SHADER_API_GLES30
    and more general question, i have cloth who are double sided, is there a way to preserve the thickness/volume without using proxy ?


    Thank for your support
     
    Last edited: Jul 26, 2021
  28. JonBanana

    JonBanana

    Joined:
    Feb 5, 2014
    Posts:
    85
    Hi @Nexusmaster,

    I m using this free matcap shader (http://www.jeanmoreno.com/unity/matcap/)

    Code (CSharp):
    1. // MatCap Shader, (c) 2015-2019 Jean Moreno
    2.  
    3. Shader "MatCap/Vertex/Plain"
    4. {
    5.     Properties
    6.     {
    7.         _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
    8.         _MatCap ("MatCap (RGB)", 2D) = "white" {}
    9.     }
    10.  
    11.     Subshader
    12.     {
    13.         Tags { "RenderType"="Opaque" }
    14.      
    15.         Pass
    16.         {
    17.             CGPROGRAM
    18.                 #pragma vertex vert
    19.                 #pragma fragment frag
    20.                 #pragma fragmentoption ARB_precision_hint_fastest
    21.                 #pragma multi_compile_fog
    22.                 #include "UnityCG.cginc"
    23.              
    24.                 struct v2f
    25.                 {
    26.                     float4 pos    : SV_POSITION;
    27.                     float2 cap    : TEXCOORD0;
    28.                     UNITY_FOG_COORDS(1)
    29.                 };
    30.              
    31.                 v2f vert (appdata_base v)
    32.                 {
    33.                     v2f o;
    34.                     o.pos = UnityObjectToClipPos(v.vertex);
    35.                  
    36.                     float3 worldNorm = normalize(unity_WorldToObject[0].xyz * v.normal.x + unity_WorldToObject[1].xyz * v.normal.y + unity_WorldToObject[2].xyz * v.normal.z);
    37.                     worldNorm = mul((float3x3)UNITY_MATRIX_V, worldNorm);
    38.                     o.cap.xy = worldNorm.xy * 0.5 + 0.5;
    39.                  
    40.                     UNITY_TRANSFER_FOG(o, o.pos);
    41.  
    42.                     return o;
    43.                 }
    44.              
    45.                 uniform float4 _Color;
    46.                 uniform sampler2D _MatCap;
    47.  
    48.                 float4 frag (v2f i) : COLOR
    49.                 {
    50.                     float4 mc = tex2D(_MatCap, i.cap);
    51.                     mc = _Color * mc * unity_ColorSpaceDouble;
    52.                     UNITY_APPLY_FOG(i.fogCoord, mc);
    53.                     return mc;
    54.                 }
    55.             ENDCG
    56.         }
    57.     }
    58.  
    59.     Fallback "VertexLit"
    60. }
    61.  
    Unfortunatly i know nothing in shader writing, what i have to change to make it work with CD ?

    Thanks
     
  29. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    In the VertexPaintEditor.cs:
    Code (CSharp):
    1.                     if (GraphicsSettings.currentRenderPipeline && GraphicsSettings.currentRenderPipeline.GetType().ToString().Contains("HighDefinition"))
    2.                         mat.shader = Resources.Load("VertexColorGraph", typeof(Shader)) as Shader;
    3.                     else
    4.                         mat.shader = Resources.Load("VertexData", typeof(Shader)) as Shader;
    5.  
    Replace "VertexColorGraph" with your shader (it must be in a Resources folder).

    The vertex colors are normally stored in your mesh file, but also my script (PaintObject.cs) can store them.

    The error comes from "URP_Lit_Graph_Cloth_Compiled" not "URP_Lit_Graph_Cloth". You can remove the "Compiled" version, it's normally not needed.

    This is tricky, you could use a custom shader that renders the thickness with offset passes. Basically the same tech as a fur shader: https://github.com/Sorumi/UnityFurShader

    Also try to reimport shaders that don't work, also sometimes the URP_Lit from Unity needs reimporting.

    Btw.: I'm still working on a Mac-Fix, it's not done, meaning the "CollisionFinder" will crash if the voxel cube box is too small or vertices leaving the voxel cube.

    Sorry for the delay again, I will cut out some features for the next version, but I want to release a new one soon, just currently there is so much work to do...
     
    Last edited: Jul 27, 2021
  30. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    You need to add this function to your custom shader and a VertexID. See the shader file in the attachment.
    Code (CSharp):
    1. #if defined(SHADER_API_D3D11) || defined(SHADER_API_GLCORE) || defined(SHADER_API_GLES3) || defined(SHADER_API_METAL) || defined(SHADER_API_VULKAN) || defined(SHADER_API_PS4) || defined(SHADER_API_XBOXONE)
    2.                 StructuredBuffer<float3> positionsBuffer;
    3.                 StructuredBuffer<float3> normalsBuffer;
    4.  
    5.                 void MyClothFunction_float(uint vertexId, out float3 vertex, out float3 normal)
    6.                 {
    7.                     vertex = positionsBuffer[vertexId];
    8.                     normal = normalsBuffer[vertexId];
    9.                 }
    10. #endif
    The "defines" are optional.
     

    Attached Files:

  31. JonBanana

    JonBanana

    Joined:
    Feb 5, 2014
    Posts:
    85
    Thank you its working perfectly :)
     
  32. JonBanana

    JonBanana

    Joined:
    Feb 5, 2014
    Posts:
    85
    Thanks for your answer @Nexusmaster

    Can you just clarify these point :

    does your script store the painted vertex data in the model file (for example the fbx file) or do you mean its able to read it

    directly inside the gameobject (scene file / prefab file) ?

    EDIT : I find the change in my prefab file (vertex color attribute). :)

    Dont worry, i understand that for just 30$ we cant expect to have this great asset and 24H hotline ;)
     
    Last edited: Jul 28, 2021
  33. ClementSchepens

    ClementSchepens

    Joined:
    May 27, 2020
    Posts:
    25
    Hi, it seems that the plugin is reimporting every FBX in my project (setting "isReadable" to true). Having isReadabe to true is not very optimized. Is it possible to do it on a case-by-case basis?

    Edit: The guilty line is on AssetPostProcessorReorderBones.cs L18 "modelImporter.isReadable = true;"
     
    Last edited: Jul 29, 2021
  34. JonBanana

    JonBanana

    Joined:
    Feb 5, 2014
    Posts:
    85
    Hello @Nexusmaster,

    • Is it possible to collid with mesh, i find only example with basic shape ?
    • I notice that the export function is not correctly working while using proxy mesh : it still export the mesh , is there another way to export the proxy mesh ?
    • Is it possible to update the export function in a next release and return the mesh, i need to use it on runtime and manage the exported mesh by myself.
    thanks
     
    Last edited: Aug 1, 2021
  35. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    976
    Hi there @Nexusmaster!

    I just bought this asset and I'm very impressed with it. It's exactly what I've been looking for - a competently put together cloth simulation solution running on GPU. And source code is even included! That's great!

    I have a few things I'm hoping will be become possible to do with this however, in a way that is officially supported.

    Right now, this asset is rather focused to only work with its own components. For example, the GPU skinning is required to make it work with collisions and/or to obtain the vertices of skinned cloth for simulation. I think this should redesigned to be more generic and allow vertices from any source. In the end, it's not where the vertices come from which is important, only that the buffer is available for the GPU to do its computation.

    This is perhaps especially true now that GPU vertex buffer can be obtained from Unity's own SkinnedMeshRenderer*. For this reason, I think the cloth system should be adapted to be more generic, allowing it to operate on vertex buffers from itself (gpu skinning), from Unity (GetVertexBuffer) or from a custom source.

    Right now, we're using a custom GPU skinning method for characters and clothing in our game. We're also using a custom GPU normal computer that produces quad normals even though the meshes are triangles. I'm hoping that GPU Cloth Dynamics can be adjusted to become more generic, in such a way that its clothing functionality can be invoked on any vertex buffer, and that we can run our own ComputeNormals() on it. Furthermore, the cloth system should be possible to invoke manually to run its dynamics and render individually, without having the component enabled. (A bit like FinalIK is possible to run even though the component isn't active, since you may want to invoke it manually from code.)

    In essence, this is what I wish we could do:

    Code (CSharp):
    1. // Setup.
    2.  
    3. // Interfaces in ClothDynamics namespace.
    4. // These should contain all the methods you need in order to get
    5. // any vertex source to work with your system.
    6. // I'm sure there's more methods required, but you get the idea ...
    7.  
    8. interface IMeshProvider
    9. {
    10.     ComputeBuffer GetVertexBuffer();
    11.     Mesh GetMesh();
    12. }
    13.  
    14. interface IClothProvider
    15. {
    16.     ComputeBuffer GetVertexBuffer();
    17.     Mesh GetMesh();
    18.     float[] GetInfluences(); // Per vertex float, instead of vertex colors.r.
    19. }
    20.  
    21. [...]
    22.  
    23. float[] customInfluences = [...]; // float array per vertex containing 0f -> 1f.
    24. var myCloth = new SomeCustomClothClass(someMesh, customInfluences); // SomeCustomClothClass implements IClothProvider.
    25.  
    26. var myCustomCharacterSkinner = new SomeCustomCharacterSkinner(...); // Implements IMeshProvider.
    27.  
    28. var gpuClothingDynamicsHandle = GPUClothingDynamics.SetupClothing(myCloth); // Wished feature.
    29. gpuClothingDynamicsHandle.AddCollider(myCustomCharacterSkinner); // Wished feature.
    30.  
    31. // I do dislike that vertex colors are hard coded to be used with this system,
    32. // as that may already be used for something else. It's fine that it CAN work with it,
    33. // but it shouldn't be FORCED. In the end, it's a float array that is required,
    34. // so this is what the system should designed to work with.
    35. // That's what GetInfluences() are for.
    36.  
    37. // Update.
    38.  
    39. myCustomCharacterSkinner.SkinVertices(); // Our code.
    40. myCloth.SkinVertices(); // Our code.
    41.  
    42. gpuClothingDynamicsHandle.RunDynamics(dt); // Wished feature. Runs on the current data, i.e. uses the vertex buffers from GetVertexBuffer() in the provided colliders and cloth.
    43.  
    44. myCloth.ComputeNormals(); // Our code.
    45.  
    46. [...]
    47.  
    48. myCloth.Render(); // Our code. Since vertex buffer now contains the dynamic cloth data, we can render it in any way we wish with our own shaders.
    It doesn't have to work exactly like this, but I think you understand what I'm asking for. It's very likely a different kind of organization would be better. For example, I haven't taken into account that multiple clothes could use the same collider, so it would be highly inefficient to have RunDynamics() do the collider update, since that would invoke it several times for the same collider which is not desirable.

    The point is that the vertex buffers should be possible to come from custom sources.

    Some other things to note:

    In the Start() method of GPUClothDynamics, there's a for loop which accesses mesh.colors in every iteration:

    Code (CSharp):
    1. for (int i = 0; i < count; i++)
    2. {
    3.     _positions[i] = baseVertices[i];
    4.     if (_useGarmentMesh) _colors[i] = baseColors[i];
    5.     _velocities[i] = Vector4.zero;
    6.     _velocities[i].w = useVertexColors ? _mesh.colors[i].r : 1;
    7.     _frictions[i] = 1;
    8. }
    This is very bad, since every time you access mesh.array, it will copy the whole thing. You should store mesh.colors in an array, then access that array in the loop.

    Code (CSharp):
    1. var colorsTmp = _mesh.colors;
    2.  
    3. for (int i = 0; i < count; i++)
    4. {
    5.     _positions[i] = baseVertices[i];
    6.     if (_useGarmentMesh) _colors[i] = baseColors[i];
    7.     _velocities[i] = Vector4.zero;
    8.     _velocities[i].w = useVertexColors ? colorsTmp[i].r : 1;
    9.     _frictions[i] = 1;
    10. }
    There may be more instances in the code where mesh arrays are used in this manner. If that's the case, then this should be fixed too.

    I've also seen that this is used for dispatch:
    Code (CSharp):
    1. Mathf.CeilToInt(length / 256.0f)
    Usally this is used to compute number of dispatches:
    Code (CSharp):
    1. (count + threads - 1) / threads;
    In which all components are integers, so you avoid float and integer conversion.

    Personally, I do it like this for my shaders:
    Code (CSharp):
    1. // Extension method.
    2. public static int GetComputeShaderThreads(this int count, int threads = 64)
    3. {
    4.     return (count + threads - 1) / threads;
    5. }
    6.  
    7. [...]
    8.  
    9. // Then you could use it like this:
    10.  
    11. myBuffer.count.GetComputeShaderThreads(256)
    Overall, I'm very excited about this asset. If you manage to get it to be more generic and work with unity's own internal buffers as well as custom buffers from custom sources, I will be giving it a 5 star rating and a positive review on the asset store.

    Thanks for reading.

    All the best.
    - Sunny

    * https://forum.unity.com/threads/feedback-wanted-mesh-compute-shader-access.1096531/
    * https://github.com/Unity-Technologies/MeshApiExamples
    * https://docs.google.com/document/d/1_YrJafo9_ZsFm4-8K2QlD0k3RgwZ_49tSA84paobfcY/edit
     
    Last edited: Aug 1, 2021
    yukocchi and JonBanana like this.
  36. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    Thanks for the info I will change that!
     
  37. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    So you need an export function for the proxy mesh, right?
     
  38. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    Hey Sunny,

    thanks! You are completely right with the future plans! CD needs to be more generic and also needs more code improvements, there is a lot of code that just not cleaned up or optimized, but thanks for the hints, I will put your tips in the next version. Currently I managed to fix a big bug, that also fixed the Mac Issue, I'm now working on the debug visualisation and then I will upload the next version. I moved some features like tearing and "strings" to the after next version, because they are not finished yet, but I like to make an update soon, so the next version is just a more stable one, with minimal extra features and debug visuals.
     
    SunnySunshine likes this.
  39. JonBanana

    JonBanana

    Joined:
    Feb 5, 2014
    Posts:
    85
    Exactly , best will be an Export function who return the mesh or the proxy mesh if set.

    What about mesh collider ?
     
  40. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Hi!
    How good this asset would perform in the following scenario:

    Curtain simulation for the interior scene. From 2 to 4 curtains visible at the same moment. About 15-20 in the scene in total. Every movable object in the scene (like chairs, vases, boxes, etc.) must properly collide with the curtains. Only one object is expected to collide at a time. Furthermore, the curtains may be opened and closed + simulate a wind interaction.

    Is this something doable?
    If it is, how hard would be to set up something like this?

    I'm particularly interested in the "Mesh collision with a point-to-point system (using vertices or triangles)." Would it be possible to add mesh colliders to all objects and be good to go?
     
  41. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    Well, it really depends on the details (triangle count) of your cloth, but when the scene is not too big, you could just combine all the curtains to one object, like I did in this test:
    https://forum.unity.com/threads/released-cloth-dynamics.1019401/page-3#post-7251941
    I'm using bones to move each part individually.

    Not all mesh colliders work well, because they don't have a fixed res of collision points, that's why I will add a voxel grid function like in Flex. It's almost finished and will be available soon.
    Currently meshes that are very low need triangle collision, which will cost more performance. I will setup a quick test scene today.
     
    Last edited: Aug 4, 2021
  42. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    Good news, I finished the next version and will send it to the asset store today, so it should be available in a few days.
    Main changes are bug fixes and visualizations. But you won't have to wait too long for the new features, most of them are almost finished and will be added soon, maybe I can send another version tomorrow or the day after.
    Here is a screenshot of the new collision point visualisation:
    upload_2021-8-4_9-55-33.png

    The cyan colored spheres are the collision vertices of the mesh object ( Vertex Collision with the "Collision Finder")
    The green cube is one voxel of the voxel gird (in this case I used a 16x16x16 grid)
    The yellow highlighted spheres are the collision vertices that will collide with the cloth vertices that are currently in the green voxel cube.

    As you can see the cyan colored spheres are not on the head, because we don't need to collide with the head vertices, that will save us performance and memory. So I used the Vertex Painter to color all the colliding vertices of the body red.
    upload_2021-8-4_10-3-37.png
     

    Attached Files:

    SunnySunshine likes this.
  43. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    Yes, you have to add the GPUMesh script to your mesh and drag and drop it in the MeshObjects list under "CollisionFinder". The upcoming version has a "Vertex Collision Scale" parameter that let you scale the collision spheres per vertex.
    (This has to be setuped before runtime, because the scale will be written into the buffer as a fixed size. I like to have this more dynamic in the future.)
     
    Last edited: Aug 4, 2021
  44. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Hi!
    Thanks for your reply!I've also read your docs. And have a couple more question:

    1) Do I have to use as few collidable objects as possible? Would hundreds of different objects that could potentially collide (although one at a time) be a problem?

    2) Are special shaders needed for cloth? Can regular HDRP shader like Fabric and Lit or ShaderGraph be applied to cloth?

    3) Have you tried it with 2021.1?
     
    Last edited: Aug 4, 2021
  45. JonBanana

    JonBanana

    Joined:
    Feb 5, 2014
    Posts:
    85
    Thank for your answer , i ll have to wait the more dynamic version because my mesh is generated at runtime.
     
    Nexusmaster likes this.
  46. JonBanana

    JonBanana

    Joined:
    Feb 5, 2014
    Posts:
    85
    Awesome ! :)
     
    Nexusmaster likes this.
  47. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    If you are using Mesh Collisions with the "CollisionFinder", CD will only use the colliders that are in the voxel box, however it will create a vertex or triangle buffer of all the objects in the mesh list, so if your 100 objects are very high res you will reach the memory limit.

    If you are using Primitve Collisions (like spheres and cubes) the number of objects will affect the performance because it needs to iterate through the objects in the compute shader. However, I'm thinking about adding the feature that only objects that are in the voxel box get iterated. Currently you could also write a script that adds or removes primitves from the list e.g.

    Code (CSharp):
    1.  
    2. GPUClothDynamics _cdScript;
    3. _cdScript._collidableObjects.Remove(_myCube);
    4. _cdScript._collidableObjects.Add(_mySphere);
    5.  
    For HDRP I'm using a custom Shader Graph, so you can modify it yourself if you like (best you create a copy). You need to apply the shader to your cloth material or it will get replaced with mine. I think the HDRP Fabric shader is also available as ShaderGraph, so you could also use my SubShader and add it to the pipeline, it "only" edits the vertex shader.

    Yes, I tried the latest version 1.6 with Unity 2021.1.12
     
  48. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    365
    So, version 1.6 will be soon in the store, currently my plan is to release another version next week.
    Main features/plans will be:
    - Integrating Unity 2020 MeshReadableData.
    - Integrating Unity 2021 MeshBuffers.
    - Adding a more flexible cloth picking system, e.g. grabbing cloth by more than one character.
    - Attachments on cloth.

    Still remaining future plans (nice to have):
    - More generic data input
    - Multi layered cloth
    - Tearable cloth
    - Volumetric cloth with tetrahedrons aka soft bodies
    - Rigidbody behaviour
    - Improved Collisions

    Yes, I must admit I'm still not happy with the collision system, but it's hard to tackle, I will have to try different approaches, I like the idea of having a sub space were the skinned character mesh is not moving, however the cloth forces will affect the cloth as it would be in normal space. Like in the link from NexarChile: http://mslab.es/projects/SelfSupervisedGarmentCollisions/
     
  49. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    976
    Good job @Nexusmaster, looking forward to following the progress!
     
  50. JonBanana

    JonBanana

    Joined:
    Feb 5, 2014
    Posts:
    85
    Hi @Nexusmaster

    I add the AutomaticBoneSpheres component at runtime,
    I succeed to make the cloth work but i dont find how to create the colliders.

    How which method i have to call after instantiate the component to create the collider ?


    EDIT

    i succeed after made some modification in your code, (mainly the checking of IsPlaying)
    Is it possible in a futur version to change the AutomaticBoneSpheres for being able to add it at runtime ?

    Thanks
     
    Last edited: Aug 7, 2021