The BRDF used for scan line rendering does not fulfill the energy conservation property in most of the cases.
Generally, the BRDF is expressed as the sum of two terms:
- The diffuse reflection: main color of the object
- The specular reflection: shiny objects tend to reflect the incoming light in a particular angle, called the specular direction
In scan-line rendering, values of the BRDF for each color frequency, and for both the diffuse and specular components, are in the range
In this course we will present the following diffuse reflection models:
- Lambert
- Oren-Nayar
- Toon
And the following specular reflection models:
- Phong specular reflection
- Blinn specular reflection
- Ward
- Cook-Torrance specular reflection
- Toon
The reflection is calculated by taking the dot product of the surface's unit normal vector,
When a face is on the opposite direction with respect to a light source, it cannot be illuminated despite of the angle. To make this happen for back faces, clamping the value at zero simply avoids illuminating the faces. In Lambert diffuse model, the viewing angle has no effect, and the final image depends only on the position of the objects and on the direction the lights. The rendering equations becomes :
$$\begin{gathered} L\left(x, \omega_{r}\right)=\boldsymbol{l} * \boldsymbol{m}{D} \cdot \operatorname{clamp}\left(\boldsymbol{d} \cdot \boldsymbol{n}{x}\right) \ L\left(x, \omega_{r}\right)=\boldsymbol{l} * \boldsymbol{m}{D} \cdot \operatorname{clamp}\left(\frac{\boldsymbol{p}-\boldsymbol{x}}{|\boldsymbol{p}-\boldsymbol{x}|} \cdot \boldsymbol{n}{x}\right) \end{gathered}$$
with
The vector that points in the direction from which the object is seen is
Note that the pixel color does not depend on
The Phong model calculates the intensity of the specular reflection using the cosine of the angular distance between the "exact" specular direction and the observer direction. When the specular direction is aligned with the observer, the value is maximum, and when the angle is greater, it is zero:
To create more contained highlight regions, the term
The formula is:
$$f_{\text {specular }}\left(x, \overrightarrow{l x}, \omega_r\right)=\boldsymbol{m}S \cdot \operatorname{clamp}\left(\omega_r \cdot \boldsymbol{r}{l, x}\right)^\gamma$$
where
The Blinn reflection model is an alternative to the Phong shading model that uses the half vector
The angle
Toon shading simplifies color output by using discrete values based on thresholds, producing a cartoon-like effect. It can be applied to both diffuse and specular BRDF components. Generally in modern hardware the thresholds are implemented not with program branching but with a color that is a function of the cosine of the angles between the considered rays.
Oren-Nayar diffuse reflection model is used for modeling materials like clay, dirt, and some types of cloths. It's pretty complex:
We have to compute the two angles: $$\theta_{\boldsymbol{i}}=\cos ^{-1}\left(\overrightarrow{l x} \cdot \boldsymbol{n}x\right)$$ $$\theta{\boldsymbol{r}}=\cos ^{-1}\left(\omega_r \cdot \boldsymbol{n}x\right)$$ and then compute both maximum and minimum of them: $$\alpha=\max \left(\theta{\boldsymbol{i}}, \theta_{\boldsymbol{r}}\right)$$$$\beta=\min \left(\theta_{\boldsymbol{i}}, \theta_{\boldsymbol{r}}\right)$$ then it's necessary to compute two coefficients for the roughness:
$$\boldsymbol{v}_{\boldsymbol{i}}=\operatorname{normalize}\left(\overrightarrow{l x}-\left(\overrightarrow{l x} \cdot \boldsymbol{n}_x\right) \boldsymbol{n}x\right)$$ $$\boldsymbol{v}{\boldsymbol{r}}=\operatorname{normalize}\left(\omega_r-\left(\omega_r \cdot \boldsymbol{n}_x\right) \boldsymbol{n}_x\right)$$
the angle between the two are just the dot product:
$$G=\max \left(0, \boldsymbol{v}{\boldsymbol{i}} \cdot \boldsymbol{v}{\boldsymbol{r}}\right)$$
and at the end after computing
The Ward specular model is derived from physically inspired principles and it supports anisotropic reflections. To support anisotropy, an orientation of the grooves ("scanalatura") on the surface must be specified: this is done assigning two extra vectors: tangent
Current game engines usually don't adopt any of these models just presented. Today we have more physically accurated models which are based on the Cook-Torrance one.
To achieve a physically accurate behavior, diffuse and specular channels are linearly interpolated, according to a coefficient
The specular term is :
-
$m_s$ is the specular color -
$F$ is the Fresnel term -
$G$ is the Geometric term -
$D$ is the Distribution term
The Distribution term accounts for the roughness of the surface. The blinn version of
where
$$\boldsymbol{h}{l, x}=\operatorname{normalize}\left(\overrightarrow{l x}+\omega_r\right)$$ $$G=\min \left(1, \frac{2\left(\boldsymbol{h}{l, x} \cdot \boldsymbol{n}x\right)\left(\omega_r \cdot \boldsymbol{n}x\right)}{\left(\omega_r \cdot \boldsymbol{h}{l, x}\right)}, \frac{2\left(\boldsymbol{h}{l, x} \cdot \boldsymbol{n}_x\right)\left(\overrightarrow{l x} \cdot \boldsymbol{n}x\right)}{\left(\omega_r \cdot \boldsymbol{h}{l, x}\right)}\right)$$
$$D=\frac{e^{-\frac{1-\left(\boldsymbol{h}_{l, x} \cdot \boldsymbol{n}x\right)^2}{\left(\boldsymbol{h}{l, x} \cdot \boldsymbol{n}x\right)^2 \rho^2}}}{\pi \cdot \rho^2\left(\boldsymbol{h}{l, x} \cdot \boldsymbol{n}_x\right)^4}$$
$$f_{\text {specular }}\left(x, \overrightarrow{l x}, \omega_r\right)=\boldsymbol{m}_S \frac{D \cdot F \cdot G}{4 \cdot \operatorname{clamp}\left(\omega_r \cdot \boldsymbol{n}x\right)}$$ $$f{\text {diffuse }}\left(x, \overrightarrow{l x}, \omega_r\right)=m_D \cdot \operatorname{clamp}\left(\overrightarrow{l x} \cdot \boldsymbol{n}_x\right)$$