Game Development Reference
In-Depth Information
Here, I D is the intensity of the diffusely reflected light (surface brightness), C is the
color, and I L is the intensity of the incoming light. -L.N is calculated as follows:
-L.N=ǀ-Lǀ ǀNǀ cosα=cos α
Here, ǀ-Lǀ and ǀNǀ are equal to 1, which are unit vectors, and α is the angle between the
direction of the two vectors. The intensity will be highest if the normal vector points
in the same direction as the light vector cos(0)=1 (the surface will be perpendicular to
the direction of the light), and lowest if the normal vector is perpendicular to the light
vector cos(π/2)=1 (the surface runs parallel with the direction of the light). Also, N
can be the normal vector or the face vector depending on the shading model used.
The following is the formula to calculate C (color):
C=C L C M
Here, C L is the color of light and C M is the color of material.
The code for the Lambert reflectance model is as follows:
//Transform the Normal Vertex/Face Vector with normal
matrix(transpose of inverse of mVMatrix
vec3 N = normalize(vec3(uNMatrix * vec4(aVertexNormal, 1.0)));
//Normalize light
vec3 L = normalize(uLightDirection);
//Lambert's cosine law
float lambertTerm = dot(N,-L);
//Final Color
vec4 colorDiffuse = uMaterialDiffuse * uLightDiffuse * lambertTerm;
vFinalColor = colorDiffuse;
vFinalColor.a = 1.0;
The Blinn-Phong model
In diffuse reflections, light is reflected in all directions. However, in specular
reflection/highlights, the angle of view is important. There are many models used
for specular reflection calculations, and amongst them, the most popular is the
Phong model. However, the Phong model has a shortcoming as it does not work
when the angle between V (eye vector) and R (light reflection vector) is greater than
90 degrees, as shown in the following diagram:
 
Search WWH ::




Custom Search