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