Search Unity

Question Skinned mesh clone with vertices culling

Discussion in 'Graphics Dev Blitz Day 2023 - Q&A' started by KamilVDono, May 24, 2023.

  1. KamilVDono

    KamilVDono

    Joined:
    Jun 2, 2016
    Posts:
    18
    Hey,

    In our project we have characters which can wear garments. Characters are skinned meshes and, to avoid clipping, we need to make it read/write, clone the mesh and remove from index buffer occluded vertices.
    Issues in such approach are:
    1. Clone mesh is slow (Instantiate)
    2. The mesh must be marked as read/write (unnecessary cpu-side mesh copies)
    3. Shared mesh data (vertices buffer) is duplicated per character
    So, is there any better way to deal with "vertices" culling? Or solution for any issue I listed?

    Thanks
     
    ModLunar likes this.
  2. Jebtor

    Jebtor

    Unity Technologies

    Joined:
    Apr 18, 2018
    Posts:
    115
    Hello, this problem can be quite content specific. An alternative approach you could consider is pushing the vertices inward so they do not stick through the garments. You can push the vertices around by either using blend shapes or through a vertex shader. Both approaches avoid point 1 and 2.

    If you use blend shapes you still end up with a vertex buffer per mesh on the GPU. But some of the meshes may already have this if they are also skinned.

    For the vertex shader approach you will share the same mesh buffer, but pay for the deformation each time the vertex shader executes. This approach potentially offers more flexibility. You could pull all vertices inwards based on the distance to a point. Or you could utilize an additional vertex channel (for example vertex colors) to mask which vertices get moved. This Unity learn tutorial shows how you can move vertices in shaders using a shader graph.
     
  3. KamilVDono

    KamilVDono

    Joined:
    Jun 2, 2016
    Posts:
    18
    Hey,

    I was hoping there is some trick to share vertex buffer (but, from your comment I get that if I have blendshapes then there will be separate vertex buffer either way) and amend indices buffer without marking mesh as read/write.

    Blendshapes are very memory intense, so it would end up even worse :)

    Custom shader would be another "entity" to maintain and require whole system to be rewritten, but maybe.

    It would be a great to have build-in layered garments system in Unity, so there wouldn't be a need for custom solution, but there are bigger needs xd So keep doing good job.
     
  4. If you haven't, check out UMA2. It is an open source system doing exactly what you need. This means you can look into their code how they are doing these things (they allow people to set up mask vertices to hide the underlying mesh upon clothing change and AFAIK they can also "bake" it, so it won't use that much resources).
     
  5. KamilVDono

    KamilVDono

    Joined:
    Jun 2, 2016
    Posts:
    18
    Never heard of UMA, but will try. Thanks
     
  6. You can find it in the asset store or on GitHub.