I have an object in the scene which uses transparency and my intention is to have text positioned in the scene and displayed on top of the translucent object. Below you can see this working correctly:
If I move the camera in the scene then sometimes the text appears as if it is behind the transparent object, even though the only thing moving is the camera. Below you can see the exact same scene but from a position ever so slightly to one side:
Why does this happen? And how can I fix this?
Notes:
For the translucent object I am using the standard shader and set the rendering mode to transparent
I have tried using the fade rendering mode but the issues persists
With the opaque rendering mode there is no issue and text is always in front
If two surfaces are too close to each other, sometimes the camera has a hard time telling which one is on top. When that is the case, just a little change may make the camera change it’s mind about which is on top. That is called “Z-Fighting”. To fix that, bring your text closer to the camera (or rather bring it away from the object it’s fighting with).
If the issue still persists, it’s because you’re either using particle shaders or UI elements. I won’t get into details on these unless you need me to, but particle depth is guessed a bit more poorly than most objects because it’s easier on the CPU and users typically don’t notice sorting issues on things as small and numerous as particles. UI depth… BAH! UI doesn’t have depth, it uses stenciling so programmers that aren’t graphics programmers can have something to bash their head against a wall about.
It’s not z-fighting, there’s a gap between the text and the object. I am using UI elements.
It seems to be fixed now. I created a sorting layer and set the world canvas with the text on to be in that new sorting layer.
It’s a long time ago now, but I just wanted to say thanks for answering your own question. Many people don’t bother. Thanks for leaving the solution for others to find. Helped a lot
In most cases the solution for this is to create a new material for the UI items and set its Rendering Queue to more than 3000.
Since transparency’s queue value is 3000, I usually set the UI’s materials to 3100. Unity will say “Transparent+100” in the queue enum.
It’s often useful for me to also have a shader that is just a clone of Unity’s UI Default material but with Z-writing turned off.