Shading

So far, we have applied a single color to each polygon that we have drawn.

  glColor3f(1.0, 1.0, 1.0);
  glBegin(GL_QUADS);
  glVertex2f(-0.5, -0.5);
  glVertex2f( 0.5, -0.5);
  glVertex2f( 0.5,  0.5);
  glVertex2f(-0.5,  0.5);
  glEnd();

However, it is possible to specify a unique color at each vertex. OpenGL will smoothly interpolate the color between the vertices. This is known as Gouraud shading. OpenGL will triangulate the polygon, linearly interpolate the RGB values for the pixel values along the edges of each triangle, and then linearly interpolate the RGB values for the internal pixels.

(This triangulation is only applicable to convex polygons. We will consider the problems involved with drawing concave polygons in a later lecture.)

Shading with different colors can be useful to produce a contour plot. For example, we can associate colors with particular values of some function defined over the surface, where red indicates the high value and blue the low value.

Shading with different intensities of the same color is useful to produce the effect of a smoothly curved surface.

  glBegin(GL_QUADS);               /* draw 2 shaded polygons */

  glColor3f(1.0, 0.0, 0.0);        /* color interpolation */
  glVertex2f(-0.8, -0.8);          /* the four vertices are */
  glColor3f(0.5, 1.0, 0.0);        /* red, green, cyan, and */
  glVertex2f(-0.1, -0.8);          /* blue */
  glColor3f(0.0, 1.0, 0.5);
  glVertex2f(-0.1,  0.8);
  glColor3f(0.0, 0.0, 1.0);
  glVertex2f(-0.8,  0.8);

  glColor3f(1.0, 1.0, 1.0);        /* intensity interpolation */
  glVertex2f( 0.1, -0.8);          /* the four vertices are */
  glColor3f(0.7, 0.7, 0.7);        /* 1, 0.7, 0.5, and 0.1 */
  glVertex2f( 0.8, -0.8);
  glColor3f(0.5, 0.5, 0.5);
  glVertex2f( 0.8,  0.8);
  glColor3f(0.1, 0.1, 0.1);
  glVertex2f( 0.1,  0.8);

  glEnd();


On to the lighting model...
Back to smooth redrawing...
Back to the 13.016 overview...