// Vertex Shader for normal mapping experiments – file "texture_norm.vert"

#version 150 core

uniform mat4 perspective_matrix;
uniform mat4 modelview_matrix;

uniform vec3 light_Dir;

in  vec4 in_position;
in  vec3 in_normal;
in  vec2 in_texcoord;
in  vec4 in_tangent;

out vec2 fragment_texcoord;
out vec3 texture_Light;
out vec3 texture_Eye;

void main(void)
{
	fragment_texcoord = in_texcoord;

	vec3 n = (modelview_matrix * vec4(in_normal, 0.0)).xyz;
	vec3 t = (modelview_matrix * vec4(in_tangent.x, in_tangent.y, in_tangent.z, 0.0)).xyz;
	vec3 b = cross(n, t);

	vec3 light = normalize(light_Dir);

	texture_Light.x = dot(light, t);
	texture_Light.y = dot(light, b);
	texture_Light.z = dot(light, n);

	vec3 eye = (modelview_matrix * in_position).xyz;
	eye = -normalize(eye);

	texture_Eye.x = dot(eye, t);
	texture_Eye.y = dot(eye, b);
	texture_Eye.z = dot(eye, n);

	gl_Position = perspective_matrix * modelview_matrix * in_position;
}
