LessonNormals and light
Why the face toward the sun is brighter
Take a flashlight and a sheet of paper. Shine the light straight at the sheet, and the spot is bright. Tilt the sheet, and the same beam spreads over a larger area, so each square centimeter gets less light. Turn the sheet edge-on, and the light slides along it and does not land at all.
How bright a surface is depends on the angle between the normal and the direction to the light: an arrow from the surface toward the sun or a lamp. The cosine of that angle tells you how quickly the surface darkens as the angle grows. The cosine is a number that falls from 1 to 0 as the angle goes from 0° to 90° (the lesson “Angles, sine and cosine” shows where it comes from). Brightness is proportional to the cosine, and this is Lambert’s cosine law. The cosine of 0° is 1 (light head-on), the cosine of 60° is 0.5, and the cosine of 90° is 0 (light grazing the surface).
A shader computes the cosine with the dot product. It takes two arrows and gives back one number: multiply their matching coordinates and add the results (the box below shows how). For two arrows of length 1, that number is the cosine of the angle between them.
brightness = max(0, dot(normal, direction to the sun))
color = BaseColor × sun color × brightness // the multiplication from lesson 1A question from the lesson
The sun is straight overhead, and a face is vertical, like a wall. How bright is it?