Pro OpenGL ES for iOS

(singke) #1

94 CHAPTER 4: Turning On the Lights^


Figure 4-2. O S X ’ s s t a n d a r d c o l o r p i c k e r s -----RGB, CMYK, HSV, and the ever-popular Crayola model

Let There Be Light

In the real world, light comes at us from all sides and with all colors and, when
combined, can create the details and rich scenes of everyday life. OpenGL doesn’t
attempt to duplicate anything like the real-world lighting models, because those are very
complex and time-consuming and generally reserved for Disney’s rendering farms. But it
can approximate it in a way that is certainly good enough for real-time gaming action.
The lighting model used in OpenGL ES 1 permits us to place several lights of varying
types around our scene. We can switch them on or off at will, specifying direction,
intensity, colors, and so on. But that’s not all, because we also need to describe various
properties of our model and how it interacts with the incoming light. Lighting defines the
way light sources interact with objects and the materials those objects are created with.
Shading specifically determines the coloring of the pixel based on the lighting and
material. Notice that a white piece of paper will reflect light completely differently than a
pink, mirrored Christmas ornament. Taken together, these properties are bundled up
into an object called a material. Blending the material’s attributes and the light’s
attributes together generates the final scene.

Note OpenGL ES 2 has no lights whatsoever, leaving that up to the programmer via the use
of shaders. The GLKit framework, new in iOS5, adds a few lights via the GLKBaseEffect object,
but that is not meant to be a general-purpose substitute for version 1.

The colors of OpenGL lights can consist of up to three different components:
„ Diffuse
„ Ambient
„ Specular
Free download pdf