title: How to change vertex position using glsl
body: <p>I am trying to move object depending on camera position. Here is my vertex shader</p>
  
  <pre><code>uniform mat4 osg_ViewMatrixInverse;
  
  void main(){
  vec4 position  = gl_ProjectionMatrix * gl_ModelViewMatrix *gl_Vertex;   
  vec3 camPos=osg_ViewMatrixInverse[3].xyz;
  
  if( camPos.z &gt;1000.0 )
    position.z = position.z+1.0;
      if( camPos.z &gt;5000.0 )
    position.z = position.z+10.0;
  if (camPos.z&lt; 300.0 )
    position.z = position.z+300.0;
  gl_Position =  position;
  }
  </code></pre>
  
  <p>But when camera's vertical position is less than 300 or more than 1000 the model simply disappears though in second case it should be moved just by one unit. I read about inside the shader coordinates are different from a world coordinates that's why i am multiplying by Projection and ModelView matrices, to get  the world coordinates. Maybe I am wrong at this point? Forgive me if it's a simple question but i couldnt find the answer.</p>
  
  <p>UPDATE: camPos is translated to world coordinates, but position is not. Maybe it has to do with the fact i am using osg_ViewMatrixInverse (passed by OpenSceneGraph) to get camera position and internal gl_ProjectionMatrix and gl_ModelViewMatrix to get the vertex coordinates? How do I translate position into world coordinates?</p>