#version 440 in vec3 f_color; out vec4 FragColors; uniform vec3 Kd; uniform vec3 Ka; uniform vec3 Ks; uniform float Shininess; struct LightInfo { vec4 Position; vec3 Intensity; }; uniform LightInfo Light[64]; uniform int LightCount; in vec3 fNormal; in vec3 pos; void main() { vec3 finalColor; vec3 ambient; ambient = Ka * Light[0].Intensity; for (int i=0; i< LightCount; i++) { vec3 L = normalize(Light[i].Position.xyz - pos); vec3 N = fNormal; vec3 V = normalize(-pos); //vec3 R = normalize(reflect(-L, N)); vec3 H = normalize(V + L); //Discretizing the diffuse component between (here 3) levels const int levels = 3; const float scaleFactor = 1.0 / levels; float cosine = dot(L, N); // Between 0 and 1 float value = floor( cosine * levels) * scaleFactor; vec3 diffuse = Kd * Light[i].Intensity * max(dot(L, N), 0.0) * value; // Not needed for cartoon shader //vec3 specular = Ks * Light[i].Intensity * pow(max(dot(H, N), 0.0), Shininess); //dirty trick to stay with the same shader params finalColor = finalColor + diffuse; } FragColors = vec4(finalColor + ambient, 1); }