diff options
Diffstat (limited to '09-september/resources/shaders/terrainShader.vert')
| -rw-r--r-- | 09-september/resources/shaders/terrainShader.vert | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/09-september/resources/shaders/terrainShader.vert b/09-september/resources/shaders/terrainShader.vert new file mode 100644 index 0000000..1850947 --- /dev/null +++ b/09-september/resources/shaders/terrainShader.vert @@ -0,0 +1,39 @@ +#version 420 + +in layout(location=0) vec3 position; /* vertex position in model space */ +in layout(location=1) vec2 Texture_UV; +in layout(location=2) vec3 normal; /* vertex normal in model space */ +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; /* UV coordinates for the fragment */ +out vec3 normal0; +out vec4 Fragment_Color; +out vec3 toLightVector[4]; +out vec3 toEyeVector; + +void main() +{ + 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] = lightPosition[i] - World_Position; + } + /* Vector hacia el ojo*/ + toEyeVector = normalize(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*/ + + /*We add a 0 on the vec4 so we can remove the translation from the matrix + (WE DONT WANT THE NORMAL TO BE TRANSLATED) */ + normal0 = normalize( (M_model * vec4(normal, 0.0)).xyz ); +} |
