Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Shader error in Unity 5 (worked in Unity 4.6)

Discussion in 'Shaders' started by esco1979, Apr 28, 2015.

  1. esco1979

    esco1979

    Joined:
    Mar 18, 2014
    Posts:
    136
    Hey everyone. I have several custom made palette shaders that worked fine in unity 4.6, but when I upgraded to Unity 5 they stopped functioning. Here is the error on all of them:

    variable 'o' used without having been completely initialized
    Compiling Vertex program

    I did some checking around but none of the solutions I could find fixed it. Can someone please help?

    full code for the first shader with an issue:
    Code (csharp):
    1.              
    2. Shader "Transparent/RedScalePalette" {
    3.     Properties
    4.     {  
    5.         _Blend ("Color Blend", Color) = (1,1,1,1)
    6.         _Add ("Color Additive", Color) = (0,0,0,0)
    7.         _MainTex ("Redscale (R)(G) Alpha (A)", 2D) = "white" {}
    8.         _PaletteCount("PaletteCount", float) = 2.0
    9.         _ColorRamp ("Color Palette", 2D) = "gray" {}
    10.     }
    11.  
    12.     Category
    13.     {
    14.         Tags {Queue=Transparent}
    15.         SubShader
    16.         {
    17.            Pass
    18.            {          
    19.                 ZWrite Off
    20.                 Cull Off
    21.                
    22.                 Blend SrcAlpha OneMinusSrcAlpha
    23.                 Color [_Blend]            
    24.                Name "RedScalePalette"
    25.            
    26.                CGPROGRAM
    27.                     #pragma glsl
    28.                     #pragma target 3.0
    29.                    #pragma vertex vert
    30.                    #pragma fragment frag
    31.                    #pragma fragmentoption ARB_precision_hint_fastest
    32.                    #include "UnityCG.cginc"
    33.                  
    34.                       struct Input
    35.                       {
    36.                           float4 _Blend : COLOR;
    37.                       };
    38.                    
    39.                       struct appdata_t
    40.                     {
    41.                         float4 color    : COLOR;
    42.                     };
    43.                                
    44.                    struct v2f
    45.                    {
    46.                        float4  pos : SV_POSITION;
    47.                         fixed4 color    : COLOR;
    48.                        float2  uv : TEXCOORD0;
    49.                         half2 texcoord  : TEXCOORD0;
    50.                    };
    51.      
    52.                    v2f vert (appdata_tan v, appdata_t u)
    53.                    {
    54.                        v2f o;
    55.                        o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    56.                        o.uv = v.texcoord.xy;
    57.                         o.color = u.color;
    58.                      
    59.                        return o;
    60.                    }
    61.                
    62.                     float4 _Blend;
    63.                     float4 _Add;
    64.                    sampler2D _MainTex;
    65.                    sampler2D _ColorRamp;
    66.                     float _PaletteCount;
    67.      
    68.                    float4 frag(v2f i) : COLOR
    69.                    {
    70.                    // SURFACE COLOUR
    71.                        float colorMap = (tex2D(_MainTex, i.uv).r);                  
    72.                      
    73.                         float4 pCoord = tex2Dlod(_MainTex, float4(i.texcoord.xy, 0.0, 0.0));
    74.                      
    75.                         float palSize = 1.0/_PaletteCount;
    76.                         float palShift = i.color.r*255.0;
    77.                
    78.                    // RESULT
    79.                        float4 result;
    80.                        result.rgb = tex2D(_ColorRamp, float2(colorMap, (pCoord.r*palSize+palSize*(palShift-1)))).rgb;
    81.                        result.r = (result.r * _Blend.r) + (_Add.r * _Add.a);
    82.                        result.g = (result.g * _Blend.g) + (_Add.g * _Add.a);                    
    83.                        result.b = (result.b * _Blend.b) + (_Add.b * _Add.a);                    
    84.                      
    85.                        result.a = tex2D(_ColorRamp, float2(colorMap, (pCoord.r*palSize+palSize*(palShift-1)))).a;
    86.                        result.a = result.a*(tex2D(_MainTex, i.uv).a)* i.color.a* _Blend.a;
    87.                        return result;
    88.                    }
    89.                ENDCG
    90.            }
    91.         }
    92.     }
    93. }
    94.  
    95.  
    And now the relevant code for the other shader with the issue:

    Code (csharp):
    1.  
    2. v2f vert (appdata_t v)
    3.                {
    4.                    v2f o;
    5.                    o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    6.                    #ifdef SOFTPARTICLES_ON
    7.                    o.projPos = ComputeScreenPos (o.vertex);
    8.                    COMPUTE_EYEDEPTH(o.projPos.z);
    9.                    #endif
    10.                    o.color = v.color;
    11.                    o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
    12.                    return o;
    13.                }
    14.  
     
    Last edited: May 1, 2015
  2. IndreamsStudios

    IndreamsStudios

    Joined:
    Jun 4, 2013
    Posts:
    9
    It might be complaining that o.projPos in your second snippet isn't set all the time. If you're multi-compiling your shaders and a material uses it with SOFTPARTICLES_ON not set, then v2f won't be fully initialized.
     
  3. esco1979

    esco1979

    Joined:
    Mar 18, 2014
    Posts:
    136
    I'm sorry but I don't even have a material setup that uses the 2nd shader, and the error is appearing on the shader itself so I do not see how that can be a cause. I also do not see any code that says multi-compile.

    If I am misunderstanding something please excuse me, as I have no knowledge on shader code.
     
    Last edited: Apr 28, 2015
  4. EmmaEwert

    EmmaEwert

    Joined:
    Mar 13, 2014
    Posts:
    30
    In those cases where SOFTPARTICLES_ON is not defined, o.projPos does not get set.

    You either need to wrap the v2f struct definition's projPos member in an #ifdef SOFTPARTICLES_ON ... #endif as well, or alternatively make sure that projPos always gets set.

    Since there is probably references to projPos in the fragment/surface shader as well, your easiest bet might be to just make sure every v2f member is initialized, either explicitly or by writing this where you declare o to initialize everything with zero:
    Code (shader):
    1. v2f o = (v2f)0;
    The best approach would probably be to make sure you wrap the declaration and every use of the member projPos in an #ifdef, though.

    The error message tells you that every single member of the v2f struct should be assigned in all cases.
     
  5. esco1979

    esco1979

    Joined:
    Mar 18, 2014
    Posts:
    136
    Hi Emma. projPos is only used in the 2nd shader, NOT the 1st. I tried throwing in the line of code above into the 1st, but then I get another error, in addition to the original one shown above:

    Inconsistent semantic definition: output semantic 'TEXCOORD0' and output semantic 'TEXCOORD0'
    Compiling Vertex program

    I included the complete shader below with your edit. Since the others are derived from this one hopefully if I can fix this one, I can make the same change to the other and it will work.

    Code (csharp):
    1.  
    2.  
    3. Shader "Transparent/RedScalePalette" {
    4.     Properties
    5.     {    
    6.         _Blend ("Color Blend", Color) = (1,1,1,1)
    7.         _Add ("Color Additive", Color) = (0,0,0,0)
    8.         _MainTex ("Redscale (R)(G) Alpha (A)", 2D) = "white" {}
    9.         _PaletteCount("PaletteCount", float) = 2.0
    10.         _ColorRamp ("Color Palette", 2D) = "gray" {}
    11.     }
    12.    
    13.     Category
    14.     {
    15.         Tags {Queue=Transparent}
    16.         SubShader
    17.         {
    18.            Pass
    19.            {            
    20.                 ZWrite Off
    21.                 Cull Off
    22.                  
    23.                 Blend SrcAlpha OneMinusSrcAlpha
    24.                 Color [_Blend]              
    25.                Name "RedScalePalette"
    26.              
    27.                CGPROGRAM
    28.                     #pragma glsl
    29.                     #pragma target 3.0
    30.                    #pragma vertex vert
    31.                    #pragma fragment frag
    32.                    #pragma fragmentoption ARB_precision_hint_fastest
    33.                    #include "UnityCG.cginc"
    34.                    
    35.                       struct Input
    36.                       {
    37.                           float4 _Blend : COLOR;
    38.                       };
    39.                      
    40.                       struct appdata_t
    41.                     {
    42.                         float4 color    : COLOR;
    43.                     };
    44.                                  
    45.                    struct v2f
    46.                    {
    47.                        float4  pos : SV_POSITION;
    48.                         fixed4 color    : COLOR;
    49.                        float2  uv : TEXCOORD0;
    50.                         half2 texcoord  : TEXCOORD0;
    51.                    };
    52.        
    53.                    v2f vert (appdata_tan v, appdata_t u)
    54.                    {
    55.                        v2f o = (v2f)0;
    56.                        o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    57.                        o.uv = v.texcoord.xy;
    58.                         o.color = u.color;
    59.                        
    60.                        return o;
    61.                    }
    62.                  
    63.                     float4 _Blend;
    64.                     float4 _Add;
    65.                    sampler2D _MainTex;
    66.                    sampler2D _ColorRamp;
    67.                     float _PaletteCount;
    68.        
    69.                    float4 frag(v2f i) : COLOR
    70.                    {
    71.                    // SURFACE COLOUR
    72.                        float colorMap = (tex2D(_MainTex, i.uv).r);                    
    73.                        
    74.                         float4 pCoord = tex2Dlod(_MainTex, float4(i.texcoord.xy, 0.0, 0.0));
    75.                        
    76.                         float palSize = 1.0/_PaletteCount;
    77.                         float palShift = i.color.r*255.0;
    78.                  
    79.                    // RESULT
    80.                        float4 result;
    81.                        result.rgb = tex2D(_ColorRamp, float2(colorMap, (pCoord.r*palSize+palSize*(palShift-1)))).rgb;
    82.                        result.r = (result.r * _Blend.r) + (_Add.r * _Add.a);
    83.                        result.g = (result.g * _Blend.g) + (_Add.g * _Add.a);                      
    84.                        result.b = (result.b * _Blend.b) + (_Add.b * _Add.a);                      
    85.                        
    86.                        result.a = tex2D(_ColorRamp, float2(colorMap, (pCoord.r*palSize+palSize*(palShift-1)))).a;
    87.                        result.a = result.a*(tex2D(_MainTex, i.uv).a)* i.color.a* _Blend.a;
    88.                        return result;
    89.                    }
    90.                ENDCG
    91.            }
    92.         }
    93.     }
    94. }
    95.  
     
  6. EmmaEwert

    EmmaEwert

    Joined:
    Mar 13, 2014
    Posts:
    30
    Well, you have half2 texcoord : TEXCOORD0 in the v2f struct. That never gets set explicity (it will always be 0), yet you use it in line 74. Additionally, both uv and texcoord in the v2f struct use the same semantic, namely TEXCOORD0.
     
  7. esco1979

    esco1979

    Joined:
    Mar 18, 2014
    Posts:
    136
    Sad to say I have no idea how to fix that; as I said above I do not know shader language. It seems to be a lot pickier than C# and the syntax is def. different. BTW this code worked fine in Unity 4.6. But when I upgraded to Unity 5 it stopped working.

    Can someone please assist with this? This is probably a 1-2 line fix, but it has been several days now.
     
  8. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    @esco1979 , I believe the answer to your problem is in this forum thread.

    Specifically, the part about the new Unity macro UNITY_INITIALIZE_OUTPUT(v2f, o);
     
    echo4papa likes this.
  9. esco1979

    esco1979

    Joined:
    Mar 18, 2014
    Posts:
    136
    Although I feel stupid asking something this simple, where is that line supposed to go? I checked the thread but it isn't very detailed and wherever I put that line of code I was still getting the error (I tried it in literally about 10 different places, including before and after the v2f o declaration).

    People don't seem to want to be detailed with answering questions here. Which obviously doesn't help people like me who want to learn these things.
     
  10. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    Look on this Unity doc page under the section Custom data computed per-vertex:
    http://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html
     
  11. esco1979

    esco1979

    Joined:
    Mar 18, 2014
    Posts:
    136
    Ok, I looked at the info you recommended and tried about 15 different things and none of it works. The problem is unlike C# I have no idea what I am doing with shaders and my code looks very different from what you are linking to. I read thru and tried a multitude of things, and after 2 weeks I just do not get what I am missing here.

    Can someone please put up the corrections I need for the code? An explanation would be nice too but seeing as what I am asking for is a tiny thing and people here just seem to want to drop hints instead of actually helping, that seems like it would be asking for waaaaaaaay too much sadly. :(
     
    Last edited: May 12, 2015
  12. esco1979

    esco1979

    Joined:
    Mar 18, 2014
    Posts:
    136
    Still in need of help here. Literally 2 weeks and unsolved, really need this thing working.
     
  13. echo4papa

    echo4papa

    Joined:
    Mar 26, 2015
    Posts:
    158
    Code (CSharp):
    1. v2f vert (appdata_tan v, appdata_t u)
    2.                    {
    3.                        v2f o;
    4. UNITY_INITIALIZE_OUTPUT(v2f,o);
    5.                        o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    6.                        o.uv = v.texcoord.xy;
    7.                         o.color = u.color;
    8.                    
    9.                        return o;
    10.                    }
    Goes like that.
     
    esco1979 likes this.
  14. echo4papa

    echo4papa

    Joined:
    Mar 26, 2015
    Posts:
    158
    Code (CSharp):
    1. v2f vert (appdata_t v)
    2.                {
    3.                    v2f o;
    4.                    UNITY_INITIALIZE_OUTPUT(v2f,o);
    5.                    o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    6.                    #ifdef SOFTPARTICLES_ON
    7.                    o.projPos = ComputeScreenPos (o.vertex);
    8.                    COMPUTE_EYEDEPTH(o.projPos.z);
    9.                    #endif
    10.                    o.color = v.color;
    11.                    o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
    12.                    return o;
    13.                }
    Your other one like this.
     
    esco1979 likes this.
  15. echo4papa

    echo4papa

    Joined:
    Mar 26, 2015
    Posts:
    158
    It does this:

    • UNITY_INITIALIZE_OUTPUT(type,name) - initialize variablename of given type to zero.
    Your error is that your output variable o is not initialized. Unity recently dropped their Cg compiler in favor of an HLSL compiler, which can be a bit more strict.
     
    esco1979 likes this.
  16. esco1979

    esco1979

    Joined:
    Mar 18, 2014
    Posts:
    136
    Thank you so much for that detailed explanation Echo4Papa. That is exactly the type of response I was hoping for and I wish more people were as helpful as you just were. :D With another small change that fixed the first shader.

    But when I tried this under the 2nd shader I got TWO errors:

    overlapping output semantics
    Compiling Vertex program with SOFTPARTICLES_OFF

    All I did was add in UNITY_INITIALIZE_OUTPUT(v2f,o). please advise.
     
    Last edited: May 15, 2015
  17. esco1979

    esco1979

    Joined:
    Mar 18, 2014
    Posts:
    136
    P.S. here is the full code for that 2nd shader:

    Code (csharp):
    1.  
    2. Shader "Transparent/Additive/RedScalePalette"
    3. {
    4.     Properties
    5.     {
    6.        _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
    7.        _MainTex ("Particle Texture", 2D) = "white" {}
    8.        _ColorRamp ("Color Palette", 2D) = "gray" {}
    9.        _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
    10.         _PaletteCount("PaletteCount", float) = 2.0
    11.     }
    12.      
    13.     Category
    14.     {
    15.        Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    16.        Blend SrcAlpha One
    17.        AlphaTest Greater .01
    18.        ColorMask RGB
    19.        Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
    20.        BindChannels
    21.        {
    22.            Bind "Color", color
    23.            Bind "Vertex", vertex
    24.            Bind "TexCoord", texcoord
    25.        }
    26.      
    27.        // ---- Fragment program cards
    28.        SubShader
    29.        {
    30.            Pass
    31.            {    
    32.                CGPROGRAM
    33.                 #pragma glsl
    34.                 #pragma target 3.0
    35.                #pragma vertex vert
    36.                #pragma fragment frag
    37.                #pragma fragmentoption ARB_precision_hint_fastest
    38.                #pragma multi_compile_particles
    39.      
    40.                #include "UnityCG.cginc"
    41.      
    42.                sampler2D _MainTex;
    43.                fixed4 _TintColor;
    44.      
    45.                struct appdata_t
    46.                {
    47.                    float4 vertex : POSITION;
    48.                    fixed4 color : COLOR;
    49.                    float2 texcoord : TEXCOORD0;
    50.                };
    51.      
    52.                struct v2f
    53.                {
    54.                    float4 vertex : POSITION;
    55.                    fixed4 color : COLOR;
    56.                    float2 texcoord : TEXCOORD0;
    57.                    float2  uv : TEXCOORD0;
    58.                    #ifdef SOFTPARTICLES_ON
    59.                    float4 projPos : TEXCOORD1;
    60.                    #endif
    61.                };
    62.      
    63.                float4 _MainTex_ST;
    64.      
    65.                v2f vert (appdata_t v)
    66.                {
    67.                    v2f o;
    68.                    UNITY_INITIALIZE_OUTPUT(v2f,o);
    69.                    o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    70.                    #ifdef SOFTPARTICLES_ON
    71.                    o.projPos = ComputeScreenPos (o.vertex);
    72.                    COMPUTE_EYEDEPTH(o.projPos.z);
    73.                    #endif
    74.                    o.color = v.color;
    75.                    o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
    76.                    return o;
    77.                }
    78.      
    79.                sampler2D _CameraDepthTexture;
    80.                float _InvFade;
    81.                sampler2D _ColorRamp;
    82.                 float _PaletteCount;
    83.      
    84.                   float4 frag (v2f i) : COLOR
    85.                   {
    86.                  
    87.                      #ifdef SOFTPARTICLES_ON
    88.                      float sceneZ = LinearEyeDepth (UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos))));
    89.                      float partZ = i.projPos.z;
    90.                      float fade = saturate (_InvFade * (sceneZ-partZ));
    91.                      i.color.a *= fade;
    92.                      #endif                
    93.                      
    94.                    float colorMap = (tex2D(_MainTex, i.uv).r);                    
    95.                    
    96.                     float4 pCoord = tex2Dlod(_MainTex, float4(i.texcoord.xy, 0.0, 0.0));
    97.                    
    98.                     float palSize = 1.0/_PaletteCount;
    99.                     float palShift = i.color.r*255.0;
    100.                
    101.                    
    102.                    float4 result;
    103.                    result.rgb = tex2D(_ColorRamp, float2(colorMap, (pCoord.r*palSize+palSize*(palShift-1)))).rgb;
    104.                    result.r = (result.r);
    105.                    result.g = (result.g);                      
    106.                    result.b = (result.b);
    107.                                      
    108.                    result.a = tex2D(_ColorRamp, float2(colorMap, (pCoord.r*palSize+palSize*(palShift-1)))).a;
    109.                    result.a = result.a*(tex2D(_MainTex, i.uv).a)* i.color.a;
    110.                    
    111.                      return 2.0f * result * _TintColor;
    112.                   }
    113.                ENDCG
    114.            }
    115.        }  
    116.      
    117.        // ---- Dual texture cards
    118.        SubShader
    119.        {
    120.            Pass
    121.            {
    122.                SetTexture [_MainTex]
    123.                {
    124.                    constantColor [_TintColor]
    125.                    combine constant * primary
    126.                }
    127.                SetTexture [_MainTex]
    128.                {
    129.                    combine texture * previous DOUBLE
    130.                }
    131.            }
    132.        }
    133.      
    134.        // ---- Single texture cards (does not do color tint)
    135.        SubShader
    136.        {
    137.            Pass
    138.            {
    139.                SetTexture [_MainTex]
    140.                {
    141.                    combine texture * primary
    142.                }
    143.            }
    144.        }
    145.     }
    146. }
    147.  
     
  18. echo4papa

    echo4papa

    Joined:
    Mar 26, 2015
    Posts:
    158
    Ah, you can't use TEXCOORD0 multiple times.

    Code (CSharp):
    1.  
    2. Shader "Transparent/Additive/RedScalePalette"
    3. {
    4.     Properties
    5.     {
    6.        _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
    7.        _MainTex ("Particle Texture", 2D) = "white" {}
    8.        _ColorRamp ("Color Palette", 2D) = "gray" {}
    9.        _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
    10.         _PaletteCount("PaletteCount", float) = 2.0
    11.     }
    12.    
    13.     Category
    14.     {
    15.        Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    16.        Blend SrcAlpha One
    17.        AlphaTest Greater .01
    18.        ColorMask RGB
    19.        Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
    20.        BindChannels
    21.        {
    22.            Bind "Color", color
    23.            Bind "Vertex", vertex
    24.            Bind "TexCoord", texcoord
    25.        }
    26.    
    27.        // ---- Fragment program cards
    28.        SubShader
    29.        {
    30.            Pass
    31.            {  
    32.                CGPROGRAM
    33.                 #pragma glsl
    34.                 #pragma target 3.0
    35.                #pragma vertex vert
    36.                #pragma fragment frag
    37.                #pragma fragmentoption ARB_precision_hint_fastest
    38.                #pragma multi_compile_particles
    39.    
    40.                #include "UnityCG.cginc"
    41.    
    42.                sampler2D _MainTex;
    43.                fixed4 _TintColor;
    44.    
    45.                struct appdata_t
    46.                {
    47.                    float4 vertex : POSITION;
    48.                    fixed4 color : COLOR;
    49.                    float2 texcoord : TEXCOORD0;
    50.                };
    51.    
    52.                struct v2f
    53.                {
    54.                    float4 vertex : POSITION;
    55.                    fixed4 color : COLOR;
    56.                    float2 texcoord : TEXCOORD0;
    57.                    float2  uv : TEXCOORD1;
    58.                    #ifdef SOFTPARTICLES_ON
    59.                    float4 projPos : TEXCOORD2;
    60.                    #endif
    61.                };
    62.    
    63.                float4 _MainTex_ST;
    64.    
    65.                v2f vert (appdata_t v)
    66.                {
    67.                    v2f o;
    68.                    UNITY_INITIALIZE_OUTPUT(v2f,o);
    69.                    o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    70.                    #ifdef SOFTPARTICLES_ON
    71.                    o.projPos = ComputeScreenPos (o.vertex);
    72.                    COMPUTE_EYEDEPTH(o.projPos.z);
    73.                    #endif
    74.                    o.color = v.color;
    75.                    o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
    76.                    return o;
    77.                }
    78.    
    79.                sampler2D _CameraDepthTexture;
    80.                float _InvFade;
    81.                sampler2D _ColorRamp;
    82.                 float _PaletteCount;
    83.    
    84.                   float4 frag (v2f i) : COLOR
    85.                   {
    86.                
    87.                      #ifdef SOFTPARTICLES_ON
    88.                      float sceneZ = LinearEyeDepth (UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos))));
    89.                      float partZ = i.projPos.z;
    90.                      float fade = saturate (_InvFade * (sceneZ-partZ));
    91.                      i.color.a *= fade;
    92.                      #endif              
    93.                    
    94.                    float colorMap = (tex2D(_MainTex, i.uv).r);                  
    95.                  
    96.                     float4 pCoord = tex2Dlod(_MainTex, float4(i.texcoord.xy, 0.0, 0.0));
    97.                  
    98.                     float palSize = 1.0/_PaletteCount;
    99.                     float palShift = i.color.r*255.0;
    100.              
    101.                  
    102.                    float4 result;
    103.                    result.rgb = tex2D(_ColorRamp, float2(colorMap, (pCoord.r*palSize+palSize*(palShift-1)))).rgb;
    104.                    result.r = (result.r);
    105.                    result.g = (result.g);                    
    106.                    result.b = (result.b);
    107.                                    
    108.                    result.a = tex2D(_ColorRamp, float2(colorMap, (pCoord.r*palSize+palSize*(palShift-1)))).a;
    109.                    result.a = result.a*(tex2D(_MainTex, i.uv).a)* i.color.a;
    110.                  
    111.                      return 2.0f * result * _TintColor;
    112.                   }
    113.                ENDCG
    114.            }
    115.        }
    116.    
    117.        // ---- Dual texture cards
    118.        SubShader
    119.        {
    120.            Pass
    121.            {
    122.                SetTexture [_MainTex]
    123.                {
    124.                    constantColor [_TintColor]
    125.                    combine constant * primary
    126.                }
    127.                SetTexture [_MainTex]
    128.                {
    129.                    combine texture * previous DOUBLE
    130.                }
    131.            }
    132.        }
    133.    
    134.        // ---- Single texture cards (does not do color tint)
    135.        SubShader
    136.        {
    137.            Pass
    138.            {
    139.                SetTexture [_MainTex]
    140.                {
    141.                    combine texture * primary
    142.                }
    143.            }
    144.        }
    145.     }
    146. }
     
    esco1979 likes this.
  19. esco1979

    esco1979

    Joined:
    Mar 18, 2014
    Posts:
    136
    Lol, that is exactly what I had to fix in the first one after adding in your line of code too. Looks like that's another change they made in Unity 5. Thanks so much for your help, that fixed it and you have no idea how happy I am right now. :D

    I'm going to look around and see if I can figure out how to set the shader to take lighting now on my own. Thanks again for helping me fix this.
     
    echo4papa likes this.
  20. echo4papa

    echo4papa

    Joined:
    Mar 26, 2015
    Posts:
    158
    No problem, you're welcome! :D