#vertex shader
#version 330 core
layout (location = 0) in vec3 coords;
layout (location = 2) in vec3 normal;
layout (location = 3) in vec3 origin;
layout (location = 4) in vec3 color;
layout (location = 5) in float relsize;
out vec3 v_normal;
out vec3 v_color;

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

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

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

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

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