#version 330 core
// Input vertex data, different for all executions of this shader.
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec3 vertexNormal_modelspace;
// Values that stay constant for the whole mesh.
uniform mat4 MVP;
uniform mat4 V;
uniform mat4 M;
uniform vec3 lightPos;
out vec4 forFragColor;
const vec3 diffuseColor = vec3(0.55, 0.09, 0.09);
void main(){
// Output position of the vertex, in clip space : MVP * position
gl_Position = MVP * vec4(vertexPosition_modelspace,1);
// all following gemetric computations are performed in the
// camera coordinate system (aka eye coordinates)
vec3 normal = (V*M*vec4(vertexNormal_modelspace,0)).xyz;
vec4 vertPos4 = MVP * vec4(vertexPosition_modelspace,1);
vec3 vertPos = vec3(vertPos4.x, vertPos4.y, vertPos4.z);
vec3 lightDir = normalize(lightPos - vertPos);
float lambertian = max(dot(lightDir,normal), 0.0);
forFragColor = vec4(lambertian*diffuseColor , 1.0);
//forFragColor = vec4(vec3(1,0,0),0);
}