Skinned mesh clone with vertices culling

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:

  • Clone mesh is slow (Instantiate)
  • The mesh must be marked as read/write (unnecessary cpu-side mesh copies)
  • 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

1 Like

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.

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.

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).

Never heard of UMA, but will try. Thanks

You can find it in the asset store or on GitHub.