Copyright Derek O'Reilly, Dundalk Institute of Technology (DkIT), Dundalk, Co. Louth, Ireland.
The rendering equation can be applied to each pixel as it is being drawn on a viewport. However, this is very inefficient.
If we are only dealing with polygons we can considerably reduce the amount of calculations needed to render a scene.
We shall discuss three methods that can be used to efficiently colour the surface of a polygon:
· Constant shading;
· Gouraud interpolation shading;
· Normalvector interpolation shading.
In constant shading NO rendering algorithm is used. The intensity of light is constant across the whole of a polygon's surface.
Constant shading is easily implemented and is computationally fast.
However, constant shading does not produce very good rendered images. For example:
· No specular or diffuse reflection is implemented.
· If several polygons are being used to approximate a curved surface, the individual surfaces will be distinguishable using constant shading, which results in a very unpleasant graphic.
Gouraud shading eliminates intensity discontinuities that are evident in constant shading. (NOTE, however, that Gouraud shading will not completely eliminate the discontinuity if the change in slope between two adjacent surfaces is large).
The Gouraud shading process consists of five steps:
1. Surface normals are calculated for all polygons.
2) Vertex normals are calculated by averaging the surface normals that share each vertex.
NOTE: If an edge is meant to be distinguishable, then separate vertex normals need to be calculated for each side of the edge. Each of the two vertex normals is calculated by averaging the polygons on that side of the edge. An example of where we would wish to keep the edge visible is at the intersection of a plane's body with one of its wings.
3) Vertex intensities are found by applying a shading model to each vertex normal.
4) Polygon edges are shaded by linear interpolation between vertex intensities.
5) The scan line polygon interior is shaded by linear interpolation between edge intensities.(as shown in the diagram on the next webpage).
Steps "4)" and "5)" fit neatly into the scanline hidden surface removal algorithm that we have already discussed.
With each edge we store the starting intensity and the change of intensity for each unit change in y.
Filling in a visible span of a scan line is done by interpolating the intensity values of the two edge values of the two edges that bound the span.
The red, green and blue components of a colour are interpolated separately.
If the intensity of light varies significantly over the surface of a polygon (i.e. specular highlights occur), then Gouraud shading is a USELESS lighting model to use. This is because in Gouraud shading all light intensities on the surface of a polygon are based solely on the intensities of the vertices. If a highlight occurs away from a vertex of a polygon, then Gouraud shading will fail to account for it. Even if the highlight occurs at a vertex, it will not show up as a highlight in the rendered image. Instead, it will show up as a smooth transition from bright light to less bright light as a result of using linear interpolation of intensity.
Gouraud shading should NEVER be used to render a scene that includes specular highlights.
In normalvector shading we interpolate the surface normal vector, rather than the intensity, across a visible span of a polygon on a scan line.
Normalvector shading produces substantially better quality rendered images than Gouraud shading does. This is because:
· Normalvector shading calculates the intensity of the incident light at each surface point.
· The intensity calculated at each point is accurate because we linearily interpolate the surface normal. A small increase in the angle of the incidence light and the surface normal will result in a large decrease in the specular highlight. Therefore, as we interpolate across the polygon surface (linearly changing the normal as we progress) we rapidly change the specular effect.
However, normalvector interpolation is computationally more expensive than Gouraud shading is.
WORKED EXAMPLE: Gouraud Intensity Shading
Assuming the intensity at the three vertices has been calculated to be:
P_{1}i 
= 0.9 
P_{2}i 
= 0.2 
P_{3}i 
= 0.3 
Q1) What is the step size of the interpolated intensity along each of the three edges: P_{1}P_{2}, P_{1}P_{3} and P_{2}P_{3}?
Q2) What is the step size of the scanline intensity at scanline y = 15?
ANSWER Q1) Calculation of the intensity step size along edge P_{1}P_{2}:
There are P_{2}y  P_{1}y scan lines (and therefore steps) along the edge.
P_{2}y  P_{1}y 
= 20  10 
= 10 
The change in between the two vertices is:
P_{2}i  P_{2}i 
= 0.2  0.9 
= 0.7 
The change in intensity (0.7) is spread evenly over 10 steps. Therefore each step is
(P_{2}i  P_{1}i) / (P_{2}y  P_{1}y) 
= 0.7 / 10 
= 0.07 
Calculation of the intensity step size along the edges P_{1}P_{3} and P_{2}P_{3} is similar:
(P_{3}iP_{1}i) / (P_{3}yP_{1}y) 
= (0.30.9) / (3010) 
= 0.6 / 20 

= 0.03 
(P_{3}iP_{2}i) / (P_{3}yP_{2}y) 
= (0.30.2) / (3020) 
= 0.1 / 10 

= 0.01 
ANSWER Q2) What is the step size of the scanline intensity at scanline y = 15?
At scanline y = 15 edge P_{1}P_{2} will have stepped through 15P_{1}y (i.e. 1510) interations. Therefore its intensity will have changed from 0.9 by 0.07*15P_{1}y steps
(i.e 0.9  0.35) to give an interpolated edge intensity value of 0.55.
Similarly edge P_{1}P_{3} will have changed from an intensity of 0.9 by 0.03 * 15P_{1}y steps
(i.e. 0.9  .15) to give an interpolated edged intensity value of 0.75.
The scanline will be interpolated from 0.55 to 0.75 across the scanline. The number of steps the scanline takes across the polygon can be calculated using the two edges' scanline x coordinates. Remember, the edges' x coordinates are kept in the polygons Active Edge Table (AET) and are therefore readily available. The two scanline polygon edge x coordinates (taken from the AET) are 10.5 and 20.
The number of steps across the scanline is 20  10.5 = 10
The interpolation is from an intensity of 0.55 to 0.75
Each interpolation step size across the scanline y = 15 between the polygon's two edges is:
(0.750.55) / 10 = 0.02
ANSWER...
The intensity along the scanline y=15 between the polygon's edges P_{1}P_{2} and P_{1}P_{3}
starts at a value of 0.55 and interpolates by a value 0.02 for 10 steps and ends up with the value 0.15
Specular and diffuse transmission of light through the surface of a polygon cannot be rendered with the scanline rendering methods discussed.
Instead, the more complex ray tracing rendering method is used.
Copyright Derek O' Reilly, Dundalk Institute of Technology (DkIT), Dundalk, Co. Louth, Ireland.