veloren/voxygen/shaders/include/light.glsl

35 lines
734 B
Plaintext
Raw Normal View History

struct Light {
vec4 light_pos;
vec4 light_col;
};
layout (std140)
uniform u_lights {
Light lights[32];
};
2019-07-21 15:04:36 +00:00
float attenuation_strength(vec3 rpos) {
return 1.0 / (rpos.x * rpos.x + rpos.y * rpos.y + rpos.z * rpos.z);
}
vec3 light_at(vec3 wpos, vec3 wnorm) {
2019-07-29 12:00:56 +00:00
const float LIGHT_AMBIENCE = 0.025;
2019-07-21 15:04:36 +00:00
vec3 light = vec3(0);
for (uint i = 0u; i < light_count.x; i ++) {
vec3 light_pos = lights[i].light_pos.xyz;
float strength = attenuation_strength(wpos - light_pos);
2019-07-29 12:00:56 +00:00
vec3 color = strength
* lights[i].light_col.rgb
* lights[i].light_col.a;
if (max(max(color.r, color.g), color.b) < 0.002) {
2019-07-21 15:04:36 +00:00
continue;
}
2019-07-29 12:00:56 +00:00
light += color * clamp(dot(normalize(light_pos - wpos), wnorm), LIGHT_AMBIENCE, 1.0);
2019-07-21 15:04:36 +00:00
}
return light;
}