#version 430 core

layout (location = 0) in vec3 position;
layout (location = 1) in vec3 normal;
layout (location = 2) in vec3 tangent;
layout (location = 3) in vec2 texture_coord;

out vec3 frag_position;
out vec3 frag_normal;
out vec3 frag_tangent;
out vec3 frag_bitangent;
out vec2 frag_texture_coord;
out vec4 view_position;

uniform mat4 view_matrix;
uniform mat4 view_matrix_inverse;
uniform mat4 model_matrix;

uniform float time;

uniform mat4 shadow_matrix;

void main()
{
	mat3 model_inverse_matrix = mat3(transpose(inverse(model_matrix))); // @Performance: Compute this only once, before calling the shader
	frag_normal    = normalize(model_inverse_matrix * normal );
	frag_tangent   = normalize(model_inverse_matrix * tangent);
	frag_bitangent = normalize(model_inverse_matrix * cross(normal, tangent));
	vec4 world_position = model_matrix * vec4(position, 1.0);
	frag_position = world_position.xyz / world_position.w;
	frag_texture_coord = texture_coord;
	gl_Position = view_matrix * world_position;
	view_position = gl_Position;
}
