C481 B581 Computer Graphics
Dana Vrajitoru
Interpolation Methods
Why. Polygon representations (like the triangulation) are often
a discretization of a smooth object. We would like the final image to look
smooth also.
The color of each polygon is constant.
Could be produced by the Phong model with directional light sources.
Interpolated shading - Each point of the polygon has its own
color. These models aim at a smooth transition from a polygon to its neighbor.
Gouraud Interpolation
-
Compute the normal in each vertex of the polygon. Average the normals of
all the polygons for which the point is a vertex.
-
Compute the color in each vertex based on the average normal, for example,
using the Phong model.
-
Interpolate the color inside each polygon.
Color with Gouraud Normals
-
Compute the color in each vertex based on the average normal.
-
Compute the color in each point inside the polygon by a linear interpolation
based on the colors of the vertices.
-
If c1, c2, and c3 are the colors computed
in P1, P2, and P3 respectively, and the
color in Q is c,
-
Q=(1-t)((1-s) P1 + s P2) + t P3
-
c = (1-t)((1-s) c1 + s c2) + t c3
Phong Shading
- Compute the normal in each vertex of the polygon. Average the normals
of all the polygons for which the point is a vertex.
- Interpolate the normal in each point inside a polygon based on the
normals of the vertices.
- Compute the color in each point based on the interpolated normal, for
example, using the Phong model.
- For the case of the triangle, compute the normals N1,
N2, and N3 in
each vertex as before. The the normal N in the point Q is
- N = (1-t)((1-s) N1 + s
N2) + t N3
- This model produces smoother results than the Gouraud model, but it's
also slower.
Light in OpenGL
Define the shade as interpolated or not;
-
non-interpolated, each polygon has a constant color:
glShadeModel(GL_FLAT);
-
interpolated color:
glShadeModel(GL_SMOOTH);
Smooth Color in OpenGL
Specifying the normal before each vertex in any sequence of geometrical
commands. All transformations apply equally to the normals.
glBegin(GL_QUADS);
...
glNormal3f(nx, ny, nx);
glVertex3f(vx, vy, vz);
...
glEnd();
Light Sources in OpenGL
-
Customize a light source:
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_AMBIENT,
light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
From the program sphere.c from the textbook CD (no normals, wireframe,
normals specified):
Left: normal defined for one vertex of each triangle. Middle:
wireframe. Right: normals defined in each vertex of each triangle.
Spotlight in OpenGL (Projection Light Source)
- After defining the position, ambient, diffuse, and specular components
of the light source,
- define the angle of the spotlight:
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 60.0);
- Define the shininess of the spotlight:
glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 60.0);
Material Properties in OpenGL
-
glMaterialfv(side, type, array_of_values);
glMaterialf(side, type, value);
- Side: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK .
- Type: GL_SPECULAR, GL_AMBIENT, GL_DIFFUSE, GL_SHININESS.
- Once the material properties are defined, they replace the usual
calls to glColor3f(...);
Lights and glColor
- When the lighting is turned on, to be able to use the glColor, one must enable some general material properties:
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
GL float spec={0.3, 0.3, 0.3, 0.1};
glMaterialfv(GL_FRONT, GL_SPECULAR, spec);
- After this, the material properties for each object can be
redefined with a simple glColor3f(...); call.
Last modified: April 12, 2017.
danav@cs.iusb.edu.