#version 300 es

#define BASE_COLOR vec4(1.0, 1.0, 1.0, 1.0)
#define AMBIENT_LIGHT vec3(0.3, 0.3, 0.3)
#define LIGHT_DIRECTION normalize(vec3(0.85, 0.8, 0.75))
#define LIGHT_COLOR vec3(1.0, 1.0, 1.0)

precision highp float;

layout(location = 0) in vec4 aVertexPosition;
layout(location = 1) in vec3 aVertexNormal;
flat out vec3 vColor;

uniform mat4 uModelViewMatrix;
uniform mat4 uProjectionMatrix;
uniform mat4 uNormalMatrix;

void main() {
  vec4 instancePosition =
      vec4(float(gl_InstanceID) * aVertexPosition.x + aVertexPosition.x,
           aVertexPosition.yzw);
  gl_Position = uProjectionMatrix * uModelViewMatrix * instancePosition;

  vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);
  float directionalLight =
      max(dot(transformedNormal.xyz, LIGHT_DIRECTION), 0.0);

  vColor = AMBIENT_LIGHT + (directionalLight * LIGHT_COLOR);
}
