#ifndef _BLINN_CG_
#define _BLINN_CG_

#include "material.cg"

struct Blinn: Material {
    float3 ambient, diffuse, specular;
    float sexp;

    float3 evaluate(vertexOutput IN, Light lights[]) {
        float3 result = 0;
        float3 Ln;
        float3 Nn = normalize(IN.Neye);
        float3 Vn = normalize(-IN.Peye);
        for (int i = 0; i < lights.length; i++) {
            if (lights[i].isEnabled()) {
                float3 lcolor = lights[i].illuminate(IN.Peye, Ln);
                float3 Hn = normalize(Vn + Ln);
                float ldn = dot(Ln,Nn);
                float hdn = dot(Hn,Nn);
                float4 litV = lit(ldn, hdn, sexp);
                float3 diffContrib = lcolor * (diffuse * litV.y + ambient);
                float3 specContrib = litV.y*litV.z * lcolor * specular;
                result += diffContrib + specContrib;
            }
        }
        return result;
    }
};

#endif // _BLINN_CG_
