specular

Specular reflectance of a surface for given light and viewer directions.

Category: Graphics > Formatting and Annotation

Syntax

R = specular(Nx, Ny, Nz, S, V)

Returns the specular reflectance with the default spread exponent of 10.

R = specular(Nx, Ny, Nz, S, V, spread)

Uses the given spread exponent.

Description

The light direction is reflected about each normal, and the cosine of the angle between the reflected ray and the view direction is raised to the power spread. When the viewer sits exactly in the mirror direction the result is 1, and it falls off quickly as the angle grows. Negative cosines count as 0.

The result is the highlight term of the Phong model and is typically added to the diffuse term to shade a surface by hand.

Input arguments

Nx, Ny, Nz
Arrays of the same size with the surface normal components.
S
Light direction, as [x y z] or [azimuth elevation] in degrees.
V
View direction, in the same forms as S.
spread
Exponent that sets how tight the highlight is. Larger values give a smaller, sharper spot.

Output arguments

R
Array of the same size as Nx with values between 0 and 1.

Example

Viewer in and off the mirror direction

specular(0, 0, 1, [0 0 1], [0 0 1])
specular(0, 0.6, 0.8, [0 0 1], [0 0 1], 2)
Output
ans = 1
ans = 0.0784

See also

diffuse surfnorm material lighting light