varying vec3 ViewPos;
varying vec3 taneye;
varying vec3 up;
varying vec4 projPos;

void main()
{
  // position
  ViewPos = (gl_ModelViewMatrix * gl_Vertex).xyz;
  up = normalize( gl_NormalMatrix * vec3( 0.0, 1.0, 0.0 ) );
  projPos = gl_ModelViewProjectionMatrix * gl_Vertex;
  
  // calc t and b from n
  vec3 tangent, binormal;
	tangent  = gl_NormalMatrix * gl_MultiTexCoord1.xyz;
	binormal = gl_NormalMatrix * gl_MultiTexCoord2.xyz; 

  // get eye in tangent space
  vec3 modeleye = ( gl_ModelViewMatrixInverse * vec4( 0.0, 0.0, 0.0, 1.0 ) ).xyz;
  modeleye = normalize( modeleye - gl_Vertex.xyz );
  taneye.x = dot( tangent, modeleye );
  taneye.y = dot( binormal, modeleye );  
  taneye.z = dot( gl_Normal, modeleye );
  // end t and b calc

  // set texture coords
  gl_TexCoord[0] = gl_MultiTexCoord0; // Color Map and normal map share coords
  
  gl_Position = ftransform();
}