Game Development Reference
In-Depth Information
In the
surf()
funcion, we have the following:
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
surf(Input IN, inout SurfaceOutput o)
funcion is basically the
funcion that will get the input informaion from
struct Input {}
. Then,
we will assign the new parameter to
SurfaceOutput
o
. This parameter will
get passed and used next in the vertex and pixel processor.
We can get more details on the
Input
struct
and the default parameter of
SurfaceOutput
struct
here:
http://unity3d.com/support/documentation/Components/
SL-SurfaceShaders.html
.
The
tex2D
funcion will return the color value (Red, Green, Blue, Alpha) or (R,G,B,A) from
the sample state (
_MainTex
) and the texture coordinate (
IN.uv_MainTex
), which we will
then assign to the
o.Albedo
and
o.Alpha
. The
o.Albedo
parameter will store the color
informaion (RGB) and the
o.Alpha
parameter will store the alpha informaion.
"
Albedo or relecion coeicient, is the difuse relecivity or relecing power
of a surface. It is deined as the raio of relected radiaion from the surface
to incident radiaion upon it."
Reference from
http://en.wikipedia.org/wiki/Albedo
The next line is to get the
normal
informaion, which is the vector that contains the posiion
(x, y, and z). Then, we used the
tex2D
funcion to get the color value (R,G,B,A) from the
sample state (
_BumpMap
) and the texture coordinate (
IN.uv_BumpMap
). Then, we used the
UnpackNormal
funcion to get the
Normal
as the result of the
tex2D
funcion.
Classified Intel
Talking about shader programming, there are a lot of things to get to know and understand,
for example, how the shader works. We will take a look at the basic structure of the shader
programming in Unity.