I’m trying to get through the shader tut #2
http://unity3d.com/support/documentation/Manual/ShaderTut2.html
It’s as though the tutorial is very thorough and then wham, hits you w/ a ton of crap that makes no sense under the premise that all is known. I wouldn’t be doing a tutorial if I already knew what all of this was. Can someone explain these elements?
First is a vertex color the area around the vertex and fragment color the color of the main body of the polygon? I’m not sure what’s what.
struct v2f {
float4 pos : SV_POSITION;
float3 color : COLOR0;
};
What is a struct? What’s a float3 vs. a float4? Where did SV_POSITION and COLOR0 come from? Are they inherit to Unity?
v2f vert (appdata_base v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.color = v.normal * 0.5 + 0.5;
return o;
}
I get that appdata_base is available because of UnityCg.cginc but what does it do? Why do I need it? I assume that the preceding code creates some sort of function but “v2f vert (appdata_base v)”?? What on earth is that? I’m guessing its similar to function vert(v2f,v) but aren’t really sure. v2f o; is this a way of declaring o as a variable of type v2f? Where did mul come from, what does it do?
half4 frag (v2f i) : COLOR
{
return half4 (i.color, 1);
}
Same questions as before on the first line except now there’s :COLOR added. I think I know what’s happening on the next line but I’m not sure what it’s returning. Does this loop through each polygon and update the color individually or all at once w/ an array?