Shading
Shading is a way to make a model look more realistic by changing colors, usually gradually, of its faces based on their angles to the light source. Shading is actually closely connected with lighting and is separated from it only because of different technologies that are used.
Each shading model uses some reflection model, on which it depends. So, the descriptions of shading models will be preceded by the descriptions of the corresponding reflection models.
Phong Reflection Model
The first model we will look at is the Phong reflection model. It is an empiric model, rather than a physical one, and it implies such simplifications:
- It is a local reflection model that does not take into account second-order reflections.
- It divides reflection from a surface into three components: ambient reflection (compensates for lack of second-order reflections), diffuse reflection, and specular reflection.
- There are four coefficients defined for each material: ambient reflection constant ( k_{a} ), diffuse reflection constant ( k_{d} ), specular reflection constant ( k_{s} ), and shininess constant for this material, which decides how "evenly" light is reflected from a shiny spot (α).
Then for each light source, components i_{s} and i_{d} are defined, which are intensities of the specular and diffuse components of the light source. There is also a single component i_{a} ,that controls the ambient lighting (it is equal for all light sources). Also, for each surface point these vectors are considered:
- L is the direction vector from the point to a light source.
- N is the normal at this point.
- R is the direction of a perfectly reflected ray of light from the point.
- V is the direction towards the viewer.
Then the shade of each surface point,
I_{p}
is calculates using this equation, which is actually the Phong reflection model:
I_{p}
=
k_{a}
i_{a}
+Σ_{lights}(
k_{d}
i_{d}
(L·N) +
k_{s}
i_{s}
(R·V)
^{α}
).
Or, simpler, the intensity of the point is a sum of the three main components: ambient, diffuse, and specular.
But this reflection model merely says how a point on a surface should look, however, when working with polygons, we have color values only at their vertices. How exactly pixels in-between will be lit depends on a particular shading model.
Phong Shading
This approach to shading was proposed by Phong along with his reflection model. The technique explains how to actually shade the points on a surface by interpolating the surface's normal across a polygon.
Given the normals at vertices of a polygon, in Phong shading we linearly interpolate a normal vector across the surface of the polygon, from these normals. This is different from Gouraud shading, where the color is interpolated across polygons. The interpolation is done for each point at the surface, and at each point it is used to obtain the final color using the Phong reflection model.
This is a more expensive way to calculate point intensities, but it solves the problem of Gouraud shading when a small highlight occurs at the center of a polygon.
Anisotropic Reflection Model And Shading
The anisotropic reflection model comes into play when you need to model surfaces that have small parallel grooves or fibers, such as brushed metal, old LP records, silk, and even hair (as a whole). It allows stretching reflections and highlights in a direction that runs perpendicular to the grooves on a surface. The peculiarity of this model is the way the specular term of reflection is calculated. Depending on a selected distribution of microfacets that constitute the surface, different parameters may be used, for example, the direction of the grooves or fibers.
This shading is also "heavier" than the Phong shading because of more elaborate computations, and its actual formula depends on the chosen distribution (see, for example, Wikipedia).