Light Sources

We are surrounded by all kind of light sources. The sun constantly throws photons at us. Our monitors emit light, surrounding us with that nice blue glow at night. Light bulbs and headlights keep us from bumping or driving into things in the dark. OpenGL ES allows you to create four types of light sources:

Ambient light: Ambient light is not a light source per se but rather the result of photons coming from other light sources bouncing around in our world. All these stray photons combined make for a certain default level of illumination that is directionless and illuminates all objects equally.

Point lights: These have a position in space and emit light in all directions. A light bulb is a point light, for example.

Directional lights: These are expressed as directions in OpenGL ES and are assumed to be infinitely far away. The sun can be idealized as a directional light source. We can assume that the light rays coming from the sun all hit the earth with the same angle because of the distance between the earth and the sun.

Spotlights: These are similar to point lights in that they have an explicit position in space. Additionally the have a direction in which they shine and create a light cone that is limited to some radius. A street lamp is a spotlight.

We'll only look into ambient, point, and directional lights. Spotlights are often hard to get right with limited GPUs like on Android devices, because of the way OpenGL ES calculates the lighting. You'll see why that is in a minute.

Besides a light source's position and direction, OpenGL ES lets us also specify the color or intensity of a light. This is expressed as an RGBA color. However, OpenGL ES requires us to actually specify four different colors per light source instead of just one.

Ambient: This is the intensity/color that contributes to the overall shading of an object. An object will be uniformly lit with this color, no matter its position or orientation relative to the light source.

Diffuse: This is the intensity/color an object will be lit with when calculating the diffuse reflection. Sides of an object that do not face the light source won't be lit, just as in real-life.

Specular: This intensity/color is similar to the diffuse color. However, it will only affect spots on the object that have a certain orientation toward the viewer and the light source.

Emissive: This is totally confusing and has very little use in real-word applications, so we won't go into it.

Usually we'll only set the diffuse and specular intensities of a light source and leave the other two at their defaults. We'll also use the same RGBA color for both the diffuse and specular intensity most of the time.

0 0

Post a comment