Game Development Reference
In-Depth Information
sign 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
Input struct
and the default parameter of
Sur-
faceOutput struct
at
http://docs.unity3d.com/Documentation/Components/SL-Sur-
Talking about
SurfaceOutput struct
, it is the default struct in Unity, which allows
us to pass the parameters easily without creating one.
Tip
SurfaceOutput struct
is the default struct in Unity, which is located in the
Lighting.cginc
file inside the Unity application. We can also create a custom
Sur-
faceOutput struct
to pass other variables that are not a part of the default struct by
creating a new
SurfaceOutputCustom {…}
struct and passing it to the
surf()
function like
surf (Input IN, inout SurfaceOutputCustom o)
.
The
tex2D()
function 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
o.Albedo
and
o.Alpha
, respect-
ively. The
o.Albedo
parameter will store the color information (RGB) and the
o.Alpha
parameter will store the alpha information.
Note
Albedo, or the reflection coefficient, is defined as the ratio of the reflected radiation from
the surface to the incident radiation upon it. It also refers to the diffuse reflectivity or the
reflecting power of a surface.
More information can be found at
http://en.wikipedia.org/wiki/Albedo
.
The next line is to get the normal information, which is the vector that contains the posi-
tion (
x
,
y
, and
z
). Then, we used the
tex2D()
function to get the color values (R,G,B,A)
from the sample state,
_BumpMap
, and the texture coordinates from
IN.uv_BumpTex
.
Then, we used the
UnpackNormal()
function to get the normal as the result of the
tex2D()
function.