A sphere without lighting is a flat circle. It is light that reveals its shape: the side facing the source is bright, the opposite side dark, and on a glossy sphere a small bright highlight appears. Lighting models are the formulas that calculate these effects for every point on a surface. From the simplest to the most realistic, they rest on a few vectors and some physical ideas.
The vectors involved
For each point on the surface we consider:
- N: the normal, perpendicular to the surface;
- L: the direction towards the light source;
- V: the direction towards the viewer;
- R: the direction in which light would be reflected as by a mirror.
All normalised, that is, of length 1. The dot product of two normalised vectors gives the cosine of the angle between them: 1 if aligned, 0 if perpendicular, negative if opposite. Almost all classical lighting boils down to dot products.
Lambertian diffuse reflection
A matte, rough surface, such as paper or plaster, scatters light evenly in all directions. Its brightness does not depend on where it is viewed from, only on the angle at which light strikes it:
diffuse = surface_color × light_color × max(0, N · L)
When light arrives perpendicular (N · L = 1) the surface is at its brightest; when it arrives at a grazing angle, the energy spreads over a larger area and the surface looks darker. The max(0, …) avoids negative values for faces pointing the other way.
Specular highlights: Phong and Blinn-Phong
Glossy surfaces show a highlight that depends on the viewpoint. The Phong model calculates it like this:
specular = light_color × max(0, R · V) ^ shininess
The shininess exponent controls the highlight's size: low values give a wide, soft glow, typical of matte plastic; high values a small, sharp spot, as on a lacquered surface.
The Blinn-Phong variant replaces R with the halfway vector H, midway between L and V, and uses N · H. It is cheaper to compute and produces more believable highlights when light is grazing. For many years it was the standard model on graphics cards.
Ambient light
In reality shaded areas are never completely black, because they receive light bounced from other surfaces. Classical models approximate this with a constant ambient term added to diffuse and specular. It is a crude approximation that makes shadows flat; techniques such as ambient occlusion and global illumination exist precisely to improve it.
Where it is computed: Gouraud and Phong shading
A detail that causes confusion: "Phong" refers to two different things.
| Technique | Where lighting is computed | Result |
|---|---|---|
| Flat shading | once per face | faceted look |
| Gouraud shading | at vertices, then colors are interpolated | smooth, but highlights distorted or lost on sparse meshes |
| Phong shading | per pixel, interpolating normals | correct highlights, higher cost |
The Phong lighting model (the formula) and Phong shading (normal interpolation) are independent. Today, with modern GPUs, per-pixel computation is the norm.
The move to physical materials (PBR)
Classical models have a flaw: their parameters have no precise physical meaning, and a material that looks right under one light looks wrong under another. Physically based rendering (PBR) introduces a few principles:
- Energy conservation: a surface cannot reflect more light than it receives. A wider highlight is also less intense.
- Microfacets: a surface is modelled as a collection of tiny mirrors oriented more or less randomly. Roughness describes how random they are.
- The Fresnel effect: every surface becomes more reflective when viewed at a grazing angle. That is why a lake reflects the landscape towards the horizon but is transparent at our feet.
- Metals and non-metals: in metals the reflection takes on the material's color and there is no diffuse component; in non-metals the reflection is neutral and the color comes from diffusion.
The most widespread workflow, called metalness/roughness, describes a material with a few maps:
- base color (albedo), with no painted shadows or highlights;
- metalness, usually 0 or 1;
- roughness, from 0 (mirror) to 1 (fully matte);
- normal map, for fine surface detail.
The practical advantage is enormous: the same material looks believable in any lighting condition, and textures can move from one program to another with consistent results.
Common mistakes
- Shadows and highlights painted into the color texture: with PBR they should be avoided, because lighting is computed by the engine.
- Calculations in gamma space: lighting must be computed in linear light, otherwise transitions between light and shadow look too harsh.
- Normals not renormalised after interpolation: highlights look irregular.
- Zero roughness everywhere: no real material is a perfect mirror; a little roughness makes everything more believable.
In short
- Classical lighting rests on dot products between normal, light, view and reflection.
- Lambert describes diffuse light, which depends only on the angle of incidence.
- Phong and Blinn-Phong add specular highlights that depend on the viewpoint.
- Gouraud interpolates colors; Phong shading interpolates normals.
- PBR introduces energy conservation, roughness, Fresnel and the metal/non-metal distinction.