Game Development Reference
In-Depth Information
The difference between directional and positional lights is that the directional lights
are defined by a direction vector, whereas positional lights are defined by their
locations in x , y , and z coordinates. The difference between directional and positional
lights is shown in the following diagram:
Va
Va
Vd
Vd
Directional ightsl
l
distance of Va
Positional lights,
l
distance of Va
and
does not effect the intensity
Vd
and
does effect the intensity
Vd
For positional lights, we calculate the light direction for a particular vertex and the
result is stored in the varying, uLightRayLamp1 . This variable is then used by the
fragment shader. The rest of the calculation remains the same as with the directional
light. Hence, for positional lights, we calculate the light direction for each vertex. We
call this a ray.
We pass the position of light as a uniform to the vertex shader. Then, the vector is
calculated per vertex and is passed to the fragment shader as a varying variable.
The following code explains the uLightPositionLamp1 uniform that is passed to the
vertex shader, and using the variable we calculate the uLightRayLamp1 varying for
use in the fragment shader:
vec4 newLightPosition1=mVMatrix * vec4(uLightPositionLamp1, 1.0);
uLightRayLamp1=vertexPos-newLightPosition1.xyz;
Lighting up the scene with lamps
Open the 03-Loading-Scene-With-Lamps.html file in your favorite editor. The
following sections in the chapter will explore the code changes to add positional
lights to our stage.
 
Search WWH ::




Custom Search