In this lesson, you will learn how to leverage the dot product of the surface normal and the view direction to create a glowing rim effect that emphasizes character silhouettes.
The Core Concept: The Dot Product
In stylized rendering, a rim light is an illumination effect that highlights the edges of a 3D object, mimicking how light wraps around a character's silhouette. To achieve this in Unity Shader Graph, we rely on the relationship between the Normal Vector (which way the surface is facing) and the View Direction (where the camera is looking).
When these two vectors point in the same direction—meaning the surface is facing away from the camera—their dot product is high. However, at the silhouette edges, the angle between the camera view and the surface normal is perpendicular (90 degrees). By calculating 1 - dot(Normal, ViewDirection), we isolate the edges of the mesh.
Implementation Logic
To create the "glow," we want the rim to appear only when the surface is at an angle to the viewer:
- Calculate the Rim: Use the
Fresnel Effectnode or manually subtract theDot Productof theNormal Vector(World Space) andView Direction(World Space) from 1. - Control the Falloff: Pass this result through a
Powernode. A higher exponent will tighten the rim to the very edge, while a lower exponent will make it spread further toward the center of the character. - Stylize the Color: Multiply the output by a
Colorproperty set to HDR mode. Adding this to your base color output (or plugging it into the Master Node's Emission) ensures the glow pops against the background.
// Conceptual Shader Logic
float rim = 1.0 - saturate(dot(normalize(Normal), normalize(ViewDir)));
float3 rimColor = pow(rim, RimPower) * RimColor;
By adjusting the RimPower variable, you can shift from a subtle highlight to a thick, cartoony outline. This technique is computationally inexpensive and highly effective for separating stylized characters from complex backgrounds, giving your game that professional, "pop-out" look.
Key Takeaway: By calculating the inverse dot product of the surface normal and the camera view, you can mathematically isolate the silhouette of an object to create a programmable, stylized rim light.