I want to tell you up front that this chapter won't teach you everything you need to know about 3D graphics—actually far from it. Walk the aisle of any decent computer bookstore and you'll see racks of books devoted entirely to 3D graphics. I'm only including two 3D chapters in this book so I can't compete with the classics on 3D graphics. What's lacking in volume I'll try to make up in focus and content. My job in the next two chapters is to open the door to 3D graphics, especially in the way game programmers utilize 3D techniques. Once inside, I'll hand you a map of the place and send you on your way. I hope you are wearing comfortable shoes because we have a lot of ground to cover. In this chapter I'll focus on the essentials, which is a nice way of saying that I'm going to load you down with some math you'll need to know. This will set the foundation so that we can start manipulating objects and perform some of the fun stuff I have planned for later in this chapter and Chapter 10.
The word pipeline describes the process of getting a 3D scene up on a screen. It's a great word because it implies a beginning that accepts raw materials, a process that occurs along the way, and a conclusion from which pours the refined result. This is almost exactly what happens inside 3D game engines. The raw materials at the beginning include collections of the following components:
Geometry: Everything you see on the screen starts with descriptions of their shape. Each shape is broken down into triangles, which is a basic drawable element in 3D engines. Meshes and polygons are different types of geometry.
Materials: These elements describe appearance. You can imagine materials as paint or wallpaper that you apply to the geometry. Each material can describe colors, translucency, and how the material reflects light.
Textures: These are images that can be applied to objects, just as you might have applied decals to plastic models.
Lights: You must have light to see anything. Light can affect an entire scene or have a local effect that mimics a spotlight.
Camera: Records the scene onto a render target such as the display. It even describes what kind of lens is used, such as a wide or narrow angle lens. You can have multiple cameras to split the screen for a multiplayer game or render a different view to create a rear view mirror.
World: A data structure that organizes the raw materials so that a minimum set of the above collections can be presented to the rendering hardware. These data structures also relate objects hierarchically to create complicated shapes such as human figures.
Some of the processes applied to the raw materials include:
Transformations: The same object can appear in the world in different orientations and locations. Objects are manipulated in 3D space via matrix multiplications.
Culling: A list of objects is selected based on their visibility.
Lighting: Each object in range of a light source is illuminated by calculating additional colors applied to each vertex.
Rasterization: Polygons are drawn.
We'll start to see how all of these components and processes act together shortly. I'm going to take a quick shortcut through two math classes you probably slept though in high school or college. I know that because I slept through the same classes—trigonometry and linear algebra.