Game Development Reference
In-Depth Information
Normal Vector
Light Vector
Vertex
Light Source
(Normal Vector) Dot (Light Vector) = 0
Figure 4-22. Diffuse light value is 0
If the angle between the Normal Vector and the Light Vector is 0, the cosine of the angle between the
vectors is 1, and the dot product and diffuse lighting are at the maximum, which is 1 (see Figure 4-23 ).
Light Source
Light Vector
Normal Vector
(Normal Vector) Dot (Light Vector) = 1
Figure 4-23. Diffuse light value is 1
In code, we find the diffuse lighting by
1.
Finding the world coordinates of the Vertex Position, by multiplying the
incoming vertex position by the ModelMatrix
vec3 WcVertexPos = vec3(uModelMatrix * vec4(aPosition,1));
2.
Finding the world coordinates of the Light Vector which is from the vertex to
the light source through standard vector math by subtracting the vertex world
position from the light source world position
vec3 WcLightDir = uWorldLightPos - WcVertexPos;
3.
Finding the Light Vector in eye coordinates by multiplying the Light Vector in
world coordinates by the ViewMatrix
vec3 EcLightDir = normalize(vec3(uViewMatrix * vec4(WcLightDir,1)));
 
 
Search WWH ::




Custom Search