The Normal Vectors

You may have noticed that both diffuse and specular reflection depend on the normal vector to the surface. How and where is this normal vector being defined?

We saw in Chapter 5 that the normal vector to a polygon (or to a vertex on the polygon) determines the orientation of the polygon. This normal vector can be used to determine front- vs. back-facing polygons: polygons: with normal vectors facing away from the viewpoint are back-facing and are culled from the scene, as shown in Fig.6.23. The normal vector also determines the orientation of the polygon or to a vertex on the polygon, relative to the light sources. This normal vector is used in the lighting calculations we looked into earlier. In OpenGL, we can define the normal vector by using the commands

glNormal3( G If I oat nx, Glfloat ny, Glfloat nz); void glNormal3fv(const GLfloat *v);

This command sets the current normal to the value of the argument passed in. Subsequent calls to glVertex*0 cause the specified vertices to be assigned the current normal. For the glutSolidObject functions that we use, the normal vectors are already identified within the routine.

In Example6_7, we read in the VRML model of the android by using our ReadVRML function. Recall that this function also reads in the normal vectors to the vertices of the polygons being defined.

In the Display function we assign normals to the vertices as shown:

glBegin(GLJTRIANGLES); glNotmal3fv(&lnormals[j][3*nindices[j][i]])); glVertex3fv(&lcoords[j][3*indicesQ][i]])); glNormal3fv(&(nomialsO][3*nindices[j][i+1]])|; glVertex3fv(&(coords[j][3*indices[j][i+1]])); glNormal3fv(&(normals[j][3*nindicesD][i+2]])); glVertex3fv(&(coords[j][3*indicesp][i+2]])); glEndO;

We also assign a shiny yellow material to the android. For each vertex, OpenGL uses the assigned normal to determine how much light that particular vertex receives and reflects, in order to generate the image. Run this program to see the Android in all its metallic glory!

In the last section, we learned how to determine the color of a surface. For every surface point, the four shading components are added together for each light in the scene. This value is then clamped to the maximum intensity of 1 to arrive at the final color of the point.

Performing this calculation for each surface point can be very tedious. Consequently, shading models are used that limit the calculations to certain key points on the surface. The surface is then colored by some average of these values. For polygonal surfaces, the key points are the vertices of the defining polygons.

0 0

Post a comment

  • Receive news updates via email from this site