#version 120

uniform vec3 lightPos;
uniform vec3 ka;
uniform vec3 kd;
uniform vec3 ks;
uniform float s;

varying vec3 color; // passed from the vertex shader
varying vec4 p;
varying vec4 n;

void main()
{
  vec4 normal = normalize(n);
  vec3 norm = vec3(normal.x, normal.y, normal.z);
 
  vec3 light = lightPos - vec3(p.x, p.y, p.z);
  vec3 lnorm = normalize(light);
  float temp = dot(lnorm, norm);
  vec3 cd = kd*max(0, temp);

  vec4 npos = normalize(p);
  vec3 pos = vec3(npos.x, npos.y, npos.z);
  vec3 h = normalize(lnorm - pos);
  vec3 cs = ks*pow(max(0, dot(h, norm)), s);

	gl_FragColor = vec4(ka.r + cd.r + cs.r, ka.g + cd.g + cs.g, ka.b + cd.b + cs.b, 1.0);
}
