Course contentsShow
← Unity Game Development
Lesson 627 of 8289. Rendering and VisualsFree lesson

Implementing Rim Lighting for Stylized Outlines

Use dot product calculations between the view direction and surface normals to add a glowing rim light effect to characters.

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:

  1. Calculate the Rim: Use the Fresnel Effect node or manually subtract the Dot Product of the Normal Vector (World Space) and View Direction (World Space) from 1.
  2. Control the Falloff: Pass this result through a Power node. 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.
  3. Stylize the Color: Multiply the output by a Color property 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.