Diffuse shader that supports 2 UVs?

Hi,

Does anyone know where I can find a Diffuse shader that supports 2 different UVs on a single model?
I need to apply 2 different textures onto my character so that I can animate one of the UV separately during game.

The old Lightmapped/Diffuse shader works somewhat, but I don’t want the 2nd texture to overlay the 1st in any way, which this shader is doing.

Any help is appreciated. Thanks! :slight_smile:

One texture will have to overlay the other in some way or you wont see it.

Quick test done with the shader editor. To stop things overlaying you’ll need to setup the UV’s not to overlap.

Shader "2uvshadertest"
{
	Properties
	{
_Color("_Color", Color) = (1,1,1,1)
_Texture1("_Texture1", 2D) = "white" {}
_Texture2("_Texture2", 2D) = "white" {}

	}

	SubShader
	{
		Tags
		{
"Queue"="Geometry"
"IgnoreProjector"="False"
"RenderType"="Opaque"

		}


Cull Back
ZWrite On
ZTest LEqual
ColorMask RGBA
Fog{
}


		CGPROGRAM
#pragma surface surf BlinnPhongEditor  vertex:vert
#pragma target 2.0


float4 _Color;
sampler2D _Texture1;
sampler2D _Texture2;

			struct EditorSurfaceOutput {
				half3 Albedo;
				half3 Normal;
				half3 Emission;
				half3 Gloss;
				half Specular;
				half Alpha;
			};

			inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
			{
half3 spec = light.a * s.Gloss;
half4 c;
c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
c.a = s.Alpha;
return c;

			}

			inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
			{
				half3 h = normalize (lightDir + viewDir);

				half diff = max (0, dot (s.Normal, lightDir));

				float nh = max (0, dot (s.Normal, h));
				float spec = pow (nh, s.Specular*128.0);

				half4 res;
				res.rgb = _LightColor0.rgb * diff * atten * 2.0;
				res.w = spec * Luminance (_LightColor0.rgb);

				return LightingBlinnPhongEditor_PrePass( s, res );
			}

			struct Input {
				float4 meshUV;

			};


			void vert (inout appdata_full v, out Input o) {
float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0);

o.meshUV.xy = v.texcoord.xy;
o.meshUV.zw = v.texcoord1.xy;

			}


			void surf (Input IN, inout EditorSurfaceOutput o) {
				o.Normal = float3(0.0,0.0,1.0);
				o.Alpha = 1.0;
				o.Albedo = 0.0;
				o.Emission = 0.0;
				o.Gloss=0.0;
				o.Specular=0.0;

float4 Tex2D0=tex2D(_Texture1,(IN.meshUV.xyxy).xy);
float4 Tex2D1=tex2D(_Texture2,(IN.meshUV.zwzw).xy);
float4 Add0=Tex2D0 + Tex2D1;
float4 Multiply0=_Color * Add0;
float4 Master0_1_NoInput = float4(0,0,1,1);
float4 Master0_2_NoInput = float4(0,0,0,0);
float4 Master0_3_NoInput = float4(0,0,0,0);
float4 Master0_4_NoInput = float4(0,0,0,0);
float4 Master0_5_NoInput = float4(1,1,1,1);
float4 Master0_6_NoInput = float4(1,1,1,1);
o.Albedo = Multiply0;

				o.Normal = normalize(o.Normal);
			}
		ENDCG
	}
	Fallback "Diffuse"
}

Thanks Frank Oz!
I’ve tried out the shader and it works great except my textures appeared brighter than usual on the model. Not sure why… :frowning:

I went to check out some shaders from the Unity Wiki and then read up about shaders in the Unity manual. After hours of fiddling and Frankenstein-ing some shader codes together, I think I’ve finally got something I’m happy with :smile:

Shader " Diffuse (2 UV sets)" {

Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Texture1 (RGB)", 2D) = "white" {}
    _Texture2 ("Texture2 (RGB)", 2D) = "white" {}
}

SubShader {
    Pass {
    	Material {
			Diffuse [_Color]
    	}

	Lighting On

        BindChannels {
            Bind "texcoord", texcoord0 // main uses 1st uv
            Bind "texcoord1", texcoord1 // texture2 uses 2nd uv
        }
        SetTexture[_MainTex] {
        	constantColor [_Color]
		Combine texture * primary DOUBLE
        }
        SetTexture[_Texture2] {
            Combine texture * previous
        }
    }
}

Fallback "Diffuse"

}

Yay! Glad you got something working :smile: My effort was pretty bad, I just wanted an excuse to make something in that guys shader editor cause it’s so much fun to use. :smile: