[Branch,~glmark2-dev/glmark2/trunk] Rev 108: Use uniforms in the fragm...

My dashboard
Submitter alexandros.frantzis@linaro.org
Subject [Branch,~glmark2-dev/glmark2/trunk] Rev 108: Use uniforms in the fragment shader for the light and the half vector in light-advanced.
Date July 13, 2011, 3:02 p.m.
List thread <20110713150221.2914.58191.launchpad@loganberry.canonical.com>
Project glmark2
State Accepted
Last updated July 13, 2011, 3:02 p.m.
Headers show

Comments

noreply@launchpad.net - July 13, 2011, 3:02 p.m.
------------------------------------------------------------
revno: 108
committer: Alexandros Frantzis <alexandros.frantzis@linaro.org>
branch nick: trunk
timestamp: Wed 2011-07-13 18:01:07 +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

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:01:07 +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:01:07 +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 = 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);

 }