Fresnel
Making the edges of a sphere brighter than the center comes down to this line:
Let's break it down.
What the Fresnel effect is
The Fresnel effect comes from physics: light hitting a water surface at a shallow angle (almost straight down) passes through mostly, while light hitting at a grazing angle (almost horizontal) reflects like a mirror. That is why you can see through a lake when looking straight down, but see only sky reflections when looking from across the water.
In shaders, we borrow this idea: the more a surface faces away from the viewer (toward the silhouette edge), the brighter or more reflective it appears.
What dot(n, v) means here
v = normalize(0, 0, 1) points straight at the screen — the view direction.
dot(n, v) measures how well the normal aligns with that view:
- Sphere center (normal faces the camera directly) → near 1.0
- Sphere edge (normal nearly perpendicular to the view) → near 0.0
1.0 - dot(n, v) flips this: edges become large, center becomes small.
What pow does
pow(..., 5.0) concentrates the effect toward the very edge — a larger exponent gives a thinner, sharper rim; a smaller exponent spreads the Fresnel glow across a wider area.
An exponent of 5 is a common approximation for dielectric materials like glass and water.
Try changing it
| Change | Effect |
|---|---|
5.0 to 2.0 | Fresnel spreads over more of the sphere |
5.0 to 10.0 | Fresnel concentrates into a very tight edge band |
vec3(1.0) to vec3(0.5, 0.8, 1.0) | Blue rim, like ice or underwater glow |
Exercise
In the exercise f = 0.0, so the sphere shows only a dark base color with no Fresnel glow. Fill in the TODO to produce a white edge-brightening effect.
Answer Breakdown
Starting state: f = 0.0 — the sphere color is baseCol * 0.2, just 20% dark ambient, no rim.
The fix: 1.0 - dot(n, v) makes the edge values large and the center values small; pow(..., 5.0) tightens that into a narrow band; vec3(1.0) * f adds white brightness to the edge.
Try changing the exponent from 5.0 to 1.5 and see whether the Fresnel glow reaches all the way to the center of the sphere.