=== modified file 'data/shaders/light-advanced.frag'
@@ -2,9 +2,10 @@
precision mediump float;
#endif
+uniform vec4 LightSourcePosition;
+uniform vec3 LightSourceHalfVector;
+
varying vec3 Normal;
-varying vec3 Light;
-varying vec3 HalfVector;
void main(void)
{
@@ -17,8 +18,12 @@
const float MaterialShininess = 100.0;
vec3 N = normalize(Normal);
- vec3 L = normalize(Light);
- vec3 H = normalize(HalfVector);
+
+ // In the lighting model we are using here (Blinn-Phong with light at
+ // infinity, viewer at infinity), the light position/direction and the
+ // half vector is constant for the all the fragments.
+ vec3 L = normalize(LightSourcePosition.xyz);
+ vec3 H = normalize(LightSourceHalfVector);
// Calculate the diffuse color according to Lambertian reflectance
vec4 diffuse = MaterialDiffuse * LightSourceDiffuse * max(dot(N, L), 0.0);
=== modified file 'data/shaders/light-advanced.vert'
@@ -3,25 +3,14 @@
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 NormalMatrix;
-uniform vec4 LightSourcePosition;
-uniform vec3 LightSourceHalfVector;
varying vec3 Normal;
-varying vec3 Light;
-varying vec3 HalfVector;
void main(void)
-{
+{
// Transform the normal to eye coordinates
- Normal = normalize(vec3(NormalMatrix * vec4(normal, 1.0)));
-
- // The LightSourcePosition is actually its direction for directional light
- Light = normalize(LightSourcePosition.xyz);
-
- // The HalfVector is used in the Blinn-Phong shading model for calculating
- // specular lighting.
- HalfVector = normalize(LightSourceHalfVector);
+ Normal = vec3(NormalMatrix * vec4(normal, 1.0));
// Transform the position to clip coordinates
- gl_Position = ModelViewProjectionMatrix * vec4(position, 1.0);
+ gl_Position = ModelViewProjectionMatrix * vec4(position, 1.0);
}