Game Development Reference
In-Depth Information
sampler2D _BumpMap;
sampler2D _Ramp;
fixed4 _AmbientColor;
fixed4 _SpecularColor;
half _Glossiness;
fixed4 _RimColor;
half _RimPower;
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
half3 viewDir;
};
3. Add the following highlighted code inside the surf() funcion as follows:
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
fixed rim = 1.0 - saturate(dot (normalize(IN.viewDir),
o.Normal));
o.Emission = (_RimColor.rgb * pow (rim, _RimPower));
}
4. Finally, go to the custom lighing models funcion. Let's modify and add this
highlighted code as follows:
inline fixed4 LightingRampSpecular (SurfaceOutput s, fixed3
lightDir, fixed3 viewDir, fixed atten) {
//Ambient Light
fixed 3 ambient = s.Albedo * _AmbientColor.rgb;
//Ramp - Diffuse color
fixed NdotL = saturate(dot (s.Normal, lightDir));
fixed diff = NdotL * 0.5 + 0.5;
fixed3 ramp = tex2D (_Ramp, float2(diff, diff)).rgb;
fixed3 diffuse = s.Albedo * _LightColor0.rgb * ramp;
//Specular - Gloss
fixed3 h = normalize (lightDir + viewDir); // Get the
Normalize of the lighting direction and view direction
 
Search WWH ::




Custom Search