UFO: Alien Invasion
Doxygen documentation generating
model_low_fs.glsl
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Low quality battlescape model fragment shader.
4  */
5 
6 #if r_postprocess
7  /*
8  * Indicates that gl_FragData is written to, not gl_FragColor.
9  * #extension needs to be placed before all non preprocessor code.
10  */
11  #extension GL_ARB_draw_buffers : enable
12 #endif
13 
14 uniform int BUMPMAP;
15 uniform float BUMP;
16 
17 uniform vec3 AMBIENT;
18 uniform vec3 SUNCOLOR;
19 
20 in_qualifier vec3 sunDir; /** < Direction towards the sun */
21 
22 /** Diffuse texture.*/
23 uniform sampler2D SAMPLER_DIFFUSE;
24 /** Normalmap.*/
25 uniform sampler2D SAMPLER_NORMALMAP;
26 
27 #define R_DYNAMIC_LIGHTS #replace r_dynamic_lights
28 #if r_dynamic_lights
29 in_qualifier vec3 lightDirs[R_DYNAMIC_LIGHTS];
30 uniform vec4 LIGHTPARAMS[R_DYNAMIC_LIGHTS];
31 #endif
32 
33 #include "light_fs.glsl"
34 #include "fog_fs.glsl"
35 #include "model_devtools_fs.glsl"
36 #include "write_fragment_fs.glsl"
37 
38 /**
39  * @brief main
40  */
41 void main(void) {
42  vec4 finalColor;
43 
44  vec4 diffuse = texture2D(SAMPLER_DIFFUSE, gl_TexCoord[0].st);
45  vec3 normal = vec3(0.0, 0.0, 1.0);
46 
47  if (BUMPMAP > 0) {
48  vec4 normalmap = texture2D(SAMPLER_NORMALMAP, gl_TexCoord[0].st);
49  normal = normalmap.rgb * 2.0 - 1.0; /** < Expanded normal */
50  normal.xy *= BUMP;
51  normal = normalize(normal);
52  }
53 
54  /* Lambert illumination model */
55  vec3 light = AMBIENT + SUNCOLOR * clamp(dot(sunDir, normal), 0.0, 1.0);
56  light = clamp(light + LightFragment(normal), 0.0, 2.0);
57 
58  finalColor.rgb = diffuse.rgb * light;
59  finalColor.a = diffuse.a;
60 
61 #if r_fog
62  /* Add fog.*/
63  finalColor = FogFragment(finalColor);
64 #endif
65 
66  /* Developer tools, if enabled */
67  finalColor = ApplyDeveloperTools(finalColor, sunDir, normal);
68 
69  writeFragment(finalColor);
70 }