Game Development Reference
In-Depth Information
2. Next, go to the SubShader secion, modify, and add the following highlighted code:
SubShader {
Tags { "RenderType"="Opaque" }
LOD 400
CGPROGRAM
// Custom lighting function that uses a texture ramp based on
angle between light direction and normal
#pragma surface surf RampSpecular
sampler2D _MainTex;
sampler2D _BumpMap;
fixed4 _AmbientColor;
fixed4 _SpecularColor;
half _Glossiness;
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
};
3. We set LOD to 400 , and set #pragma surface surf to RampSpecular instead
of Lambert , and get the other three properies for Ambient and Specular light.
Now, we will need the custom lighing models funcion. Let's add the following
highlighted code under the surf() funcion:
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));
}
inline fixed4 LightingRampSpecular (SurfaceOutput s, fixed3
lightDir, fixed3 viewDir, fixed atten) {
//Ambient Light
fixed3 ambient = s.Albedo * _AmbientColor.rgb;
//Diffuse
fixed NdotL = saturate(dot (s.Normal, lightDir)); //Get the
direction of the light source related to the normal of character
fixed3 diffuse = s.Albedo * _LightColor0.rgb * NdotL;
 
Search WWH ::




Custom Search