I’m trying to create a shader which displays a texture based on the slope of the vert normals on my mesh, I’m new to shader programming so I’m a little stuck. So far I have managed to calculate the slope and use it to “mask” out the MainTex.
The next stage is to draw into the masked area with _MainTex2 this is where I am stuck.
Shader "SlopeShader" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_MainTex2 ("Grass Texture", 2D) = "white" { }
_Detail ("Detail", 2D) = "gray" {}
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert vertex:vert
struct Input {
float2 uv_MainTex;
float2 uv_MainTex2;
//float2 uv_Detail;
float slope;
};
sampler2D _MainTex;
sampler2D _MainTex2;
//sampler2D _Detail;
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
o.slope = 1.0f - v.normal.y;
}
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb * IN.slope;
o.Alpha = IN.slope;
//o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
}
ENDCG
}
Fallback "Diffuse"
}
In my attempt the black area is what I want the _MainTex2 to show up. Anyone know how I can achieve this?
Thanks, C.