diffuse

Diffuse (Lambertian) reflectance of a surface for a given light direction.

Category: Graphics > Formatting and Annotation

Syntax

R = diffuse(Nx, Ny, Nz, S)

Returns the diffuse reflectance at each surface point, given the surface normal components and the light direction S.

Description

The function implements Lambert's cosine law. Each normal and the light direction are scaled to unit length, and the result is their dot product, clipped at zero so that surfaces facing away from the light are simply dark.

The values are used to shade a surface by hand. For lighting a graphics object directly, use light and lighting instead.

Input arguments

Nx, Ny, Nz
Arrays of the same size with the x, y and z components of the surface normals, for example from surfnorm.
S
Light direction, either a vector [x y z] or the pair [azimuth elevation] in degrees.

Output arguments

R
Array of the same size as Nx, with values from 0 (unlit) to 1 (light hitting head on).

Example

Normals tilted away from the light

Nx = [0 0 1];
Ny = [0 1 0];
Nz = [1 1 1];
R = diffuse(Nx, Ny, Nz, [0 0 1])
Output
R = 1×3

    1.0000    0.7071    0.7071

See also

specular surfnorm light lighting material