OK so I’m trying my hand at writing a shader in CG. It’s supposed to use two textures that blend together along inverse gradients.
The first version here is with only the first texture worked in:
Shader "Tutorial/Textured Colored v1" {
Properties {
_MainTex ("Texture", 2D) = "white" { }
_BlendText ("Texture", 2D) = "black" { }
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_fog_exp2
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _BlendTex;
struct v2f {
V2F_POS_FOG;
float2 uv : TEXCOORD0;
};
v2f vert (appdata_base v)
{
v2f o;
PositionFog( v.vertex, o.pos, o.fog );
o.uv = TRANSFORM_UV(0);
return o;
}
half4 frag (v2f i) : COLOR
{
float alpha = i.uv;
half4 texcol = tex2D( _MainTex, i.uv );
return texcol * (1,1,1,alpha);
}
ENDCG
}
}
Fallback "VertexLit"
}
It seems to work pretty well: http://www.ohlonegdc.com/file-host/shader_v1.jpg
Ok, but when I try to include the second texture along the inverse gradient, here is the code:
Shader "Tutorial/Textured Colored" {
Properties {
_MainTex ("Texture", 2D) = "white" { }
_BlendText ("Texture", 2D) = "black" { }
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_fog_exp2
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _BlendTex;
struct v2f {
V2F_POS_FOG;
float2 uv : TEXCOORD0;
float2 uv2 : TEXCOORD1;
};
v2f vert (appdata_base v)
{
v2f o;
PositionFog( v.vertex, o.pos, o.fog );
o.uv = TRANSFORM_UV(0);
o.uv2 = TRANSFORM_UV(1);
return o;
}
half4 frag (v2f i) : COLOR
{
float alpha = i.uv;
float inverseAlpha = 1 - i.uv2;
half4 texcol = tex2D( _MainTex, i.uv ) * (1,1,1,alpha);
half4 texcolblend = tex2D( _BlendTex, i.uv2) * (1,1,1,inverseAlpha);
return texcol + texcolblend;
}
ENDCG
}
}
Fallback "VertexLit"
}
And the result looks like the second texture is just being interpreted as a solid color: http://www.ohlonegdc.com/file-host/shader_v2.jpg
Any idea what’s happening here? I appreciate any help in advance.