Game Development Reference
In-Depth Information
Objective complete - mini debriefing
In this section, first we added three properties, _RimColor , _RimPower , and _Ramp , in
the Properties section, which are used to calculate the Rim Light as well as the Toon
Ramp shader styles.
Then, we placed exclude_path:prepass after #pragma surface surf
RampSpecular . This means that we set our shader to compile without the deferred ren-
dering. Why would we want to do this? As our Toon Ramp shader needs the angle data
between the light direction and surface normals to calculate the lighting that can't be calcu-
lated in the deferred rendering, we excluded it.
Note
In Unity, we can choose three types of rendering paths: Vertex Lit, Forward, and Deferred
Lighting. Vertex Lit is basically the lowest lighting quality and doesn't support any real-
time shadows. Forward is shader-based, which is the default setting in Unity and only sup-
ports real-time shadows from one-directional light. Deferred Lighting is the rendering path
with the most lighting and shadow quality, which is available only in Unity Pro with no
support for mobile devices. We can get more information about the rendering path from ht-
tp://docs.unity3d.com/Documentation/Manual/RenderingPaths.html .
Next, we added half3 viewDir; in struct Input {} , which allows us to get the
user view direction vector. This parameter will be used to calculate the specular reflection
on our model.
Inside the surf() function, we calculated the rim power or the brightness of our back-
light, which is fixed rim = 1.0 - saturate(dot (normal-
ize(IN.viewDir), o.Normal)); , by using the saturation of the dot product of the
view direction normalize and surface normals. In the next line, o.Emission =
(_RimColor.rgb * pow (rim, _ RimPower)); , we multiplied the Rim Light
color with the power of the rim power that we got. Then, we assigned the result to
o.Emission to show the rim light effect on our object.
In the LightingRampSpecular() function, we changed the calculation of the lighting
by using the Half Lambert model, which makes our object brighter with the light that warps
around the object by dividing it by half and adding 0.5 :
Search WWH ::




Custom Search