charcoal/OpenGLEngine/LitFS.glsl

31 lines
728 B
Plaintext
Raw Normal View History

2018-09-14 22:09:43 +00:00
#version 430
struct Light
{
vec3 position;
2018-09-14 22:09:43 +00:00
vec3 ambient;
vec3 diffuse;
2018-09-14 22:09:43 +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];
layout(location = 52) uniform uint num_lights;
2018-09-14 22:09:43 +00:00
out vec4 frag_color;
void main()
{
vec3 norm_normal = normalize(fragment_normal);
2018-09-14 22:09:43 +00:00
vec3 accum = vec3(0.0);
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) {
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);
}