3 * @brief Medium quality battlescape model 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
15uniform int SPECULARMAP;
19in_qualifier vec3 sunDir; /** < Direction towards the sun */
22uniform sampler2D SAMPLER_DIFFUSE;
24uniform sampler2D SAMPLER_SPECULAR;
26uniform sampler2D SAMPLER_NORMALMAP;
28#define R_DYNAMIC_LIGHTS #replace r_dynamic_lights
30in_qualifier vec3 lightDirs[R_DYNAMIC_LIGHTS];
31uniform vec4 LIGHTPARAMS[R_DYNAMIC_LIGHTS];
34#include "light_fs.glsl"
35#include "bump_fs.glsl"
37#include "model_devtools_fs.glsl"
38#include "write_fragment_fs.glsl"
46 vec4 specularmap = vec4(HARDNESS, HARDNESS, HARDNESS, SPECULAR);
48 vec3 sun = normalize(sunDir);
49 vec3 normal = vec3(0.0, 0.0, 1.0);
50 vec2 offset = vec2(0.0);
53 vec4 normalmap = texture2D(SAMPLER_NORMALMAP, gl_TexCoord[0].st);
54 normal = normalmap.rgb * 2.0 - 1.0; /** < Expanded normal */
56 normal = normalize(normal);
58 /* Resolve parallax offset */
59 offset = BumpTexcoord(normalmap.a);
62 /* Sample the diffuse texture, honoring the parallax offset.*/
63 vec4 diffusemap = texture2D(SAMPLER_DIFFUSE, gl_TexCoord[0].st + offset);
65 /* Sample specularity map, if any */
66 if (SPECULARMAP > 0) {
67 specularmap = texture2D(SAMPLER_SPECULAR, gl_TexCoord[0].st + offset);
70 /* Lambert illumination model */
71 vec3 light = AMBIENT + SUNCOLOR * clamp(dot(sun, normal), 0.0, 1.0);
73 /* Calculate specular component via Phong model */
74 vec3 V = reflect(-normalize(eyedir), normal);
75 float LdotV = dot(V, sun);
76 specular = SUNCOLOR * specularmap.rgb * pow(max(LdotV, 0.0), specularmap.a * 512.0);
78 /* Calculate dynamic lights (if any) */
79 light = clamp(light + LightFragment(normal), 0.0, 2.0);
81 finalColor.rgb = diffusemap.rgb * light + specular;
82 finalColor.a = diffusemap.a;
86 finalColor = FogFragment(finalColor);
89 /* Developer tools, if enabled */
90 finalColor = ApplyDeveloperTools(finalColor, sunDir, normal);
92 writeFragment(finalColor);