diff mbox

[Branch,~glmark2-dev/glmark2/trunk] Rev 108: Use uniforms in the fragment shader for the light and the half vector in light-advanced.

Message ID 20110713150535.3163.6418.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

alexandros.frantzis@linaro.org July 13, 2011, 3:05 p.m. UTC
------------------------------------------------------------
revno: 108
committer: Alexandros Frantzis <alexandros.frantzis@linaro.org>
branch nick: trunk
timestamp: Wed 2011-07-13 18:03:43 +0300
message:
  Use uniforms in the fragment shader for the light and the half vector in light-advanced.
  
  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 vertices/fragments. Therefore, there is no need to
  use a varying for them, we can access them as uniforms.
modified:
  data/shaders/light-advanced.frag
  data/shaders/light-advanced.vert


--
lp:glmark2
https://code.launchpad.net/~glmark2-dev/glmark2/trunk

You are subscribed to branch lp:glmark2.
To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'data/shaders/light-advanced.frag'
--- data/shaders/light-advanced.frag	2011-07-12 17:53:10 +0000
+++ data/shaders/light-advanced.frag	2011-07-13 15:03:43 +0000
@@ -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'
--- data/shaders/light-advanced.vert	2010-07-09 13:34:12 +0000
+++ data/shaders/light-advanced.vert	2011-07-13 15:03:43 +0000
@@ -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 = normalize(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);
 }