#vertex shader
#version 330 core
layout (location = 0) in vec3 coords;
layout (location = 2) in vec3 normal;
layout (location = 3) in vec3 origin;
out vec3 v_normal;

uniform mat4 MVP;
uniform mat4 OM;
uniform mat3 NormalMatrix;
uniform float size;

void main()
{
  gl_Position = MVP * OM * vec4(origin + size*coords, 1.0);
  v_normal = NormalMatrix * normal;
};

#fragment shader
#version 330 core
out vec4 FragColor;
in vec3 v_normal;

uniform vec3 color;

const vec3 lightdir = vec3(1.0, 1.0, 1.0) / sqrt(3);

void main()
{
  vec3 N = normalize(v_normal);
  vec3 ambient = color * 0.5;
  vec3 diffuse = color * max(0.0, dot(N, lightdir)) * 0.5;
  FragColor = vec4(clamp(ambient + diffuse, 0.0, 1.0), 1.0);
};
