Pro OpenGL ES for iOS

(singke) #1

192 CHAPTER 6: Will It Blend?^


Figure 6-13. Relatively little detail shows on the left, while with oblique lighting, a lot more shows on the right.

Understanding how highlights and shadows work together is absolutely critical to the
training of fine artists and illustrators.
Adding real surface displacement to replicate the entire lunar surface would likely
require many gigabytes of data and is out of the question for the current generation of
small handheld devices from both a memory and a CPU standpoint. Thus enters the
rather elegant hack of bump mapping to the center stage.
If you remember in Chapter 4 on lighting, you had to add an array of ‘‘face normals’’ to
the sphere model. Normals are merely vectors that are perpendicular to the face that
show the direction the face is pointing. It is the angle of the normal to any of the light
sources that largely determines just how bright or dark the face will be. And the more
directly oriented the face is toward the light, the brighter it will be. So, what if you had a
compact way to encode normals not on a face-by-face basis, because a model might
have relatively few faces, but on, say, a pixel-by-pixel basis? And what if you could
combine that encoded normal array with a real image texture and process it in a way
that could brighten or darken a pixel from the image, based on the direction of incoming
light?
This brings us back to the texture combiners. In Table 6-3, notice the last two combiner
types: GL_DOT3_RGB and GL_DOT3_RGBA. Now, reach back, way back to your high-school
geometry classes. Remember the dot product of two vectors? Both the dot products
and cross products were those things that you scorned with the whine ‘‘Teacherrrrr??
Why do I need to know this?’’ Well, now you are going to get your answer.
The dot product is the length of a vector based on the angle of two other vectors. Still
not following? Consider Figure 6-14 (left). The dot product is the ‘‘amount’’ of the normal
vector that is aiming toward the light, and that value is used to directly illuminate the
face. In Figure 6-14 (right), the face is at a right angle to the direction of the sun, so it is
not illuminated.
Free download pdf