Game Development Reference
In-Depth Information
4.
Finding the diffuse light amount by taking the dot product between the Vertex
Normal in eye coordinates and the Light Vector in eye coordinates or 0,
whichever is greater
vDiffuse = max(dot(EcLightDir, EcNormal), 0.0);
Listing 4-43 is the full shader code.
Listing 4-43. Diffuse Calculations in the Vertex Shader
// Calculate Diffuse Lighting for vertex
// maximum of ( N dot L, 0)
vec3 WcVertexPos = vec3(uModelMatrix * vec4(aPosition,1));
vec3 WcLightDir = uWorldLightPos - WcVertexPos;
vec3 EcLightDir = normalize(vec3(uViewMatrix * vec4(WcLightDir,1)));
vDiffuse = max(dot(EcLightDir, EcNormal), 0.0);
The vDiffuse shader variable is then passed into the fragment shader as a varying float variable:
varying float vDiffuse;
Specular
The specular value of light is meant to simulate the shine an object gives off when viewed from a
certain angle when being illuminated by a light source—for example, the shine on a chrome bumper
on a car when being hit by the sun's rays and viewed at a certain angle.
The specular light amount for a vertex is calculated by
1.
Calculating the vector S, which is the sum of the Light Vector and the Eye
Vector (see Figure 4-24 ).
EyeVec
S = LightVector + EyeVector
PointLight
Eye
Normal
EyeVec
LightVec
Figure 4-24. Specular lighting
 
Search WWH ::




Custom Search