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

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

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

  up = normalize( gl_NormalMatrix * vec3( 0.0, 1.0, 0.0 ) );
  // 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); 

  tangent  = gl_NormalMatrix * tangent;
  binormal = gl_NormalMatrix * binormal;

  // set texture coords
  gl_TexCoord[0] = gl_MultiTexCoord0; // Color Map and normal map share coords
  

  // transform position
  gl_Position = ftransform();
}