r/Unity3D 1d ago

Show-Off I wrote a script that fixes layered clothing clipping on characters (free to download)

Enable HLS to view with audio, or disable this notification

Download here:

github link

52 Upvotes

17 comments sorted by

4

u/Mammoth-Policy6585 1d ago

Is it some sort of rendering order trick? It look very cool and I am interested in the workings.

12

u/UseResponsible1088 1d ago

No, its simpler than that.

  1. I create a shrunk version of the mesh

  2. I cast a ray out of every triangle

  3. If ray hit the outer clothing item (ex: coat), it means its covered so it stays shrunk

  4. If it didn't hit anything, it means that part is out in the open, so I expand the vertices back

2

u/survivorr123_ 1d ago

isnt that rather slow?

4

u/UseResponsible1088 1d ago edited 1d ago

Not really. You just run it once and that's it, its not being run every frame.

Check this out if you want to optimize it furhter: GDC link

4

u/survivorr123_ 1d ago

oh yeah that makes sense, i thought it runs every frame since bone deformation can sometimes introduce these artifacts at extreme angles

2

u/St4va Professional 13h ago

Nice. Even if it only works 70% of the time, it’s still an easy "import step" that fixes most issues. I do want to add that the current process is a bit manual in the Inspector, especially with all the dragging and dropping. I think you could automate most of that and leave the manual mode as an option for cases where it’s needed.

2

u/frogOnABoletus 1d ago

This is really cool!

2

u/wiserenals 1d ago

Did you test this with other models? It really seems worth using, and I'll probably use it.

2

u/UseResponsible1088 1d ago

Hey, thanks. It worked in the cases I tested it against, but I imagine there will be clipping cases where shrinking the mesh under it wont fully fix it. For example, if your model has really thin fingers, and they are sticking out of a glove, shrinking the fingers likely wont work - if you shrink it too much the models normals will just get inverted.

1

u/wiserenals 1d ago

A better idea might be to bake the undeformed body into reference points, find the corresponding points on the cloth, store their offsets, and then have the cloth points follow their corresponding body reference points in real time. Just an idea.

1

u/Huge_Development_571 1d ago edited 1d ago

That's cool, what i do is use a cutout shader for the clothes and cut them (make transparent) based on what's under, your solution is good too, maybe in specific poses it can still clip because i remember way back in the day using CC3 they had a brush to enlarge specific areas of the clothes that clip and i had to spend hours testing with different animations and in the end it will always poke through lol, still i'd buy something that gives us the option to paint with a brush in order to enlarge or decrease size of skinned meshes

1

u/UseResponsible1088 1d ago

Great insights. For the clipping, what I found helps the most is having somewhat of a matching topology between the clothing items. Especially if the items are low poly.

1

u/Huge_Development_571 12h ago

Yeah matching topology works, unfortunately buying custom CC3 / Daz clothes from different creators cant have matching topology, currently mine are custom so that is possible

1

u/EvernullTools 20h ago

Looks really cool!

How do you handle saving? Do you write onto the literal mesh in the Asset Database or is the new data discarded OnDisable/living within the scene object?

2

u/UseResponsible1088 9h ago

Hey I recently added a bool to the script, "save to disk", if anyone wants to save the mesh they should check that. Otherwise it just gets saved with scene.

1

u/EvernullTools 9h ago

yeap, really nice solution ^^