Diffuse (Lambert)
Brightness from how squarely a surface faces the light, the same from every viewing angle.
Cards
One live example to tweak, learn and copy.
How it works
Diffuse light is the soft, matte part of shading: the light a surface scatters equally in every direction, so it looks
the same wherever the camera stands. Its brightness depends on one thing, the angle between the surface and the
incoming light, and Lambert’s cosine lawA matte surface's brightness follows the cosine of the angle between its normal and the direction toward the light, and looks the same from every viewing angle. In a shader it is the clamped dot product of the two unit vectors. Lambert's cosine law A matte surface's brightness follows the cosine of the angle between its normal and the direction toward the light, and looks the same from every viewing angle. In a shader it is the clamped dot product of the two unit vectors.diffuse = max(N · L, 0)
In a shader that cosine is a single dot productMultiplies two vectors component by component and adds the results. For unit vectors it is the cosine of the angle between them, from 1 (same direction) to -1 (opposite). Dot product Multiplies two vectors component by component and adds the results. For unit vectors it is the cosine of the angle between them, from 1 (same direction) to -1 (opposite). Normal A unit vector perpendicular to a surface, pointing the way it faces. Lighting and Fresnel effects compare it with other directions.dot(a, b) = |a| |b| cos θ
float diffuse = max(dot(n, toLight), 0.0);
vec3 color = albedo * (lightColor * diffuse + ambient);
That one line is the base of almost every lighting model. Engines run it once per light and add the results; toon
shading cuts it into bands; specular highlights sit on top of it; physically based shading divides it by π and pairs it
with a microfacet specular term. Getting it right comes down to three checks: both vectors are normalized, both are in
the same spaceThe frame a position or direction is measured in, such as object, world, view, clip or screen space. Only values in the same space can be combined. Coordinate space The frame a position or direction is measured in, such as object, world, view, clip or screen space. Only values in the same space can be combined.
Diffuse alone looks like chalk or clay. What it lacks is anything that depends on the viewer: shine, rims, reflections. Those are the Specular highlights and Fresnel techniques.
Further reading
- dot (opens in a new tab)Reference
- Dot product (opens in a new tab)Reference
- Basic Lighting (opens in a new tab)Article
- Normal (geometry) (opens in a new tab)Reference
- Normal Mapping (opens in a new tab)Article
- Lambertian reflectance (opens in a new tab)Reference
- max (opens in a new tab)Reference