Game Development Reference
In-Depth Information
Figure 11-3. Different material/light types. Left: ambient only. Center: Diffuse only. Right: Ambient and diffuse with specular
highlight
In Figure 11-3 , we can see the contributions of the different material and light properties.
Ambient light illuminates the object uniformly. Diffuse light will be reflected depending on the
angle at which the light rays hit the object; areas that directly face the light source will be
brighter, and areas that can't be reached by light rays are dark. The rightmost image shows the
combination of ambient, diffuse, and specular light. The specular light manifests itself as a white
highlight on the sphere.
How OpenGL ES Calculates Lighting: Vertex Normals
You know that the intensity of the reflected light bouncing back from an object depends on the
angle at which the light rays hit the surface of the object. OpenGL ES uses this fact to calculate
lighting. It does so by using vertex normals , which we have to define in our code, just as we
define texture coordinates and vertex colors. Figure 11-4 shows a sphere with its vertex normals.
Figure 11-4. A sphere and its vertex normals
Normals are simply unit-length vectors that point in the direction a surface is facing. In our case,
a surface is a triangle. Instead of specifying a surface normal, though, we have to specify a
vertex normal. The difference between a surface normal and a vertex normal is that the vertex
normal might not have to point in the same direction as the surface normal. We can clearly
see this in Figure 11-4 , where each vertex normal is actually the average of the normals of the
triangles to which that vertex belongs. This averaging makes for a smooth shading of the object.
When we render an object with vertex normals and lighting enabled, OpenGL ES will determine
the angle between each vertex and light source. With this angle, it can calculate the vertex's
 
Search WWH ::




Custom Search