From ea33f1e725436f87d222151b1458d10830e28893 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 12 May 2014 11:36:55 -0430 Subject: [PATCH] Added specular color and geometric transformations. --- .../singleDiffuseLight/singleDiffuseLight_frag.glsl | 5 ++++- .../singleDiffuseLight/singleDiffuseLight_vert.glsl | 12 +++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/assets/shaders/singleDiffuseLight/singleDiffuseLight_frag.glsl b/assets/shaders/singleDiffuseLight/singleDiffuseLight_frag.glsl index e5ba28f..04fc4c6 100644 --- a/assets/shaders/singleDiffuseLight/singleDiffuseLight_frag.glsl +++ b/assets/shaders/singleDiffuseLight/singleDiffuseLight_frag.glsl @@ -21,6 +21,9 @@ precision mediump float; // Ambient light color. uniform vec4 u_ambient; +// Specular light color. +uniform vec4 u_specular; + // Shininess. uniform float u_shiny; @@ -47,7 +50,7 @@ void main(){ vec3 reflectedVector = normalize(v_reflectedVector); // 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. vec4 lightColor = clamp(vec4(u_ambient.rgb + v_diffuse.rgb + specular.rgb, 1.0), 0.0, 1.0); diff --git a/assets/shaders/singleDiffuseLight/singleDiffuseLight_vert.glsl b/assets/shaders/singleDiffuseLight/singleDiffuseLight_vert.glsl index 6301ac7..f125146 100644 --- a/assets/shaders/singleDiffuseLight/singleDiffuseLight_vert.glsl +++ b/assets/shaders/singleDiffuseLight/singleDiffuseLight_vert.glsl @@ -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; }