UFO: Alien Invasion
Doxygen documentation generating
light_fs.glsl
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Dynamic lighting fragment shader.
4  */
5 
6 vec3 LightContribution(vec4 lightParams, vec3 lightDir, vec3 normal) {
7  vec3 delta = lightDir;
8  vec3 dir = normalize(delta);
9  float NdotL = clamp(dot(normal, dir), 0.0, 1.0);
10 
11  float dist = length(delta);
12  float attenDiv = max(lightParams.a * dist * dist, 0.5);
13  float attenuation = 1.0 / attenDiv;
14 
15  return lightParams.rgb * NdotL * attenuation;
16 }
17 
18 /**
19  * @brief LightFragment.
20  */
21 vec3 LightFragment(vec3 normal) {
22  vec3 light = vec3(0.0);
23 
24 #unroll r_dynamic_lights
25  light += LightContribution(LIGHTPARAMS[$], lightDirs[$], normal);
26 #endunroll
27 
28  return light;
29 }