// $LastChangedDate: 2009-05-19 20:41:43 -0400 (Tue, 19 May 2009) $
// Based on osgShadow/StandardShadowMap (OpenSceneGraph Public License).

/*****************************************************************************
 * Directional light (w == 0).
 *****************************************************************************/
void
DirectionalLight( in int i,
                  in vec3 normal,
                  inout vec4 ambient,
                  inout vec4 diffuse,
                  inout vec4 specular )
{
#if 1
    // ComputeDiffuseSpecular() is used instead.
    ambient  += gl_LightSource[i].ambient;
    diffuse  += gl_LightSource[i].diffuse;
    specular += gl_LightSource[i].specular;
#else
    // nDotVP : normal . light direction
    // nDotHV : normal . light half vector
    // pf     : power factor
    float nDotVP = max( 0.0, dot(normal,normalize(vec3(gl_LightSource[i].position))) );
    float nDotHV = max( 0.0, dot(normal,vec3(gl_LightSource[i].halfVector)) );
    float pf = 0.0;
    if ( nDotVP )
        pf = pow( nDotHV, gl_FrontMaterial.shininess );

    ambient  += gl_LightSource[i].ambient;
    diffuse  += gl_LightSource[i].diffuse * nDotVP;
    specular += gl_LightSource[i].specular * pf;
#endif
}
