Detail Without Triangles
Picture a piece of toast. From afar, the toast looks like an ordinary golden rectangular prism. But up close we see that the surface is not perfectly flat or uniform in color. It's full of holes, fossils of the carbon dioxide bubbles generated by the yeast. To render convincing toast, we need to make these irregularities visible.
One way to add detail to a surface is to add more triangles. But this is costly. Models made of many small triangles are challenging to manipulate, just as sand is harder to build with than bricks. Adding triangles also slows down rendering. The more triangles we have, the more matrix multiplications, clipping, and perspective divisions we have to compute. To achieve fast rendering, we want fewer triangles.
A cheaper way to get detail is to paste an image on the surface of a mesh. The image might even be photo of some real toast. Putting an image on a model to give the appearance of detail is called texturing. The detail is an illusion; no triangles are actually added. The pixels of the texture, which are called texels, provide the detail at a much lower cost than extra triangles.
This renderer uses just 112 vertices to render a piece of low-poly toast:
Toggle the texture to see the simple underlying geometry.
In this chapter we explore the process of applying textures to models. By its end, you'll be able to answer the following questions:
- How we load texture images in from disk or the network and send the pixel data to the graphics card?
- How do we apply a flat 2D image to a 3D surface?
- What happens in hardware when we look up a texel?
- How do we address the visual artifacts that appear when just a few texels cover a very large area? Or when many texels cover a very small area?
For the time being, we'll use textures only as a source of fine-grained albedo. In a later chapter, we'll see how we can use texture to produce a variety of visual effects.