Search Unity

Shader broken in 2.6

Discussion in 'Shaders' started by Mixaster, Oct 29, 2009.

  1. Mixaster

    Mixaster

    Joined:
    Sep 15, 2009
    Posts:
    6
    I downloaded the new 2.6 version and found the main shader I'm using for our ground geometry is broken. It only shows black. Here's the code:

    Code (csharp):
    1. Shader "Terrain/Three Layer" {
    2. Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _MainTex ("Color 1 (RGB)", 2D) = "grey" {}
    5.     _MainTex2 ("Color 2 (RGB)", 2D) = "grey" {}
    6.     _MainTex3 ("Color 3 (RGB)", 2D) = "grey" {}
    7.     _Mask ("Mixing Mask (RGBA)", 2D) = "white" {}
    8. }
    9. SubShader {
    10.    
    11.        
    12.         // Ambient pass
    13.         Pass {
    14.             Name "BASE"
    15.             Tags {"LightMode" = "PixelOrNone"}
    16.             Color [_PPLAmbient]
    17.             SetTexture [_MainTex] {constantColor [_Color] Combine texture * primary DOUBLE, texture * constant}
    18.         }
    19.         // Vertex lights
    20.         Pass {
    21.             Name "BASE"
    22.             Tags {"LightMode" = "Vertex"}
    23.             Lighting On
    24.             Material {
    25.                 Diffuse [_Color]
    26.                 Emission [_PPLAmbient]
    27.             }
    28.             SetTexture [_MainTex] { constantColor [_Color] Combine texture * primary DOUBLE, texture * constant}
    29.         }
    30.         // Pixel lights
    31.         Pass {
    32.             Name "PPL"
    33.             Tags { "LightMode" = "Pixel" }
    34.    
    35. CGPROGRAM
    36. #pragma vertex vert
    37. #pragma fragment frag
    38. #pragma multi_compile_builtin
    39. #pragma fragmentoption ARB_fog_exp2
    40. #pragma fragmentoption ARB_precision_hint_fastest
    41. #include "UnityCG.cginc"
    42. #include "AutoLight.cginc"
    43.  
    44. struct v2f {
    45.     V2F_POS_FOG;
    46.     LIGHTING_COORDS
    47.     float2  uv[4];
    48.     float3  normal;
    49.     float3  lightDirT;
    50. };
    51.  
    52. uniform float4 _MainTex_ST, _MainTex2_ST, _MainTex3_ST, _Mask_ST;
    53.  
    54. v2f vert (appdata_tan v)
    55. {
    56.     v2f o;
    57.     PositionFog( v.vertex, o.pos, o.fog );
    58.     o.normal = v.normal;
    59.     o.uv[0].xy = TRANSFORM_TEX(v.texcoord, _MainTex);
    60.     o.uv[1].xy = TRANSFORM_TEX(v.texcoord, _MainTex2);
    61.     o.uv[2].xy = TRANSFORM_TEX(v.texcoord, _MainTex3);
    62.     o.uv[3].xy = TRANSFORM_TEX(v.texcoord, _Mask);
    63.    
    64.     TANGENT_SPACE_ROTATION;
    65.     o.lightDirT = ObjSpaceLightDir( v.vertex );
    66.    
    67.     TRANSFER_VERTEX_TO_FRAGMENT(o);
    68.     return o;
    69. }
    70.  
    71. uniform sampler2D _MainTex : register(s0);
    72. uniform sampler2D _MainTex2 : register(s1);
    73. uniform sampler2D _MainTex3 : register(s2);
    74. uniform sampler2D _Mask : register(s3);
    75.  
    76. half4 frag( v2f i ) : COLOR
    77. {
    78.     // get the four layer colors
    79.     half4 color1 = tex2D( _MainTex, i.uv[0].xy );
    80.     half4 color2 = tex2D( _MainTex2, i.uv[1].xy );
    81.     half4 color3 = tex2D( _MainTex3, i.uv[2].xy );
    82.     // get the mixing mask texture
    83.     half4 mask = tex2D( _Mask, i.uv[3].xy );
    84.     // mix the four layers
    85.     half4 color = color1 * mask.r + color2 * mask.g + color3 * mask.b;
    86.     // match mask alpha
    87.     color.a = mask.a;  
    88.    
    89.     float3 normal = i.normal;
    90.    
    91.    
    92.    //multiply and double by the lighting
    93.     return DiffuseLight( i.lightDirT, normal, color, LIGHT_ATTENUATION(i) );
    94.  
    95. }
    96. ENDCG
    97.         SetTexture[_MainTex] {}
    98.         SetTexture[_MainTex2] {}
    99.         SetTexture[_MainTex3] {}
    100.         SetTexture[_Mask] {}
    101.     }
    102. }
    103. FallBack " VertexLit", 1
    104. }
    If I change the return out of the fragment program to just "return color;", textures show up, but it looks like the tiling is multiplied by a factor of 30...

    I'm not adept at shaders yet, and really just cobbled this together from pieces of other shaders, so I'm not surprised it's messed up. Any insights as to what could be causing it? I'm at a loss...
     
  2. Mixaster

    Mixaster

    Joined:
    Sep 15, 2009
    Posts:
    6
    Nevermind. Turns out it wasn't the shader, but it was having two pixel lights in the scene (one directional, one spot).
     
  3. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Is the behaviour different in 2.6, though?
     
  4. Mixaster

    Mixaster

    Joined:
    Sep 15, 2009
    Posts:
    6
    Well, it was working fine in 2.5.1, but I'm still not convinced that it doesn't have something to do with the shader.
     
  5. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    It worked with two lights in 2.5.1?
     
  6. Mixaster

    Mixaster

    Joined:
    Sep 15, 2009
    Posts:
    6
    Yeah, worked fine.
     
  7. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    You should file a bug report on that regression.