/*
 * vertex shader for rendering the water surface
 *
 * 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;
uniform mat3 NormalMatrix;
uniform vec4 Light0Position;

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

out vec4 my_Position;
out vec3 my_WorldSpacePosition;
out vec3 my_Texcoord;
out vec3 my_EyeDir;
out vec3 my_LightDir;

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

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

  my_Texcoord = in_Texcoord;

  vec3 vVertex = (ModelViewMatrix * vec4(in_Position, 1.0)).xyz;
  vec3 my_Lightpos = (ModelViewMatrix * Light0Position).xyz;
  my_LightDir = my_Lightpos - vVertex;
  my_EyeDir = -vVertex;

  gl_ClipDistance[0] = dot( vec4(0.0, 1.0, 0.0, 0.0), vec4(in_Position,1.0));
}
