Game Development Reference
In-Depth Information
Objective complete - mini debriefing
In this step, we first added the new properties, _AmbientColor , _SpecularColor ,
and _Shininess , which will be used to calculate in our custom lighting models function
to get the specular reflection.
Next, we increased LOD to 400 because we wanted to increase the LOD for our custom
lighting model that will calculate the specular lighting.
Next, in the surf() function, we changed the first line from half4 c = tex2D (_
MainTex, IN.uv_MainTex); to fixed4 c = tex2D (_MainTex,
IN.uv_MainTex); to increase the performance of our shader. As the return value from
the tex2D() function is the color value (R,G,B,A), which has a range from 0 to 1 , it will
be expensive to use half or float .
Tip
What are the half and fixed parameters for? When we are writing a shader in Cg/
HLSL, there are three types of parameters that we can use: fixed , half , and float .
These parameters determine the precision of computations. The parameter fixed is low
precision (11 bits, should be in the range of -2.0 to +2.0, and has a precision value of
1/256), half is medium precision (16 bits, in the range of -60000 to +60000, and 3.3
decimal digits of precision), and float is high precision (32 bits and similar to float on
the computer architecture).
The reference is taken from http://docs.unity3d.com/Documentation/Components/SL-
ShaderPerformance.html .
However, it follows a trend wherein the more precision we have, the more calculation we
need. If we use float every time for our shader, it will cause the game to slow down. So,
if we want to improve the performance of our game, we should use the lowest precision
possible while still having enough output. It's the task of the programmer to decide which
aspects need to be precise and which do not.
Then, in the surf() function, we also multiplied c.rgb with _AmbientColor.rgb
and c.a with _AmbientColor.a , which will get passed to o.Albedo and o.Alpha ,
respectively. This will add the color value from the _AmbientColor properties with our
Search WWH ::




Custom Search