- Home /
Combining Textures and Shaders
So I have a question about shaders. What we want is a shader that combines two textures and applies diffuse lighting to it. I have the parts of the shader in that we have a shader that combines textures and I have the source code for the mobile diffuse shader that has the right lighting, but I don't have the knowledge of Shaderlab to actually combine the two shaders. I've included the source for both of them below, any help combining the two would be greatly appreciated.
Thanks in advance for anyone that provides any help!
Shader "Pat/PlumberTattoo" {
Properties
{
_MainTex ("Main Tex (RGBA)", 2D) = "white"
_DecalTex ("Decal Tex (RGBA)", 2D) = ""
}
SubShader
{
Pass
{
SetTexture[_MainTex]
{
Combine texture Lerp(texture) constant
}
SetTexture[_DecalTex] {Combine texture Lerp(texture) previous}
}
}
}
// Simplified Diffuse shader. Differences from regular Diffuse one:
// - no Main Color
// - fully supports only 1 directional light. Other lights can affect it, but it will be per-vertex/SH.
Shader "Mobile/Diffuse" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 150
CGPROGRAM
#pragma surface surf Lambert noforwardadd
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
Fallback "Mobile/VertexLit"
}
Comment
Answer by cg · Dec 21, 2012 at 12:58 AM
You can use lerp to combine two textures
Pass {
//First Texture
SetTexture [_MainTex] {
combine texture
}
//Second Texture
SetTexture [_SecondTex] {
combine texture lerp (texture) previous
}
}