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

@@ -21,6 +21,9 @@ precision mediump float;
// Ambient light color. // Ambient light color.
uniform vec4 u_ambient; uniform vec4 u_ambient;
// Specular light color.
uniform vec4 u_specular;
// Shininess. // Shininess.
uniform float u_shiny; uniform float u_shiny;
@@ -47,7 +50,7 @@ void main(){
vec3 reflectedVector = normalize(v_reflectedVector); vec3 reflectedVector = normalize(v_reflectedVector);
// Specular Term: // Specular Term:
vec4 specular = vec4(1.0) * pow(max(dot(reflectedVector, eyeVector), 0.0), 0.3 * u_shiny); vec4 specular = u_specular * pow(max(dot(reflectedVector, eyeVector), 0.0), 0.3 * u_shiny);
// Aggregate light color. // Aggregate light color.
vec4 lightColor = clamp(vec4(u_ambient.rgb + v_diffuse.rgb + specular.rgb, 1.0), 0.0, 1.0); vec4 lightColor = clamp(vec4(u_ambient.rgb + v_diffuse.rgb + specular.rgb, 1.0), 0.0, 1.0);

View File

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