Hi,
This problem might take a bit to explain but i’ll try my best.
I have a bunch of characters, each has a mesh for their haircut. Sometimes they might have a hat, so obviously I don’t want the hair to stick out the top of the hat.
First I went with the DepthMask found in the Unify wiki (which basically sets the renderDepth of the hat and the hair, so the hat is rendered second and just wipes the RGB, essentially “removing” the hair), this works fine, adding a “CullingMesh” to all the hats correctly stops the hair sticking out.
However…the hats will cull all hair materials in the game. So if someone with say…a huge afro…walks behind someone with a hat, their afro will suddenly be cropped as if they were wearing the hat, and this looks really really bad.
I then tried experimenting with the render depth of each hair and hat to get them in order, firstly I just tried pairing up hats and hairs to have “similar” depths but all different to each other, this wasn’t working, but what I could do is write a script that works out the render order of all the hats and hairs based of word coordinates, and updates all the materials to have the correct render depth each update…
However I was wondering, is there a way to read whats currently in the ZBuffer in a Shader, and also write a custom value there? One possible idea was to have all the Hats render first, and each hat will write its own custom id to the zbuffer, then render all the hair, and each hair will check if its ID is in the zbuffer or not, if it is then don’t render as it’s hat will be in the way.
That may all sound a bit confusing, bit hard to explain, but even if this isn’t the best way to do it (or if that definitely won’t even work anyway), and a script sorting render order is the best way (or if anyone has any other suggestions i’m all ears!), i’d still like to know for interests sake if it is possible to read and write to the zbuffer in this way?
-Iain