varying vec3 pos;
varying vec3 vdir;

void main(void)
{
  gl_Position = vec4( gl_Vertex.xyz, 1.0 );

  // construct a point at the near-plane
  vec4 vNearPlane = gl_ModelViewProjectionMatrixInverse *
    vec4(gl_Vertex.xy, -1.0, 1.0);
  vNearPlane.xyz /= vNearPlane.w;

  // construct a point on the camera-plane
  vec4 vCamPlane = gl_ModelViewProjectionMatrixInverse *
    vec4(gl_Vertex.xy, -1e+10, 0.0);
  vCamPlane.xyz /= vCamPlane.w;

  // take direction
  vdir = vNearPlane.xyz - vCamPlane.xyz;

  pos = vCamPlane.xyz;
}
