Shader depth issue, Object disappears.

Hi there,

In my scene I have a text mesh sitting on the surface of another object. It’s fine most of the time but from some angles, the text mesh completely disappears. I think it’s something to do with how the shader sorts out depth but I’m not sure.

The thing is, I think it might have more to do with the shader on the object under the text mesh as the text mesh shader usually always renders on top of other objects.

This is the Text Shader

Shader "GUI/Textured Text Shader"
 {
    Properties {
       _MainTex ("Font Texture", 2D) = "white" {}
       _Color ("Text Color", Color) = (1,1,1,1)
    }
    
    SubShader {
       Lighting Off
       cull off
       ztest always
       Zwrite off
       Tags {"Queue" = "Transparent" }
       Pass {
          Blend SrcAlpha OneMinusSrcAlpha
          SetTexture [_MainTex] {
             constantColor [_Color]
             Combine texture * constant, texture * constant
          }
       }
    }
 }

this is the underlying object’s shader

Shader "My Shaders/No Lighting + Alpha" {
    Properties {
        _Color ("Color Tint", Color) = (1,1,1,1)
        _MainTex ("SelfIllum Color (RGB) Alpha (A)", 2D) = "white"
    }
    Category {
       Lighting On
       ZWrite off
       Cull Back
       Blend SrcAlpha OneMinusSrcAlpha
       Tags {Queue=Transparent}
       SubShader {
            Material {
               Emission [_Color]
            }
            Pass {
               SetTexture [_MainTex] {
                      Combine Texture * Primary, Texture * Primary
                }
            }
        }
    }
}

Can anyone shed some light on this for me?
Thanks
Pete

None of those shaders write into Z-buffer (ZWrite Off), that combined with the fact that both use the same queue (Queue=Transparent), makes the order in which they will appear not really determined.

In case both of your objects need to be alpha blended you can change the queue in the text shader to Transparent+1, so it will be rendered after the other object was rendered (so it will always appear in front of it).

Another solution would be not to use alpha blending on the underlying object…

Hey thanks Kuba!
Worked great!!! Awesome :slight_smile: