Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Shaders] Always on top shader causing UI text to be black

Discussion in 'Scripting' started by Velcrohead, Jun 30, 2015.

  1. Velcrohead

    Velcrohead

    Joined:
    Apr 26, 2014
    Posts:
    78
    Hi all,
    I'm using a shader for my UI which renders the objects on top of everything else (specifically, everything on the canvas). This pretty much works as I need it to, however, when a material using this shader is placed onto the Text component in the UI, the text is displayed as black.

    It's pretty important that the text isn't black, and I'm hoping someone could lend a hand in identifying the problem as I'm not too familiar with shader code.

    This is the code for the shader I'm using :

    Code (CSharp):
    1. Shader "Custom/DrawGUIOnTop" {
    2.     Properties {
    3.         _Color ("Color", Color) = (1,1,1,1)
    4.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
    5.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
    6.         _Metallic ("Metallic", Range(0,1)) = 0.0
    7.     }
    8.     SubShader {
    9.         Tags { "RenderType"="Transparent" "Queue" = "Overlay" }
    10.         LOD 200
    11.         ZWrite Off
    12.         ZTest Always
    13.     Blend SrcAlpha OneMinusSrcAlpha
    14.        
    15.         CGPROGRAM
    16.         // Physically based Standard lighting model, and enable shadows on all light types
    17.         #pragma surface surf Standard  alpha:fade
    18.  
    19.         // Use shader model 3.0 target, to get nicer looking lighting
    20.         #pragma target 3.0
    21.  
    22.         sampler2D _MainTex;
    23.  
    24.         struct Input {
    25.             float2 uv_MainTex;
    26.         };
    27.  
    28.         half _Glossiness;
    29.         half _Metallic;
    30.         fixed4 _Color;
    31.  
    32.         void surf (Input IN, inout SurfaceOutputStandard o) {
    33.             // Albedo comes from a texture tinted by color
    34.             fixed3 c = tex2D (_MainTex, IN.uv_MainTex);
    35.             //fixed3 c = _MainTex.rgb;
    36.             o.Albedo = c.rgb;
    37.             // Metallic and smoothness come from slider variables
    38.             o.Metallic = _Metallic;
    39.             o.Smoothness = _Glossiness;
    40.             o.Alpha = tex2D(_MainTex, IN.uv_MainTex).a;
    41.         }
    42.         ENDCG
    43.     }
    44.     FallBack "Diffuse"
    45. }
    46.  
    Thanks in advance!
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148