Problems with Shader utilizing Uv2

I’m currently trying to modify the Toony Gooch Shader to use the 2nd Uv layer coordinates (which are normally reserved for Unity Lightmapping) to multiply with the color returned from the Uv1 coordinates… The line that’s supposed to accomplish this is “o.Albedo = c.rgb * c2.rgb * _Color.rgb * IN.color.rgb * IN.color.a;”. I also defined all the needed variables and encountered no problem until I actually tried multiplying “c2” in the above code. Now according to my (admittedly shaky) understanding of Shaders so far the code below should work. It appears though that the compiled shader creates unexpected errors namely:

GLSL vertex shader: ERROR: 0:416: ‘_MainTexST’ : redefinition at line 22 (which appears to be a comment in the compiled Shader?)
Program ‘frag_surf’, declaration of “_MainTex_ST” conflicts with previous declaration at line 101
Program ‘vert_surf’, declaration of “_MainTex_ST” conflicts with previous declaration at line 101

Here the excerpt from line 101 of the compiled shader:

#ifndef LIGHTMAP_OFF
struct v2f_surf {
  float4 pos : SV_POSITION;
  float4 pack0 : TEXCOORD0;
  float3 viewDir : TEXCOORD1;
  fixed4 color : COLOR0;
  fixed3 normal : TEXCOORD2;
  float2 lmap : TEXCOORD3;
  LIGHTING_COORDS(4,5)
};
#endif

And here the uncompiled shader as is:

Shader "Uv2"
{
	Properties
	{
		_Color ("Main Color", Color) = (1,1,1,1)
	
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
		
		_RimColor ("Rim Color", Color) = (0.8,0.8,0.8,0.6)
        _RimPower ("Rim Power", Float) = 1.4
        
        _SColor ("Shadow Color", Color) = (0.0,0.0,0.0,1)
		_LColor ("Highlight Color", Color) = (0.5,0.5,0.5,1)
	}

	SubShader
	{
		Tags { "RenderType"="Opaque" }
		LOD 200
		
CGPROGRAM
		#pragma surface surf ToonRamp nolightmap 
		
		sampler2D _MainTex;
		sampler2D _Ramp;
		float4 _LColor;
		float4 _SColor;
		float4 _Color;
		float _RimPower;
		float4 _RimColor;
		
		// custom lighting function that uses a texture ramp based
		// on angle between light direction and normal
		#pragma lighting ToonRamp exclude_path:prepass
		inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
		{
			#ifndef USING_DIRECTIONAL_LIGHT
			lightDir = normalize(lightDir);
			#endif
			
			half d = dot (s.Normal, lightDir)*0.5 + 0.5;
			half3 ramp = tex2D(_Ramp, float2(d,d)).rgb;
			ramp = lerp(_SColor,_LColor,ramp);
			
			half4 c;
			c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
			c.a = 0;
			
			return c;
		}
		
		struct Input
		{
			float2 uv_MainTex : TEXCOORD0;
			float2 uv2_MainTex : TEXCOORD1;
			float3 pos : POSITION0;
			float3 viewDir;
			float4 color      : COLOR;
		};
		
		void surf (Input IN, inout SurfaceOutput o)
		{
			half4 c = tex2D(_MainTex, IN.uv_MainTex);
			half4 c2 = tex2D(_MainTex, IN.uv2_MainTex);
			
			o.Albedo = c.rgb * c2.rgb * _Color.rgb * IN.color.rgb * IN.color.a;
			o.Alpha = c.a;
			
			//Rim Light
			half rim = 1.0f - saturate( dot(normalize(IN.viewDir), o.Normal) );
			o.Emission = (_RimColor.rgb * pow(rim, _RimPower)) * _RimColor.a;
		}
ENDCG
	
	}

	Fallback "Toon/Lighted"
}

Did anybody else perhaps already try abusing the second Uv set? Is this a huge undertaking or can this be fixed rather unspectacularly ?

Currently using Unity 3.5.5f3 on Windows 7.

Hi There!

I’m experiencing a similar issue when I tried to declare an UV2 that I want to use with the same sampler

struct Input
        {
            float2 uv_MainTex : TEXCOORD0;
            float2 uv2_MainTex : TEXCOORD1;
}

Anyone have an hint how to solve it or a workaround to make it work?
Thank you.

I have an macbook pro with OSX Lion.

I have the same problem.I think it’s a bug.should be fixed

Still not working with Unity 4.2 :shock:

Seems shader don’t see uv2(to make it clear, uv2 - exist, its a 100% info :wink:) of custom builded mesh on Android (I had tested on three devices Nexus 7, GoClever tab,Samsung Galaxy tab 10.1 ).

I’m seeing the same problem with script set uv2 in both Unity4.2.2f1 and Unity4.3.1f1 (Testing on an OUYA)

Anyone got any ideas … or seen any shaders that work using uv2 on android?

Is this still broken?

It seems it is still broken. Fix it please or mark it as “known issue” at least.

I did get some success with this but only by writing my own shader completely from scratch.

I am able to get uv2 by doing this.

SubShader
{
Tags { “RenderType”=“Opaque” }
LOD 200

CGPROGRAM
#pragma target 3.0
#pragma surface surf Lambert vertex:vert

sampler2D _MainTex;

struct Input
{
float2 uv_MainTex;
float2 getUV2;
};

void vert (inout appdata_full v, out Input o)
{
o.getUV2 = v.texcoord1.xy;
};

void surf (Input IN, inout SurfaceOutput o)
{
float2 uv2 = IN.getUV2;
}
ENDCG
}