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;
· Normal-vector 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 scan-line 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 normal-vector shading we interpolate the surface normal vector, rather than the intensity, across a visible span of a polygon on a scan line.
Normal-vector shading produces substantially better quality rendered images than Gouraud shading does. This is because:
· Normal-vector 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, normal-vector 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:
P1i |
= 0.9 |
P2i |
= 0.2 |
P3i |
= 0.3 |
Q1) What is the step size of the interpolated intensity along each of the three edges: P1P2, P1P3 and P2P3?
Q2) What is the step size of the scanline intensity at scanline y = 15?
ANSWER Q1) Calculation of the intensity step size along edge P1P2:
There are P2y - P1y scan lines (and therefore steps) along the edge.
P2y - P1y |
= 20 - 10 |
= 10 |
The change in between the two vertices is:
P2i - P2i |
= 0.2 - 0.9 |
= -0.7 |
The change in intensity (-0.7) is spread evenly over 10 steps. Therefore each step is
(P2i - P1i) / (P2y - P1y) |
= -0.7 / 10 |
= -0.07 |
Calculation of the intensity step size along the edges P1P3 and P2P3 is similar:
(P3i-P1i) / (P3y-P1y) |
= (0.3-0.9) / (30-10) |
= -0.6 / 20 |
|
= -0.03 |
(P3i-P2i) / (P3y-P2y) |
= (0.3-0.2) / (30-20) |
= 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 P1P2 will have stepped through 15-P1y (i.e. 15-10) interations. Therefore its intensity will have changed from 0.9 by -0.07*15-P1y steps
(i.e 0.9 - 0.35) to give an interpolated edge intensity value of 0.55.
Similarly edge P1P3 will have changed from an intensity of 0.9 by -0.03 * 15-P1y 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.75-0.55) / 10 = 0.02
ANSWER...
The intensity along the scanline y=15 between the polygon's edges P1P2 and P1P3
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 scan-line 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.