title: FxPlug Inverts Cube Map At A Distance
body: <p>I'm trying to implement cube mapping in FxPlug using GLSL code from <a href="http://antongerdelan.net/opengl/cubemaps.html" rel="nofollow">http://antongerdelan.net/opengl/cubemaps.html</a>. The only major modifications I made to the code were variable name changes and using gl_Vertex and gl_Normal instead of attributes.</p>
  
  <p><strong>vertex program snippet</strong>:</p>
  
  <pre><code>varying vec3 pos_eye;
  varying vec3 n_eye;
  
  pos_eye = vec3(ViewMatrix * ModelMatrix * gl_Vertex);
  n_eye = vec3(ViewMatrix * ModelMatrix * vec4(gl_Normal, 0.0));
  gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * gl_Vertex;
  </code></pre>
  
  <p><strong>fragment program snippet</strong>:</p>
  
  <pre><code>vec3 incident_eye = normalize(pos_eye);
  vec3 norm = normalize(n_eye);
  vec3 reflected = reflect(incident_eye, norm);
  reflected = vec3(InverseViewMatrix * vec4(reflected, 0.0));
  vec3 cubemapColor = textureCube(cubemap, reflected).rgb;
  </code></pre>
  
  <p>When I load in a model then insert a camera, the cube map actually starts out inverted, but once I move the camera away at a certain distance, I get the proper results. Has anyone seen this problem before when implementing cube maps? I'm thinking this is an issue with Motion and/or FxPlug with how it handles the cameras.</p>
  
  <p>A video of the problem in action can be found at <a href="http://youtu.be/Yj85y-VKjCY" rel="nofollow">http://youtu.be/Yj85y-VKjCY</a></p>
  
  <p>In the video, I load up a basic sphere, scale it up, and enable the skybox. The cubemap on the sphere starts upside-down. When I rotate the sphere, the cube map doesn't even move (Disregard the black texturing artifacts throughout the video when the camera moves; that seems to happen when there's insufficient memory or something). After zooming into the sphere, I get a more realistic "reflection" distortion, but the cube map is still upside-down. 
  It isn't until I start zooming out into a reasonable distance that the cube map transforms into how it's supposed to look. What I did notice is that the cube map looks correct when the white rectangle that surrounds the sphere is fully visible.</p>
  
  <p>I would appreciate any advice on how to solve this problem. Thanks in advance!</p>