Subsections

Illumination and Shading Models

Realistic views of scenes are obtained by generating perspective projections with hidden surfaces removed and appropriate lighting and colouring applied to the model. A Shading model is used to calculate the intensity of light(colour) we should see when we view the surface. The exact colour of a surface when viewed depends on more than pigmentation; the amount of light striking the surface, the colour of the light, the angle the light strikes the surface, the orientation of the viewer and the texture of the surface all contribute to the actual colour we see (figs 7.1 and 7.2). When we view an object what we see is light from light sources reflected from the surface. There are two basic types of light sources;

In a scene, illumination from light emitting sources is reflected off multiple surfaces, these reflections combine to produce a uniform illumination called ambient light. Ambient light appears to come equally from all directions.

Figure 7.1: Effect of lighting model (left to right); Wireframe, Faces Colored (with wireframe), Faces Colored (without wireframe), lighting model applied (flat shading).
\includegraphics{C:/MyDocuments/Class/Graphics/Notes/shading1.eps}

Figure 7.2: Effect of ambient and directed Light (left to right); No lighting, Ambient light only, Directed light only (diffuse reflection), Ambient and Directed Light.
\includegraphics{C:/MyDocuments/Class/Graphics/Notes/shading2.eps}

Light emitting sources come in two basic types;

Point light sources:
these are modelled as a light emanating from a single point in space, light from the Sun and incandescent bulbs can be modelled successfully this way.
Area light Sources (distributed light sources):
these represent finite areas, which emit light uniformly over their surface, examples are windows and fluorescent bulbs. These are much harder to model.

Diffuse Reflection

When light strikes a surface, most of it is scattered equally in all directions (figure 7.3). This is called Diffuse reflection. The amount of diffuse reflection from a surface is primarily determined by the roughness or texture of the surface.

Figure 7.3: Diffuse Reflection, Light is scattered in all directions
\includegraphics{C:/MyDocuments/Class/Graphics/Notes/diffuse-reflection.eps}

If a surface is exposed only to ambient light then we can express the intensity of diffuse reflection as:

\begin{displaymath}I=R_{d}I_{a}\end{displaymath}

(where $R_{d} $= Co-efficient of reflection of the surface (constant for a given surface $(0<=Rd<=1)$), $I_{a}$ is the intensity of Ambient light).

The level of diffuse reflection of ambient light is similar in all directions. Highly reflective surfaces (smooth or polished) have a $R_{d} $ near one, which means that almost all the incident light is reflected.

Lambert's Cosine Law

More realistic shading models will include illumination from light sources as well as ambient light. The calculation of diffuse reflection from a point source is based on Lambert's cosine law, which states that the intensity of reflected light is dependant on on the angle of illumination. When a surface is at a steep angle to the light rays, less light strikes the surface (figure 7.4).

Figure 7.4: Angled surfaces receive less light
\includegraphics{C:/MyDocuments/Class/Graphics/Notes/lambert1.eps}

To simplify calculations we will assume that the light rays are parallel as they strike the surface (This is a good approximation for sources which are reasonably far away from the surface). We will describe the orientation of a surface with a unit normal vector $\vec{\mathbf{N}}$ and the direction of the light source is the unit vector $\vec{\mathbf{S}}$ (figure 7.5).

Figure 7.5: Angle of incidence
\includegraphics{C:/MyDocuments/Class/Graphics/Notes/lambert2.eps}

The angle between the two vectors, $\theta$, is called the angle of incidence. Lambert's law states that the amount of reflected light is proportional to the cosine of the angle of incidence. This can also be written as a dot product;


\begin{displaymath}\mbox{$\vec{\mathbf{N}}$}.\mbox{$\vec{\mathbf{S}}$}=\cos(\the...
...ert\vert S\vert=\cos(\theta)\qquad(\vert N\vert=\vert S\vert=1)\end{displaymath}

A surface is illuminated by a light source only if the angle of incidence is between $0^{\circ}$ and $90^{\circ}$.

The intensity of light from a point source drops off as the source is moved away from the object. So we can model the intensity of the light striking the surface as:

\begin{displaymath}I_{s}/(\delta_{d}+d)\end{displaymath}

($I_{s}$ intensity of light from source, $d$= distance of light source, $\delta_{d}$ is a small value which prevents divide by zero).

Putting all of this together, we get the following equation for the intensity of diffuse reflection due to a point source:

\begin{displaymath}I=R_{d}(I_{s}/(\delta_{d} + d)) \mbox{$\vec{\mathbf{N}}$}.\mbox{$\vec{\mathbf{S}}$}\end{displaymath}

These equations assume we are dealing with mono-chromatic (white) light. In real world situations, light sources have different colors, and our model should be able to handle this. To accommodate the use of colours, our light intensity values and our reflectivity constants should become 3-Vectors, each vector contains values for the Red, Green and Blue components of the light source.

Now $I_{s}$ becomes ( $I_{sr},I_{sg},I_{sb}$) and $R_{d} $ becomes ( $R_{dr},R_{dg},R_{db}$) where $I_{sr}$ represents the amount of red light in the source and so on. This breakdown is important as different surfaces reflect the colours by different amount; e.g. A surface with yellow pigmentation will reflect a lot of Red and Green, but will absorb most of the Blue light.


Specular Reflection

When viewing a shiny surface in the presence of a light source, bright spots on the surface are often seen. This is called specular reflection (fig 7.6.

Figure 7.6: Effect of specular reflection (left to right); No Specular reflection, low f=2, medium f=20, high f=200.
\includegraphics{C:/MyDocuments/Class/Graphics/Notes/shading3.eps}

Specular reflection is only observed at certain viewing angles and depends on the orientation of the viewer with respect to the light source. On a shiny surface, much of the incident light is reflected away from the surface at an angle similar to the angle of incidence (figure 7.7). For real surfaces, specular reflection is observed over a small range of angles around the angle of reflection. As the viewer moves away from the angle of reflection, the specular component decreases.

Figure 7.7: Specular Reflection
\includegraphics{C:/MyDocuments/Class/Graphics/Notes/specular1.eps}

Figure 7.8: The angle $\phi $ determines the amount of specular reflection visible
\includegraphics{C:/MyDocuments/Class/Graphics/Notes/specular2.eps}

In figure 7.8, $\vec{\mathbf{V}}$ is a unit vector in the direction of the viewer and $\vec{\mathbf{R}}$ is a vector along the angle of reflection. When $\vec{\mathbf{V}}$ and $\vec{\mathbf{R}}$ coincide, the viewer sees maximum specular refection, as $\phi $ increases, the specular reflection decreases. For shiny surfaces the specular reflection is very bright but visible only over a small range of angles, for less shiny surfaces, the specular reflection is not as bright, but is visible over a wide range of angles. A good approximation to the observed behavior of specular reflection is the Phong Specular Model.

Figure: The Phong Function $\cos^{f}(\phi)$ for various values of $f$
\includegraphics{C:/MyDocuments/Class/Graphics/Notes/phongfun.eps}

In the Phong model, the intensity of specular reflection is proportional to $\cos^{f}(\phi)$, where $f$ depends on the surface and ranges between 1 and 200. Very shiny surfaces have high values of $f$, as specular refection is exhibited over a small range of $f$. We know that $cos(\phi)=\mbox{$\vec{\mathbf{R}}$}.\mbox{$\vec{\mathbf{V}}$}$, so;

\begin{displaymath}I_{sp}=I_{s}R_{s}(\mbox{$\vec{\mathbf{R}}$}.\mbox{$\vec{\mathbf{V}}$})^{f}\end{displaymath}

($I_{sp}$= intensity of specular reflection, $R_{s}$= co-efficient of specular reflection; $R_{s}$ is usually = $R_{d} $).

There now remains the problem of determining $\vec{\mathbf{R}}$;

Figure: Determining $\vec{\mathbf{R}}$
\includegraphics{C:/MyDocuments/Class/Graphics/Notes/specular3.eps}


$\displaystyle -\mbox{$\vec{\mathbf{S}}$}$ $\textstyle =$ $\displaystyle \mbox{$\vec{\mathbf{M}}$}+\mbox{$\vec{\mathbf{E}}$}$ (8.1)
$\displaystyle \mbox{$\vec{\mathbf{E}}$}$ $\textstyle =$ $\displaystyle -\mbox{$\vec{\mathbf{S}}$}-\mbox{$\vec{\mathbf{M}}$}$ (8.2)
$\displaystyle \mbox{$\vec{\mathbf{R}}$}$ $\textstyle =$ $\displaystyle \mbox{$\vec{\mathbf{E}}$}-\mbox{$\vec{\mathbf{M}}$}$ (8.3)
$\displaystyle \mbox{$\vec{\mathbf{M}}$}$ $\textstyle =$ $\displaystyle -\mbox{$\vec{\mathbf{S}}$}-\mbox{$\vec{\mathbf{E}}$}$ (8.4)
$\displaystyle \mbox{$\vec{\mathbf{R}}$}$ $\textstyle =$ $\displaystyle \mbox{$\vec{\mathbf{E}}$}-(-\mbox{$\vec{\mathbf{S}}$}-\mbox{$\vec{\mathbf{E}}$})$ (8.5)
$\displaystyle \mbox{$\vec{\mathbf{R}}$}$ $\textstyle =$ $\displaystyle \mbox{$\vec{\mathbf{S}}$}+2\mbox{$\vec{\mathbf{E}}$}$ (8.6)
$\displaystyle \mbox{$\vec{\mathbf{M}}$}$ $\textstyle =$ $\displaystyle k\mbox{$\vec{\mathbf{N}}$} \qquad (\mbox{$\vec{\mathbf{M}}$}\Vert\mbox{$\vec{\mathbf{N}}$})$ (8.7)
$\displaystyle \mbox{$\vec{\mathbf{E}}$}.\mbox{$\vec{\mathbf{N}}$}$ $\textstyle =$ $\displaystyle 0 \qquad (\mbox{$\vec{\mathbf{E}}$}\bot \mbox{$\vec{\mathbf{N}}$})$ (8.8)
$\displaystyle (-\mbox{$\vec{\mathbf{S}}$}-k\mbox{$\vec{\mathbf{N}}$}).\mbox{$\vec{\mathbf{N}}$}$ $\textstyle =$ $\displaystyle 0$ (8.9)
$\displaystyle -\mbox{$\vec{\mathbf{S}}$}.\mbox{$\vec{\mathbf{N}}$}-k\mbox{$\vec{\mathbf{N}}$}.\mbox{$\vec{\mathbf{N}}$}$ $\textstyle =$ $\displaystyle 0 -\mbox{$\vec{\mathbf{S}}$}.\mbox{$\vec{\mathbf{N}}$}=k\mbox{$\vec{\mathbf{N}}$}.\mbox{$\vec{\mathbf{N}}$}$ (8.10)
$\displaystyle -\mbox{$\vec{\mathbf{S}}$}.\mbox{$\vec{\mathbf{N}}$}$ $\textstyle =$ $\displaystyle k$ (8.11)
$\displaystyle \mbox{$\vec{\mathbf{E}}$}$ $\textstyle =$ $\displaystyle -\mbox{$\vec{\mathbf{S}}$}-k\mbox{$\vec{\mathbf{N}}$}$ (8.12)
$\displaystyle \mbox{$\vec{\mathbf{E}}$}$ $\textstyle =$ $\displaystyle -\mbox{$\vec{\mathbf{S}}$}-(\mbox{$\vec{\mathbf{S}}$}.\mbox{$\vec{\mathbf{N}}$}).\mbox{$\vec{\mathbf{N}}$}$ (8.13)
$\displaystyle \mbox{$\vec{\mathbf{R}}$}$ $\textstyle =$ $\displaystyle \mbox{$\vec{\mathbf{S}}$}-2(-\mbox{$\vec{\mathbf{S}}$}+(\mbox{$\vec{\mathbf{S}}$}.\mbox{$\vec{\mathbf{N}}$}).\mbox{$\vec{\mathbf{N}}$})$ (8.14)

Incremental Shading Techniques

Polygon mesh models are distinguished by the fact that the model only approximates the actual objects represented. A Shading model must apply some reflection model (e.g. Phong reflection) to these faces, in order to determine how the face is to be colored. The reflection model should take into account orientation of light sources, position of viewer and properties of the surface being rendered. Polygon meshes are typically collections of planer faces, which model smooth surfaces. Combining diffuse and specular reflection models, we get the following model for light intensity at a point on a surface (the underlined term must be repeated for each additional light source in the scene);

\begin{displaymath}I=I_{a}R_{d}+\underline{I_{s}[R_{d}(\mbox{$\vec{\mathbf{N}}$}...
..._{s}(\mbox{$\vec{\mathbf{R}}$}.\mbox{$\vec{\mathbf{V}}$})^{f}]}\end{displaymath}

Flat Shading

A naive Flat Shading technique will apply a refection model to one point on a face and the shade determined is applied to the entire face. This method is quick and produces acceptable results if smooth surfaces are not involved. Specular reflection will be shown in flat shading, but only very coarsely. If realistic scenes are to be generated, flat shading requires so many polygons as to be infeasible. Regardless of the number of polygons, flat shading will almost always give a faceted appearance (figure 7.11) in certain areas because of Mach Banding (figure 7.12), which tends to exaggerate the differences between faces. Flat shading is generally only used for prototyping or testing an application where speed, not accuracy is important. Other methods can produce more realistic displays with much fewer polygons.

Figure 7.11: Shading methods (left to right); Flat shading, Smooth shading no specular, Smooth shading f=20, Smooth shading f=200.
\includegraphics{C:/MyDocuments/Class/Graphics/Notes/shading4.eps}

Figure 7.12: Mach Banding
\includegraphics{C:/MyDocuments/Class/Graphics/Notes/mach-banding.eps}

Smooth Shading

In order to accurately render curved surfaces represented by a polygon mesh, we need to implement an Incremental or Smooth Shading technique to smooth out the faceted nature of the mesh. The first smooth shading technique developed was Gouraud Shading.

Gouraud Shading

This method simply calculates the Surface Normal at each vertex by averaging the normals of the faces which share the vertex (figure 7.13).

Figure 7.13: Averaging Normals
\includegraphics{C:/MyDocuments/Class/Graphics/Notes/gouraud1.eps}

This average normal will coincide closely with the normal of the actual modelled surface at that point. This vector is then used in a reflection model to determine the light intensity at that point. This process is repeated for all vertices in the model. Once the correct intensity has been calculated for each vertex, these are used to interpolate intensity values over the face. The interpolation scheme is know as bi-linear interpolation.

Figure 7.14: Interpolating Intensities
\includegraphics{C:/MyDocuments/Class/Graphics/Notes/gouraud2.eps}

In the figure 7.14, intensities are known for $I_{1}$,$I_{2}$ and $I_{3}$. $I_{a}$ and $I_{c}$ can be interpolated as follows:

\begin{eqnarray*}
I_{a}=I_{1}+(I_{2}-I_{1})\frac{y_{a}-y_1}{y_2-y_1}\\
I_{c}=I_{a}+(I_{b}-I_{a})\frac{x_{c}-x_a}{x_b-x_a}
\end{eqnarray*}



Gouraud smoothes the faceted appearance of meshes, because the interpolated intensities along an edge are used to shade both polygons which share that edge. This means that there is not a discontinuity of colour at the edges of adjoining faces.

However, although the mesh appears smooth, the polygons are still visible at the edge of the object when viewed as a silhouette. Gouraud can also interpolate incorrectly which results in some rendering errors which remove some detail (figure 7.15).

Figure 7.15: Surface Rendered Incorrectly
\includegraphics[width=\textwidth]{C:/MyDocuments/Class/Graphics/Notes/gouraud3.eps}

The biggest problem with Gouraud shading is the fact it reproduces specular shading poorly and if specular reflection is displayed, it is determined by the polygon mesh rather than the modelled surface. If a highlight occurs in the middle of a polygon, but not at any of the vertices, the highlight will not be rendered by interpolation (figure 7.16). Also, Mach banding can occur when specular refection is incorporated into Gouraud, for this reason, the specular component is often ignored when using Gouraud, giving 'smother' results.

Figure 7.16: Specular Reflection Not Rendered
\includegraphics[width=\textwidth]{C:/MyDocuments/Class/Graphics/Notes/gouraud4.eps}

Phong Shading

Phong shading overcomes the problems of specular reflection encountered in Gouraud shading. This method again calculates the normals at the vertices by averaging the normals for the faces at that vertex. These vertex normals are then interpolated across the face (figure 7.17).

Figure 7.17: Interpolating Normals
\includegraphics{C:/MyDocuments/Class/Graphics/Notes/phong1.eps}

Thus we have a good approximation of the surface normal at each scanline position (pixel) and therefore we are able to calculate more accurately the intensity at that point, including specular highlights. The interpolation scheme for normals, is similar to Intensity interpolation.

Figure 7.18: Bi-Linear Normal Interpolation
\includegraphics{C:/MyDocuments/Class/Graphics/Notes/phong2.eps}


\begin{displaymath}N_{a}=N_{1}+(N_{2}-N_{1})\frac{y_{a}-y_1}{y_2-y_1}\end{displaymath}


\begin{displaymath}N_{c}=N_{a}+(N_{b}-N_{a})\frac{x_{c}-x_a}{x_b-x_a}\end{displaymath}

Phong shading requires intensity calculations at each point on the face, so is therefore far more expensive that Gouraud which only performs intensity calculations at the vertices. Note that the computation of normals in both Gouraud and Phong must be done in world coordinates, as pre-warping distorts the relative orientation between surface, light-source and eye. Both these methods can be integrated with Z-Buffer or scanline filling algorithms.



powerk 2004-07-14