Pro OpenGL ES for iOS

(singke) #1

194 CHAPTER 6: Will It Blend?^


shows a bit of our earth map, while Figure 6-15 (right) shows its corresponding normal
map.

Figure 6-15. The left side is our image; the right is the matching normal map.

And why is the normal map primarily purple? The straight-up vector pointing away from
the earth’s surface is encoded such that red=.5, green=.5, and blue=1. (Keep in mind
that .5 is actually 0.)
When the texture combiner is set to the DOT3 mode, it uses the normal and a lighting
vector to determine the intensity of each texel. That value is then used to modulate the
color of the real image texture.
Now it’s time to recycle the previous multitexture project. We’ll need to add a second
texture composed of the bump map, available from the Apress site, and change the way
the combiners are set.
To the viewDidLoad() method, load the normal map for this example into m_Texture0,
followed by the companion earth texture as m_Texture1. Then add the new routine,
MultiTextureBumpMap(), as shown in Listing 6-6.
Listing 6-6. Setting Up the Combiners for Bump Mapping

-(void)multiTextureBumpMap:(GLuint)tex0 tex1:(GLuint)tex1
{
GLfloat x,y,z;
static float lightAngle=0.0;

lightAngle+=1.0; //1

if(lightAngle>180)
lightAngle=0;

// Set up the light vector.

x = sin(lightAngle * (3.14159 / 180.0)); //2
y = 0.0;
Free download pdf