What is Gouraud-Shading
Gouraud shading, also called intensity interpolation shading, eliminates
intensity discontinuities, although not completely.
Gouraud shading requires that the colors of all edges of a polygon are known
in advance.
This can be accomplished by applying the illumination model for each vertex
of the polygon.
Then linair interpolation is used to determine the color at each point inside
the polygon. This can be done for each scanline (see figure).
Now the following formula can be used to get the intensity of vertex p
- la=l1-(l1-l2)*(y1-ys)/(y1-y2)
- lb=l1-(l1-l3)*(y1-ys)/(y1-y3)
- lp=l1-(lb-la)*(xb-xp)/(xb-xa)
To speed things up however it's better to use forward differences. You
just calculate the slopes of the lines once. Then you can use those
values to calculate the intensity of a new point given the value of the
previous point.
Because gouraud shading uses linear interpolation this is simply done by adding
a contant value to the previous one.
See the lowlevel part of the 3DSView source for an implementation of this
technique.