3 * @brief Low quality battlescape fragment shader.
8 * Indicates that gl_FragData is written to, not gl_FragColor.
9 * #extension needs to be placed before all non preprocessor code.
11 #extension GL_ARB_draw_buffers : enable
18uniform sampler2D SAMPLER_DIFFUSE;
20uniform sampler2D SAMPLER_LIGHTMAP;
22uniform sampler2D SAMPLER_DELUXEMAP;
24uniform sampler2D SAMPLER_NORMALMAP;
26#define R_DYNAMIC_LIGHTS #replace r_dynamic_lights
28in_qualifier vec3 lightDirs[R_DYNAMIC_LIGHTS];
29uniform vec4 LIGHTPARAMS[R_DYNAMIC_LIGHTS];
32#include "light_fs.glsl"
34#include "world_devtools_fs.glsl"
35#include "write_fragment_fs.glsl"
37in_qualifier vec4 blendColor;
43 vec4 finalColor = vec4(0.0);
44 vec3 light = vec3(0.0);
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);
49 /* lightmap contains pre-computed incoming light color */
50 light = texture2D(SAMPLER_LIGHTMAP, gl_TexCoord[1].st).rgb;
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);
58 /* Sample normalmap.*/
59 normalmap = texture2D(SAMPLER_NORMALMAP, gl_TexCoord[0].st);
60 normalmap.rgb = normalize(normalmap.rgb * 2.0 - 1.0);
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);
67 /* Sample the diffuse texture, honoring the parallax offset.*/
68 vec4 diffuse = texture2D(SAMPLER_DIFFUSE, gl_TexCoord[0].st);
70 /* Add dynamic lights, if any */
71 light = clamp(light + LightFragment(normalmap.rgb), 0.0, 2.0);
73 finalColor.rgb = diffuse.rgb * light;
74 finalColor.a = diffuse.a;
76 finalColor *= blendColor;
80 finalColor = FogFragment(finalColor);
83 /* Developer tools, if enabled */
84 finalColor = ApplyDeveloperTools(finalColor, normalmap.rgb, light, deluxemap);
86 writeFragment(finalColor);