Answer to Problem

Solving the problem in my previous post allows me to do Gouraud Shading.

Here is the before picture. I calculate the color of each polygon face using the face normals (the line perpendicular to the face of the polygon).

With Gouraud Shading, I use the normals at each vertex, not the face. The normal for a vertex is the average of the normals of all the faces that use that vertex. With this normal I calculate the shading value for each vertex and create a gradient in each triangle.

I'll post the answer to the problem in the future if someone wants me to.


Problem of the week

Here's the problem:

You have a triangle with points A, B and C (known). Each point has a shading value s: As, Bs, and Cs that are also known.

You want to shade the triangle with a single linear gradient so that each point has the right shading value.

So what is the starting and ending point of the gradient?

Some hints:

If As = Bs = Cs, the triangle is all the same color, so any points will do.
If Bs = Cs but not As, then the gradient should go from As to the closest point on the line BC to A.