varying vec3 eyePos;
varying vec4 projPos;
varying vec3 normal;
varying vec3 tangent;
varying vec3 binormal;

void main()
{

  // eye position
  eyePos = ( gl_ModelViewMatrix * gl_Vertex ).xyz;
  
  // view projection
  gl_Position = ftransform();
  projPos = gl_Position;
  
  // texture coords
	gl_TexCoord[0] = gl_MultiTexCoord0;

  // normal
  normal = normalize( gl_NormalMatrix * gl_Normal );
  // calc t and b from n
	vec3 c1 = cross(gl_Normal, vec3(0.0, 0.0, 1.0)); 
	vec3 c2 = cross(gl_Normal, vec3(0.0, 1.0, 0.0)); 
	
	if(length(c1)>length(c2))
	{
		tangent = c1;	
	}
	else
	{
		tangent = c2;	
	}
	
	tangent = normalize(tangent);
	binormal = cross(gl_Normal, tangent); 
 	binormal = normalize(binormal);

  tangent = normalize( gl_NormalMatrix * tangent );
  binormal = normalize( gl_NormalMatrix * binormal );
}
