varying vec4 TexCoord;
varying float fogFactor; 


uniform vec4 Tangent;
uniform vec4 Normal;
uniform vec4 BiNormal;

//uniform vec4 Eye;
//varying vec3 EyeDir;

varying vec3 lightDir;
varying vec3 halfVector;


void main(void)
{
  gl_Position = ftransform();//gl_ModelViewProjectionMatrix* gl_Vertex;
  TexCoord = gl_Color;
  
  vec2 TexCoord0 = vec2(TexCoord[0],TexCoord[1]);
  vec2 TexCoord1 = vec2(TexCoord[2],TexCoord[3]);
  
  // BumpMapping ======================================================
  
  vec3 n = normalize(gl_NormalMatrix * gl_Normal);
  vec3 t = normalize(gl_NormalMatrix * gl_Color.xyz);
  vec3 b = cross(n, t) * gl_Color.w;
    
  mat3 tbnMatrix = mat3(t.x, b.x, n.x,
                          t.y, b.y, n.y,
                          t.z, b.z, n.z);
    
  lightDir = gl_LightSource[0].position.xyz;
  lightDir = tbnMatrix * lightDir;
    
  halfVector = gl_LightSource[0].halfVector.xyz;
  halfVector = tbnMatrix * halfVector;
  
  // FOG ================================================================
  vec3 m_Vector = vec3(gl_ModelViewMatrix * gl_Vertex);
  const float LOG2 = 1.442695;
  gl_FogFragCoord = length(m_Vector);
  fogFactor = exp2( -gl_Fog.density * 
					   gl_Fog.density * 
					   gl_FogFragCoord * 
					   gl_FogFragCoord * 
					   LOG2 );
  fogFactor = clamp(fogFactor, 0.0, 1.0);

}

