Rim Light

4 / 17
Learn core lighting terms (diffuse/specular/rim) on a simple sphere.

Adding a bright edge ring to a sphere comes down to this line:

Let's break it down.


What rim light is

Rim light is a classic technique in film and games: place a light behind a character so that a bright halo appears along the silhouette, visually separating the subject from the background and enhancing the sense of depth.

In a shader, you do not need an actual back light — the view direction alone is enough to simulate this effect.


What 1.0 - dot(n, v) does

v = normalize(0, 0, 1) is the view direction pointing toward the screen.

dot(n, v) measures how well the normal aligns with the view:

  • Sphere center: normal faces the camera directly → near 1.0
  • Sphere edge: normal is nearly sideways → near 0.0

1.0 - dot(n, v) flips this: edges become large, center becomes small.

pow(..., 2.0) tightens the gradient — the bright edge stays concentrated rather than spreading evenly across the whole sphere.


What mix does

mix(a, b, t) interpolates between a and b by t: when t = 0 you get the first color, when t = 1 you get the second. At the edges rim is close to 1, so the edge goes white; at the center rim is near 0, so the base color shows through.


Try changing it

ChangeEffect
2.0 to 5.0Rim narrows to a very thin ring
2.0 to 0.8Rim glow spreads across most of the sphere
vec3(1.0) to vec3(1.0, 0.5, 0.2)Orange rim light

Exercise

In the exercise rim = 0.0, so there is no bright edge. Fill in the TODO to compute the correct rim value.

Answer Breakdown

Starting state: rim = 0.0 — the t argument to mix is always zero, so the sphere shows only its base color.

The fix: 1.0 - dot(n, v) puts large values at the silhouette edge; pow(..., 2.0) concentrates the effect there; mix blends the base color toward white at the edge.

Try changing the exponent from 2.0 to 4.0 and see how narrow the rim band becomes.

GLSL Code Editor

Correct Code Preview

Current Code Preview