home/ atoms/ diffuse-lighting-lambert

Diffuse (Lambertian) brightness is the clamped dot product of the surface normal and the light direction

Lambertian diffuse lighting models a matte surface whose brightness depends only on how directly it faces the light — the angle between the unit surface normal and the unit direction to the light — and not on the viewer’s position. It is computed as dot(normal, lightDir): 1 when the surface faces the light head-on (fully lit), near 0 when the surface is edge-on (dark), and negative when it faces away. The result is clamped to zero so back-facing surfaces receive no direct light; skipping the clamp lets negative values wrongly darken or corrupt the shade. Multiplied by light color and surface albedo, this single dot product is the cheapest realistic shading term and the base layer onto which specular highlights and ambient light are added in fuller models. Common mistake: forgetting to normalize the vectors or to clamp, which breaks the physical meaning of the dot product as ‘how aligned the surface is with the light.‘

Examples

float diff = clamp(dot(normal, lightDir), 0.0, 1.0);
vec3 col = objectColor * diff;

Normal (0,1,0) with light dir (0.7,0.7,0): dot = 0.7, a mid-bright surface.

Assessment

Given normal (0,1,0) and light direction (0.7,0.7,0), compute the diffuse factor and describe the resulting brightness. Add diffuse shading to a raymarched sphere, move the light, confirm the bright spot tracks the light independently of the camera, and explain why clamping the dot product matters.

“this dot product, line just in here, is basically measuring exactly that, how aligned two vectors are. So we are taking the normal”
corpus · inigo-quilez-live-coding-happy-jumping-video · chunk 4
“This is commonly done by taking the dot product between the ray direction of a light source and the direction of a surface normal.”