#version 430 struct Light { vec3 position; vec3 ambient; vec3 diffuse; }; in vec3 fragment_position; in vec3 fragment_normal; in float fragment_specular_exponent; #define MAX_LIGHTS 16 layout(location = 4) uniform Light lights[MAX_LIGHTS]; layout(location = 68) uniform uint num_lights; layout(location = 69) uniform vec3 eye_position; out vec4 frag_color; void main() { vec3 hard_eye_position = vec3(0.0f, 0.0f, -5.0f); vec3 norm_normal = normalize(fragment_normal); vec3 norm_eye_vector = normalize(eye_position - fragment_position); vec3 accum = vec3(0.0); float diffuse_multiplier; float specular_multiplier; vec3 light_vector; vec3 reflected_light_vector; for (uint i = 0; i < MAX_LIGHTS && i < num_lights; ++i) { light_vector = normalize(lights[i].position - fragment_position); reflected_light_vector = reflect(-light_vector, norm_normal); diffuse_multiplier = clamp(dot(light_vector, norm_normal), 0.0, 1.0); specular_multiplier = pow(clamp(dot(reflected_light_vector, norm_eye_vector), 0.0, 1.0), fragment_specular_exponent); accum += lights[i].ambient; accum += diffuse_multiplier * lights[i].diffuse; accum += specular_multiplier * lights[i].diffuse; } frag_color = vec4(accum, 1.0); }