How do you make a transparent Character, without making the eyes and teeth show through the body and just have the background show through. I wouldn’t want to see teeth through the lips, or eyes, even though the lids are closed (or eye spheres from the back of the head).
So I think what you want is for your material to selectively render the nearest translucent surface.
This method is limited, for example, the nearest translucent surface won’t only occlude internal translucent surfaces of your model, it will occlude any translucent surface behind it that’s using the same opacity function. So if one transparent character is standing behind another, the further one will be occluded.
In all the translucent materials used by parts of these characters, you need to Allow Custom Depth Writes. The mesh components must have Render CustomDepth Pass enabled. Make the Opacity Mask Clip Value very small.
Only the nearest surface is written to CustomDepth. Depth is orthographic, so pixels at the edge of the screen are given relatively high values compared to pixels at the edge. CustomDepth is converted to back to WorldPosition. This position is pushed away from the camera by a tolerance factor, scaled by distance, so that errors in the CustomDepth texture don’t cause the mesh to disappear at longer distances. If the distance from the camera to this position, is less than the distance from the camera to the surface’s WorldPosition, the base opacity is multiplied by 0.
I think I misunderstood the description earlier, because I thought it would have my desired results. However, it only works with seperate meshes with the same material, not within a singular mesh, so the eyes and teeth arms etc, will still be seen through the mesh. Is there a way for translucency to ignore the same mesh?
Here is what it looks like with the custom depth material:
Hmmm…I did enable custom depth pass on my mesh for the previous screenshot.
I just disabled cast shadow. It made no difference. In fact, I put a cube with the same material in front of the character and it still rendered the character behind the cube.
Well I’m not exactly sure what’s going on. Messing around with it, I have seen some inconsistent compiles. Once, adding a metallic channel caused bugs to appear, but I can’t repro now. I’ve had it not look right after migrating these assets, only to have it work when I move a node and recompile without changing any connections. Changing the aspect ratio of your viewport can make bugs pop in and out. But, at least now, it looks good in standalone.
I tweaked the distance function that scales the tolerance. That dealt with a few small glitches I saw.
I added a world position offset as a hack to deal with meshes using multiple material slots. Material slots use copies of the same polys, so they have to be moved(even though no value for world position offset will move them visibly) for the function to discriminate between them. Use instances with different values of MaterialSlot. If for example, you saw the patch in the middle of this char’s chest turn from green to yellow, it would mean the world position offset needs adjusting.
Thank you very much. I will test it out right away. It really means a lot to me that you would put so much effort into answering my question. So, thank you.
EDIT: Okay, I have looked it over and so far it looks perfect. I am assuming the Material Slots are simple material instances, or are there any other steps needed to make another slot (other than making a material instance of First Surface)?
It’s all good. I like learning stuff solving problems.
Material slots are regions of a mesh with different materials(or material instances) applied. If you have multiple slots with materials that all use FirstSurfaceFunc on the same mesh, they need different values of the MaterialSlot parameter, found within FirstSurfaceFunc, or they will overlap. Making an instance is just an easy way to set the value.