title: Reflection mapping in GLSL
body: <p>I'm trying to get reflection mapping with a cube map working in OpenGL ES 2.0. I'm not sure if I'm calculating the reflection direction correctly to pass to a samplerCube in the fragment shader.</p>
  
  <p>To begin with I have Projection, Model and View matrices as well as a combined ModelView matrix. Here is the code for my vertex shader in GLSL:</p>
  
  <pre><code>attribute vec4 Position;
  attribute vec3 Normal;
  
  uniform mat4 Projection;
  uniform mat4 ModelView;
  uniform mat3 Model;
  uniform mat4 ModelViewProjectionMatrix;
  uniform vec3 EyePosition;
  
  varying vec3 ReflectDir;
  
  
  void main()
  {
      gl_Position = Projection * ModelView * Position;
      mediump vec3 EyeDir = normalize(Position.xyz - EyePosition);
  
      // Reflect eye direction by normal, and transform to world space
      ReflectDir = Model * reflect(EyeDir, Normal);
  }
  </code></pre>
  
  <p>My assumptions are EyeDirection must be in object space. (Correct?)
  How do I get the EyePosition in object space? Do I just transform the camera position (i.e. always at {0,0,0} in OpenGL?) by the inverse ModelView matrix?</p>
  
  <p>I've tried this but my fragment shader is colouring everything black, as if the ReflectDir is incorrect.</p>
  
  <p>Has anyone got a working example of OpenGL ES 2.0 reflection mapping (with a samplerCube) working in Xcode? </p>