2018-09-14 22:09:43 +00:00
|
|
|
#version 430
|
|
|
|
|
|
|
|
struct Light
|
|
|
|
{
|
2018-09-15 01:29:05 +00:00
|
|
|
vec3 position;
|
2018-09-14 22:09:43 +00:00
|
|
|
vec3 ambient;
|
2018-09-15 01:29:05 +00:00
|
|
|
vec3 diffuse;
|
2018-09-14 22:09:43 +00:00
|
|
|
};
|
|
|
|
|
2018-09-15 01:29:05 +00:00
|
|
|
in vec3 fragment_position;
|
|
|
|
in vec3 fragment_normal;
|
|
|
|
|
2018-09-14 22:09:43 +00:00
|
|
|
#define MAX_LIGHTS 16
|
|
|
|
layout(location = 4) uniform Light lights[MAX_LIGHTS];
|
2018-09-15 01:29:05 +00:00
|
|
|
layout(location = 52) uniform uint num_lights;
|
2018-09-14 22:09:43 +00:00
|
|
|
|
|
|
|
out vec4 frag_color;
|
|
|
|
void main()
|
|
|
|
{
|
2018-09-15 01:29:05 +00:00
|
|
|
vec3 norm_normal = normalize(fragment_normal);
|
2018-09-14 22:09:43 +00:00
|
|
|
vec3 accum = vec3(0.0);
|
2018-09-15 01:29:05 +00:00
|
|
|
float diffuse_multiplier;
|
|
|
|
vec3 light_vector;
|
2018-09-14 22:09:43 +00:00
|
|
|
for (uint i = 0; i < MAX_LIGHTS && i < num_lights; ++i) {
|
2018-09-15 01:29:05 +00:00
|
|
|
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;
|
2018-09-14 22:09:43 +00:00
|
|
|
}
|
|
|
|
frag_color = vec4(accum, 1.0);
|
|
|
|
}
|