Search Unity

GUI Text Shader not using custom texture color

Discussion in 'Shaders' started by Thunder0ne, Jan 26, 2011.

  1. Thunder0ne

    Thunder0ne

    Joined:
    Mar 8, 2009
    Posts:
    23
    Hi all,

    [I posted this before on support, I have realised now that maybe this is the right place, sorry for that]

    I am using a custom font in GUIText objects with a GUI Text Shader, but the colour is not rendered.
    The Alpha is rendered correctly and the font is well recognisable, but the colour is not the same as the original font contained in the texture.
    I had a look into the shader and it looks like it is not using the texture colour at all.
    I have tried (just by guessing, since I do not know shaders) to have it use it but no luck.

    Code (csharp):
    1. Shader "GUI/Text Shader Custom" {
    2.     Properties {
    3.         _MainTex ("Font Texture", 2D) = "white" {}
    4.         _Color ("Text Color", Color) = (1,1,1,1)
    5.     }
    6.  
    7.     SubShader {
    8.  
    9.         Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    10.         Lighting Off Cull Off ZTest Always ZWrite Off Fog { Mode Off }
    11.         Blend SrcAlpha OneMinusSrcAlpha
    12.  
    13.         Pass { 
    14.             CGPROGRAM
    15.             #pragma vertex vert
    16.             #pragma fragment frag
    17.             #pragma fragmentoption ARB_precision_hint_fastest
    18.  
    19.             #include "UnityCG.cginc"
    20.  
    21.             struct appdata_t {
    22.                 float4 vertex : POSITION;
    23.                 float2 texcoord : TEXCOORD0;
    24.             };
    25.  
    26.             struct v2f {
    27.                 float4 vertex : POSITION;
    28.                 float2 texcoord : TEXCOORD0;
    29.             };
    30.  
    31.             sampler2D _MainTex;
    32.             uniform float4 _MainTex_ST;
    33.             uniform float4 _Color;
    34.            
    35.             v2f vert (appdata_t v)
    36.             {
    37.                 v2f o;
    38.                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    39.                 o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
    40.                 return o;
    41.             }
    42.  
    43.             half4 frag (v2f i) : COLOR
    44.             {
    45.                 float4 col = _Color;
    46.                 col.a *= tex2D(_MainTex, i.texcoord).a;
    47.                 //col.rgb = tex2D(_MainTex, i.texcoord).rgb;//my custom line that did not have any result
    48.                 return col;
    49.             }
    50.             ENDCG
    51.         }
    52.     }  
    53.  
    54.     SubShader {
    55.         Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    56.         Lighting Off Cull Off ZTest Always ZWrite Off Fog { Mode Off }
    57.         Blend SrcAlpha OneMinusSrcAlpha
    58.         Pass {
    59.             Color [_Color]
    60.             SetTexture [_MainTex] {
    61.                 combine primary, texture * primary
    62.             }
    63.         }
    64.     }
    65. }
    Any suggestion?
     
  2. boxerlin

    boxerlin

    Joined:
    Nov 18, 2010
    Posts:
    11
    Just multiply by the whole color :)
     
    uniteiro likes this.