From 6b8af9cf83851c075c6c9514b1deaa931c2b19a4 Mon Sep 17 00:00:00 2001 From: Thomas Guillermo Albers Raviola Date: Fri, 16 Jan 2026 23:02:32 +0100 Subject: Initial commit --- 09-september/resources/shaders/shader.vert | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 09-september/resources/shaders/shader.vert (limited to '09-september/resources/shaders/shader.vert') diff --git a/09-september/resources/shaders/shader.vert b/09-september/resources/shaders/shader.vert new file mode 100644 index 0000000..69a30e0 --- /dev/null +++ b/09-september/resources/shaders/shader.vert @@ -0,0 +1,52 @@ +#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; + +uniform float number_of_rows; +uniform vec2 offset; + +out vec2 Fragment_UV; +out vec4 Fragment_Color; +out vec3 toLightVector[4]; +out vec3 toEyeVector; + +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*/ + Fragment_UV = (Fragment_UV / number_of_rows) + offset; +} -- cgit v1.2.3