// VERTEX SHADER :  TEXTURE + BUMP

varying vec3 vLight0;
varying vec3 vHalfAngleVec0;
varying vec3 vLight1;
varying vec3 vVertex;
varying vec3 vNormal;

void main ()
{
	vVertex = gl_Vertex.xyz;
	vNormal = gl_Normal.xyz;

	// Set up tangent-space matrix
	vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
	vec3 tangent = normalize(gl_NormalMatrix * gl_Normal.xyz);
	vec3 binorm = -normalize(cross(normal, tangent));

	// Transform position
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;


//LIGHTING
	//Light0
	vec3 light = normalize(gl_LightSource[0].position.xyz);

	// Convert lightVec to tangent space
	vLight0.x = dot(light, tangent);
	vLight0.y = dot(light, binorm);
	vLight0.z = dot(light, normal);

	vLight0 = vec3(0.5, 0.5, 1.0);
	
	// compute the half angle vector
	light.z += 1.0;
	vec3 halfAngleVector = normalize(light);
	vHalfAngleVec0.x = dot(halfAngleVector, tangent); 
	vHalfAngleVec0.y = dot(halfAngleVector, binorm); 
	vHalfAngleVec0.z = dot(halfAngleVector, normal); 


	//Light1
	light = normalize(gl_LightSource[1].position.xyz);

	// Convert lightVec to tangent space
	vLight1.x = dot(light, tangent);
	vLight1.y = dot(light, binorm);
	vLight1.z = dot(light, normal);
}