#version 330

uniform mat4 model;
uniform mat4 view;
uniform mat4 proj;
uniform mat3 modelIT;
uniform vec3 lightDir;
uniform float texId;

layout(location = 0) in vec4 position;
layout(location = 1) in vec4 normal;
layout(location = 2) in vec4 tangent;
layout(location = 3) in vec4 binormal;
layout(location = 4) in vec4 coord;

out GS {
	vec3 eye;
	vec3 coord;
	vec3 light;
} o;

void main(){
	// compute normal space rotation matrix
	mat3 tbnMat = modelIT * mat3(tangent.xyz, binormal.xyz, normal.xyz);
	
	// transform vertex into view space
	vec4 viewPosition = view * model * position;
	// transform vertex into projection space
	gl_Position = proj * viewPosition;
	// transform vertex into normal space
	o.eye = viewPosition.xyz * tbnMat;
	// texture coordinates, texture index
	o.coord = vec3(coord.xy, texId);
	// vector pointing to the directional light
	o.light = (modelIT * lightDir.xyz) * tbnMat;
}