Unity3 b4 shader compiler bug

So it seems that if you try to use uv1 and uv2 in the same shader the compile will fail. The reason seems to be that in the compiled shader it names them with the same name. Heres some example code that will fail (although I have not actually tested this exact code).

  Shader "Example/Diffuse Overlay" {
    Properties {
      _MainTex ("Texture", 2D) = "white" {}
      _OtherTex("OtherTex", 2D) = "white" {}
    }
    SubShader {
      Tags { "RenderType" = "Opaque" }
      CGPROGRAM
      #pragma surface surf Lambert
      struct Input {
        float2 uvCoords; //Builtin for uv1
        float2 uv2Coords; //Builtin for uv2
      };
      sampler2D _MainTex;
      sampler2D _OtherTex;
      void surf (Input IN, inout SurfaceOutput o) {
        float4 mainColor = tex2D(_MainTex, IN.uvCoords);
        float4 otherColor = tex2D(_OtherTex, IN.uv2Coords);
        o.Albedo = mainColor*otherColor;
      }
      ENDCG
    }
    Fallback "Diffuse"
  }

this code also seems to fail(the difference is within the Input struct).

  Shader "Example/Diffuse Overlay" {
    Properties {
      _MainTex ("Texture", 2D) = "white" {}
      _OtherTex("OtherTex", 2D) = "white" {}
    }
    SubShader {
      Tags { "RenderType" = "Opaque" }
      CGPROGRAM
      #pragma surface surf Lambert
      struct Input {
        float2 uv_MainTex;
        float2 uv2_OtherTex;
      };
      sampler2D _MainTex;
      sampler2D _OtherTex;
      void surf (Input IN, inout SurfaceOutput o) {
        float4 mainColor = tex2D(_MainTex, IN.uv_MainTex);
        float4 otherColor = tex2D(_OtherTex, IN.uv2_OtherTex);
        o.Albedo = mainColor*otherColor;
      }
      ENDCG
    }
    Fallback "Diffuse"
  }

This must be a compiler bug unless Im missing something. I filed a bug with another example shader. The case number is 369318.

Added a few ;'s to the examples so now they fail to compile where I was saying.

Im also noticing that uvCoords seems to be scaled incorrectly, and multiplying it by 1.14275 seems to correct the scaling :confused:

EDIT: It seems that uvCoords is inconsistant, sometimes it has an strange scale, and sometimes it doesnt. It seems to be based on your camera angle (maybe what order the objects are being drawn in?).

So your second example should work. In the vertex shader, it will apply scale/offset properties of _MainTex and _OtherTex respectively.

In the first example, it will try to apply scale/offset properties of texture called “Coords”, but since there’s no such texture, the results will be either zero or some garbage.

But yeah, I guess the use case when both UV and UV2 get translated by the same texture (e.g. uv_MainTex and uv2_MainTex) should be made to work. I’ll see what I can do.