#version 420 in layout(location=0) vec3 position; in layout(location=1) vec2 Texture_UV; in layout(location=2) vec3 normal; in layout(location=3) vec3 tangent; uniform mat4 M_MVP; /* Total Transform matrix */ uniform mat4 M_model; /* Model to world space transformation matrix */ uniform vec3 lightPosition[4]; uniform vec3 World_eyePosition; out vec2 Fragment_UV; out vec4 Fragment_Color; out vec3 toLightVector[4]; out vec3 toEyeVector; out vec3 tangent0; void main() { /*We add a 0 on the vec4 so we can remove the translation from the matrix (WE DONT WANT THE NORMAL TO BE TRANSLATED) */ vec3 n = normalize( (M_model * vec4(normal, 0.0)).xyz ); vec3 t = normalize( (M_model * vec4(tangent, 0.0)).xyz ); /* Orthogonalization */ t = normalize(t - dot(t, n) * n); vec3 biTangent = normalize( cross(t, n) ); /* Matrix use by normal mapping */ mat3 tbnMatrix = mat3(t, biTangent, n); tbnMatrix = transpose(tbnMatrix); vec3 World_Position = vec3(M_model * vec4(position, 1.0)); for(int i = 0; i < 4; i++) { /* vector que apunta hacia la luz*/ toLightVector[i] = tbnMatrix * (lightPosition[i] - World_Position); } /* Vector hacia el ojo*/ toEyeVector = normalize( tbnMatrix * (World_eyePosition - World_Position) ); gl_Position = M_MVP * vec4(position, 1.0); Fragment_UV = vec2(Texture_UV.x, 1 - Texture_UV.y); /*Invert y axis*/ tangent0 = tangent; }