The vast majority of 3-D objects created for computer games are made up of polygons. A polygon is an area defined by lines. To have a polygon, you must have at least three lines.
The lines connect a series of coordinates in the three-dimensional "space" the computer creates. The point where the lines connect is known as a vertex. Each vertex has X, Y and Z coordinates.
- X determines the position relative to right or left in the virtual space
- Y determines the position relative to top or bottom in the virtual space
- Z determines the position relative to front or back in the virtual space
Once each polygon has a set of vertices to define its shape, it needs information that tells it what to look like. There are four common ways to do this:
- Flat shading
- Gouraud shading
- Phong shading
- Texture mapping
Flat shading simply assigns a single color to a polygon. It is very simple and fast, but makes the object look artificial. Gouraud shading is more complex. Colors are assigned to each vertex and then are blended across the face of the polygon. Since each vertex is typically associated with at least three distinct polygons, this makes the object look natural instead of faceted. Look at this example:
You will notice that the ball with Gouraud shading appears much smoother than the flat shaded one. But look closely at the outlines of the two balls. That's where you can tell that both balls have the exact same number of polygons.
An even more complex version of shading, Phong, improves upon Gouraud shading. Whereas Gouraud shading interpolates colors by averaging between the vertices, Phong shading averages each pixel based on the colors of the pixels adjacent to it to create smooth surfaces.
Another common technique for determining the appearance of a polygon is to use texture mapping. Think of texture mapping as wrapping a present. Each side of the box you are wrapping is a blank polygon. You could paint the box, but it would be very difficult to make it match all the designs on the wrapping paper. However, if you take the wrapping paper and tightly cover the box with it, you have completely transformed the box with just a little effort.
Texture mapping works the same way. Mapping requires the use of another image. Essentially, this other image is stretched over the object like a skin. Most video game consoles and computer graphics adapters contain a special chip and dedicated memory that store the special images used for texture mapping and apply them to each polygon on the fly. This allows games such as Portal Runner to have incredibly detailed 3-D environments that you can interact with in real time.