#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 trc1;
layout (location = 5) in vec3 trc2;
layout (location = 6) in vec3 trc3;
layout (location = 7) in vec3 color;
out vec3 v_normal;
out vec3 v_color;

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

void main()
{
  mat3 A = mat3(trc1, trc2, trc3);
  gl_Position = MVP * OM * vec4(origin + size*A*(coords + vec3(0, 0, displacement.x)), 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;

uniform vec3 color;
uniform bool AttribColors;

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

void main()
{
  vec3 actcolor = mix(color, v_color, float(AttribColors));
  vec3 N = normalize(v_normal);
  vec3 ambient = actcolor * 0.5;
  vec3 diffuse = actcolor * max(0.0, dot(N, lightdir)) * 0.5;
  vec3 shadow = actcolor * max(0.0, pow(dot(N, shadowdir), 64)) * 0.05;
  FragColor = vec4(clamp(ambient + diffuse - shadow, 0.0, 1.0), 1.0);
};
