Graphics › Drawing it
Normals & lighting
A surface normal, a light direction, one dot product — that's the brightness of a face. Almost all shading is variations on that single idea.
3.16
3.16
= signed area of the parallelogram
The normal: which way a surface faces
Every triangle (and every vertex) carries a normal — a unit vector pointing straight out of the surface. You can get a triangle's normal from two of its edges with a cross product: n = normalize((B − A) × (C − A)). Vertex normals are usually the averaged face normals around them, which is what makes a low-poly sphere look smooth instead of faceted.
Diffuse (Lambert) lighting: the dot product
A matte surface looks brightest when it faces the light head-on, dimmer as it tilts away, and dark once it turns past 90°. That's exactly n · l for unit vectors (clamped at 0): the cosine of the angle between the normal and the direction to the light. So brightness = max(0, n · l) — one dot product, and you have the classic shaded look.
Specular: a second dot product
l about n to get r, then the highlight is max(0, r · v) raised to a power (the “shininess” — bigger exponent = tighter, glossier dot). Diffuse + specular + a constant ambient term = the textbook Phong model.Normals don't transform like positions
When the model matrix has non-uniform scale, multiplying a normal by it stops it being perpendicular to the surface (and breaks lighting). The fix: transform normals by the inverse-transpose of the model matrix's rotation/scale part — then renormalize. (For pure rotations the inverse-transpose is the matrix, so you only worry about it when scaling.)
Beyond Lambert
Modern engines use physically based rendering (PBR) — microfacet BRDFs with roughness/metalness parameters — but it's still, at heart, dot products of normals, light directions, view directions and half-vectors. Learn the n · l and the rest is bookkeeping.