varying vec3 normal;
varying vec3 tangent;
varying vec3 binormal;
varying vec3 taneye;
varying float pos;

void main()
{
  // position
  pos = length( gl_ModelViewMatrix * gl_Vertex );

  // normal
  normal = normalize( gl_NormalMatrix * gl_Normal );
	tangent = normalize( gl_NormalMatrix * gl_MultiTexCoord1.xyz );
	binormal = cross(gl_Normal, tangent); 
	binormal = normalize(binormal);

  // 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 );

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