Problem with Z testing???
Hey,
I'm running into this issue where the Standard Transparency shader doesn't seem to be testing pixel depths properly and sometimes pieces of geometry are being rendered in front of things they are behind.
Since I am just using a standard unity shader I'm leaning towards the thought that I did something wrong while setting up the model. anyone have any suggestions about what might be causing this issues.
F.Y.I i'm using the transparency for a cheap invisibility effect.
Here's a sample of how they look with standard opaque.
and here's a sample of it with Standard Transparent ( Fade will also give the same result).
Answer by ericbegue · Jun 02, 2016 at 12:06 PM
This is expect when rendering transparent meshes. Transparent meshes does not render to the Z-buffer, therefore each face of the mesh is ignored during the visibility test, which simply make each face being drawn over the previous face. So, the visibility of a face does not depend on its depth, but in the order it is drawn.
Though, it is possible to obtain the effect you want by using some advanced rendering technique. For that you would need to implement a custom shader that render your object with two passes:
The first pass would only draw the object to the Z-Buffer ( not to the color buffer).
The second pass would be a normal transparent rendering. But this time since the object has rendered in the the Z-Buffer, it will perform a visibility test against itself.
To avoid Z-fighting one of the pass should be displaced by an offset in depth.
Thanks, you answer does a good job of explaining what's required here. I just managed to stumble upon a solution in the online documentation here
What you described sounds similar to whats going on in that shader
`