Reputation: 4110
I have thoses two meshes:
In my game, I put the hat on the hair at runtime:
As you can see, as expected, the hair is visible outise the hat part.
How can I achieve this in Unity (what kind of mask shader should I use?):
I've tryed to make a depth mask but it hides every meshes in my scene. I just want to hide the hair, not others meshes. And what if I have two player having the same case? Would player mask hide player 2 hair? How can I avoid that?
Upvotes: 1
Views: 1332
Reputation: 7724
What I would do:
write a C# code that gets the pivot position (bottom part of the hat) and its up vector every frame.
build a plane with these values. The up vector would be the normal vector of the plane and a plane can be defined by a point and a normal vector.
I would pass the equation of the plane to the shader (via Material.SetFloat
or Material.SetVector
) and evaluate if the world positions of the hair vertices are in the correct or in the wrong side of the plane.
Upvotes: 2