#version 120

/**
 * Phong shader.
 *
 **Project Name:**      MakeHuman
 *
 **Product Home Page:** http://www.makehuman.org/
 *
 **Code Home Page:**    https://bitbucket.org/MakeHuman/makehuman/
 *
 **Authors:**           Marc Flerackers
 *
 **Copyright(c):**      MakeHuman Team 2001-2014
 *
 **Licensing:**         AGPL3 (see also http://www.makehuman.org/node/318)
 *
 **Coding Standards:**  See http://www.makehuman.org/node/165
 *
 * Abstract
 * --------
 *
 * Standard per-pixel lighting shader.
 * Supports one light only.
**/

varying vec3 normal, lightDir, halfVector;
varying vec4 ambient_color, diffuse_color, specular_color, emissive_color;

uniform vec4 diffuse, specular;
uniform vec3 ambient, emissive;


void main()
{
    normal = gl_NormalMatrix * gl_Normal;

    vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex);

    lightDir = vec3(gl_LightSource[0].position.xyz - vVertex);
    halfVector = normalize(gl_LightSource[0].halfVector.xyz);

    ambient_color = (gl_FrontLightModelProduct.sceneColor * gl_FrontMaterial.ambient) + 
    (gl_LightSource[0].ambient * vec4(ambient.rgb, 1.0));

    diffuse_color = gl_LightSource[0].diffuse * diffuse;

    specular_color.rgb = gl_LightSource[0].specular.rgb * specular.rgb;
    specular_color.a = specular.a;

    emissive_color = vec4(emissive, 1.0);

    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_Position = ftransform();
}
