Greetings. I’m writing a custom shader (for the first time ever), based on the built-in Diffuse, which attempts to incorporate a second (“overlay”) texture in it. As I’m using this material onto procedurally-generated meshes, I reckoned I’d use the second UV set of the mesh as UV coordinates for the overlay texture. (Mostly because I’ve got no idea how to pass UVs to a different texture in a material during runtime.)
In any case, I seem to be unable to use IN.uv2_MainTex as a parameter to my tex2D for _OverlayTex.
Here’s my code (not all of it, the rest of the usual stuff is not included in this snippet):
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
sampler2D _OverlayTex;
fixed4 _Color;
struct Input {
float2 uv_MainTex;
float2 uv2_MainTex;
float4 _Color;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
fixed4 c2 = tex2D(_OverlayTex, IN.uv2_MainTex) * _Color;
o.Albedo = lerp(c.rgb, c2.rgb, c2.a);
o.Alpha = c.a;
}
ENDCG
}
I’m having problems with the "fixed4 c2 = " line: “Shader error in ‘Diffuse-OverlayTex’: Program ‘frag_surf’, declaration of “_MainTex_ST” conflicts with previous declaration at (51) at line 51”, and one for “vert_surf”, accordingly. And given that I mostly have got no idea what I’m doing, can someone please tell me what I’ve got to do to get this to work?