Game Development Reference
In-Depth Information
PointLight
Eye
Normal
EyeVec
LightVec
Figure 4-21. Important lighting vectors
In OpenGL ES 2.0, the lighting calculations are carried out in the programmable vertex and fragment
shaders. I discuss these shaders later in this section; however, first let's go over the class that
represents our point light.
The PointLight Class
The PointLight class will provide the lighting for our 3D scenes. The data contained in this class is
shown in Listing 4-36.
Listing 4-36. Point Light Data
private float[] m_light_ambient = new float[3];
private float[] m_light_diffuse = new float[3];
private float[] m_light_specular = new float[3];
private float m_specular_shininess = 5;
private Vector3 m_Position;
The array variable m_light_ambient holds the color value of the ambient light emitted from this light.
The array variable m_light_diffuse holds the color value of the diffuse light emitted from this light.
The array variable m_light_specular holds the color value of the specular light emitted from this light.
For all of the preceding variable arrays, the first array element is the red value, the second element is
the green value, and the third element is the blue value. These values range from 0 to 1. A value of all
1's for the r, g, b color would represent white, and a value of all 0's would represent black.
The m_specular_shininess variable sets the level of specular shininess caused by m_light_specular .
The m_Position variable holds the position of the light in 3D space.
The PointLight constructor is shown in Listing 4-37. By default, the PointLight object is initialized by
the constructor to emit a light that has a maximum intensity of white light (red, green, blue values are
all 1.0) for ambient, diffuse, and specular light. The default position of the light is at the origin.
 
Search WWH ::




Custom Search