Added specular color and geometric transformations.

This commit is contained in:
2014-05-12 11:36:55 -04:30
parent 8d13493c2a
commit ea33f1e725
2 changed files with 13 additions and 4 deletions

View File

@@ -17,6 +17,9 @@
// Model-view matrix.
uniform mat4 u_projTrans;
// The world space geometric transformation to apply to this vertex.
uniform mat4 u_geomTrans;
// Light source position
uniform vec4 u_lightPos;
@@ -51,14 +54,17 @@ varying vec3 v_eyeVector;
varying vec3 v_reflectedVector;
void main(){
// Apply the geometric transformation to the original position of the vertex.
vec4 transformedPosition = u_geomTrans * a_position;
// Set the varyings.
v_lightVector = normalize(u_lightPos.xyz - a_position.xyz);
v_eyeVector = normalize(u_cameraPos.xyz - a_position.xyz);
v_lightVector = normalize(u_lightPos.xyz - transformedPosition.xyz);
v_eyeVector = normalize(u_cameraPos.xyz - transformedPosition.xyz);
v_reflectedVector = normalize(-reflect(v_lightVector, a_normal.xyz));
v_color = a_color;
// Diffuse Term.
v_diffuse = u_lightDiffuse * max(dot(a_normal.xyz, v_lightVector), 0.0);
gl_Position = u_projTrans * a_position;
gl_Position = u_projTrans * transformedPosition;
}