// normalMappingShader.vert

#version 150 core

// uniform shader-parameters
uniform mat4 modelViewProjection;
uniform mat3 normalMatrix;
uniform mat4 SM_matrix; // shiftrange * lightProjection * lightView * model

uniform vec3 light_vector;

// vertex-shader input variables
in vec4 vertex;
in vec4 normal;
in vec4 binormal;	// this is in tangent space
in vec4 tangent;	// this is in tangent space

in vec2 texCoord;

// vertex-shader output variables (passed to fragment-shader)
out vec2 frag_texCoord;
out vec2 frag_normalCoord;
out vec3 tangentLightDirection;

out vec4 SM_texCoord;


void main()
{
	vec3 n = normalize(normalMatrix*normal.xyz);
	vec3 t = normalize(normalMatrix*tangent.xyz);
	vec3 b = normalize(normalMatrix*binormal.xyz);

	vec3 lightDir = normalize(light_vector);


	vec3 v;
	v.x = dot(lightDir, t);
	v.y = dot(lightDir, b);
	v.z = dot(lightDir, n);
	tangentLightDirection = normalize(v);
	

	// just pass the texture coordinates to fragment-shader
	frag_texCoord = texCoord;
	frag_normalCoord = texCoord;

	// shadow texture coords in projected light space
	SM_texCoord = SM_matrix * vertex;

    // transform vertex down the pipeline
	gl_Position = modelViewProjection * vertex;
}
