]> git.xonotic.org Git - xonotic/darkplaces.git/blob - shader_glsl.h
enable UBO extension for skeletal
[xonotic/darkplaces.git] / shader_glsl.h
1 "// ambient+diffuse+specular+normalmap+attenuation+cubemap+fog shader\n",
2 "// written by Forest 'LordHavoc' Hale\n",
3 "// shadowmapping enhancements by Lee 'eihrul' Salzman\n",
4 "\n",
5 "#ifdef USECELSHADING\n",
6 "# define SHADEDIFFUSE myhalf diffuse = cast_myhalf(min(max(float(dot(surfacenormal, lightnormal)) * 2.0, 0.0), 1.0));\n",
7 "# ifdef USEEXACTSPECULARMATH\n",
8 "#  define SHADESPECULAR(specpow) myhalf specular = pow(cast_myhalf(max(float(dot(reflect(lightnormal, surfacenormal), eyenormal))*-1.0, 0.0)), 1.0 + specpow);specular = max(0.0, specular * 10.0 - 9.0);\n",
9 "# else\n",
10 "#  define SHADESPECULAR(specpow) myhalf3 specularnormal = normalize(lightnormal + eyenormal);myhalf specular = pow(cast_myhalf(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + specpow);specular = max(0.0, specular * 10.0 - 9.0);\n",
11 "# endif\n",
12 "#else\n",
13 "# define SHADEDIFFUSE myhalf diffuse = cast_myhalf(max(float(dot(surfacenormal, lightnormal)), 0.0));\n",
14 "# ifdef USEEXACTSPECULARMATH\n",
15 "#  define SHADESPECULAR(specpow) myhalf specular = pow(cast_myhalf(max(float(dot(reflect(lightnormal, surfacenormal), eyenormal))*-1.0, 0.0)), 1.0 + specpow);\n",
16 "# else\n",
17 "#  define SHADESPECULAR(specpow) myhalf3 specularnormal = normalize(lightnormal + eyenormal);myhalf specular = pow(cast_myhalf(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + specpow);\n",
18 "# endif\n",
19 "#endif\n",
20 "\n",
21 "#if defined(GLSL130) || defined(GLSL140)\n",
22 "precision highp float;\n",
23 "# ifdef VERTEX_SHADER\n",
24 "#  define dp_varying out\n",
25 "#  define dp_attribute in\n",
26 "# endif\n",
27 "# ifdef FRAGMENT_SHADER\n",
28 "out vec4 dp_FragColor;\n",
29 "#  define dp_varying in\n",
30 "#  define dp_attribute in\n",
31 "# endif\n",
32 "# define dp_offsetmapping_dFdx dFdx\n",
33 "# define dp_offsetmapping_dFdy dFdy\n",
34 "# define dp_textureGrad textureGrad\n",
35 "# define dp_textureOffset(a,b,c,d) textureOffset(a,b,ivec2(c,d))\n",
36 "# define dp_texture2D texture\n",
37 "# define dp_texture3D texture\n",
38 "# define dp_textureCube texture\n",
39 "# define dp_shadow2D(a,b) float(texture(a,b))\n",
40 "#else\n",
41 "# ifdef FRAGMENT_SHADER\n",
42 "#  define dp_FragColor gl_FragColor\n",
43 "# endif\n",
44 "# define dp_varying varying\n",
45 "# define dp_attribute attribute\n",
46 "# define dp_offsetmapping_dFdx(a) vec2(0.0, 0.0)\n",
47 "# define dp_offsetmapping_dFdy(a) vec2(0.0, 0.0)\n",
48 "# define dp_textureGrad(a,b,c,d) texture2D(a,b)\n",
49 "# define dp_textureOffset(a,b,c,d) texture2DOffset(a,b,ivec2(c,d))\n",
50 "# define dp_texture2D texture2D\n",
51 "# define dp_texture3D texture3D\n",
52 "# define dp_textureCube textureCube\n",
53 "# define dp_shadow2D(a,b) float(shadow2D(a,b))\n",
54 "#endif\n",
55 "\n",
56 "// GL ES and GLSL130 shaders use precision modifiers, standard GL does not\n",
57 "// in GLSL130 we don't use them though because of syntax differences (can't use precision with inout)\n",
58 "#ifndef GL_ES\n",
59 "#define lowp\n",
60 "#define mediump\n",
61 "#define highp\n",
62 "#endif\n",
63 "\n",
64 "#ifdef USEDEPTHRGB\n",
65 "       // for 565 RGB we'd need to use different multipliers\n",
66 "#define decodedepthmacro(d) dot((d).rgb, vec3(1.0, 255.0 / 65536.0, 255.0 / 16777215.0))\n",
67 "#define encodedepthmacro(d) (vec4(d, d*256.0, d*65536.0, 0.0) - floor(vec4(d, d*256.0, d*65536.0, 0.0)))\n",
68 "#endif\n",
69 "\n",
70 "#ifdef VERTEX_SHADER\n",
71 "#ifdef USESKELETAL\n",
72 "#ifdef GL_ARB_uniform_buffer_object\n",
73 "#extension GL_ARB_uniform_buffer_object : enable\n",
74 "#endif\n", 
75 "#endif\n",
76 "dp_attribute vec4 Attrib_Position;  // vertex\n",
77 "dp_attribute vec4 Attrib_Color;     // color\n",
78 "dp_attribute vec4 Attrib_TexCoord0; // material texcoords\n",
79 "dp_attribute vec3 Attrib_TexCoord1; // svector\n",
80 "dp_attribute vec3 Attrib_TexCoord2; // tvector\n",
81 "dp_attribute vec3 Attrib_TexCoord3; // normal\n",
82 "dp_attribute vec4 Attrib_TexCoord4; // lightmap texcoords\n",
83 "#ifdef USESKELETAL\n",
84 "//uniform mat4 Skeletal_Transform[128];\n",
85 "// this is used with glBindBufferRange to bind a uniform block to the name\n",
86 "// Skeletal_Transform12_UniformBlock, the Skeletal_Transform12 variable is\n",
87 "// directly accessible without a namespace.\n",
88 "// explanation: http://www.opengl.org/wiki/Interface_Block_%28GLSL%29#Syntax\n",
89 "uniform Skeletal_Transform12_UniformBlock\n",
90 "{\n",
91 "       vec4 Skeletal_Transform12[768];\n",
92 "};\n",
93 "dp_attribute vec4 Attrib_SkeletalIndex;\n",
94 "dp_attribute vec4 Attrib_SkeletalWeight;\n",
95 "#endif\n",
96 "#endif\n",
97 "dp_varying mediump vec4 VertexColor;\n",
98 "\n",
99 "#if defined(USEFOGINSIDE) || defined(USEFOGOUTSIDE) || defined(USEFOGHEIGHTTEXTURE)\n",
100 "# define USEFOG\n",
101 "#endif\n",
102 "#if defined(MODE_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP)\n",
103 "# define USELIGHTMAP\n",
104 "#endif\n",
105 "#if defined(USESPECULAR) || defined(USEOFFSETMAPPING) || defined(USEREFLECTCUBE) || defined(MODE_FAKELIGHT) || defined(USEFOG)\n",
106 "# define USEEYEVECTOR\n",
107 "#endif\n",
108 "\n",
109 "#ifdef USESHADOWMAP2D\n",
110 "# ifdef GL_EXT_gpu_shader4\n",
111 "#   extension GL_EXT_gpu_shader4 : enable\n",
112 "# endif\n",
113 "# ifdef GL_ARB_texture_gather\n",
114 "#   extension GL_ARB_texture_gather : enable\n",
115 "# else\n",
116 "#   ifdef GL_AMD_texture_texture4\n",
117 "#     extension GL_AMD_texture_texture4 : enable\n",
118 "#   endif\n",
119 "# endif\n",
120 "#endif\n",
121 "\n",
122 "//#ifdef __GLSL_CG_DATA_TYPES\n",
123 "//# define myhalf half\n",
124 "//# define myhalf2 half2\n",
125 "//# define myhalf3 half3\n",
126 "//# define myhalf4 half4\n",
127 "//# define cast_myhalf half\n",
128 "//# define cast_myhalf2 half2\n",
129 "//# define cast_myhalf3 half3\n",
130 "//# define cast_myhalf4 half4\n",
131 "//#else\n",
132 "# define myhalf mediump float\n",
133 "# define myhalf2 mediump vec2\n",
134 "# define myhalf3 mediump vec3\n",
135 "# define myhalf4 mediump vec4\n",
136 "# define cast_myhalf float\n",
137 "# define cast_myhalf2 vec2\n",
138 "# define cast_myhalf3 vec3\n",
139 "# define cast_myhalf4 vec4\n",
140 "//#endif\n",
141 "\n",
142 "#ifdef VERTEX_SHADER\n",
143 "uniform highp mat4 ModelViewProjectionMatrix;\n",
144 "#endif\n",
145 "\n",
146 "#ifdef VERTEX_SHADER\n",
147 "#ifdef USETRIPPY\n",
148 "// LordHavoc: based on shader code linked at: http://www.youtube.com/watch?v=JpksyojwqzE\n",
149 "// tweaked scale\n",
150 "uniform highp float ClientTime;\n",
151 "vec4 TrippyVertex(vec4 position)\n",
152 "{\n",
153 "       float worldTime = ClientTime;\n",
154 "       // tweaked for Quake\n",
155 "       worldTime *= 10.0;\n",
156 "       position *= 0.125;\n",
157 "       //~tweaked for Quake\n",
158 "       float distanceSquared = (position.x * position.x + position.z * position.z);\n",
159 "       position.y += 5.0*sin(distanceSquared*sin(worldTime/143.0)/1000.0);\n",
160 "       float y = position.y;\n",
161 "       float x = position.x;\n",
162 "       float om = sin(distanceSquared*sin(worldTime/256.0)/5000.0) * sin(worldTime/200.0);\n",
163 "       position.y = x*sin(om)+y*cos(om);\n",
164 "       position.x = x*cos(om)-y*sin(om);\n",
165 "       return position;\n",
166 "}\n",
167 "#endif\n",
168 "#endif\n",
169 "\n",
170 "#ifdef MODE_DEPTH_OR_SHADOW\n",
171 "dp_varying highp float Depth;\n",
172 "#ifdef VERTEX_SHADER\n",
173 "void main(void)\n",
174 "{\n",
175 "#ifdef USESKELETAL\n",
176 "       ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n",
177 "       ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n",
178 "       ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n",
179 "       vec4 sw = Attrib_SkeletalWeight;\n",
180 "       vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n",
181 "       vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n",
182 "       vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n",
183 "       mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n",
184 "       vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n",
185 "#define Attrib_Position SkeletalVertex\n",
186 "#endif\n",
187 "       gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
188 "#ifdef USETRIPPY\n",
189 "       gl_Position = TrippyVertex(gl_Position);\n",
190 "#endif\n",
191 "       Depth = gl_Position.z;\n",
192 "}\n",
193 "#endif\n",
194 "\n",
195 "#ifdef FRAGMENT_SHADER\n",
196 "void main(void)\n",
197 "{\n",
198 "#ifdef USEDEPTHRGB\n",
199 "       dp_FragColor = encodedepthmacro(Depth);\n",
200 "#else\n",
201 "       dp_FragColor = vec4(1.0,1.0,1.0,1.0);\n",
202 "#endif\n",
203 "}\n",
204 "#endif\n",
205 "#else // !MODE_DEPTH_ORSHADOW\n",
206 "\n",
207 "\n",
208 "\n",
209 "\n",
210 "#ifdef MODE_POSTPROCESS\n",
211 "dp_varying mediump vec2 TexCoord1;\n",
212 "dp_varying mediump vec2 TexCoord2;\n",
213 "\n",
214 "#ifdef VERTEX_SHADER\n",
215 "void main(void)\n",
216 "{\n",
217 "       gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
218 "       TexCoord1 = Attrib_TexCoord0.xy;\n",
219 "#ifdef USEBLOOM\n",
220 "       TexCoord2 = Attrib_TexCoord4.xy;\n",
221 "#endif\n",
222 "}\n",
223 "#endif\n",
224 "\n",
225 "#ifdef FRAGMENT_SHADER\n",
226 "uniform sampler2D Texture_First;\n",
227 "#ifdef USEBLOOM\n",
228 "uniform sampler2D Texture_Second;\n",
229 "uniform mediump vec4 BloomColorSubtract;\n",
230 "#endif\n",
231 "#ifdef USEGAMMARAMPS\n",
232 "uniform sampler2D Texture_GammaRamps;\n",
233 "#endif\n",
234 "#ifdef USESATURATION\n",
235 "uniform mediump float Saturation;\n",
236 "#endif\n",
237 "#ifdef USEVIEWTINT\n",
238 "uniform mediump vec4 ViewTintColor;\n",
239 "#endif\n",
240 "//uncomment these if you want to use them:\n",
241 "uniform mediump vec4 UserVec1;\n",
242 "uniform mediump vec4 UserVec2;\n",
243 "// uniform mediump vec4 UserVec3;\n",
244 "// uniform mediump vec4 UserVec4;\n",
245 "// uniform highp float ClientTime;\n",
246 "uniform mediump vec2 PixelSize;\n",
247 "void main(void)\n",
248 "{\n",
249 "       dp_FragColor = dp_texture2D(Texture_First, TexCoord1);\n",
250 "#ifdef USEBLOOM\n",
251 "       dp_FragColor += max(vec4(0,0,0,0), dp_texture2D(Texture_Second, TexCoord2) - BloomColorSubtract);\n",
252 "#endif\n",
253 "#ifdef USEVIEWTINT\n",
254 "       dp_FragColor = mix(dp_FragColor, ViewTintColor, ViewTintColor.a);\n",
255 "#endif\n",
256 "\n",
257 "#ifdef USEPOSTPROCESSING\n",
258 "// do r_glsl_dumpshader, edit glsl/default.glsl, and replace this by your own postprocessing if you want\n",
259 "// this code does a blur with the radius specified in the first component of r_glsl_postprocess_uservec1 and blends it using the second component\n",
260 "       float sobel = 1.0;\n",
261 "       // vec2 ts = textureSize(Texture_First, 0);\n",
262 "       // vec2 px = vec2(1/ts.x, 1/ts.y);\n",
263 "       vec2 px = PixelSize;\n",
264 "       vec3 x1 = dp_texture2D(Texture_First, TexCoord1 + vec2(-px.x, px.y)).rgb;\n",
265 "       vec3 x2 = dp_texture2D(Texture_First, TexCoord1 + vec2(-px.x,  0.0)).rgb;\n",
266 "       vec3 x3 = dp_texture2D(Texture_First, TexCoord1 + vec2(-px.x,-px.y)).rgb;\n",
267 "       vec3 x4 = dp_texture2D(Texture_First, TexCoord1 + vec2( px.x, px.y)).rgb;\n",
268 "       vec3 x5 = dp_texture2D(Texture_First, TexCoord1 + vec2( px.x,  0.0)).rgb;\n",
269 "       vec3 x6 = dp_texture2D(Texture_First, TexCoord1 + vec2( px.x,-px.y)).rgb;\n",
270 "       vec3 y1 = dp_texture2D(Texture_First, TexCoord1 + vec2( px.x,-px.y)).rgb;\n",
271 "       vec3 y2 = dp_texture2D(Texture_First, TexCoord1 + vec2(  0.0,-px.y)).rgb;\n",
272 "       vec3 y3 = dp_texture2D(Texture_First, TexCoord1 + vec2(-px.x,-px.y)).rgb;\n",
273 "       vec3 y4 = dp_texture2D(Texture_First, TexCoord1 + vec2( px.x, px.y)).rgb;\n",
274 "       vec3 y5 = dp_texture2D(Texture_First, TexCoord1 + vec2(  0.0, px.y)).rgb;\n",
275 "       vec3 y6 = dp_texture2D(Texture_First, TexCoord1 + vec2(-px.x, px.y)).rgb;\n",
276 "       float px1 = -1.0 * dot(vec3(0.3, 0.59, 0.11), x1);\n",
277 "       float px2 = -2.0 * dot(vec3(0.3, 0.59, 0.11), x2);\n",
278 "       float px3 = -1.0 * dot(vec3(0.3, 0.59, 0.11), x3);\n",
279 "       float px4 =  1.0 * dot(vec3(0.3, 0.59, 0.11), x4);\n",
280 "       float px5 =  2.0 * dot(vec3(0.3, 0.59, 0.11), x5);\n",
281 "       float px6 =  1.0 * dot(vec3(0.3, 0.59, 0.11), x6);\n",
282 "       float py1 = -1.0 * dot(vec3(0.3, 0.59, 0.11), y1);\n",
283 "       float py2 = -2.0 * dot(vec3(0.3, 0.59, 0.11), y2);\n",
284 "       float py3 = -1.0 * dot(vec3(0.3, 0.59, 0.11), y3);\n",
285 "       float py4 =  1.0 * dot(vec3(0.3, 0.59, 0.11), y4);\n",
286 "       float py5 =  2.0 * dot(vec3(0.3, 0.59, 0.11), y5);\n",
287 "       float py6 =  1.0 * dot(vec3(0.3, 0.59, 0.11), y6);\n",
288 "       sobel = 0.25 * abs(px1 + px2 + px3 + px4 + px5 + px6) + 0.25 * abs(py1 + py2 + py3 + py4 + py5 + py6);\n",
289 "       dp_FragColor += dp_texture2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*vec2(-0.987688, -0.156434)) * UserVec1.y;\n",
290 "       dp_FragColor += dp_texture2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*vec2(-0.156434, -0.891007)) * UserVec1.y;\n",
291 "       dp_FragColor += dp_texture2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*vec2( 0.891007, -0.453990)) * UserVec1.y;\n",
292 "       dp_FragColor += dp_texture2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*vec2( 0.707107,  0.707107)) * UserVec1.y;\n",
293 "       dp_FragColor += dp_texture2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*vec2(-0.453990,  0.891007)) * UserVec1.y;\n",
294 "       dp_FragColor /= (1.0 + 5.0 * UserVec1.y);\n",
295 "       dp_FragColor.rgb = dp_FragColor.rgb * (1.0 + UserVec2.x) + vec3(max(0.0, sobel - UserVec2.z))*UserVec2.y;\n",
296 "#endif\n",
297 "\n",
298 "#ifdef USESATURATION\n",
299 "       //apply saturation BEFORE gamma ramps, so v_glslgamma value does not matter\n",
300 "       float y = dot(dp_FragColor.rgb, vec3(0.299, 0.587, 0.114));\n",
301 "       // 'vampire sight' effect, wheres red is compensated\n",
302 "       #ifdef SATURATION_REDCOMPENSATE\n",
303 "               float rboost = max(0.0, (dp_FragColor.r - max(dp_FragColor.g, dp_FragColor.b))*(1.0 - Saturation));\n",
304 "               dp_FragColor.rgb = mix(vec3(y), dp_FragColor.rgb, Saturation);\n",
305 "               dp_FragColor.r += rboost;\n",
306 "       #else\n",
307 "               // normal desaturation\n",
308 "               //dp_FragColor = vec3(y) + (dp_FragColor.rgb - vec3(y)) * Saturation;\n",
309 "               dp_FragColor.rgb = mix(vec3(y), dp_FragColor.rgb, Saturation);\n",
310 "       #endif\n",
311 "#endif\n",
312 "\n",
313 "#ifdef USEGAMMARAMPS\n",
314 "       dp_FragColor.r = dp_texture2D(Texture_GammaRamps, vec2(dp_FragColor.r, 0)).r;\n",
315 "       dp_FragColor.g = dp_texture2D(Texture_GammaRamps, vec2(dp_FragColor.g, 0)).g;\n",
316 "       dp_FragColor.b = dp_texture2D(Texture_GammaRamps, vec2(dp_FragColor.b, 0)).b;\n",
317 "#endif\n",
318 "}\n",
319 "#endif\n",
320 "#else // !MODE_POSTPROCESS\n",
321 "\n",
322 "\n",
323 "\n",
324 "\n",
325 "#ifdef MODE_GENERIC\n",
326 "#ifdef USEDIFFUSE\n",
327 "dp_varying mediump vec2 TexCoord1;\n",
328 "#endif\n",
329 "#ifdef USESPECULAR\n",
330 "dp_varying mediump vec2 TexCoord2;\n",
331 "#endif\n",
332 "uniform myhalf Alpha;\n",
333 "#ifdef VERTEX_SHADER\n",
334 "void main(void)\n",
335 "{\n",
336 "#ifdef USESKELETAL\n",
337 "       ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n",
338 "       ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n",
339 "       ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n",
340 "       vec4 sw = Attrib_SkeletalWeight;\n",
341 "       vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n",
342 "       vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n",
343 "       vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n",
344 "       mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n",
345 "       vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n",
346 "#define Attrib_Position SkeletalVertex\n",
347 "#endif\n",
348 "       VertexColor = Attrib_Color;\n",
349 "#ifdef USEDIFFUSE\n",
350 "       TexCoord1 = Attrib_TexCoord0.xy;\n",
351 "#endif\n",
352 "#ifdef USESPECULAR\n",
353 "       TexCoord2 = Attrib_TexCoord1.xy;\n",
354 "#endif\n",
355 "       gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
356 "#ifdef USETRIPPY\n",
357 "       gl_Position = TrippyVertex(gl_Position);\n",
358 "#endif\n",
359 "}\n",
360 "#endif\n",
361 "\n",
362 "#ifdef FRAGMENT_SHADER\n",
363 "#ifdef USEDIFFUSE\n",
364 "uniform sampler2D Texture_First;\n",
365 "#endif\n",
366 "#ifdef USESPECULAR\n",
367 "uniform sampler2D Texture_Second;\n",
368 "#endif\n",
369 "#ifdef USEGAMMARAMPS\n",
370 "uniform sampler2D Texture_GammaRamps;\n",
371 "#endif\n",
372 "\n",
373 "void main(void)\n",
374 "{\n",
375 "#ifdef USEVIEWTINT\n",
376 "       dp_FragColor = VertexColor;\n",
377 "#else\n",
378 "       dp_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n",
379 "#endif\n",
380 "#ifdef USEDIFFUSE\n",
381 "# ifdef USEREFLECTCUBE\n",
382 "       // suppress texture alpha\n",
383 "       dp_FragColor.rgb *= dp_texture2D(Texture_First, TexCoord1).rgb;\n",
384 "# else\n",
385 "       dp_FragColor *= dp_texture2D(Texture_First, TexCoord1);\n",
386 "# endif\n",
387 "#endif\n",
388 "\n",
389 "#ifdef USESPECULAR\n",
390 "       vec4 tex2 = dp_texture2D(Texture_Second, TexCoord2);\n",
391 "# ifdef USECOLORMAPPING\n",
392 "       dp_FragColor *= tex2;\n",
393 "# endif\n",
394 "# ifdef USEGLOW\n",
395 "       dp_FragColor += tex2;\n",
396 "# endif\n",
397 "# ifdef USEVERTEXTEXTUREBLEND\n",
398 "       dp_FragColor = mix(dp_FragColor, tex2, tex2.a);\n",
399 "# endif\n",
400 "#endif\n",
401 "#ifdef USEGAMMARAMPS\n",
402 "       dp_FragColor.r = dp_texture2D(Texture_GammaRamps, vec2(dp_FragColor.r, 0)).r;\n",
403 "       dp_FragColor.g = dp_texture2D(Texture_GammaRamps, vec2(dp_FragColor.g, 0)).g;\n",
404 "       dp_FragColor.b = dp_texture2D(Texture_GammaRamps, vec2(dp_FragColor.b, 0)).b;\n",
405 "#endif\n",
406 "#ifdef USEALPHAKILL\n",
407 "       dp_FragColor.a *= Alpha;\n",
408 "#endif\n",
409 "}\n",
410 "#endif\n",
411 "#else // !MODE_GENERIC\n",
412 "\n",
413 "\n",
414 "\n",
415 "\n",
416 "#ifdef MODE_BLOOMBLUR\n",
417 "dp_varying mediump vec2 TexCoord;\n",
418 "#ifdef VERTEX_SHADER\n",
419 "void main(void)\n",
420 "{\n",
421 "       VertexColor = Attrib_Color;\n",
422 "       TexCoord = Attrib_TexCoord0.xy;\n",
423 "       gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
424 "}\n",
425 "#endif\n",
426 "\n",
427 "#ifdef FRAGMENT_SHADER\n",
428 "uniform sampler2D Texture_First;\n",
429 "uniform mediump vec4 BloomBlur_Parameters;\n",
430 "\n",
431 "void main(void)\n",
432 "{\n",
433 "       int i;\n",
434 "       vec2 tc = TexCoord;\n",
435 "       vec3 color = dp_texture2D(Texture_First, tc).rgb;\n",
436 "       tc += BloomBlur_Parameters.xy;\n",
437 "       for (i = 1;i < SAMPLES;i++)\n",
438 "       {\n",
439 "               color += dp_texture2D(Texture_First, tc).rgb;\n",
440 "               tc += BloomBlur_Parameters.xy;\n",
441 "       }\n",
442 "       dp_FragColor = vec4(color * BloomBlur_Parameters.z + vec3(BloomBlur_Parameters.w), 1);\n",
443 "}\n",
444 "#endif\n",
445 "#else // !MODE_BLOOMBLUR\n",
446 "#ifdef MODE_REFRACTION\n",
447 "dp_varying mediump vec2 TexCoord;\n",
448 "dp_varying highp vec4 ModelViewProjectionPosition;\n",
449 "uniform highp mat4 TexMatrix;\n",
450 "#ifdef VERTEX_SHADER\n",
451 "\n",
452 "void main(void)\n",
453 "{\n",
454 "#ifdef USESKELETAL\n",
455 "       ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n",
456 "       ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n",
457 "       ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n",
458 "       vec4 sw = Attrib_SkeletalWeight;\n",
459 "       vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n",
460 "       vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n",
461 "       vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n",
462 "       mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n",
463 "       vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n",
464 "#define Attrib_Position SkeletalVertex\n",
465 "#endif\n",
466 "#ifdef USEALPHAGENVERTEX\n",
467 "       VertexColor = Attrib_Color;\n",
468 "#endif\n",
469 "       TexCoord = vec2(TexMatrix * Attrib_TexCoord0);\n",
470 "       gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
471 "       ModelViewProjectionPosition = gl_Position;\n",
472 "#ifdef USETRIPPY\n",
473 "       gl_Position = TrippyVertex(gl_Position);\n",
474 "#endif\n",
475 "}\n",
476 "#endif\n",
477 "\n",
478 "#ifdef FRAGMENT_SHADER\n",
479 "uniform sampler2D Texture_Normal;\n",
480 "uniform sampler2D Texture_Refraction;\n",
481 "\n",
482 "uniform mediump vec4 DistortScaleRefractReflect;\n",
483 "uniform mediump vec4 ScreenScaleRefractReflect;\n",
484 "uniform mediump vec4 ScreenCenterRefractReflect;\n",
485 "uniform mediump vec4 RefractColor;\n",
486 "uniform mediump vec4 ReflectColor;\n",
487 "uniform highp float ClientTime;\n",
488 "#ifdef USENORMALMAPSCROLLBLEND\n",
489 "uniform highp vec2 NormalmapScrollBlend;\n",
490 "#endif\n",
491 "\n",
492 "void main(void)\n",
493 "{\n",
494 "       vec2 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect.xy * (1.0 / ModelViewProjectionPosition.w);\n",
495 "       //vec2 ScreenTexCoord = (ModelViewProjectionPosition.xy + normalize(vec3(dp_texture2D(Texture_Normal, TexCoord)) - vec3(0.5)).xy * DistortScaleRefractReflect.xy * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n",
496 "       vec2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n",
497 "#ifdef USEALPHAGENVERTEX\n",
498 "       vec2 distort = DistortScaleRefractReflect.xy * VertexColor.a;\n",
499 "       vec4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), VertexColor.a);\n",
500 "#else\n",
501 "       vec2 distort = DistortScaleRefractReflect.xy;\n",
502 "       vec4 refractcolor = RefractColor;\n",
503 "#endif\n",
504 "       #ifdef USENORMALMAPSCROLLBLEND\n",
505 "               vec3 normal = dp_texture2D(Texture_Normal, (TexCoord + vec2(0.08, 0.08)*ClientTime*NormalmapScrollBlend.x*0.5)*NormalmapScrollBlend.y).rgb - vec3(1.0);\n",
506 "               normal += dp_texture2D(Texture_Normal, (TexCoord + vec2(-0.06, -0.09)*ClientTime*NormalmapScrollBlend.x)*NormalmapScrollBlend.y*0.75).rgb;\n",
507 "               vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(cast_myhalf3(normal))).xy * distort;\n",
508 "       #else\n",
509 "               vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(cast_myhalf3(dp_texture2D(Texture_Normal, TexCoord)) - cast_myhalf3(0.5))).xy * distort;\n",
510 "       #endif\n",
511 "       // FIXME temporary hack to detect the case that the reflection\n",
512 "       // gets blackened at edges due to leaving the area that contains actual\n",
513 "       // content.\n",
514 "       // Remove this 'ack once we have a better way to stop this thing from\n",
515 "       // 'appening.\n",
516 "       float f = min(1.0, length(dp_texture2D(Texture_Refraction, ScreenTexCoord + vec2(0.01, 0.01)).rgb) / 0.05);\n",
517 "       f      *= min(1.0, length(dp_texture2D(Texture_Refraction, ScreenTexCoord + vec2(0.01, -0.01)).rgb) / 0.05);\n",
518 "       f      *= min(1.0, length(dp_texture2D(Texture_Refraction, ScreenTexCoord + vec2(-0.01, 0.01)).rgb) / 0.05);\n",
519 "       f      *= min(1.0, length(dp_texture2D(Texture_Refraction, ScreenTexCoord + vec2(-0.01, -0.01)).rgb) / 0.05);\n",
520 "       ScreenTexCoord = mix(SafeScreenTexCoord, ScreenTexCoord, f);\n",
521 "       dp_FragColor = vec4(dp_texture2D(Texture_Refraction, ScreenTexCoord).rgb, 1.0) * refractcolor;\n",
522 "}\n",
523 "#endif\n",
524 "#else // !MODE_REFRACTION\n",
525 "\n",
526 "\n",
527 "\n",
528 "\n",
529 "#ifdef MODE_WATER\n",
530 "dp_varying mediump vec2 TexCoord;\n",
531 "dp_varying highp vec3 EyeVector;\n",
532 "dp_varying highp vec4 ModelViewProjectionPosition;\n",
533 "#ifdef VERTEX_SHADER\n",
534 "uniform highp vec3 EyePosition;\n",
535 "uniform highp mat4 TexMatrix;\n",
536 "\n",
537 "void main(void)\n",
538 "{\n",
539 "#ifdef USESKELETAL\n",
540 "       ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n",
541 "       ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n",
542 "       ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n",
543 "       vec4 sw = Attrib_SkeletalWeight;\n",
544 "       vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n",
545 "       vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n",
546 "       vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n",
547 "       mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n",
548 "       mat3 SkeletalNormalMatrix = mat3(cross(SkeletalMatrix[1].xyz, SkeletalMatrix[2].xyz), cross(SkeletalMatrix[2].xyz, SkeletalMatrix[0].xyz), cross(SkeletalMatrix[0].xyz, SkeletalMatrix[1].xyz)); // is actually transpose(inverse(mat3(SkeletalMatrix))) * det(mat3(SkeletalMatrix))\n",
549 "       vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n",
550 "       vec3 SkeletalSVector = normalize(Attrib_TexCoord1.xyz * SkeletalNormalMatrix);\n",
551 "       vec3 SkeletalTVector = normalize(Attrib_TexCoord2.xyz * SkeletalNormalMatrix);\n",
552 "       vec3 SkeletalNormal  = normalize(Attrib_TexCoord3.xyz * SkeletalNormalMatrix);\n",
553 "#define Attrib_Position SkeletalVertex\n",
554 "#define Attrib_TexCoord1 SkeletalSVector\n",
555 "#define Attrib_TexCoord2 SkeletalTVector\n",
556 "#define Attrib_TexCoord3 SkeletalNormal\n",
557 "#endif\n",
558 "#ifdef USEALPHAGENVERTEX\n",
559 "       VertexColor = Attrib_Color;\n",
560 "#endif\n",
561 "       TexCoord = vec2(TexMatrix * Attrib_TexCoord0);\n",
562 "       vec3 EyeRelative = EyePosition - Attrib_Position.xyz;\n",
563 "       EyeVector.x = dot(EyeRelative, Attrib_TexCoord1.xyz);\n",
564 "       EyeVector.y = dot(EyeRelative, Attrib_TexCoord2.xyz);\n",
565 "       EyeVector.z = dot(EyeRelative, Attrib_TexCoord3.xyz);\n",
566 "       gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
567 "       ModelViewProjectionPosition = gl_Position;\n",
568 "#ifdef USETRIPPY\n",
569 "       gl_Position = TrippyVertex(gl_Position);\n",
570 "#endif\n",
571 "}\n",
572 "#endif\n",
573 "\n",
574 "#ifdef FRAGMENT_SHADER\n",
575 "uniform sampler2D Texture_Normal;\n",
576 "uniform sampler2D Texture_Refraction;\n",
577 "uniform sampler2D Texture_Reflection;\n",
578 "\n",
579 "uniform mediump vec4 DistortScaleRefractReflect;\n",
580 "uniform mediump vec4 ScreenScaleRefractReflect;\n",
581 "uniform mediump vec4 ScreenCenterRefractReflect;\n",
582 "uniform mediump vec4 RefractColor;\n",
583 "uniform mediump vec4 ReflectColor;\n",
584 "uniform mediump float ReflectFactor;\n",
585 "uniform mediump float ReflectOffset;\n",
586 "uniform highp float ClientTime;\n",
587 "#ifdef USENORMALMAPSCROLLBLEND\n",
588 "uniform highp vec2 NormalmapScrollBlend;\n",
589 "#endif\n",
590 "\n",
591 "void main(void)\n",
592 "{\n",
593 "       vec4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n",
594 "       //vec4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(vec3(dp_texture2D(Texture_Normal, TexCoord)) - vec3(0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
595 "       vec4 SafeScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
596 "       //SafeScreenTexCoord = gl_FragCoord.xyxy * vec4(1.0 / 1920.0, 1.0 / 1200.0, 1.0 / 1920.0, 1.0 / 1200.0);\n",
597 "       // slight water animation via 2 layer scrolling (todo: tweak)\n",
598 "#ifdef USEALPHAGENVERTEX\n",
599 "       vec4 distort = DistortScaleRefractReflect * VertexColor.a;\n",
600 "       float reflectoffset = ReflectOffset * VertexColor.a;\n",
601 "       float reflectfactor = ReflectFactor * VertexColor.a;\n",
602 "       vec4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), VertexColor.a);\n",
603 "#else\n",
604 "       vec4 distort = DistortScaleRefractReflect;\n",
605 "       float reflectoffset = ReflectOffset;\n",
606 "       float reflectfactor = ReflectFactor;\n",
607 "       vec4 refractcolor = RefractColor;\n",
608 "#endif\n",
609 "       #ifdef USENORMALMAPSCROLLBLEND\n",
610 "               vec3 normal = dp_texture2D(Texture_Normal, (TexCoord + vec2(0.08, 0.08)*ClientTime*NormalmapScrollBlend.x*0.5)*NormalmapScrollBlend.y).rgb - vec3(1.0);\n",
611 "               normal += dp_texture2D(Texture_Normal, (TexCoord + vec2(-0.06, -0.09)*ClientTime*NormalmapScrollBlend.x)*NormalmapScrollBlend.y*0.75).rgb;\n",
612 "               vec4 ScreenTexCoord = SafeScreenTexCoord + vec2(normalize(normal) + vec3(0.15)).xyxy * distort;\n",
613 "       #else\n",
614 "               vec4 ScreenTexCoord = SafeScreenTexCoord + vec2(normalize(vec3(dp_texture2D(Texture_Normal, TexCoord)) - vec3(0.5))).xyxy * distort;\n",
615 "       #endif\n",
616 "       // FIXME temporary hack to detect the case that the reflection\n",
617 "       // gets blackened at edges due to leaving the area that contains actual\n",
618 "       // content.\n",
619 "       // Remove this 'ack once we have a better way to stop this thing from\n",
620 "       // 'appening.\n",
621 "       float f  = min(1.0, length(dp_texture2D(Texture_Refraction, ScreenTexCoord.xy + vec2(0.005, 0.01)).rgb) / 0.002);\n",
622 "       f       *= min(1.0, length(dp_texture2D(Texture_Refraction, ScreenTexCoord.xy + vec2(0.005, -0.01)).rgb) / 0.002);\n",
623 "       f       *= min(1.0, length(dp_texture2D(Texture_Refraction, ScreenTexCoord.xy + vec2(-0.005, 0.01)).rgb) / 0.002);\n",
624 "       f       *= min(1.0, length(dp_texture2D(Texture_Refraction, ScreenTexCoord.xy + vec2(-0.005, -0.01)).rgb) / 0.002);\n",
625 "       ScreenTexCoord.xy = mix(SafeScreenTexCoord.xy, ScreenTexCoord.xy, f);\n",
626 "       f  = min(1.0, length(dp_texture2D(Texture_Reflection, ScreenTexCoord.zw + vec2(0.005, 0.005)).rgb) / 0.002);\n",
627 "       f *= min(1.0, length(dp_texture2D(Texture_Reflection, ScreenTexCoord.zw + vec2(0.005, -0.005)).rgb) / 0.002);\n",
628 "       f *= min(1.0, length(dp_texture2D(Texture_Reflection, ScreenTexCoord.zw + vec2(-0.005, 0.005)).rgb) / 0.002);\n",
629 "       f *= min(1.0, length(dp_texture2D(Texture_Reflection, ScreenTexCoord.zw + vec2(-0.005, -0.005)).rgb) / 0.002);\n",
630 "       ScreenTexCoord.zw = mix(SafeScreenTexCoord.zw, ScreenTexCoord.zw, f);\n",
631 "       float Fresnel = pow(min(1.0, 1.0 - float(normalize(EyeVector).z)), 2.0) * reflectfactor + reflectoffset;\n",
632 "       dp_FragColor = mix(vec4(dp_texture2D(Texture_Refraction, ScreenTexCoord.xy).rgb, 1) * refractcolor, vec4(dp_texture2D(Texture_Reflection, ScreenTexCoord.zw).rgb, 1) * ReflectColor, Fresnel);\n",
633 "}\n",
634 "#endif\n",
635 "#else // !MODE_WATER\n",
636 "\n",
637 "\n",
638 "\n",
639 "\n",
640 "// common definitions between vertex shader and fragment shader:\n",
641 "\n",
642 "dp_varying mediump vec4 TexCoordSurfaceLightmap;\n",
643 "#ifdef USEVERTEXTEXTUREBLEND\n",
644 "dp_varying mediump vec2 TexCoord2;\n",
645 "#endif\n",
646 "\n",
647 "#ifdef MODE_LIGHTSOURCE\n",
648 "dp_varying mediump vec3 CubeVector;\n",
649 "#endif\n",
650 "\n",
651 "#if (defined(MODE_LIGHTSOURCE) || defined(MODE_LIGHTDIRECTION)) && defined(USEDIFFUSE)\n",
652 "dp_varying mediump vec3 LightVector;\n",
653 "#endif\n",
654 "\n",
655 "#ifdef USEEYEVECTOR\n",
656 "dp_varying highp vec4 EyeVectorFogDepth;\n",
657 "#endif\n",
658 "\n",
659 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE) || defined(USEBOUNCEGRIDDIRECTIONAL)\n",
660 "dp_varying highp vec4 VectorS; // direction of S texcoord (sometimes crudely called tangent)\n",
661 "dp_varying highp vec4 VectorT; // direction of T texcoord (sometimes crudely called binormal)\n",
662 "dp_varying highp vec4 VectorR; // direction of R texcoord (surface normal)\n",
663 "#else\n",
664 "# ifdef USEFOG\n",
665 "dp_varying highp vec3 EyeVectorModelSpace;\n",
666 "# endif\n",
667 "#endif\n",
668 "\n",
669 "#ifdef USEREFLECTION\n",
670 "dp_varying highp vec4 ModelViewProjectionPosition;\n",
671 "#endif\n",
672 "#ifdef MODE_DEFERREDLIGHTSOURCE\n",
673 "uniform highp vec3 LightPosition;\n",
674 "dp_varying highp vec4 ModelViewPosition;\n",
675 "#endif\n",
676 "\n",
677 "#ifdef MODE_LIGHTSOURCE\n",
678 "uniform highp vec3 LightPosition;\n",
679 "#endif\n",
680 "uniform highp vec3 EyePosition;\n",
681 "#ifdef MODE_LIGHTDIRECTION\n",
682 "uniform highp vec3 LightDir;\n",
683 "#endif\n",
684 "uniform highp vec4 FogPlane;\n",
685 "\n",
686 "#ifdef USESHADOWMAPORTHO\n",
687 "dp_varying highp vec3 ShadowMapTC;\n",
688 "#endif\n",
689 "\n",
690 "#ifdef USEBOUNCEGRID\n",
691 "dp_varying highp vec3 BounceGridTexCoord;\n",
692 "#endif\n",
693 "\n",
694 "#ifdef MODE_DEFERREDGEOMETRY\n",
695 "dp_varying highp float Depth;\n",
696 "#endif\n",
697 "\n",
698 "\n",
699 "\n",
700 "\n",
701 "\n",
702 "\n",
703 "// TODO: get rid of tangentt (texcoord2) and use a crossproduct to regenerate it from tangents (texcoord1) and normal (texcoord3), this would require sending a 4 component texcoord1 with W as 1 or -1 according to which side the texcoord2 should be on\n",
704 "\n",
705 "// fragment shader specific:\n",
706 "#ifdef FRAGMENT_SHADER\n",
707 "\n",
708 "uniform sampler2D Texture_Normal;\n",
709 "uniform sampler2D Texture_Color;\n",
710 "uniform sampler2D Texture_Gloss;\n",
711 "#ifdef USEGLOW\n",
712 "uniform sampler2D Texture_Glow;\n",
713 "#endif\n",
714 "#ifdef USEVERTEXTEXTUREBLEND\n",
715 "uniform sampler2D Texture_SecondaryNormal;\n",
716 "uniform sampler2D Texture_SecondaryColor;\n",
717 "uniform sampler2D Texture_SecondaryGloss;\n",
718 "#ifdef USEGLOW\n",
719 "uniform sampler2D Texture_SecondaryGlow;\n",
720 "#endif\n",
721 "#endif\n",
722 "#ifdef USECOLORMAPPING\n",
723 "uniform sampler2D Texture_Pants;\n",
724 "uniform sampler2D Texture_Shirt;\n",
725 "#endif\n",
726 "#ifdef USEFOG\n",
727 "#ifdef USEFOGHEIGHTTEXTURE\n",
728 "uniform sampler2D Texture_FogHeightTexture;\n",
729 "#endif\n",
730 "uniform sampler2D Texture_FogMask;\n",
731 "#endif\n",
732 "#ifdef USELIGHTMAP\n",
733 "uniform sampler2D Texture_Lightmap;\n",
734 "#endif\n",
735 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE)\n",
736 "uniform sampler2D Texture_Deluxemap;\n",
737 "#endif\n",
738 "#ifdef USEREFLECTION\n",
739 "uniform sampler2D Texture_Reflection;\n",
740 "#endif\n",
741 "\n",
742 "#ifdef MODE_DEFERREDLIGHTSOURCE\n",
743 "uniform sampler2D Texture_ScreenNormalMap;\n",
744 "#endif\n",
745 "#ifdef USEDEFERREDLIGHTMAP\n",
746 "#ifdef USECELOUTLINES\n",
747 "uniform sampler2D Texture_ScreenNormalMap;\n",
748 "#endif\n",
749 "uniform sampler2D Texture_ScreenDiffuse;\n",
750 "uniform sampler2D Texture_ScreenSpecular;\n",
751 "#endif\n",
752 "\n",
753 "uniform mediump vec3 Color_Pants;\n",
754 "uniform mediump vec3 Color_Shirt;\n",
755 "uniform mediump vec3 FogColor;\n",
756 "\n",
757 "#ifdef USEFOG\n",
758 "uniform highp float FogRangeRecip;\n",
759 "uniform highp float FogPlaneViewDist;\n",
760 "uniform highp float FogHeightFade;\n",
761 "vec3 FogVertex(vec4 surfacecolor)\n",
762 "{\n",
763 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE) || defined(USEBOUNCEGRIDDIRECTIONAL)\n",
764 "       vec3 EyeVectorModelSpace = vec3(VectorS.w, VectorT.w, VectorR.w);\n",
765 "#endif\n",
766 "       float FogPlaneVertexDist = EyeVectorFogDepth.w;\n",
767 "       float fogfrac;\n",
768 "       vec3 fc = FogColor;\n",
769 "#ifdef USEFOGALPHAHACK\n",
770 "       fc *= surfacecolor.a;\n",
771 "#endif\n",
772 "#ifdef USEFOGHEIGHTTEXTURE\n",
773 "       vec4 fogheightpixel = dp_texture2D(Texture_FogHeightTexture, vec2(1,1) + vec2(FogPlaneVertexDist, FogPlaneViewDist) * (-2.0 * FogHeightFade));\n",
774 "       fogfrac = fogheightpixel.a;\n",
775 "       return mix(fogheightpixel.rgb * fc, surfacecolor.rgb, dp_texture2D(Texture_FogMask, cast_myhalf2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n",
776 "#else\n",
777 "# ifdef USEFOGOUTSIDE\n",
778 "       fogfrac = min(0.0, FogPlaneVertexDist) / (FogPlaneVertexDist - FogPlaneViewDist) * min(1.0, min(0.0, FogPlaneVertexDist) * FogHeightFade);\n",
779 "# else\n",
780 "       fogfrac = FogPlaneViewDist / (FogPlaneViewDist - max(0.0, FogPlaneVertexDist)) * min(1.0, (min(0.0, FogPlaneVertexDist) + FogPlaneViewDist) * FogHeightFade);\n",
781 "# endif\n",
782 "       return mix(fc, surfacecolor.rgb, dp_texture2D(Texture_FogMask, cast_myhalf2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n",
783 "#endif\n",
784 "}\n",
785 "#endif\n",
786 "\n",
787 "#ifdef USEOFFSETMAPPING\n",
788 "uniform mediump vec4 OffsetMapping_ScaleSteps;\n",
789 "uniform mediump float OffsetMapping_Bias;\n",
790 "#ifdef USEOFFSETMAPPING_LOD\n",
791 "uniform mediump float OffsetMapping_LodDistance;\n",
792 "#endif\n",
793 "vec2 OffsetMapping(vec2 TexCoord, vec2 dPdx, vec2 dPdy)\n",
794 "{\n",
795 "       float i;\n",
796 "       // distance-based LOD\n",
797 "#ifdef USEOFFSETMAPPING_LOD\n",
798 "       //mediump float LODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n",
799 "       //mediump vec4 ScaleSteps = vec4(OffsetMapping_ScaleSteps.x, OffsetMapping_ScaleSteps.y * LODFactor, OffsetMapping_ScaleSteps.z / LODFactor, OffsetMapping_ScaleSteps.w * LODFactor);\n",
800 "       mediump float GuessLODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n",
801 "#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n",
802 "       // stupid workaround because 1-step and 2-step reliefmapping is void\n",
803 "       mediump float LODSteps = max(3.0, ceil(GuessLODFactor * OffsetMapping_ScaleSteps.y));\n",
804 "#else\n",
805 "       mediump float LODSteps = ceil(GuessLODFactor * OffsetMapping_ScaleSteps.y);\n",
806 "#endif\n",
807 "       mediump float LODFactor = LODSteps / OffsetMapping_ScaleSteps.y;\n",
808 "       mediump vec4 ScaleSteps = vec4(OffsetMapping_ScaleSteps.x, LODSteps, 1.0 / LODSteps, OffsetMapping_ScaleSteps.w * LODFactor);\n",
809 "#else\n",
810 "       #define ScaleSteps OffsetMapping_ScaleSteps\n",
811 "#endif\n",
812 "#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n",
813 "       float f;\n",
814 "       // 14 sample relief mapping: linear search and then binary search\n",
815 "       // this basically steps forward a small amount repeatedly until it finds\n",
816 "       // itself inside solid, then jitters forward and back using decreasing\n",
817 "       // amounts to find the impact\n",
818 "       //vec3 OffsetVector = vec3(EyeVectorFogDepth.xy * ((1.0 / EyeVectorFogDepth.z) * ScaleSteps.x) * vec2(-1, 1), -1);\n",
819 "       //vec3 OffsetVector = vec3(normalize(EyeVectorFogDepth.xy) * ScaleSteps.x * vec2(-1, 1), -1);\n",
820 "       vec3 OffsetVector = vec3(normalize(EyeVectorFogDepth.xyz).xy * ScaleSteps.x * vec2(-1, 1), -1);\n",
821 "       vec3 RT = vec3(vec2(TexCoord.xy - OffsetVector.xy*OffsetMapping_Bias), 1);\n",
822 "       OffsetVector *= ScaleSteps.z;\n",
823 "       for(i = 1.0; i < ScaleSteps.y; ++i)\n",
824 "               RT += OffsetVector *  step(dp_textureGrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z);\n",
825 "       for(i = 0.0, f = 1.0; i < ScaleSteps.w; ++i, f *= 0.5)\n",
826 "               RT += OffsetVector * (step(dp_textureGrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * f - 0.5 * f);\n",
827 "       return RT.xy;\n",
828 "#else\n",
829 "       // 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits)\n",
830 "       //vec2 OffsetVector = vec2(EyeVectorFogDepth.xy * ((1.0 / EyeVectorFogDepth.z) * ScaleSteps.x) * vec2(-1, 1));\n",
831 "       //vec2 OffsetVector = vec2(normalize(EyeVectorFogDepth.xy) * ScaleSteps.x * vec2(-1, 1));\n",
832 "       vec2 OffsetVector = vec2(normalize(EyeVectorFogDepth.xyz).xy * ScaleSteps.x * vec2(-1, 1));\n",
833 "       OffsetVector *= ScaleSteps.z;\n",
834 "       for(i = 0.0; i < ScaleSteps.y; ++i)\n",
835 "               TexCoord += OffsetVector * ((1.0 - OffsetMapping_Bias) - dp_textureGrad(Texture_Normal, TexCoord, dPdx, dPdy).a);\n",
836 "       return TexCoord;\n",
837 "#endif\n",
838 "}\n",
839 "#endif // USEOFFSETMAPPING\n",
840 "\n",
841 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE)\n",
842 "uniform sampler2D Texture_Attenuation;\n",
843 "uniform samplerCube Texture_Cube;\n",
844 "#endif\n",
845 "\n",
846 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n",
847 "\n",
848 "#ifdef USESHADOWMAP2D\n",
849 "# ifdef USESHADOWSAMPLER\n",
850 "uniform sampler2DShadow Texture_ShadowMap2D;\n",
851 "# else\n",
852 "uniform sampler2D Texture_ShadowMap2D;\n",
853 "# endif\n",
854 "#endif\n",
855 "\n",
856 "#ifdef USESHADOWMAPVSDCT\n",
857 "uniform samplerCube Texture_CubeProjection;\n",
858 "#endif\n",
859 "\n",
860 "#if defined(USESHADOWMAP2D)\n",
861 "uniform mediump vec2 ShadowMap_TextureScale;\n",
862 "uniform mediump vec4 ShadowMap_Parameters;\n",
863 "#endif\n",
864 "\n",
865 "#if defined(USESHADOWMAP2D)\n",
866 "# ifdef USESHADOWMAPORTHO\n",
867 "#  define GetShadowMapTC2D(dir) (min(dir, ShadowMap_Parameters.xyz))\n",
868 "# else\n",
869 "#  ifdef USESHADOWMAPVSDCT\n",
870 "vec3 GetShadowMapTC2D(vec3 dir)\n",
871 "{\n",
872 "       vec3 adir = abs(dir);\n",
873 "       float m = max(max(adir.x, adir.y), adir.z);\n",
874 "       vec4 proj = dp_textureCube(Texture_CubeProjection, dir);\n",
875 "#ifdef USEDEPTHRGB\n",
876 "       return vec3(mix(dir.xy, dir.zz, proj.xy) * (ShadowMap_Parameters.x / m) +  proj.zw * ShadowMap_Parameters.z, m + 64.0 * ShadowMap_Parameters.w);\n",
877 "#else\n",
878 "       vec2 mparams = ShadowMap_Parameters.xy / m;\n",
879 "       return vec3(mix(dir.xy, dir.zz, proj.xy) * mparams.x + proj.zw * ShadowMap_Parameters.z, mparams.y + ShadowMap_Parameters.w);\n",
880 "#endif\n",
881 "}\n",
882 "#  else\n",
883 "vec3 GetShadowMapTC2D(vec3 dir)\n",
884 "{\n",
885 "       vec3 adir = abs(dir);\n",
886 "       float m; vec4 proj;\n",
887 "       if (adir.x > adir.y) { m = adir.x; proj = vec4(dir.zyx, 0.5); } else { m = adir.y; proj = vec4(dir.xzy, 1.5); }\n",
888 "       if (adir.z > m) { m = adir.z; proj = vec4(dir, 2.5); }\n",
889 "#ifdef USEDEPTHRGB\n",
890 "       return vec3(proj.xy * (ShadowMap_Parameters.x / m) + vec2(0.5,0.5) + vec2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, m + 64.0 * ShadowMap_Parameters.w);\n",
891 "#else\n",
892 "       vec2 mparams = ShadowMap_Parameters.xy / m;\n",
893 "       return vec3(proj.xy * mparams.x + vec2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, mparams.y + ShadowMap_Parameters.w);\n",
894 "#endif\n",
895 "}\n",
896 "#  endif\n",
897 "# endif\n",
898 "#endif // defined(USESHADOWMAP2D)\n",
899 "\n",
900 "# ifdef USESHADOWMAP2D\n",
901 "float ShadowMapCompare(vec3 dir)\n",
902 "{\n",
903 "       vec3 shadowmaptc = GetShadowMapTC2D(dir);\n",
904 "       float f;\n",
905 "\n",
906 "#  ifdef USEDEPTHRGB\n",
907 "#   ifdef USESHADOWMAPPCF\n",
908 "#    define texval(x, y) decodedepthmacro(dp_texture2D(Texture_ShadowMap2D, center + vec2(x, y)*ShadowMap_TextureScale))\n",
909 "#    if USESHADOWMAPPCF > 1\n",
910 "       vec2 center = shadowmaptc.xy - 0.5, offset = fract(center);\n",
911 "       center *= ShadowMap_TextureScale;\n",
912 "       vec4 row1 = step(shadowmaptc.z, vec4(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0), texval( 2.0, -1.0)));\n",
913 "       vec4 row2 = step(shadowmaptc.z, vec4(texval(-1.0,  0.0), texval( 0.0,  0.0), texval( 1.0,  0.0), texval( 2.0,  0.0)));\n",
914 "       vec4 row3 = step(shadowmaptc.z, vec4(texval(-1.0,  1.0), texval( 0.0,  1.0), texval( 1.0,  1.0), texval( 2.0,  1.0)));\n",
915 "       vec4 row4 = step(shadowmaptc.z, vec4(texval(-1.0,  2.0), texval( 0.0,  2.0), texval( 1.0,  2.0), texval( 2.0,  2.0)));\n",
916 "       vec4 cols = row2 + row3 + mix(row1, row4, offset.y);\n",
917 "       f = dot(mix(cols.xyz, cols.yzw, offset.x), vec3(1.0/9.0));\n",
918 "#    else\n",
919 "       vec2 center = shadowmaptc.xy*ShadowMap_TextureScale, offset = fract(shadowmaptc.xy);\n",
920 "       vec3 row1 = step(shadowmaptc.z, vec3(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0)));\n",
921 "       vec3 row2 = step(shadowmaptc.z, vec3(texval(-1.0,  0.0), texval( 0.0,  0.0), texval( 1.0,  0.0)));\n",
922 "       vec3 row3 = step(shadowmaptc.z, vec3(texval(-1.0,  1.0), texval( 0.0,  1.0), texval( 1.0,  1.0)));\n",
923 "       vec3 cols = row2 + mix(row1, row3, offset.y);\n",
924 "       f = dot(mix(cols.xy, cols.yz, offset.x), vec2(0.25));\n",
925 "#    endif\n",
926 "#   else\n",
927 "       f = step(shadowmaptc.z, decodedepthmacro(dp_texture2D(Texture_ShadowMap2D, shadowmaptc.xy*ShadowMap_TextureScale)));\n",
928 "#   endif\n",
929 "#  else\n",
930 "#   ifdef USESHADOWSAMPLER\n",
931 "#     ifdef USESHADOWMAPPCF\n",
932 "#       define texval(off) dp_shadow2D(Texture_ShadowMap2D, vec3(off, shadowmaptc.z))  \n",
933 "       vec2 offset = fract(shadowmaptc.xy - 0.5);\n",
934 "   vec4 size = vec4(offset + 1.0, 2.0 - offset);\n",
935 "#       if USESHADOWMAPPCF > 1\n",
936 "   vec2 center = (shadowmaptc.xy - offset + 0.5)*ShadowMap_TextureScale;\n",
937 "   vec4 weight = (vec4(-1.5, -1.5, 2.0, 2.0) + (shadowmaptc.xy - 0.5*offset).xyxy)*ShadowMap_TextureScale.xyxy;\n",
938 "       f = (1.0/25.0)*dot(size.zxzx*size.wwyy, vec4(texval(weight.xy), texval(weight.zy), texval(weight.xw), texval(weight.zw))) +\n",
939 "               (2.0/25.0)*dot(size, vec4(texval(vec2(weight.z, center.y)), texval(vec2(center.x, weight.w)), texval(vec2(weight.x, center.y)), texval(vec2(center.x, weight.y)))) +\n",
940 "               (4.0/25.0)*texval(center);\n",
941 "#       else\n",
942 "       vec4 weight = (vec4(1.0, 1.0, -0.5, -0.5) + (shadowmaptc.xy - 0.5*offset).xyxy)*ShadowMap_TextureScale.xyxy;\n",
943 "       f = (1.0/9.0)*dot(size.zxzx*size.wwyy, vec4(texval(weight.zw), texval(weight.xw), texval(weight.zy), texval(weight.xy)));\n",
944 "#       endif        \n",
945 "#     else\n",
946 "       f = dp_shadow2D(Texture_ShadowMap2D, vec3(shadowmaptc.xy*ShadowMap_TextureScale, shadowmaptc.z));\n",
947 "#     endif\n",
948 "#   else\n",
949 "#     ifdef USESHADOWMAPPCF\n",
950 "#      if defined(GL_ARB_texture_gather) || defined(GL_AMD_texture_texture4)\n",
951 "#       ifdef GL_ARB_texture_gather\n",
952 "#         define texval(x, y) textureGatherOffset(Texture_ShadowMap2D, center, ivec2(x, y))\n",
953 "#       else\n",
954 "#         define texval(x, y) texture4(Texture_ShadowMap2D, center + vec2(x, y)*ShadowMap_TextureScale)\n",
955 "#       endif\n",
956 "       vec2 offset = fract(shadowmaptc.xy - 0.5), center = (shadowmaptc.xy - offset)*ShadowMap_TextureScale;\n",
957 "#       if USESHADOWMAPPCF > 1\n",
958 "   vec4 group1 = step(shadowmaptc.z, texval(-2.0, -2.0));\n",
959 "   vec4 group2 = step(shadowmaptc.z, texval( 0.0, -2.0));\n",
960 "   vec4 group3 = step(shadowmaptc.z, texval( 2.0, -2.0));\n",
961 "   vec4 group4 = step(shadowmaptc.z, texval(-2.0,  0.0));\n",
962 "   vec4 group5 = step(shadowmaptc.z, texval( 0.0,  0.0));\n",
963 "   vec4 group6 = step(shadowmaptc.z, texval( 2.0,  0.0));\n",
964 "   vec4 group7 = step(shadowmaptc.z, texval(-2.0,  2.0));\n",
965 "   vec4 group8 = step(shadowmaptc.z, texval( 0.0,  2.0));\n",
966 "   vec4 group9 = step(shadowmaptc.z, texval( 2.0,  2.0));\n",
967 "       vec4 locols = vec4(group1.ab, group3.ab);\n",
968 "       vec4 hicols = vec4(group7.rg, group9.rg);\n",
969 "       locols.yz += group2.ab;\n",
970 "       hicols.yz += group8.rg;\n",
971 "       vec4 midcols = vec4(group1.rg, group3.rg) + vec4(group7.ab, group9.ab) +\n",
972 "                               vec4(group4.rg, group6.rg) + vec4(group4.ab, group6.ab) +\n",
973 "                               mix(locols, hicols, offset.y);\n",
974 "       vec4 cols = group5 + vec4(group2.rg, group8.ab);\n",
975 "       cols.xyz += mix(midcols.xyz, midcols.yzw, offset.x);\n",
976 "       f = dot(cols, vec4(1.0/25.0));\n",
977 "#      else\n",
978 "       vec4 group1 = step(shadowmaptc.z, texval(-1.0, -1.0));\n",
979 "       vec4 group2 = step(shadowmaptc.z, texval( 1.0, -1.0));\n",
980 "       vec4 group3 = step(shadowmaptc.z, texval(-1.0,  1.0));\n",
981 "       vec4 group4 = step(shadowmaptc.z, texval( 1.0,  1.0));\n",
982 "       vec4 cols = vec4(group1.rg, group2.rg) + vec4(group3.ab, group4.ab) +\n",
983 "                               mix(vec4(group1.ab, group2.ab), vec4(group3.rg, group4.rg), offset.y);\n",
984 "       f = dot(mix(cols.xyz, cols.yzw, offset.x), vec3(1.0/9.0));\n",
985 "#       endif\n",
986 "#      else\n",
987 "#       ifdef GL_EXT_gpu_shader4\n",
988 "#         define texval(x, y) dp_textureOffset(Texture_ShadowMap2D, center, x, y).r\n",
989 "#       else\n",
990 "#         define texval(x, y) dp_texture2D(Texture_ShadowMap2D, center + vec2(x, y)*ShadowMap_TextureScale).r  \n",
991 "#       endif\n",
992 "#       if USESHADOWMAPPCF > 1\n",
993 "       vec2 center = shadowmaptc.xy - 0.5, offset = fract(center);\n",
994 "       center *= ShadowMap_TextureScale;\n",
995 "       vec4 row1 = step(shadowmaptc.z, vec4(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0), texval( 2.0, -1.0)));\n",
996 "       vec4 row2 = step(shadowmaptc.z, vec4(texval(-1.0,  0.0), texval( 0.0,  0.0), texval( 1.0,  0.0), texval( 2.0,  0.0)));\n",
997 "       vec4 row3 = step(shadowmaptc.z, vec4(texval(-1.0,  1.0), texval( 0.0,  1.0), texval( 1.0,  1.0), texval( 2.0,  1.0)));\n",
998 "       vec4 row4 = step(shadowmaptc.z, vec4(texval(-1.0,  2.0), texval( 0.0,  2.0), texval( 1.0,  2.0), texval( 2.0,  2.0)));\n",
999 "       vec4 cols = row2 + row3 + mix(row1, row4, offset.y);\n",
1000 "       f = dot(mix(cols.xyz, cols.yzw, offset.x), vec3(1.0/9.0));\n",
1001 "#       else\n",
1002 "       vec2 center = shadowmaptc.xy*ShadowMap_TextureScale, offset = fract(shadowmaptc.xy);\n",
1003 "       vec3 row1 = step(shadowmaptc.z, vec3(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0)));\n",
1004 "       vec3 row2 = step(shadowmaptc.z, vec3(texval(-1.0,  0.0), texval( 0.0,  0.0), texval( 1.0,  0.0)));\n",
1005 "       vec3 row3 = step(shadowmaptc.z, vec3(texval(-1.0,  1.0), texval( 0.0,  1.0), texval( 1.0,  1.0)));\n",
1006 "       vec3 cols = row2 + mix(row1, row3, offset.y);\n",
1007 "       f = dot(mix(cols.xy, cols.yz, offset.x), vec2(0.25));\n",
1008 "#       endif\n",
1009 "#      endif\n",
1010 "#     else\n",
1011 "       f = step(shadowmaptc.z, dp_texture2D(Texture_ShadowMap2D, shadowmaptc.xy*ShadowMap_TextureScale).r);\n",
1012 "#     endif\n",
1013 "#   endif\n",
1014 "#  endif\n",
1015 "#  ifdef USESHADOWMAPORTHO\n",
1016 "       return mix(ShadowMap_Parameters.w, 1.0, f);\n",
1017 "#  else\n",
1018 "       return f;\n",
1019 "#  endif\n",
1020 "}\n",
1021 "# endif\n",
1022 "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n",
1023 "#endif // FRAGMENT_SHADER\n",
1024 "\n",
1025 "\n",
1026 "\n",
1027 "\n",
1028 "#ifdef MODE_DEFERREDGEOMETRY\n",
1029 "#ifdef VERTEX_SHADER\n",
1030 "uniform highp mat4 TexMatrix;\n",
1031 "#ifdef USEVERTEXTEXTUREBLEND\n",
1032 "uniform highp mat4 BackgroundTexMatrix;\n",
1033 "#endif\n",
1034 "uniform highp mat4 ModelViewMatrix;\n",
1035 "void main(void)\n",
1036 "{\n",
1037 "#ifdef USESKELETAL\n",
1038 "       ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n",
1039 "       ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n",
1040 "       ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n",
1041 "       vec4 sw = Attrib_SkeletalWeight;\n",
1042 "       vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n",
1043 "       vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n",
1044 "       vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n",
1045 "       mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n",
1046 "       mat3 SkeletalNormalMatrix = mat3(cross(SkeletalMatrix[1].xyz, SkeletalMatrix[2].xyz), cross(SkeletalMatrix[2].xyz, SkeletalMatrix[0].xyz), cross(SkeletalMatrix[0].xyz, SkeletalMatrix[1].xyz)); // is actually transpose(inverse(mat3(SkeletalMatrix))) * det(mat3(SkeletalMatrix))\n",
1047 "       vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n",
1048 "       vec3 SkeletalSVector = normalize(Attrib_TexCoord1.xyz * SkeletalNormalMatrix);\n",
1049 "       vec3 SkeletalTVector = normalize(Attrib_TexCoord2.xyz * SkeletalNormalMatrix);\n",
1050 "       vec3 SkeletalNormal  = normalize(Attrib_TexCoord3.xyz * SkeletalNormalMatrix);\n",
1051 "#define Attrib_Position SkeletalVertex\n",
1052 "#define Attrib_TexCoord1 SkeletalSVector\n",
1053 "#define Attrib_TexCoord2 SkeletalTVector\n",
1054 "#define Attrib_TexCoord3 SkeletalNormal\n",
1055 "#endif\n",
1056 "       TexCoordSurfaceLightmap = vec4((TexMatrix * Attrib_TexCoord0).xy, 0.0, 0.0);\n",
1057 "#ifdef USEVERTEXTEXTUREBLEND\n",
1058 "       VertexColor = Attrib_Color;\n",
1059 "       TexCoord2 = vec2(BackgroundTexMatrix * Attrib_TexCoord0);\n",
1060 "#endif\n",
1061 "\n",
1062 "       // transform unnormalized eye direction into tangent space\n",
1063 "#ifdef USEOFFSETMAPPING\n",
1064 "       vec3 EyeRelative = EyePosition - Attrib_Position.xyz;\n",
1065 "       EyeVectorFogDepth.x = dot(EyeRelative, Attrib_TexCoord1.xyz);\n",
1066 "       EyeVectorFogDepth.y = dot(EyeRelative, Attrib_TexCoord2.xyz);\n",
1067 "       EyeVectorFogDepth.z = dot(EyeRelative, Attrib_TexCoord3.xyz);\n",
1068 "       EyeVectorFogDepth.w = 0.0;\n",
1069 "#endif\n",
1070 "\n",
1071 "       VectorS = (ModelViewMatrix * vec4(Attrib_TexCoord1.xyz, 0));\n",
1072 "       VectorT = (ModelViewMatrix * vec4(Attrib_TexCoord2.xyz, 0));\n",
1073 "       VectorR = (ModelViewMatrix * vec4(Attrib_TexCoord3.xyz, 0));\n",
1074 "       gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
1075 "#ifdef USETRIPPY\n",
1076 "       gl_Position = TrippyVertex(gl_Position);\n",
1077 "#endif\n",
1078 "       Depth = (ModelViewMatrix * Attrib_Position).z;\n",
1079 "}\n",
1080 "#endif // VERTEX_SHADER\n",
1081 "\n",
1082 "#ifdef FRAGMENT_SHADER\n",
1083 "void main(void)\n",
1084 "{\n",
1085 "#ifdef USEOFFSETMAPPING\n",
1086 "       // apply offsetmapping\n",
1087 "       vec2 dPdx = dp_offsetmapping_dFdx(TexCoordSurfaceLightmap.xy);\n",
1088 "       vec2 dPdy = dp_offsetmapping_dFdy(TexCoordSurfaceLightmap.xy);\n",
1089 "       vec2 TexCoordOffset = OffsetMapping(TexCoordSurfaceLightmap.xy, dPdx, dPdy);\n",
1090 "# define offsetMappedTexture2D(t) dp_textureGrad(t, TexCoordOffset, dPdx, dPdy)\n",
1091 "#else\n",
1092 "# define offsetMappedTexture2D(t) dp_texture2D(t, TexCoordSurfaceLightmap.xy)\n",
1093 "#endif\n",
1094 "\n",
1095 "#ifdef USEALPHAKILL\n",
1096 "       if (offsetMappedTexture2D(Texture_Color).a < 0.5)\n",
1097 "               discard;\n",
1098 "#endif\n",
1099 "\n",
1100 "#ifdef USEVERTEXTEXTUREBLEND\n",
1101 "       float alpha = offsetMappedTexture2D(Texture_Color).a;\n",
1102 "       float terrainblend = clamp(float(VertexColor.a) * alpha * 2.0 - 0.5, float(0.0), float(1.0));\n",
1103 "       //float terrainblend = min(float(VertexColor.a) * alpha * 2.0, float(1.0));\n",
1104 "       //float terrainblend = float(VertexColor.a) * alpha > 0.5;\n",
1105 "#endif\n",
1106 "\n",
1107 "#ifdef USEVERTEXTEXTUREBLEND\n",
1108 "       vec3 surfacenormal = mix(vec3(dp_texture2D(Texture_SecondaryNormal, TexCoord2)), vec3(offsetMappedTexture2D(Texture_Normal)), terrainblend) - vec3(0.5, 0.5, 0.5);\n",
1109 "       float a = mix(dp_texture2D(Texture_SecondaryGloss, TexCoord2).a, offsetMappedTexture2D(Texture_Gloss).a, terrainblend);\n",
1110 "#else\n",
1111 "       vec3 surfacenormal = vec3(offsetMappedTexture2D(Texture_Normal)) - vec3(0.5, 0.5, 0.5);\n",
1112 "       float a = offsetMappedTexture2D(Texture_Gloss).a;\n",
1113 "#endif\n",
1114 "\n",
1115 "       vec3 pixelnormal = normalize(surfacenormal.x * VectorS.xyz + surfacenormal.y * VectorT.xyz + surfacenormal.z * VectorR.xyz);\n",
1116 "       dp_FragColor = vec4(pixelnormal.x, pixelnormal.y, Depth, a);\n",
1117 "}\n",
1118 "#endif // FRAGMENT_SHADER\n",
1119 "#else // !MODE_DEFERREDGEOMETRY\n",
1120 "\n",
1121 "\n",
1122 "\n",
1123 "\n",
1124 "#ifdef MODE_DEFERREDLIGHTSOURCE\n",
1125 "#ifdef VERTEX_SHADER\n",
1126 "uniform highp mat4 ModelViewMatrix;\n",
1127 "void main(void)\n",
1128 "{\n",
1129 "       ModelViewPosition = ModelViewMatrix * Attrib_Position;\n",
1130 "       gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
1131 "}\n",
1132 "#endif // VERTEX_SHADER\n",
1133 "\n",
1134 "#ifdef FRAGMENT_SHADER\n",
1135 "uniform highp mat4 ViewToLight;\n",
1136 "// ScreenToDepth = vec2(Far / (Far - Near), Far * Near / (Near - Far));\n",
1137 "uniform highp vec2 ScreenToDepth;\n",
1138 "uniform myhalf3 DeferredColor_Ambient;\n",
1139 "uniform myhalf3 DeferredColor_Diffuse;\n",
1140 "#ifdef USESPECULAR\n",
1141 "uniform myhalf3 DeferredColor_Specular;\n",
1142 "uniform myhalf SpecularPower;\n",
1143 "#endif\n",
1144 "uniform myhalf2 PixelToScreenTexCoord;\n",
1145 "void main(void)\n",
1146 "{\n",
1147 "       // calculate viewspace pixel position\n",
1148 "       vec2 ScreenTexCoord = gl_FragCoord.xy * PixelToScreenTexCoord;\n",
1149 "       vec3 position;\n",
1150 "       // get the geometry information (depth, normal, specular exponent)\n",
1151 "       myhalf4 normalmap = dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord);\n",
1152 "       // decode viewspace pixel normal\n",
1153 "//     myhalf3 surfacenormal = normalize(normalmap.rgb - cast_myhalf3(0.5,0.5,0.5));\n",
1154 "       myhalf3 surfacenormal = myhalf3(normalmap.rg, sqrt(1.0-dot(normalmap.rg, normalmap.rg)));\n",
1155 "       // decode viewspace pixel position\n",
1156 "//     position.z = decodedepthmacro(dp_texture2D(Texture_ScreenDepth, ScreenTexCoord));\n",
1157 "       position.z = normalmap.b;\n",
1158 "//     position.z = ScreenToDepth.y / (dp_texture2D(Texture_ScreenDepth, ScreenTexCoord).r + ScreenToDepth.x);\n",
1159 "       position.xy = ModelViewPosition.xy * (position.z / ModelViewPosition.z);\n",
1160 "\n",
1161 "       // now do the actual shading\n",
1162 "       // surfacenormal = pixel normal in viewspace\n",
1163 "       // LightVector = pixel to light in viewspace\n",
1164 "       // CubeVector = pixel in lightspace\n",
1165 "       // eyenormal = pixel to view direction in viewspace\n",
1166 "       vec3 CubeVector = vec3(ViewToLight * vec4(position,1));\n",
1167 "       myhalf fade = cast_myhalf(dp_texture2D(Texture_Attenuation, vec2(length(CubeVector), 0.0)));\n",
1168 "#ifdef USEDIFFUSE\n",
1169 "       // calculate diffuse shading\n",
1170 "       myhalf3 lightnormal = cast_myhalf3(normalize(LightPosition - position));\n",
1171 "SHADEDIFFUSE\n",
1172 "#endif\n",
1173 "#ifdef USESPECULAR\n",
1174 "       // calculate directional shading\n",
1175 "       myhalf3 eyenormal = -normalize(cast_myhalf3(position));\n",
1176 "SHADESPECULAR(SpecularPower * normalmap.a)\n",
1177 "#endif\n",
1178 "\n",
1179 "#if defined(USESHADOWMAP2D)\n",
1180 "       fade *= ShadowMapCompare(CubeVector);\n",
1181 "#endif\n",
1182 "\n",
1183 "#ifdef USESPECULAR\n",
1184 "       gl_FragData[0] = vec4((DeferredColor_Ambient + DeferredColor_Diffuse * diffuse) * fade, 1.0);\n",
1185 "       gl_FragData[1] = vec4(DeferredColor_Specular * (specular * fade), 1.0);\n",
1186 "# ifdef USECUBEFILTER\n",
1187 "       vec3 cubecolor = dp_textureCube(Texture_Cube, CubeVector).rgb;\n",
1188 "       gl_FragData[0].rgb *= cubecolor;\n",
1189 "       gl_FragData[1].rgb *= cubecolor;\n",
1190 "# endif\n",
1191 "#else\n",
1192 "# ifdef USEDIFFUSE\n",
1193 "       gl_FragColor = vec4((DeferredColor_Ambient + DeferredColor_Diffuse * diffuse) * fade, 1.0);\n",
1194 "# else\n",
1195 "       gl_FragColor = vec4(DeferredColor_Ambient * fade, 1.0);\n",
1196 "# endif\n",
1197 "# ifdef USECUBEFILTER\n",
1198 "       vec3 cubecolor = dp_textureCube(Texture_Cube, CubeVector).rgb;\n",
1199 "       gl_FragColor.rgb *= cubecolor;\n",
1200 "# endif\n",
1201 "#endif\n",
1202 "}\n",
1203 "#endif // FRAGMENT_SHADER\n",
1204 "#else // !MODE_DEFERREDLIGHTSOURCE\n",
1205 "\n",
1206 "\n",
1207 "\n",
1208 "\n",
1209 "#ifdef VERTEX_SHADER\n",
1210 "uniform highp mat4 TexMatrix;\n",
1211 "#ifdef USEVERTEXTEXTUREBLEND\n",
1212 "uniform highp mat4 BackgroundTexMatrix;\n",
1213 "#endif\n",
1214 "#ifdef MODE_LIGHTSOURCE\n",
1215 "uniform highp mat4 ModelToLight;\n",
1216 "#endif\n",
1217 "#ifdef USESHADOWMAPORTHO\n",
1218 "uniform highp mat4 ShadowMapMatrix;\n",
1219 "#endif\n",
1220 "#ifdef USEBOUNCEGRID\n",
1221 "uniform highp mat4 BounceGridMatrix;\n",
1222 "#endif\n",
1223 "void main(void)\n",
1224 "{\n",
1225 "#ifdef USESKELETAL\n",
1226 "       ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n",
1227 "       ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n",
1228 "       ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n",
1229 "       vec4 sw = Attrib_SkeletalWeight;\n",
1230 "       vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n",
1231 "       vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n",
1232 "       vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n",
1233 "       mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n",
1234 "//     ivec4 si = ivec4(Attrib_SkeletalIndex);\n",
1235 "//     mat4 SkeletalMatrix = Skeletal_Transform[si.x] * Attrib_SkeletalWeight.x + Skeletal_Transform[si.y] * Attrib_SkeletalWeight.y + Skeletal_Transform[si.z] * Attrib_SkeletalWeight.z + Skeletal_Transform[si.w] * Attrib_SkeletalWeight.w;\n",
1236 "       mat3 SkeletalNormalMatrix = mat3(cross(SkeletalMatrix[1].xyz, SkeletalMatrix[2].xyz), cross(SkeletalMatrix[2].xyz, SkeletalMatrix[0].xyz), cross(SkeletalMatrix[0].xyz, SkeletalMatrix[1].xyz)); // is actually transpose(inverse(mat3(SkeletalMatrix))) * det(mat3(SkeletalMatrix))\n",
1237 "       vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n",
1238 "       SkeletalVertex.w = 1.0;\n",
1239 "       vec3 SkeletalSVector = normalize(Attrib_TexCoord1.xyz * SkeletalNormalMatrix);\n",
1240 "       vec3 SkeletalTVector = normalize(Attrib_TexCoord2.xyz * SkeletalNormalMatrix);\n",
1241 "       vec3 SkeletalNormal  = normalize(Attrib_TexCoord3.xyz * SkeletalNormalMatrix);\n",
1242 "#define Attrib_Position SkeletalVertex\n",
1243 "#define Attrib_TexCoord1 SkeletalSVector\n",
1244 "#define Attrib_TexCoord2 SkeletalTVector\n",
1245 "#define Attrib_TexCoord3 SkeletalNormal\n",
1246 "#endif\n",
1247 "\n",
1248 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR) || defined(USEALPHAGENVERTEX)\n",
1249 "       VertexColor = Attrib_Color;\n",
1250 "#endif\n",
1251 "       // copy the surface texcoord\n",
1252 "#ifdef USELIGHTMAP\n",
1253 "       TexCoordSurfaceLightmap = vec4((TexMatrix * Attrib_TexCoord0).xy, Attrib_TexCoord4.xy);\n",
1254 "#else\n",
1255 "       TexCoordSurfaceLightmap = vec4((TexMatrix * Attrib_TexCoord0).xy, 0.0, 0.0);\n",
1256 "#endif\n",
1257 "#ifdef USEVERTEXTEXTUREBLEND\n",
1258 "       TexCoord2 = vec2(BackgroundTexMatrix * Attrib_TexCoord0);\n",
1259 "#endif\n",
1260 "\n",
1261 "#ifdef USEBOUNCEGRID\n",
1262 "       BounceGridTexCoord = vec3(BounceGridMatrix * Attrib_Position);\n",
1263 "#ifdef USEBOUNCEGRIDDIRECTIONAL\n",
1264 "       BounceGridTexCoord.z *= 0.125;\n",
1265 "#endif\n",
1266 "#endif\n",
1267 "\n",
1268 "#ifdef MODE_LIGHTSOURCE\n",
1269 "       // transform vertex position into light attenuation/cubemap space\n",
1270 "       // (-1 to +1 across the light box)\n",
1271 "       CubeVector = vec3(ModelToLight * Attrib_Position);\n",
1272 "\n",
1273 "# ifdef USEDIFFUSE\n",
1274 "       // transform unnormalized light direction into tangent space\n",
1275 "       // (we use unnormalized to ensure that it interpolates correctly and then\n",
1276 "       //  normalize it per pixel)\n",
1277 "       vec3 lightminusvertex = LightPosition - Attrib_Position.xyz;\n",
1278 "       LightVector.x = dot(lightminusvertex, Attrib_TexCoord1.xyz);\n",
1279 "       LightVector.y = dot(lightminusvertex, Attrib_TexCoord2.xyz);\n",
1280 "       LightVector.z = dot(lightminusvertex, Attrib_TexCoord3.xyz);\n",
1281 "# endif\n",
1282 "#endif\n",
1283 "\n",
1284 "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE)\n",
1285 "       LightVector.x = dot(LightDir, Attrib_TexCoord1.xyz);\n",
1286 "       LightVector.y = dot(LightDir, Attrib_TexCoord2.xyz);\n",
1287 "       LightVector.z = dot(LightDir, Attrib_TexCoord3.xyz);\n",
1288 "#endif\n",
1289 "\n",
1290 "       // transform unnormalized eye direction into tangent space\n",
1291 "#ifdef USEEYEVECTOR\n",
1292 "       vec3 EyeRelative = EyePosition - Attrib_Position.xyz;\n",
1293 "       EyeVectorFogDepth.x = dot(EyeRelative, Attrib_TexCoord1.xyz);\n",
1294 "       EyeVectorFogDepth.y = dot(EyeRelative, Attrib_TexCoord2.xyz);\n",
1295 "       EyeVectorFogDepth.z = dot(EyeRelative, Attrib_TexCoord3.xyz);\n",
1296 "#ifdef USEFOG\n",
1297 "       EyeVectorFogDepth.w = dot(FogPlane, Attrib_Position);\n",
1298 "#else\n",
1299 "       EyeVectorFogDepth.w = 0.0;\n",
1300 "#endif\n",
1301 "#endif\n",
1302 "\n",
1303 "\n",
1304 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(USEREFLECTCUBE) || defined(USEBOUNCEGRIDDIRECTIONAL)\n",
1305 "# ifdef USEFOG\n",
1306 "       VectorS = vec4(Attrib_TexCoord1.xyz, EyePosition.x - Attrib_Position.x);\n",
1307 "       VectorT = vec4(Attrib_TexCoord2.xyz, EyePosition.y - Attrib_Position.y);\n",
1308 "       VectorR = vec4(Attrib_TexCoord3.xyz, EyePosition.z - Attrib_Position.z);\n",
1309 "# else\n",
1310 "       VectorS = vec4(Attrib_TexCoord1, 0);\n",
1311 "       VectorT = vec4(Attrib_TexCoord2, 0);\n",
1312 "       VectorR = vec4(Attrib_TexCoord3, 0);\n",
1313 "# endif\n",
1314 "#else\n",
1315 "# ifdef USEFOG\n",
1316 "       EyeVectorModelSpace = EyePosition - Attrib_Position.xyz;\n",
1317 "# endif\n",
1318 "#endif\n",
1319 "\n",
1320 "       // transform vertex to clipspace (post-projection, but before perspective divide by W occurs)\n",
1321 "       gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
1322 "\n",
1323 "#ifdef USESHADOWMAPORTHO\n",
1324 "       ShadowMapTC = vec3(ShadowMapMatrix * gl_Position);\n",
1325 "#endif\n",
1326 "\n",
1327 "#ifdef USEREFLECTION\n",
1328 "       ModelViewProjectionPosition = gl_Position;\n",
1329 "#endif\n",
1330 "#ifdef USETRIPPY\n",
1331 "       gl_Position = TrippyVertex(gl_Position);\n",
1332 "#endif\n",
1333 "}\n",
1334 "#endif // VERTEX_SHADER\n",
1335 "\n",
1336 "\n",
1337 "\n",
1338 "\n",
1339 "#ifdef FRAGMENT_SHADER\n",
1340 "#ifdef USEDEFERREDLIGHTMAP\n",
1341 "uniform myhalf2 PixelToScreenTexCoord;\n",
1342 "uniform myhalf3 DeferredMod_Diffuse;\n",
1343 "uniform myhalf3 DeferredMod_Specular;\n",
1344 "#endif\n",
1345 "uniform myhalf3 Color_Ambient;\n",
1346 "uniform myhalf3 Color_Diffuse;\n",
1347 "uniform myhalf3 Color_Specular;\n",
1348 "uniform myhalf SpecularPower;\n",
1349 "#ifdef USEGLOW\n",
1350 "uniform myhalf3 Color_Glow;\n",
1351 "#endif\n",
1352 "uniform myhalf Alpha;\n",
1353 "#ifdef USEREFLECTION\n",
1354 "uniform mediump vec4 DistortScaleRefractReflect;\n",
1355 "uniform mediump vec4 ScreenScaleRefractReflect;\n",
1356 "uniform mediump vec4 ScreenCenterRefractReflect;\n",
1357 "uniform mediump vec4 ReflectColor;\n",
1358 "#endif\n",
1359 "#ifdef USEREFLECTCUBE\n",
1360 "uniform highp mat4 ModelToReflectCube;\n",
1361 "uniform sampler2D Texture_ReflectMask;\n",
1362 "uniform samplerCube Texture_ReflectCube;\n",
1363 "#endif\n",
1364 "#ifdef MODE_LIGHTDIRECTION\n",
1365 "uniform myhalf3 LightColor;\n",
1366 "#endif\n",
1367 "#ifdef MODE_LIGHTSOURCE\n",
1368 "uniform myhalf3 LightColor;\n",
1369 "#endif\n",
1370 "#ifdef USEBOUNCEGRID\n",
1371 "uniform sampler3D Texture_BounceGrid;\n",
1372 "uniform float BounceGridIntensity;\n",
1373 "uniform highp mat4 BounceGridMatrix;\n",
1374 "#endif\n",
1375 "uniform highp float ClientTime;\n",
1376 "#ifdef USENORMALMAPSCROLLBLEND\n",
1377 "uniform highp vec2 NormalmapScrollBlend;\n",
1378 "#endif\n",
1379 "void main(void)\n",
1380 "{\n",
1381 "#ifdef USEOFFSETMAPPING\n",
1382 "       // apply offsetmapping\n",
1383 "       vec2 dPdx = dp_offsetmapping_dFdx(TexCoordSurfaceLightmap.xy);\n",
1384 "       vec2 dPdy = dp_offsetmapping_dFdy(TexCoordSurfaceLightmap.xy);\n",
1385 "       vec2 TexCoordOffset = OffsetMapping(TexCoordSurfaceLightmap.xy, dPdx, dPdy);\n",
1386 "# define offsetMappedTexture2D(t) dp_textureGrad(t, TexCoordOffset, dPdx, dPdy)\n",
1387 "# define TexCoord TexCoordOffset\n",
1388 "#else\n",
1389 "# define offsetMappedTexture2D(t) dp_texture2D(t, TexCoordSurfaceLightmap.xy)\n",
1390 "# define TexCoord TexCoordSurfaceLightmap.xy\n",
1391 "#endif\n",
1392 "\n",
1393 "       // combine the diffuse textures (base, pants, shirt)\n",
1394 "       myhalf4 color = cast_myhalf4(offsetMappedTexture2D(Texture_Color));\n",
1395 "#ifdef USEALPHAKILL\n",
1396 "       if (color.a < 0.5)\n",
1397 "               discard;\n",
1398 "#endif\n",
1399 "       color.a *= Alpha;\n",
1400 "#ifdef USECOLORMAPPING\n",
1401 "       color.rgb += cast_myhalf3(offsetMappedTexture2D(Texture_Pants)) * Color_Pants + cast_myhalf3(offsetMappedTexture2D(Texture_Shirt)) * Color_Shirt;\n",
1402 "#endif\n",
1403 "#ifdef USEVERTEXTEXTUREBLEND\n",
1404 "#ifdef USEBOTHALPHAS\n",
1405 "       myhalf4 color2 = cast_myhalf4(dp_texture2D(Texture_SecondaryColor, TexCoord2));\n",
1406 "       myhalf terrainblend = clamp(cast_myhalf(VertexColor.a) * color.a, cast_myhalf(1.0 - color2.a), cast_myhalf(1.0));\n",
1407 "       color.rgb = mix(color2.rgb, color.rgb, terrainblend);\n",
1408 "#else\n",
1409 "       myhalf terrainblend = clamp(cast_myhalf(VertexColor.a) * color.a * 2.0 - 0.5, cast_myhalf(0.0), cast_myhalf(1.0));\n",
1410 "       //myhalf terrainblend = min(cast_myhalf(VertexColor.a) * color.a * 2.0, cast_myhalf(1.0));\n",
1411 "       //myhalf terrainblend = cast_myhalf(VertexColor.a) * color.a > 0.5;\n",
1412 "       color.rgb = mix(cast_myhalf3(dp_texture2D(Texture_SecondaryColor, TexCoord2)), color.rgb, terrainblend);\n",
1413 "#endif\n",
1414 "       color.a = 1.0;\n",
1415 "       //color = mix(cast_myhalf4(1, 0, 0, 1), color, terrainblend);\n",
1416 "#endif\n",
1417 "#ifdef USEALPHAGENVERTEX\n",
1418 "       color.a *= VertexColor.a;\n",
1419 "#endif\n",
1420 "\n",
1421 "       // get the surface normal\n",
1422 "#ifdef USEVERTEXTEXTUREBLEND\n",
1423 "       myhalf3 surfacenormal = normalize(mix(cast_myhalf3(dp_texture2D(Texture_SecondaryNormal, TexCoord2)), cast_myhalf3(offsetMappedTexture2D(Texture_Normal)), terrainblend) - cast_myhalf3(0.5, 0.5, 0.5));\n",
1424 "#else\n",
1425 "       myhalf3 surfacenormal = normalize(cast_myhalf3(offsetMappedTexture2D(Texture_Normal)) - cast_myhalf3(0.5, 0.5, 0.5));\n",
1426 "#endif\n",
1427 "\n",
1428 "       // get the material colors\n",
1429 "       myhalf3 diffusetex = color.rgb;\n",
1430 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n",
1431 "# ifdef USEVERTEXTEXTUREBLEND\n",
1432 "       myhalf4 glosstex = mix(cast_myhalf4(dp_texture2D(Texture_SecondaryGloss, TexCoord2)), cast_myhalf4(offsetMappedTexture2D(Texture_Gloss)), terrainblend);\n",
1433 "# else\n",
1434 "       myhalf4 glosstex = cast_myhalf4(offsetMappedTexture2D(Texture_Gloss));\n",
1435 "# endif\n",
1436 "#endif\n",
1437 "\n",
1438 "#ifdef USEREFLECTCUBE\n",
1439 "       vec3 TangentReflectVector = reflect(-EyeVectorFogDepth.xyz, surfacenormal);\n",
1440 "       vec3 ModelReflectVector = TangentReflectVector.x * VectorS.xyz + TangentReflectVector.y * VectorT.xyz + TangentReflectVector.z * VectorR.xyz;\n",
1441 "       vec3 ReflectCubeTexCoord = vec3(ModelToReflectCube * vec4(ModelReflectVector, 0));\n",
1442 "       diffusetex += cast_myhalf3(offsetMappedTexture2D(Texture_ReflectMask)) * cast_myhalf3(dp_textureCube(Texture_ReflectCube, ReflectCubeTexCoord));\n",
1443 "#endif\n",
1444 "\n",
1445 "#ifdef USESPECULAR\n",
1446 "       myhalf3 eyenormal = normalize(cast_myhalf3(EyeVectorFogDepth.xyz));\n",
1447 "#endif\n",
1448 "\n",
1449 "\n",
1450 "\n",
1451 "\n",
1452 "#ifdef MODE_LIGHTSOURCE\n",
1453 "       // light source\n",
1454 "#ifdef USEDIFFUSE\n",
1455 "       myhalf3 lightnormal = cast_myhalf3(normalize(LightVector));\n",
1456 "SHADEDIFFUSE\n",
1457 "       color.rgb = diffusetex * (Color_Ambient + diffuse * Color_Diffuse);\n",
1458 "#ifdef USESPECULAR\n",
1459 "SHADESPECULAR(SpecularPower * glosstex.a)\n",
1460 "       color.rgb += glosstex.rgb * (specular * Color_Specular);\n",
1461 "#endif\n",
1462 "#else\n",
1463 "       color.rgb = diffusetex * Color_Ambient;\n",
1464 "#endif\n",
1465 "       color.rgb *= LightColor;\n",
1466 "       color.rgb *= cast_myhalf(dp_texture2D(Texture_Attenuation, vec2(length(CubeVector), 0.0)));\n",
1467 "#if defined(USESHADOWMAP2D)\n",
1468 "       color.rgb *= ShadowMapCompare(CubeVector);\n",
1469 "#endif\n",
1470 "# ifdef USECUBEFILTER\n",
1471 "       color.rgb *= cast_myhalf3(dp_textureCube(Texture_Cube, CubeVector));\n",
1472 "# endif\n",
1473 "#endif // MODE_LIGHTSOURCE\n",
1474 "\n",
1475 "\n",
1476 "\n",
1477 "\n",
1478 "#ifdef MODE_LIGHTDIRECTION\n",
1479 "       #define SHADING\n",
1480 "       #ifdef USEDIFFUSE\n",
1481 "               myhalf3 lightnormal = cast_myhalf3(normalize(LightVector));\n",
1482 "       #endif\n",
1483 "       #define lightcolor LightColor\n",
1484 "#endif // MODE_LIGHTDIRECTION\n",
1485 "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n",
1486 "   #define SHADING\n",
1487 "       // deluxemap lightmapping using light vectors in modelspace (q3map2 -light -deluxe)\n",
1488 "       myhalf3 lightnormal_modelspace = cast_myhalf3(dp_texture2D(Texture_Deluxemap, TexCoordSurfaceLightmap.zw)) * 2.0 + cast_myhalf3(-1.0, -1.0, -1.0);\n",
1489 "       myhalf3 lightcolor = cast_myhalf3(dp_texture2D(Texture_Lightmap, TexCoordSurfaceLightmap.zw));\n",
1490 "       // convert modelspace light vector to tangentspace\n",
1491 "       myhalf3 lightnormal;\n",
1492 "       lightnormal.x = dot(lightnormal_modelspace, cast_myhalf3(VectorS));\n",
1493 "       lightnormal.y = dot(lightnormal_modelspace, cast_myhalf3(VectorT));\n",
1494 "       lightnormal.z = dot(lightnormal_modelspace, cast_myhalf3(VectorR));\n",
1495 "       lightnormal = normalize(lightnormal); // VectorS/T/R are not always perfectly normalized, and EXACTSPECULARMATH is very picky about this\n",
1496 "       // calculate directional shading (and undoing the existing angle attenuation on the lightmap by the division)\n",
1497 "       // note that q3map2 is too stupid to calculate proper surface normals when q3map_nonplanar\n",
1498 "       // is used (the lightmap and deluxemap coords correspond to virtually random coordinates\n",
1499 "       // on that luxel, and NOT to its center, because recursive triangle subdivision is used\n",
1500 "       // to map the luxels to coordinates on the draw surfaces), which also causes\n",
1501 "       // deluxemaps to be wrong because light contributions from the wrong side of the surface\n",
1502 "       // are added up. To prevent divisions by zero or strong exaggerations, a max()\n",
1503 "       // nudge is done here at expense of some additional fps. This is ONLY needed for\n",
1504 "       // deluxemaps, tangentspace deluxemap avoid this problem by design.\n",
1505 "       lightcolor *= 1.0 / max(0.25, lightnormal.z);\n",
1506 "#endif // MODE_LIGHTDIRECTIONMAP_MODELSPACE\n",
1507 "#ifdef MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n",
1508 "   #define SHADING\n",
1509 "       // deluxemap lightmapping using light vectors in tangentspace (hmap2 -light)\n",
1510 "       myhalf3 lightnormal = cast_myhalf3(dp_texture2D(Texture_Deluxemap, TexCoordSurfaceLightmap.zw)) * 2.0 + cast_myhalf3(-1.0, -1.0, -1.0);\n",
1511 "       myhalf3 lightcolor = cast_myhalf3(dp_texture2D(Texture_Lightmap, TexCoordSurfaceLightmap.zw));\n",
1512 "#endif\n",
1513 "#if defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n",
1514 "       #define SHADING\n",
1515 "       // forced deluxemap on lightmapped/vertexlit surfaces\n",
1516 "       myhalf3 lightnormal = cast_myhalf3(0.0, 0.0, 1.0);\n",
1517 "   #ifdef USELIGHTMAP\n",
1518 "               myhalf3 lightcolor = cast_myhalf3(dp_texture2D(Texture_Lightmap, TexCoordSurfaceLightmap.zw));\n",
1519 "   #else\n",
1520 "               myhalf3 lightcolor = cast_myhalf3(VertexColor.rgb);\n",
1521 "   #endif\n",
1522 "#endif\n",
1523 "#ifdef MODE_FAKELIGHT\n",
1524 "       #define SHADING\n",
1525 "       myhalf3 lightnormal = cast_myhalf3(normalize(EyeVectorFogDepth.xyz));\n",
1526 "       myhalf3 lightcolor = cast_myhalf3(1.0);\n",
1527 "#endif // MODE_FAKELIGHT\n",
1528 "\n",
1529 "\n",
1530 "\n",
1531 "\n",
1532 "#ifdef MODE_LIGHTMAP\n",
1533 "       color.rgb = diffusetex * (Color_Ambient + cast_myhalf3(dp_texture2D(Texture_Lightmap, TexCoordSurfaceLightmap.zw)) * Color_Diffuse);\n",
1534 "#endif // MODE_LIGHTMAP\n",
1535 "#ifdef MODE_VERTEXCOLOR\n",
1536 "       color.rgb = diffusetex * (Color_Ambient + cast_myhalf3(VertexColor.rgb) * Color_Diffuse);\n",
1537 "#endif // MODE_VERTEXCOLOR\n",
1538 "#ifdef MODE_FLATCOLOR\n",
1539 "       color.rgb = diffusetex * Color_Ambient;\n",
1540 "#endif // MODE_FLATCOLOR\n",
1541 "\n",
1542 "\n",
1543 "\n",
1544 "\n",
1545 "#ifdef SHADING\n",
1546 "# ifdef USEDIFFUSE\n",
1547 "SHADEDIFFUSE\n",
1548 "#  ifdef USESPECULAR\n",
1549 "SHADESPECULAR(SpecularPower * glosstex.a)\n",
1550 "       color.rgb = diffusetex * Color_Ambient + (diffusetex * Color_Diffuse * diffuse + glosstex.rgb * Color_Specular * specular) * lightcolor;\n",
1551 "#  else\n",
1552 "       color.rgb = diffusetex * (Color_Ambient + Color_Diffuse * diffuse * lightcolor);\n",
1553 "#  endif\n",
1554 "# else\n",
1555 "       color.rgb = diffusetex * Color_Ambient;\n",
1556 "# endif\n",
1557 "#endif\n",
1558 "\n",
1559 "#ifdef USESHADOWMAPORTHO\n",
1560 "       color.rgb *= ShadowMapCompare(ShadowMapTC);\n",
1561 "#endif\n",
1562 "\n",
1563 "#ifdef USEDEFERREDLIGHTMAP\n",
1564 "       vec2 ScreenTexCoord = gl_FragCoord.xy * PixelToScreenTexCoord;\n",
1565 "       color.rgb += diffusetex * cast_myhalf3(dp_texture2D(Texture_ScreenDiffuse, ScreenTexCoord)) * DeferredMod_Diffuse;\n",
1566 "       color.rgb += glosstex.rgb * cast_myhalf3(dp_texture2D(Texture_ScreenSpecular, ScreenTexCoord)) * DeferredMod_Specular;\n",
1567 "//     color.rgb = dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord).rgb * vec3(1.0, 1.0, 0.001);\n",
1568 "#endif\n",
1569 "\n",
1570 "#ifdef USEBOUNCEGRID\n",
1571 "#ifdef USEBOUNCEGRIDDIRECTIONAL\n",
1572 "//     myhalf4 bouncegrid_coeff1 = cast_myhalf4(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord                        ));\n",
1573 "//     myhalf4 bouncegrid_coeff2 = cast_myhalf4(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord + vec3(0.0, 0.0, 0.125))) * 2.0 + cast_myhalf4(-1.0, -1.0, -1.0, -1.0);\n",
1574 "       myhalf4 bouncegrid_coeff3 = cast_myhalf4(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord + vec3(0.0, 0.0, 0.250)));\n",
1575 "       myhalf4 bouncegrid_coeff4 = cast_myhalf4(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord + vec3(0.0, 0.0, 0.375)));\n",
1576 "       myhalf4 bouncegrid_coeff5 = cast_myhalf4(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord + vec3(0.0, 0.0, 0.500)));\n",
1577 "       myhalf4 bouncegrid_coeff6 = cast_myhalf4(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord + vec3(0.0, 0.0, 0.625)));\n",
1578 "       myhalf4 bouncegrid_coeff7 = cast_myhalf4(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord + vec3(0.0, 0.0, 0.750)));\n",
1579 "       myhalf4 bouncegrid_coeff8 = cast_myhalf4(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord + vec3(0.0, 0.0, 0.875)));\n",
1580 "       myhalf3 bouncegrid_dir = normalize(mat3(BounceGridMatrix) * (surfacenormal.x * VectorS.xyz + surfacenormal.y * VectorT.xyz + surfacenormal.z * VectorR.xyz));\n",
1581 "       myhalf3 bouncegrid_dirp = max(cast_myhalf3(0.0, 0.0, 0.0), bouncegrid_dir);\n",
1582 "       myhalf3 bouncegrid_dirn = max(cast_myhalf3(0.0, 0.0, 0.0), -bouncegrid_dir);\n",
1583 "//     bouncegrid_dirp  = bouncegrid_dirn = cast_myhalf3(1.0,1.0,1.0);\n",
1584 "       myhalf3 bouncegrid_light = cast_myhalf3(\n",
1585 "               dot(bouncegrid_coeff3.xyz, bouncegrid_dirp) + dot(bouncegrid_coeff6.xyz, bouncegrid_dirn),\n",
1586 "               dot(bouncegrid_coeff4.xyz, bouncegrid_dirp) + dot(bouncegrid_coeff7.xyz, bouncegrid_dirn),\n",
1587 "               dot(bouncegrid_coeff5.xyz, bouncegrid_dirp) + dot(bouncegrid_coeff8.xyz, bouncegrid_dirn));\n",
1588 "       color.rgb += diffusetex * bouncegrid_light * BounceGridIntensity;\n",
1589 "//     color.rgb = bouncegrid_dir.rgb * 0.5 + vec3(0.5, 0.5, 0.5);\n",
1590 "#else\n",
1591 "       color.rgb += diffusetex * cast_myhalf3(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord)) * BounceGridIntensity;\n",
1592 "#endif\n",
1593 "#endif\n",
1594 "\n",
1595 "#ifdef USEGLOW\n",
1596 "#ifdef USEVERTEXTEXTUREBLEND\n",
1597 "       color.rgb += mix(cast_myhalf3(dp_texture2D(Texture_SecondaryGlow, TexCoord2)), cast_myhalf3(offsetMappedTexture2D(Texture_Glow)), terrainblend) * Color_Glow;\n",
1598 "#else\n",
1599 "       color.rgb += cast_myhalf3(offsetMappedTexture2D(Texture_Glow)) * Color_Glow;\n",
1600 "#endif\n",
1601 "#endif\n",
1602 "\n",
1603 "#ifdef USECELOUTLINES\n",
1604 "# ifdef USEDEFERREDLIGHTMAP\n",
1605 "//     vec2 ScreenTexCoord = gl_FragCoord.xy * PixelToScreenTexCoord;\n",
1606 "       vec4 ScreenTexCoordStep = vec4(PixelToScreenTexCoord.x, 0.0, 0.0, PixelToScreenTexCoord.y);\n",
1607 "       vec4 DepthNeighbors;\n",
1608 "\n",
1609 "       // enable to test ink on white geometry\n",
1610 "//     color.rgb = vec3(1.0, 1.0, 1.0);\n",
1611 "\n",
1612 "       // note: this seems to be negative\n",
1613 "       float DepthCenter = dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord).b;\n",
1614 "\n",
1615 "       // edge detect method\n",
1616 "//     DepthNeighbors.x = dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord - ScreenTexCoordStep.xy).b;\n",
1617 "//     DepthNeighbors.y = dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + ScreenTexCoordStep.xy).b;\n",
1618 "//     DepthNeighbors.z = dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + ScreenTexCoordStep.zw).b;\n",
1619 "//     DepthNeighbors.w = dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord - ScreenTexCoordStep.zw).b;\n",
1620 "//     float DepthAverage = dot(DepthNeighbors, vec4(0.25, 0.25, 0.25, 0.25));\n",
1621 "//     float DepthDelta = abs(dot(DepthNeighbors.xy, vec2(-1.0, 1.0))) + abs(dot(DepthNeighbors.zw, vec2(-1.0, 1.0)));\n",
1622 "//     color.rgb *= max(0.5, 1.0 - max(0.0, abs(DepthCenter - DepthAverage) - 0.2 * DepthDelta) / (0.01 + 0.2 * DepthDelta));\n",
1623 "//     color.rgb *= step(abs(DepthCenter - DepthAverage), 0.2 * DepthDelta); \n",
1624 "\n",
1625 "       // shadow method\n",
1626 "       float DepthScale1 = 4.0 / DepthCenter; // inner ink (shadow on object)\n",
1627 "//     float DepthScale1 = -4.0 / DepthCenter; // outer ink (shadow around object)\n",
1628 "//     float DepthScale1 = 0.003;\n",
1629 "       float DepthScale2 = DepthScale1 / 2.0;\n",
1630 "//     float DepthScale3 = DepthScale1 / 4.0;\n",
1631 "       float DepthBias1 = -DepthCenter * DepthScale1;\n",
1632 "       float DepthBias2 = -DepthCenter * DepthScale2;\n",
1633 "//     float DepthBias3 = -DepthCenter * DepthScale3;\n",
1634 "       float DepthShadow = max(0.0, dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2(-1.0,  0.0)).b * DepthScale1 + DepthBias1)\n",
1635 "                         + max(0.0, dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 1.0,  0.0)).b * DepthScale1 + DepthBias1)\n",
1636 "                         + max(0.0, dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 0.0, -1.0)).b * DepthScale1 + DepthBias1)\n",
1637 "                         + max(0.0, dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 0.0,  1.0)).b * DepthScale1 + DepthBias1)\n",
1638 "                         + max(0.0, dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2(-2.0,  0.0)).b * DepthScale2 + DepthBias2)\n",
1639 "                         + max(0.0, dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 2.0,  0.0)).b * DepthScale2 + DepthBias2)\n",
1640 "                         + max(0.0, dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 0.0, -2.0)).b * DepthScale2 + DepthBias2)\n",
1641 "                         + max(0.0, dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 0.0,  2.0)).b * DepthScale2 + DepthBias2)\n",
1642 "//                       + max(0.0, dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2(-3.0,  0.0)).b * DepthScale3 + DepthBias3)\n",
1643 "//                       + max(0.0, dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 3.0,  0.0)).b * DepthScale3 + DepthBias3)\n",
1644 "//                       + max(0.0, dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 0.0, -3.0)).b * DepthScale3 + DepthBias3)\n",
1645 "//                       + max(0.0, dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 0.0,  3.0)).b * DepthScale3 + DepthBias3)\n",
1646 "                         - 0.0;\n",
1647 "       color.rgb *= 1.0 - max(0.0, min(DepthShadow, 1.0));\n",
1648 "//     color.r = DepthCenter / -1024.0;\n",
1649 "# endif\n",
1650 "#endif\n",
1651 "\n",
1652 "#ifdef USEFOG\n",
1653 "       color.rgb = FogVertex(color);\n",
1654 "#endif\n",
1655 "\n",
1656 "       // reflection must come last because it already contains exactly the correct fog (the reflection render preserves camera distance from the plane, it only flips the side) and ContrastBoost/SceneBrightness\n",
1657 "#ifdef USEREFLECTION\n",
1658 "       vec4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n",
1659 "       //vec4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(cast_myhalf3(offsetMappedTexture2D(Texture_Normal)) - cast_myhalf3(0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
1660 "       vec2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW.zw + ScreenCenterRefractReflect.zw;\n",
1661 "       #ifdef USENORMALMAPSCROLLBLEND\n",
1662 "# ifdef USEOFFSETMAPPING\n",
1663 "               vec3 normal = dp_textureGrad(Texture_Normal, (TexCoord + vec2(0.08, 0.08)*ClientTime*NormalmapScrollBlend.x*0.5)*NormalmapScrollBlend.y, dPdx*NormalmapScrollBlend.y, dPdy*NormalmapScrollBlend.y).rgb - vec3(1.0);\n",
1664 "# else\n",
1665 "               vec3 normal = dp_texture2D(Texture_Normal, (TexCoord + vec2(0.08, 0.08)*ClientTime*NormalmapScrollBlend.x*0.5)*NormalmapScrollBlend.y).rgb - vec3(1.0);\n",
1666 "# endif\n",
1667 "               normal += dp_texture2D(Texture_Normal, (TexCoord + vec2(-0.06, -0.09)*ClientTime*NormalmapScrollBlend.x)*NormalmapScrollBlend.y*0.75).rgb;\n",
1668 "               vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(cast_myhalf3(normal))).xy * DistortScaleRefractReflect.zw;\n",
1669 "       #else\n",
1670 "               vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(cast_myhalf3(offsetMappedTexture2D(Texture_Normal)) - cast_myhalf3(0.5))).xy * DistortScaleRefractReflect.zw;\n",
1671 "       #endif\n",
1672 "       // FIXME temporary hack to detect the case that the reflection\n",
1673 "       // gets blackened at edges due to leaving the area that contains actual\n",
1674 "       // content.\n",
1675 "       // Remove this 'ack once we have a better way to stop this thing from\n",
1676 "       // 'appening.\n",
1677 "       float f = min(1.0, length(dp_texture2D(Texture_Reflection, ScreenTexCoord + vec2(0.01, 0.01)).rgb) / 0.05);\n",
1678 "       f      *= min(1.0, length(dp_texture2D(Texture_Reflection, ScreenTexCoord + vec2(0.01, -0.01)).rgb) / 0.05);\n",
1679 "       f      *= min(1.0, length(dp_texture2D(Texture_Reflection, ScreenTexCoord + vec2(-0.01, 0.01)).rgb) / 0.05);\n",
1680 "       f      *= min(1.0, length(dp_texture2D(Texture_Reflection, ScreenTexCoord + vec2(-0.01, -0.01)).rgb) / 0.05);\n",
1681 "       ScreenTexCoord = mix(SafeScreenTexCoord, ScreenTexCoord, f);\n",
1682 "       color.rgb = mix(color.rgb, cast_myhalf3(dp_texture2D(Texture_Reflection, ScreenTexCoord)) * ReflectColor.rgb, ReflectColor.a);\n",
1683 "#endif\n",
1684 "\n",
1685 "       dp_FragColor = vec4(color);\n",
1686 "}\n",
1687 "#endif // FRAGMENT_SHADER\n",
1688 "\n",
1689 "#endif // !MODE_DEFERREDLIGHTSOURCE\n",
1690 "#endif // !MODE_DEFERREDGEOMETRY\n",
1691 "#endif // !MODE_WATER\n",
1692 "#endif // !MODE_REFRACTION\n",
1693 "#endif // !MODE_BLOOMBLUR\n",
1694 "#endif // !MODE_GENERIC\n",
1695 "#endif // !MODE_POSTPROCESS\n",
1696 "#endif // !MODE_DEPTH_OR_SHADOW\n",