////////////////////////////////////////////////////////////////////////
//
//   Harvard Computer Science
//	    CS 175: Introduction to Computer Graphics
//   Professor: Hanspeter Pfister
//         TFs: Moritz Baecher, Yuanchen Zhu, Kalyan Sunkavalli, Kevin Dale
//
//   File: ground.frag
//   Name: Felix Gonda (felix.e.gonda@gmail.com)
//   Date: Dec 3rd, 2010
//   Desc: vertex shader for ground surface
//   
//////////////////////////////////////////////////////////////////////////


#version 110
#define MAX_LIGHTS 5
uniform float lightRadius;
varying vec3 lightDir[MAX_LIGHTS];
varying vec3 viewDir;

void main()
{

    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    gl_TexCoord[0] = gl_MultiTexCoord0;

    vec3 vertexPos = vec3(gl_ModelViewMatrix * gl_Vertex);
    
    vec3 n = normalize(gl_NormalMatrix * gl_Normal);
    vec3 t = normalize(gl_NormalMatrix * gl_MultiTexCoord1.xyz);
    vec3 b = cross(n, t) * gl_MultiTexCoord1.w;
    
    mat3 tbnMatrix = mat3(t.x, b.x, n.x,
                          t.y, b.y, n.y,
                          t.z, b.z, n.z);

    int i;
    for(i=0; i<MAX_LIGHTS; i++)
    {
		lightDir[i] = (gl_LightSource[i].position.xyz - vertexPos);
		lightDir[i] = tbnMatrix * lightDir[i];
    }

    viewDir = -vertexPos;
    viewDir = tbnMatrix * viewDir;
}