Shading involves color determination of points inside a polygon (face) based upon
the colors at vertices of the polygon. We discuss here the color computation used in
smooth shading (also called Gouraud shading) of a triangle. The particular triangle
is shown to the left with vertices marked as 1, 2 and 3. The colors for these vertices
are, respectively, red, green and blue.
The color at point 6, the center of the cross-hair, is computed from the colors at points
4 and 5. Points 4 and 5 are the intersection points of the horizontal scan line with the sides
of the triangle. Their colors are computed from those at the vertices of the triangle, vertices
1 and 3 for point 4 and vertices 2 and 3 for point 5. Once the colors are computed for points
4 and 5, they are then used to compute the color at point 6. Linear interpolation is used in each
of the computations. Also, the computation of a color is done for each of the components red, green
and blue. This scheme for computing the color of a point inside a triangular face is call Gouraud
interpolation. The computation for point 4 takes the form
(1.0 - Factor)*C1 + Factor*C3
where
Factor = (distance between 1 and 4) /
(distance between 1 and 3)
and C1 and C3 are the colors at the vertices 1 and 3, respectively.
A similar computation is done for point 5 using the vertices 2 and 3 and the corresponding
distances and colors. Last, the color of point 6 is computed using linear interpolation and the
colors computed for points 4 and 5.