glstuff

experiments with opengl2/ogles2/sdl
git clone http://frotz.net/git/glstuff.git
Log | Files | Refs

test5.vs (678B)


      1 uniform mat4 uMVP;
      2 uniform mat4 uMV;
      3 uniform vec4 uLight;
      4 
      5 attribute vec4 aVertex;
      6 attribute vec4 aNormal;
      7 attribute vec2 aTexCoord;
      8 
      9 varying vec2 vTexCoord;
     10 varying float vDiffuse;
     11 
     12 void main() {
     13 	vec3 mvVertex = vec3(uMV * aVertex);
     14 
     15 	// this is cheating, as you should use the inverse transpose of the MV
     16 	// matrix, but if there's no nonuniform scaling going on, it works 
     17 	vec3 mvNormal = vec3(uMV * vec4(aNormal.xyz, 0));
     18 
     19 	vec3 lightVector = normalize(vec3(uLight) - mvVertex);
     20 	float lightDistance = length(vec3(uLight) - mvVertex);
     21 
     22 	float diffuse = max(dot(mvNormal, lightVector), 0.0);
     23 
     24 	vTexCoord = aTexCoord;
     25 	vDiffuse = diffuse;
     26 
     27 	gl_Position = uMVP * aVertex;
     28 }
     29