Game Development Reference
In-Depth Information
Shader programming—Rim light and
toon ramp
In this last step, we will add the last three properies,
_RimColor
,
_RimPower
, and
_Ramp
to get the toon shader result. The
_RimColor
and
_RimPower
properies basically control
the back lighing efect of our character. The
_Ramp
properies will be the ramp textures
that are used to calculate the lighing efect based on the angle between
light direction
and
surface normal
of the object.
Engage Thrusters
This is the last secion, ater which you will be able to see the result of your custom shader.
1. Go to MonoDevelop, open the
MyShader.shader
file, and go to the
Properties
secion and add the highlighted script as follows:
Properties {
_MainTex ("Texture", 2D) = "white" {}
_BumpMap ("Bumpmap", 2D) = "bump" {}
_AmbientColor ("Ambient Color", Color) = (0.1, 0.1, 0.1, 1.0)
_SpecularColor ("Specular Color", Color) = (0.12, 0.31, 0.47,
1.0)
_Glossiness ("Gloss", Range(1.0,512.0)) = 80.0
_RimColor ("Rim Color", Color) = (0.12, 0.31, 0.47, 1.0)
_RimPower ("Rim Power", Range(0.5,8.0)) = 3.0
_Ramp ("Shading Ramp", 2D) = "gray" {}
}
2. Go to the
SubShader
secion, modify, and add the highlighted code as follows:
SubShader {
Tags { "RenderType"="Opaque" }
LOD 400
CGPROGRAM
// Custom lighting function that uses a texture ramp based on
angle between light direction and normal
// We use exclude_path:prepass because this lighting model won't
work on the deferred lighting
// Since we don't have the angle between the light direction and
normal to calculate in the prepass
#pragma surface surf RampSpecular exclude_path:prepass
sampler2D _MainTex;