title: glsl Vertex Lighting Shader
body: <p>I am having a problem with some simple vertex point light in a glsl shader.</p>
  
  <p>I am still confused by what coordinate space to do the lighting in.</p>
  
  <p>Right now I am transforming the position by the modelview and the normal by the upper 3x3 modelview(no translation).  I am also transforming the lightposition by the view matrix to get it into the same space.</p>
  
  <p>The problem is the light position moves when the camera moves.</p>
  
  <pre><code>void main()  {
  attribute vec4 position;
  attribute vec3 normal;
  attribute vec2 texcoord0;
  
  varying vec4 colorVarying;
  varying vec2 texOut0;
  
  uniform mat4 Projection;
  uniform mat4 Modelview;
  uniform mat3 NormalMatrix;//this is the upper 3x3 of the modelview
  uniform vec3 LightPosition; //already transformed by view matrix
  
  vec3 N = NormalMatrix * normal;
  vec4 P = Modelview * position;  //no view    
  vec3 L = normalize(LightPosition - P.xyz);
  float df = max(0.0, dot(N, L.xyz));
  vec3 final_color = AmbientMaterial + df * DiffuseMaterial;
  colorVarying = vec4(final_color,1);
  gl_Position = Projection * Modelview * position;
  }
  </code></pre>
  
  <p>I figured out my error - I am using es 2.0 and was sending my normal matrix via </p>
  
  <pre><code>glUniformMatrix3fv(gVertexLightingShader-&gt;Uniforms[UNIFORM_NORMALMATRIX], 1, 0, m_modelview.data());
  </code></pre>
  
  <p>But m_modelview was a 4x4 matrix - so the normal matrix was not correct.</p>