Game Development Reference
In-Depth Information
Objective Complete - Mini Debriefing
In this step, we irst added the new properies _AmbientColor , e , and _Glossiness ,
which will be used to calculate in our custom lighing models funcion to get the
specular relecion.
Next, we increased the LOD to 400 because we wanted to increase the Level of Detail
for our custom lighing model that will calculate the specular lighing. Then we changed
#pragma surface surf from Lambert to RampSpecular , which means that we changed
our lighing calculated from the Lambert built-in to RampSpecular (our custom lighing
funcion, LightingRampSpecular ).
In the surf() funcion, we have changed the irst line from half4 c = tex2D (_
MainTex, IN.uv_MainTex); to fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
to increase the performance of our shader. Also, since the return value from the tex2D()
funcion 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 .
What are half and fixed parameters for? When we are wriing a shader
in Cg/HLSL , there are three types of the parameter that we can use, which
are fixed , half , and float . These parameters determine the precision of
computaions. The parameter fixed is low precision (11 bits, the range of -2.0
to +2.0 and 1/256th precision), half is medium precision (16 bits, the range
of -60000 to +60000 and 3.3 decimal digits of precision), and float is high
precision (32 bits, similar to the float in regular programming language).
Reference from:
http://unity3d.com/support/documentation/Components/
SL-ShaderPerformance.html
However, it follows a trend wherein the more precision we have, the more
calculaion we need. If we use all float 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 as possible.
Then, we created our custom lighing funcion, which is inline half4
LightingRampSpecular (SurfaceOutput s, half3 lightDir, half3
viewDir, half atten) . This funcion passes four parameters, SurfaceOutput , light
Direction , view direction , and light attenuation that we will use to calculate the
output for our shader.
 
Search WWH ::




Custom Search