In a classic local lighting model, what do the ambient, Lambert diffuse and specular terms each add, and why is dot(N, L) clamped at zero?
answer
- three terms summed per light
- cosine of the incoming angle
- a tilted beam covers more area
- negative means the light is behind
basics
~20 sAmbient adds a constant stand-in for bounced light, Lambert diffuse scales each light by dot(N, L), the cosine between normal and light direction, and specular adds a view-dependent highlight. Clamping at zero stops back-facing light subtracting.
solid answer
~50 sThe classic model sums `ambient + diffuse + specular`, with diffuse and specular evaluated per light. Lambert's diffuse term is `kd * lightColour * max(0, dot(n, l))`, where `n` is the unit surface normal and `l` the unit vector from the surface toward the light. The cosine is geometry, not taste: a beam striking a tilted surface spreads its power over a larger area, so each bit of surface receives less. The term never looks at the camera, so a matte surface looks the same from every angle; the specular term adds the highlight that moves with the viewer. The ambient term is a constant so that faces turned away from every light are not pure black. The clamp matters because a negative `dot(n, l)` means the light is behind the surface; summed unclamped, it would subtract from the ambient and from the other lights.
go deeper
Recall the three terms, write the Lambert formula with max(0, dot(n, l)), and say which vectors must be unit length and point which way.
Derive the cosine from a beam spreading over a tilted area, and explain why an unclamped negative term darkens a surface even when the final colour is clamped.
Separate what the clamp does from what shadowing does, and explain what a constant ambient term costs a scene and which cheap upgrades replace it on static geometry.
Weigh where a project can live with constant or hemisphere ambient and where flat shadowed sides justify paying for baked or computed indirect light.
## The three terms of the classic model A **local lighting model** computes the colour of a surface point from the point itself, its normal, the camera and a list of lights, ignoring every other surface in the scene. The classic form, used in real-time rendering for decades, sums three terms: | Term | What it stands for | Depends on | |---|---|---| | **Ambient** | light that bounced off other surfaces, approximated as uniform | nothing per light | | **Diffuse (Lambert)** | light scattered equally in all directions by a matte surface | normal and light direction | | **Specular** | the glossy highlight, a blurred reflection of the light | normal, light and view directions | Written out for one light: `colour = ka * ambientColour + lightColour * (kd * max(0, dot(n, l)) + specular)`. With several lights the ambient is added once and the bracketed part once per light. Here `kd` is the surface's diffuse colour (its **albedo**) and `ka` its response to ambient light, often the same colour. ## Lambert's cosine law, derived Picture a light beam of fixed cross-section `A` arriving at angle `theta` from the surface normal. On a surface facing the light squarely (`theta = 0`) the beam covers an area `A`. Tilt the surface and the same beam smears over an area `A / cos(theta)`. The power carried by the beam has not changed, so the power per unit area, which is what the eye sees as brightness on a matte surface, falls by `cos(theta)`. With `n` and `l` both **unit vectors**, `dot(n, l) = cos(theta)`, which is why the diffuse term is a dot product. Two consequences follow: - The term is **view-independent**: no camera vector appears, so an ideal matte surface such as chalk or unglazed clay looks equally bright from any angle. - Both vectors must be **normalised** and expressed in the **same space**; a normal that is shorter than 1, or a light vector in world space dotted with a normal in object space, gives a wrong cosine. ## Why the clamp at zero When the light lies behind the surface, `theta` exceeds 90 degrees and `dot(n, l)` goes **negative**. Physically that face receives no light from this source. Mathematically, a negative term added to the sum *removes* light: 1. A wall lit by two torches, one in front and one behind it, would be darkened by the one behind. 2. The ambient term on that face would be partly cancelled. 3. A final clamp of the summed colour to `[0, 1]` does not help, because the subtraction already happened inside the sum. So each light's diffuse term is clamped with `max(0, dot(n, l))` before it is added. The same `dot(n, l) > 0` test is also the usual guard for the specular term, so that a highlight never appears on a face the light cannot reach. ## The ambient term and its limits Real indirect light comes from every bright surface around the point and varies across the scene. A single constant replaces all of it, which has known costs: - **Flat look**: faces away from the light all get the same colour, so shapes on the shadowed side read as flat silhouettes. - **No occlusion**: corners and crevices receive as much ambient light as open walls. - **Wrong colour**: a red carpet does not tint the wall above it. Cheap improvements keep the same spirit. A **hemisphere ambient** blends a sky colour and a ground colour by how far the normal points up. Baking bounced light into **lightmaps** for static geometry replaces the constant with stored, position-dependent values. Probes and screen-space techniques go further, but they are separate subjects. ## Traps worth naming in an interview - Clamping `dot(n, l)` is **not shadowing**. A face that points at a torch but sits behind a pillar still gets the full Lambert term, because the term knows nothing about occluders. Shadows need a separate visibility test multiplied into the direct light. - The cosine is applied to **incoming** light only. The camera direction does not enter the diffuse term at all. - Lighting sums should happen in **linear** light; adding colours that are still encoded for display gives falloffs and highlights that look wrong. - Physically based models scale the Lambert term by an albedo-over-pi factor to conserve energy; the classic model folds such constants into the light's intensity. A clear answer names the three terms, derives the cosine from area spreading in a sentence, and explains that the clamp stops back-facing light from subtracting, which an unclamped sum would do before any final clamp could intervene.
- Does clamping dot(N, L) at zero make surfaces behind a wall go dark, giving shadows?No. The clamp only darkens faces that point away from the light. A face that points toward a torch but has a pillar between them still receives the full Lambert term, because the term uses only the normal and the light direction and knows nothing about other geometry. Shadows need a separate visibility test, such as a shadow map lookup, multiplied into that light's direct contribution.
- What is wrap lighting, and why is it sometimes used on characters?Wrap lighting remaps the cosine so light reaches past the 90-degree terminator, for example `(dot(n, l) * 0.5 + 0.5)^2`, which reaches zero only when the surface faces directly away. The dark side then falls off gently instead of going flat. It is not physically based: it fakes light scattering under skin or cloth and softens a hard terminator on low-detail characters, at the cost of lighting faces the light cannot see.
- Why does the Lambert term not depend on the camera position?An ideal matte surface scatters the light it receives equally in all directions, so its brightness is the same from any viewpoint. The formula reflects that: only the normal and the light direction appear. View dependence enters through the specular term, which is why a highlight slides across a surface as the camera moves while the diffuse shading stays put.
Shine a torch straight at a sheet of card and you get a small bright disc; tilt the card and the same light stretches into a larger, dimmer ellipse. Lambert's cosine is exactly that stretch.
- The diffuse term changes as the camera moves around a matte object.
- A negative dot(N, L) is harmless because the final colour gets clamped anyway.
- Clamping dot(N, L) at zero is what puts surfaces behind a wall into shadow.
- The cosine falloff is an artistic choice rather than a consequence of geometry.
- A constant ambient term accounts properly for bounced light, so indirect light is solved.