# specular

## Purpose

Specular reflectance.

## Synopsis

````r = specular(Nx,Ny,Nz,S,V)`
r = specular(Nx`,Ny,Nz,S,V,spread)`
```

## Description

`specular` returns the reflectance `r` of a specular surface from the normal vector components. The reflectance is the fraction of light that reflects from the surface toward the viewer. `r` is a scalar that varies from 0.0 (no light reflected) to 1.0 (all the light reflected).

`r` `=` `specular(Nx,Ny,Nz,S,V)` returns the reflectance of the surface with normal vector components `[Nx,Ny,Nz]`. The normal vector components can be matrices so that the normal is

````n(i,j) = [Nx(i,j), Ny(i,j), Nz(i,j)]`
```
These normal components can be calculated using `surfnorm`. The light source vector `S = [Sx,Sy,Sz]` is a three-element vector that specifies the direction from the surface to the light source. `V` is three-element vector that specifies the viewpoint. Both can be two-element vectors specifying azimuth and elevation.

`r = specular(Nx,Ny,Nz,S,V,spread)` specifies the surface spread exponent.

`specular` is used as part of the function `surfl` to produce shaded surfaces.

## Algorithm

`specular` implements a common approximation for the reflectance of shiny metal-like surfaces. The specular highlight is strongest when the normal vector is in the direction of (s+v)/2, where s is the source direction and v is the view direction.

````diffuse`, `surfl`, `surfnorm`