Game Development Reference
In-Depth Information
This is to make sure that our properties can be passed and used in the
CGPROGRAM
sec-
tion.
We can see more details about this and see what each parameter does at
ht-
Then, we set the
LOD
(
Level of Detail
) for our shader to
300
. The LOD is the setup that
will limit our shader to use the maximum graphic details of this
SubShader
section to
the number that we set. We used 300 because we have included a bump map in our shader,
which is the same number of the Unity built-in setup for the diffuse bump. You can get
more information on shader LOD at
http://unity3d.com/support/documentation/Compon-
We added the
sampler2D _BumpMap;
line, which is the same property that gets
passed from the
Properties
section:
_BumpMap ("Bumpmap", 2D) = "bump" {}
Note
sampler2
is basically a two-dimensional texture, which is the type of parameter used in
Cg/HLSL. We can get more information about the Cg parameter from
ht-
Next, we added
float2 uv_BumpMap
in
struct Input {}
, which will be used to
calculate the color information from
_BumpMap
. The
uv_BumpMap
parameter is the
texture coordinate, which is basically similar to
vector2
.
In the
surf()
function, 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));
Note
The surf(Input IN, inout SurfaceOutput o)
function is basically the
function that will get the input information from
struct Input {}
. Then, we will as-