Game Development Reference
In-Depth Information
lightDir, fixed3 viewDir, fixed atten) {
//Ambient
fixed3 ambient = s.Albedo * _AmbientColor.rgb;
//Diffuse
fixed NdotL = saturate(dot (s.Normal, lightDir));
fixed3 diffuse = s.Albedo * _LightColor0.rgb * NdotL;
//Specular
fixed3 h = normalize (lightDir + viewDir);
float nh = saturate(dot (s.Normal, h));
float specPower = pow (nh, s.Specular * 128) * s.Gloss;
fixed3 specular = _LightColor0.rgb * specPower *
_SpecularColor.rgb;
//Result
fixed4 c;
c.rgb = (ambient + diffuse + specular) * (atten * 2);
c.a = s.Alpha + (_LightColor0.a * _SpecularColor.a *
specPower* atten);
return c;
}
ENDCG
Next, go to the #pragma surface surf Lambert line and change it to the follow-
ing code:
#pragma surface surf RampSpecular
We can now go back to Unity and click on Play to see our result with the specular reflec-
tion, as shown in the following screenshot:
Search WWH ::




Custom Search