/*
 * vertex shader for phong shading
 *
 * does simple phong lighting
 * TODO: set lighting parameters with uniforms or uniform buffer objects
 *
 * written by:
 * christian moellinger <ch.moellinger@gmail.com>
 * 11/2010
 */

#version 330 core

uniform mat4 Camera_ProjectionMatrix;
uniform mat4 Camera_TransformMatrix;
uniform mat4 Model_TransformMatrix[128];
uniform mat3 NormalMatrix;
//uniform int instance;

in vec3 in_Position;
in vec3 in_Normal;
in vec3 in_Texcoord;

out mat3 NormalMatrix2;
out vec3 my_Normal;
out vec3 my_Texcoord;
out vec3 my_LightDir;
out vec3 my_EyeDir;
out vec4 my_WorldPosition;

/*
layout(shared) uniform lightingParam
{
    vec4 LightPosition;
    vec3 LightColorDiffuse;
    vec3 LightColorSpecular;
    vec3 MaterialDiffuse;
    vec3 MaterialSpecular;
    float MaterialShininess;
};*/

void main(void)
{
  mat4 ProjectionMatrix = Camera_ProjectionMatrix;
  mat4 ModelViewMatrix = Camera_TransformMatrix * Model_TransformMatrix[gl_InstanceID];

  gl_Position = ProjectionMatrix * ModelViewMatrix * vec4(in_Position, 1.0);

  vec3 vVertex = (ModelViewMatrix * vec4(in_Position, 1.0)).xyz;
  vec3 my_Lightpos = (ModelViewMatrix * vec4(-100.0, 30.0, 100.0, 1.0)).xyz;

  NormalMatrix2 = NormalMatrix;
  my_Normal = in_Normal;
  my_Texcoord = in_Texcoord;
  my_LightDir = my_Lightpos - vVertex;
  my_EyeDir = -vVertex;
  my_WorldPosition = Model_TransformMatrix[gl_InstanceID] * vec4(in_Position, 1.0);
}
