/* Universidade Federal Fluminense
 * Programa de Pós-Graduação em Computação
 *
 * Tópicos Avançados em Computação Visual e Interfaces II (Técnicas Avançadas de Rendering)
 * Professor: Leandro Augusto Frata Fernandes
 *
 * Version: 2012.05.05-001
 */

// User-defined matrices (from application).
uniform mat4 ViewMatrix;
uniform mat4 ModelViewMatrix;
uniform mat4 ModelViewMatrixInverseTranspose;
uniform mat4 ModelViewProjectionMatrix;

// User-defined light in WCS (from application).
uniform vec3 LightPosition; // WCS

// User-defined mesh attributes (from vertex buffer object).
attribute vec4 rm_Vertex;
attribute vec3 rm_Normal;

// User-defined output variables.
varying vec3 Normal;          // CCS
varying vec3 ViewDirection;   // CCS
varying vec3 LightDirection;  // CCS

// The main method.
void main(void)
{
   // OCS to Homogeneous Clip Space.
   gl_Position = ModelViewProjectionMatrix * rm_Vertex;
   
   // OCS to CCS.
   vec4 fvVertexPosition = ModelViewMatrix * rm_Vertex;
   vec4 fvLightPosition = ViewMatrix * vec4(LightPosition, 1.0);
   
   // Compute user-defined output variables.
   Normal = (ModelViewMatrixInverseTranspose * vec4(rm_Normal, 0.0)).xyz;
   ViewDirection  = -fvVertexPosition.xyz;
   LightDirection = fvLightPosition.xyz - fvVertexPosition.xyz;
}
