UFO: Alien Invasion
Loading...
Searching...
No Matches
world_low_fs.glsl
Go to the documentation of this file.
1/**
2 * @file
3 * @brief Low quality battlescape 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
14uniform int BUMPMAP;
15uniform float BUMP;
16
17/** Diffuse texture.*/
18uniform sampler2D SAMPLER_DIFFUSE;
19/** Lightmap.*/
20uniform sampler2D SAMPLER_LIGHTMAP;
21/** Deluxemap.*/
22uniform sampler2D SAMPLER_DELUXEMAP;
23/** Normalmap.*/
24uniform sampler2D SAMPLER_NORMALMAP;
25
26#define R_DYNAMIC_LIGHTS #replace r_dynamic_lights
27#if r_dynamic_lights
28in_qualifier vec3 lightDirs[R_DYNAMIC_LIGHTS];
29uniform vec4 LIGHTPARAMS[R_DYNAMIC_LIGHTS];
30#endif
31
32#include "light_fs.glsl"
33#include "fog_fs.glsl"
34#include "world_devtools_fs.glsl"
35#include "write_fragment_fs.glsl"
36
37in_qualifier vec4 blendColor;
38
39/**
40 * @brief main
41 */
42void main(void) {
43 vec4 finalColor = vec4(0.0);
44 vec3 light = vec3(0.0);
45 vec3 deluxemap;
46 /* normalmap should be declared in this scope for developer tools to work */
47 vec4 normalmap = vec4(0.0, 0.0, 1.0, 0.5);
48
49 /* lightmap contains pre-computed incoming light color */
50 light = texture2D(SAMPLER_LIGHTMAP, gl_TexCoord[1].st).rgb;
51
52 /* deluxemap contains pre-computed incoming light vectors in object tangent space */
53 deluxemap = texture2D(SAMPLER_DELUXEMAP, gl_TexCoord[1].st).rgb;
54 deluxemap = normalize(deluxemap * 2.0 - 1.0);
55
56#if r_bumpmap
57 if (BUMPMAP > 0) {
58 /* Sample normalmap.*/
59 normalmap = texture2D(SAMPLER_NORMALMAP, gl_TexCoord[0].st);
60 normalmap.rgb = normalize(normalmap.rgb * 2.0 - 1.0);
61 }
62#endif
63
64 /* Modulate incoming light by cos(angle_of_incidence); should be done even bump mapping is disabled, to avoid having flat shading as a result.*/
65 light *= clamp(dot(deluxemap, vec3(normalmap.x * BUMP, normalmap.y * BUMP, normalmap.z)), 0.0, 1.0);
66
67 /* Sample the diffuse texture, honoring the parallax offset.*/
68 vec4 diffuse = texture2D(SAMPLER_DIFFUSE, gl_TexCoord[0].st);
69
70 /* Add dynamic lights, if any */
71 light = clamp(light + LightFragment(normalmap.rgb), 0.0, 2.0);
72
73 finalColor.rgb = diffuse.rgb * light;
74 finalColor.a = diffuse.a;
75
76 finalColor *= blendColor;
77
78#if r_fog
79 /* Add fog.*/
80 finalColor = FogFragment(finalColor);
81#endif
82
83 /* Developer tools, if enabled */
84 finalColor = ApplyDeveloperTools(finalColor, normalmap.rgb, light, deluxemap);
85
86 writeFragment(finalColor);
87}