]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - shader_hlsl.h
Added DP_CSQC_ENTITYMODELLIGHT extension (CSQC-updated modellight using modellight_...
[xonotic/darkplaces.git] / shader_hlsl.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 "// FIXME: we need to get rid of ModelViewProjectionPosition to make room for the texcoord for this\n"
6 "#if defined(USEREFLECTION)\n"
7 "#undef USESHADOWMAPORTHO\n"
8 "#endif\n"
9 "\n"
10 "#if defined(USEFOGINSIDE) || defined(USEFOGOUTSIDE) || defined(USEFOGHEIGHTTEXTURE)\n"
11 "# define USEFOG\n"
12 "#endif\n"
13 "#if defined(MODE_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP)\n"
14 "#define USELIGHTMAP\n"
15 "#endif\n"
16 "#if defined(USESPECULAR) || defined(USEOFFSETMAPPING) || defined(USEREFLECTCUBE) || defined(MODE_FAKELIGHT)\n"
17 "#define USEEYEVECTOR\n"
18 "#endif\n"
19 "\n"
20 "#ifdef FRAGMENT_SHADER\n"
21 "#ifdef HLSL\n"
22 "//#undef USESHADOWMAPPCF\n"
23 "//#define texDepth2D(tex,texcoord) tex2D(tex,texcoord).r\n"
24 "#define texDepth2D(tex,texcoord) dot(tex2D(tex,texcoord).rgb, float3(1.0, 255.0/65536.0, 255.0/16777216.0))\n"
25 "#else\n"
26 "#define texDepth2D(tex,texcoord) tex2D(tex,texcoord).r\n"
27 "#endif\n"
28 "#endif\n"
29 "\n"
30 "#ifdef VERTEX_SHADER\n"
31 "#ifdef USETRIPPY\n"
32 "// LordHavoc: based on shader code linked at: http://www.youtube.com/watch?v=JpksyojwqzE\n"
33 "// tweaked scale\n"
34 "float4 TrippyVertex(float4 position)\n"
35 "(\n"
36 "uniform float ClientTime : register(c2)\n"
37 ")\n"
38 "{\n"
39 "       float worldTime = ClientTime;\n"
40 "       // tweaked for Quake\n"
41 "       worldTime *= 10.0;\n"
42 "       position *= 0.125;\n"
43 "       //~tweaked for Quake\n"
44 "       float distanceSquared = (position.x * position.x + position.z * position.z);\n"
45 "       position.y += 5.0*sin(distanceSquared*sin(worldTime/143.0)/1000.0);\n"
46 "       float y = position.y;\n"
47 "       float x = position.x;\n"
48 "       float om = sin(distanceSquared*sin(worldTime/256.0)/5000.0) * sin(worldTime/200.0);\n"
49 "       position.y = x*sin(om)+y*cos(om);\n"
50 "       position.x = x*cos(om)-y*sin(om);\n"
51 "       return position;\n"
52 "}\n"
53 "#endif\n"
54 "#endif\n"
55 "\n"
56 "#ifdef MODE_DEPTH_OR_SHADOW\n"
57 "#ifdef VERTEX_SHADER\n"
58 "void main\n"
59 "(\n"
60 "float4 gl_Vertex : POSITION,\n"
61 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
62 "out float4 gl_Position : POSITION,\n"
63 "out float Depth : TEXCOORD0\n"
64 ")\n"
65 "{\n"
66 "       gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
67 "#ifdef USETRIPPY\n"
68 "       gl_Position = TrippyVertex(gl_Position);\n"
69 "#endif\n"
70 "       Depth = gl_Position.z;\n"
71 "}\n"
72 "#endif\n"
73 "\n"
74 "#ifdef FRAGMENT_SHADER\n"
75 "void main\n"
76 "(\n"
77 "float Depth : TEXCOORD0,\n"
78 "out float4 gl_FragColor : COLOR\n"
79 ")\n"
80 "{\n"
81 "//     float4 temp = float4(Depth,Depth*(65536.0/255.0),Depth*(16777216.0/255.0),0.0);\n"
82 "       float4 temp = float4(Depth,Depth*256.0,Depth*65536.0,0.0);\n"
83 "       temp.yz -= floor(temp.yz);\n"
84 "       gl_FragColor = temp;\n"
85 "//     gl_FragColor = float4(Depth,0,0,0);\n"
86 "}\n"
87 "#endif\n"
88 "#else // !MODE_DEPTH_ORSHADOW\n"
89 "\n"
90 "\n"
91 "\n"
92 "\n"
93 "#ifdef MODE_SHOWDEPTH\n"
94 "#ifdef VERTEX_SHADER\n"
95 "void main\n"
96 "(\n"
97 "float4 gl_Vertex : POSITION,\n"
98 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
99 "out float4 gl_Position : POSITION,\n"
100 "out float4 gl_FrontColor : COLOR0\n"
101 ")\n"
102 "{\n"
103 "       gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
104 "#ifdef USETRIPPY\n"
105 "       gl_Position = TrippyVertex(gl_Position);\n"
106 "#endif\n"
107 "       gl_FrontColor = float4(gl_Position.z, gl_Position.z, gl_Position.z, 1.0);\n"
108 "}\n"
109 "#endif\n"
110 "\n"
111 "#ifdef FRAGMENT_SHADER\n"
112 "void main\n"
113 "(\n"
114 "float4 gl_FrontColor : COLOR0,\n"
115 "out float4 gl_FragColor : COLOR\n"
116 ")\n"
117 "{\n"
118 "       gl_FragColor = gl_FrontColor;\n"
119 "}\n"
120 "#endif\n"
121 "#else // !MODE_SHOWDEPTH\n"
122 "\n"
123 "\n"
124 "\n"
125 "\n"
126 "#ifdef MODE_POSTPROCESS\n"
127 "\n"
128 "#ifdef VERTEX_SHADER\n"
129 "void main\n"
130 "(\n"
131 "float4 gl_Vertex : POSITION,\n"
132 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
133 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
134 "float4 gl_MultiTexCoord4 : TEXCOORD4,\n"
135 "out float4 gl_Position : POSITION,\n"
136 "out float2 TexCoord1 : TEXCOORD0,\n"
137 "out float2 TexCoord2 : TEXCOORD1\n"
138 ")\n"
139 "{\n"
140 "       gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
141 "       TexCoord1 = gl_MultiTexCoord0.xy;\n"
142 "#ifdef USEBLOOM\n"
143 "       TexCoord2 = gl_MultiTexCoord4.xy;\n"
144 "#endif\n"
145 "}\n"
146 "#endif\n"
147 "\n"
148 "#ifdef FRAGMENT_SHADER\n"
149 "void main\n"
150 "(\n"
151 "float2 TexCoord1 : TEXCOORD0,\n"
152 "float2 TexCoord2 : TEXCOORD1,\n"
153 "uniform sampler Texture_First : register(s0),\n"
154 "#ifdef USEBLOOM\n"
155 "uniform sampler Texture_Second : register(s1),\n"
156 "#endif\n"
157 "#ifdef USEGAMMARAMPS\n"
158 "uniform sampler Texture_GammaRamps : register(s2),\n"
159 "#endif\n"
160 "#ifdef USESATURATION\n"
161 "uniform float Saturation : register(c30),\n"
162 "#endif\n"
163 "#ifdef USEVIEWTINT\n"
164 "uniform float4 ViewTintColor : register(c41),\n"
165 "#endif\n"
166 "uniform float4 UserVec1 : register(c37),\n"
167 "uniform float4 UserVec2 : register(c38),\n"
168 "uniform float4 UserVec3 : register(c39),\n"
169 "uniform float4 UserVec4 : register(c40),\n"
170 "uniform float ClientTime : register(c2),\n"
171 "uniform float2 PixelSize : register(c25),\n"
172 "uniform float4 BloomColorSubtract : register(c43),\n"
173 "out float4 gl_FragColor : COLOR\n"
174 ")\n"
175 "{\n"
176 "       gl_FragColor = tex2D(Texture_First, TexCoord1);\n"
177 "#ifdef USEBLOOM\n"
178 "       gl_FragColor += max(float4(0,0,0,0), tex2D(Texture_Second, TexCoord2) - BloomColorSubtract);\n"
179 "#endif\n"
180 "#ifdef USEVIEWTINT\n"
181 "       gl_FragColor = lerp(gl_FragColor, ViewTintColor, ViewTintColor.a);\n"
182 "#endif\n"
183 "\n"
184 "#ifdef USEPOSTPROCESSING\n"
185 "// do r_glsl_dumpshader, edit glsl/default.glsl, and replace this by your own postprocessing if you want\n"
186 "// 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"
187 "       float sobel = 1.0;\n"
188 "       // float2 ts = textureSize(Texture_First, 0);\n"
189 "       // float2 px = float2(1/ts.x, 1/ts.y);\n"
190 "       float2 px = PixelSize;\n"
191 "       float3 x1 = tex2D(Texture_First, TexCoord1 + float2(-px.x, px.y)).rgb;\n"
192 "       float3 x2 = tex2D(Texture_First, TexCoord1 + float2(-px.x,  0.0)).rgb;\n"
193 "       float3 x3 = tex2D(Texture_First, TexCoord1 + float2(-px.x,-px.y)).rgb;\n"
194 "       float3 x4 = tex2D(Texture_First, TexCoord1 + float2( px.x, px.y)).rgb;\n"
195 "       float3 x5 = tex2D(Texture_First, TexCoord1 + float2( px.x,  0.0)).rgb;\n"
196 "       float3 x6 = tex2D(Texture_First, TexCoord1 + float2( px.x,-px.y)).rgb;\n"
197 "       float3 y1 = tex2D(Texture_First, TexCoord1 + float2( px.x,-px.y)).rgb;\n"
198 "       float3 y2 = tex2D(Texture_First, TexCoord1 + float2(  0.0,-px.y)).rgb;\n"
199 "       float3 y3 = tex2D(Texture_First, TexCoord1 + float2(-px.x,-px.y)).rgb;\n"
200 "       float3 y4 = tex2D(Texture_First, TexCoord1 + float2( px.x, px.y)).rgb;\n"
201 "       float3 y5 = tex2D(Texture_First, TexCoord1 + float2(  0.0, px.y)).rgb;\n"
202 "       float3 y6 = tex2D(Texture_First, TexCoord1 + float2(-px.x, px.y)).rgb;\n"
203 "       float px1 = -1.0 * dot(float3(0.3, 0.59, 0.11), x1);\n"
204 "       float px2 = -2.0 * dot(float3(0.3, 0.59, 0.11), x2);\n"
205 "       float px3 = -1.0 * dot(float3(0.3, 0.59, 0.11), x3);\n"
206 "       float px4 =  1.0 * dot(float3(0.3, 0.59, 0.11), x4);\n"
207 "       float px5 =  2.0 * dot(float3(0.3, 0.59, 0.11), x5);\n"
208 "       float px6 =  1.0 * dot(float3(0.3, 0.59, 0.11), x6);\n"
209 "       float py1 = -1.0 * dot(float3(0.3, 0.59, 0.11), y1);\n"
210 "       float py2 = -2.0 * dot(float3(0.3, 0.59, 0.11), y2);\n"
211 "       float py3 = -1.0 * dot(float3(0.3, 0.59, 0.11), y3);\n"
212 "       float py4 =  1.0 * dot(float3(0.3, 0.59, 0.11), y4);\n"
213 "       float py5 =  2.0 * dot(float3(0.3, 0.59, 0.11), y5);\n"
214 "       float py6 =  1.0 * dot(float3(0.3, 0.59, 0.11), y6);\n"
215 "       sobel = 0.25 * abs(px1 + px2 + px3 + px4 + px5 + px6) + 0.25 * abs(py1 + py2 + py3 + py4 + py5 + py6);\n"
216 "       gl_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.987688, -0.156434)) * UserVec1.y;\n"
217 "       gl_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.156434, -0.891007)) * UserVec1.y;\n"
218 "       gl_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2( 0.891007, -0.453990)) * UserVec1.y;\n"
219 "       gl_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2( 0.707107,  0.707107)) * UserVec1.y;\n"
220 "       gl_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.453990,  0.891007)) * UserVec1.y;\n"
221 "       gl_FragColor /= (1.0 + 5.0 * UserVec1.y);\n"
222 "       gl_FragColor.rgb = gl_FragColor.rgb * (1.0 + UserVec2.x) + float3(1,1,1)*max(0.0, sobel - UserVec2.z)*UserVec2.y;\n"
223 "#endif\n"
224 "\n"
225 "#ifdef USESATURATION\n"
226 "       //apply saturation BEFORE gamma ramps, so v_glslgamma value does not matter\n"
227 "       float y = dot(gl_FragColor.rgb, float3(0.299, 0.587, 0.114));\n"
228 "       // 'vampire sight' effect, wheres red is compensated\n"
229 "       #ifdef SATURATION_REDCOMPENSATE\n"
230 "               float rboost = max(0.0, (gl_FragColor.r - max(gl_FragColor.g, gl_FragColor.b))*(1.0 - Saturation));\n"
231 "               gl_FragColor.rgb = lerp(float3(y,y,y), gl_FragColor.rgb, Saturation);\n"
232 "               gl_FragColor.r += r;\n"
233 "       #else\n"
234 "               // normal desaturation\n"
235 "               //gl_FragColor = float3(y,y,y) + (gl_FragColor.rgb - float3(y)) * Saturation;\n"
236 "               gl_FragColor.rgb = lerp(float3(y,y,y), gl_FragColor.rgb, Saturation);\n"
237 "       #endif\n"
238 "#endif\n"
239 "\n"
240 "#ifdef USEGAMMARAMPS\n"
241 "       gl_FragColor.r = tex2D(Texture_GammaRamps, float2(gl_FragColor.r, 0)).r;\n"
242 "       gl_FragColor.g = tex2D(Texture_GammaRamps, float2(gl_FragColor.g, 0)).g;\n"
243 "       gl_FragColor.b = tex2D(Texture_GammaRamps, float2(gl_FragColor.b, 0)).b;\n"
244 "#endif\n"
245 "}\n"
246 "#endif\n"
247 "#else // !MODE_POSTPROCESS\n"
248 "\n"
249 "\n"
250 "\n"
251 "\n"
252 "#ifdef MODE_GENERIC\n"
253 "#ifdef VERTEX_SHADER\n"
254 "void main\n"
255 "(\n"
256 "float4 gl_Vertex : POSITION,\n"
257 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
258 "float4 gl_Color : COLOR0,\n"
259 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
260 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n"
261 "out float4 gl_Position : POSITION,\n"
262 "#ifdef USEDIFFUSE\n"
263 "out float2 TexCoord1 : TEXCOORD0,\n"
264 "#endif\n"
265 "#ifdef USESPECULAR\n"
266 "out float2 TexCoord2 : TEXCOORD1,\n"
267 "#endif\n"
268 "out float4 gl_FrontColor : COLOR\n"
269 ")\n"
270 "{\n"
271 "       gl_FrontColor = gl_Color;\n"
272 "#ifdef USEDIFFUSE\n"
273 "       TexCoord1 = gl_MultiTexCoord0.xy;\n"
274 "#endif\n"
275 "#ifdef USESPECULAR\n"
276 "       TexCoord2 = gl_MultiTexCoord1.xy;\n"
277 "#endif\n"
278 "       gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
279 "#ifdef USETRIPPY\n"
280 "       gl_Position = TrippyVertex(gl_Position);\n"
281 "#endif\n"
282 "}\n"
283 "#endif\n"
284 "\n"
285 "#ifdef FRAGMENT_SHADER\n"
286 "\n"
287 "void main\n"
288 "(\n"
289 "float4 gl_FrontColor : COLOR0,\n"
290 "float2 TexCoord1 : TEXCOORD0,\n"
291 "float2 TexCoord2 : TEXCOORD1,\n"
292 "#ifdef USEDIFFUSE\n"
293 "uniform sampler Texture_First : register(s0),\n"
294 "#endif\n"
295 "#ifdef USESPECULAR\n"
296 "uniform sampler Texture_Second : register(s1),\n"
297 "#endif\n"
298 "#ifdef USEGAMMARAMPS\n"
299 "uniform sampler Texture_GammaRamps : register(s2),\n"
300 "#endif\n"
301 "out float4 gl_FragColor : COLOR\n"
302 ")\n"
303 "{\n"
304 "#ifdef USEVIEWTINT\n"
305 "       gl_FragColor = gl_FrontColor;\n"
306 "#else\n"
307 "       gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
308 "#endif\n"
309 "#ifdef USEDIFFUSE\n"
310 "       gl_FragColor *= tex2D(Texture_First, TexCoord1);\n"
311 "#endif\n"
312 "\n"
313 "#ifdef USESPECULAR\n"
314 "       float4 tex2 = tex2D(Texture_Second, TexCoord2);\n"
315 "# ifdef USECOLORMAPPING\n"
316 "       gl_FragColor *= tex2;\n"
317 "# endif\n"
318 "# ifdef USEGLOW\n"
319 "       gl_FragColor += tex2;\n"
320 "# endif\n"
321 "# ifdef USEVERTEXTEXTUREBLEND\n"
322 "       gl_FragColor = lerp(gl_FragColor, tex2, tex2.a);\n"
323 "# endif\n"
324 "#endif\n"
325 "#ifdef USEGAMMARAMPS\n"
326 "       dp_FragColor.r = dp_texture2D(Texture_GammaRamps, vec2(dp_FragColor.r, 0)).r;\n"
327 "       dp_FragColor.g = dp_texture2D(Texture_GammaRamps, vec2(dp_FragColor.g, 0)).g;\n"
328 "       dp_FragColor.b = dp_texture2D(Texture_GammaRamps, vec2(dp_FragColor.b, 0)).b;\n"
329 "#endif\n"
330 "}\n"
331 "#endif\n"
332 "#else // !MODE_GENERIC\n"
333 "\n"
334 "\n"
335 "\n"
336 "\n"
337 "#ifdef MODE_BLOOMBLUR\n"
338 "#ifdef VERTEX_SHADER\n"
339 "void main\n"
340 "(\n"
341 "float4 gl_Vertex : POSITION,\n"
342 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
343 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
344 "out float4 gl_Position : POSITION,\n"
345 "out float2 TexCoord : TEXCOORD0\n"
346 ")\n"
347 "{\n"
348 "       TexCoord = gl_MultiTexCoord0.xy;\n"
349 "       gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
350 "}\n"
351 "#endif\n"
352 "\n"
353 "#ifdef FRAGMENT_SHADER\n"
354 "\n"
355 "void main\n"
356 "(\n"
357 "float2 TexCoord : TEXCOORD0,\n"
358 "uniform sampler Texture_First : register(s0),\n"
359 "uniform float4 BloomBlur_Parameters : register(c1),\n"
360 "out float4 gl_FragColor : COLOR\n"
361 ")\n"
362 "{\n"
363 "       int i;\n"
364 "       float2 tc = TexCoord;\n"
365 "       float3 color = tex2D(Texture_First, tc).rgb;\n"
366 "       tc += BloomBlur_Parameters.xy;\n"
367 "       for (i = 1;i < SAMPLES;i++)\n"
368 "       {\n"
369 "               color += tex2D(Texture_First, tc).rgb;\n"
370 "               tc += BloomBlur_Parameters.xy;\n"
371 "       }\n"
372 "       gl_FragColor = float4(color * BloomBlur_Parameters.z + float3(BloomBlur_Parameters.w), 1);\n"
373 "}\n"
374 "#endif\n"
375 "#else // !MODE_BLOOMBLUR\n"
376 "#ifdef MODE_REFRACTION\n"
377 "#ifdef VERTEX_SHADER\n"
378 "void main\n"
379 "(\n"
380 "float4 gl_Vertex : POSITION,\n"
381 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
382 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
383 "uniform float4x4 TexMatrix : register(c0),\n"
384 "uniform float3 EyePosition : register(c24),\n"
385 "out float4 gl_Position : POSITION,\n"
386 "out float2 TexCoord : TEXCOORD0,\n"
387 "out float3 EyeVector : TEXCOORD1,\n"
388 "out float4 ModelViewProjectionPosition : TEXCOORD2\n"
389 ")\n"
390 "{\n"
391 "       TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n"
392 "       gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
393 "       ModelViewProjectionPosition = gl_Position;\n"
394 "#ifdef USETRIPPY\n"
395 "       gl_Position = TrippyVertex(gl_Position);\n"
396 "#endif\n"
397 "}\n"
398 "#endif\n"
399 "\n"
400 "#ifdef FRAGMENT_SHADER\n"
401 "void main\n"
402 "(\n"
403 "float2 TexCoord : TEXCOORD0,\n"
404 "float3 EyeVector : TEXCOORD1,\n"
405 "float4 ModelViewProjectionPosition : TEXCOORD2,\n"
406 "uniform sampler Texture_Normal : register(s0),\n"
407 "uniform sampler Texture_Refraction : register(s3),\n"
408 "uniform sampler Texture_Reflection : register(s7),\n"
409 "uniform float4 DistortScaleRefractReflect : register(c14),\n"
410 "uniform float4 ScreenScaleRefractReflect : register(c32),\n"
411 "uniform float4 ScreenCenterRefractReflect : register(c31),\n"
412 "uniform float4 RefractColor : register(c29),\n"
413 "out float4 gl_FragColor : COLOR\n"
414 ")\n"
415 "{\n"
416 "       float2 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect.xy * (1.0 / ModelViewProjectionPosition.w);\n"
417 "       //float2 ScreenTexCoord = (ModelViewProjectionPosition.xy + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy * DistortScaleRefractReflect.xy * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n"
418 "       float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n"
419 "       float2 ScreenTexCoord = SafeScreenTexCoord + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy * DistortScaleRefractReflect.xy;\n"
420 "       // FIXME temporary hack to detect the case that the reflection\n"
421 "       // gets blackened at edges due to leaving the area that contains actual\n"
422 "       // content.\n"
423 "       // Remove this 'ack once we have a better way to stop this thing from\n"
424 "       // 'appening.\n"
425 "       float f = min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(0.01, 0.01)).rgb) / 0.05);\n"
426 "       f      *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(0.01, -0.01)).rgb) / 0.05);\n"
427 "       f      *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(-0.01, 0.01)).rgb) / 0.05);\n"
428 "       f      *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(-0.01, -0.01)).rgb) / 0.05);\n"
429 "       ScreenTexCoord = lerp(SafeScreenTexCoord, ScreenTexCoord, f);\n"
430 "       gl_FragColor = float4(tex2D(Texture_Refraction, ScreenTexCoord).rgb, 1) * RefractColor;\n"
431 "}\n"
432 "#endif\n"
433 "#else // !MODE_REFRACTION\n"
434 "\n"
435 "\n"
436 "\n"
437 "\n"
438 "#ifdef MODE_WATER\n"
439 "#ifdef VERTEX_SHADER\n"
440 "\n"
441 "void main\n"
442 "(\n"
443 "float4 gl_Vertex : POSITION,\n"
444 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
445 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
446 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n"
447 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n"
448 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n"
449 "uniform float4x4 TexMatrix : register(c0),\n"
450 "uniform float3 EyePosition : register(c24),\n"
451 "out float4 gl_Position : POSITION,\n"
452 "out float2 TexCoord : TEXCOORD0,\n"
453 "out float3 EyeVector : TEXCOORD1,\n"
454 "out float4 ModelViewProjectionPosition : TEXCOORD2\n"
455 ")\n"
456 "{\n"
457 "       TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n"
458 "       float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n"
459 "       EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n"
460 "       gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
461 "       ModelViewProjectionPosition = gl_Position;\n"
462 "#ifdef USETRIPPY\n"
463 "       gl_Position = TrippyVertex(gl_Position);\n"
464 "#endif\n"
465 "}\n"
466 "#endif\n"
467 "\n"
468 "#ifdef FRAGMENT_SHADER\n"
469 "void main\n"
470 "(\n"
471 "float2 TexCoord : TEXCOORD0,\n"
472 "float3 EyeVector : TEXCOORD1,\n"
473 "float4 ModelViewProjectionPosition : TEXCOORD2,\n"
474 "uniform sampler Texture_Normal : register(s0),\n"
475 "uniform sampler Texture_Refraction : register(s3),\n"
476 "uniform sampler Texture_Reflection : register(s7),\n"
477 "uniform float4 DistortScaleRefractReflect : register(c14),\n"
478 "uniform float4 ScreenScaleRefractReflect : register(c32),\n"
479 "uniform float4 ScreenCenterRefractReflect : register(c31),\n"
480 "uniform float4 RefractColor : register(c29),\n"
481 "uniform float4 ReflectColor : register(c26),\n"
482 "uniform float ReflectFactor : register(c27),\n"
483 "uniform float ReflectOffset : register(c28),\n"
484 "out float4 gl_FragColor : COLOR\n"
485 ")\n"
486 "{\n"
487 "       float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n"
488 "       //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n"
489 "       float4 SafeScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n"
490 "       //SafeScreenTexCoord = gl_FragCoord.xyxy * float4(1.0 / 1920.0, 1.0 / 1200.0, 1.0 / 1920.0, 1.0 / 1200.0);\n"
491 "       float4 ScreenTexCoord = SafeScreenTexCoord + float2(normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy).xyxy * DistortScaleRefractReflect;\n"
492 "       // FIXME temporary hack to detect the case that the reflection\n"
493 "       // gets blackened at edges due to leaving the area that contains actual\n"
494 "       // content.\n"
495 "       // Remove this 'ack once we have a better way to stop this thing from\n"
496 "       // 'appening.\n"
497 "       float f = min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(0.01, 0.01)).rgb) / 0.05);\n"
498 "       f      *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(0.01, -0.01)).rgb) / 0.05);\n"
499 "       f      *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(-0.01, 0.01)).rgb) / 0.05);\n"
500 "       f      *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(-0.01, -0.01)).rgb) / 0.05);\n"
501 "       ScreenTexCoord.xy = lerp(SafeScreenTexCoord.xy, ScreenTexCoord.xy, f);\n"
502 "       f  = min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(0.01, 0.01)).rgb) / 0.05);\n"
503 "       f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(0.01, -0.01)).rgb) / 0.05);\n"
504 "       f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(-0.01, 0.01)).rgb) / 0.05);\n"
505 "       f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(-0.01, -0.01)).rgb) / 0.05);\n"
506 "       ScreenTexCoord.zw = lerp(SafeScreenTexCoord.zw, ScreenTexCoord.zw, f);\n"
507 "       float Fresnel = pow(min(1.0, 1.0 - float(normalize(EyeVector).z)), 2.0) * ReflectFactor + ReflectOffset;\n"
508 "       gl_FragColor = lerp(float4(tex2D(Texture_Refraction, ScreenTexCoord.xy).rgb, 1) * RefractColor, float4(tex2D(Texture_Reflection, ScreenTexCoord.zw).rgb, 1) * ReflectColor, Fresnel);\n"
509 "}\n"
510 "#endif\n"
511 "#else // !MODE_WATER\n"
512 "\n"
513 "\n"
514 "\n"
515 "\n"
516 "// 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"
517 "\n"
518 "// fragment shader specific:\n"
519 "#ifdef FRAGMENT_SHADER\n"
520 "\n"
521 "#ifdef USEFOG\n"
522 "float3 FogVertex(float4 surfacecolor, float3 FogColor, float3 EyeVectorModelSpace, float FogPlaneVertexDist, float FogRangeRecip, float FogPlaneViewDist, float FogHeightFade, sampler Texture_FogMask, sampler Texture_FogHeightTexture)\n"
523 "{\n"
524 "       float fogfrac;\n"
525 "       float3 fc = FogColor;\n"
526 "#ifdef USEFOGALPHAHACK\n"
527 "       fc *= surfacecolor.a;\n"
528 "#endif\n"
529 "#ifdef USEFOGHEIGHTTEXTURE\n"
530 "       float4 fogheightpixel = tex2D(Texture_FogHeightTexture, float2(1,1) + float2(FogPlaneVertexDist, FogPlaneViewDist) * (-2.0 * FogHeightFade));\n"
531 "       fogfrac = fogheightpixel.a;\n"
532 "       return lerp(fogheightpixel.rgb * fc, surfacecolor.rgb, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n"
533 "#else\n"
534 "# ifdef USEFOGOUTSIDE\n"
535 "       fogfrac = min(0.0, FogPlaneVertexDist) / (FogPlaneVertexDist - FogPlaneViewDist) * min(1.0, min(0.0, FogPlaneVertexDist) * FogHeightFade);\n"
536 "# else\n"
537 "       fogfrac = FogPlaneViewDist / (FogPlaneViewDist - max(0.0, FogPlaneVertexDist)) * min(1.0, (min(0.0, FogPlaneVertexDist) + FogPlaneViewDist) * FogHeightFade);\n"
538 "# endif\n"
539 "       return lerp(fc, surfacecolor.rgb, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n"
540 "#endif\n"
541 "}\n"
542 "#endif\n"
543 "\n"
544 "#ifdef USEOFFSETMAPPING\n"
545 "float2 OffsetMapping(float2 TexCoord, float4 OffsetMapping_ScaleSteps, float OffsetMapping_Bias, float OffsetMapping_LodDistance, float3 EyeVector, sampler Texture_Normal, float2 dPdx, float2 dPdy)\n"
546 "{\n"
547 "       float i;\n"
548 "       // distance-based LOD\n"
549 "#ifdef USEOFFSETMAPPING_LOD\n"
550 "       float LODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n"
551 "       mediump vec4 ScaleSteps = float4(OffsetMapping_ScaleSteps.x, OffsetMapping_ScaleSteps.y * LODFactor, OffsetMapping_ScaleSteps.z / LODFactor, OffsetMapping_ScaleSteps.w * LODFactor);\n"
552 "#else\n"
553 "       #define ScaleSteps OffsetMapping_ScaleSteps\n"
554 "#endif\n"
555 "#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n"
556 "       // 14 sample relief mapping: linear search and then binary search\n"
557 "       // this basically steps forward a small amount repeatedly until it finds\n"
558 "       // itself inside solid, then jitters forward and back using decreasing\n"
559 "       // amounts to find the impact\n"
560 "       //float3 OffsetVector = float3(EyeVector.xy * ((1.0 / EyeVector.z) * ScaleSteps.x) * float2(-1, 1), -1);\n"
561 "       //float3 OffsetVector = float3(normalize(EyeVector.xy) * ScaleSteps.x * float2(-1, 1), -1);\n"
562 "       float3 OffsetVector = float3(normalize(EyeVector).xy * ScaleSteps.x * float2(-1, 1), -1);\n"
563 "       float3 RT = float3(float2(TexCoord.xy - OffsetVector.xy*OffsetMapping_Bias), 1);\n"
564 "       OffsetVector *= ScaleSteps.z;\n"
565 "       for(i = 1.0; i < ScaleSteps.y; ++i)\n"
566 "               RT += OffsetVector *  step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z);\n"
567 "       for(i = 0.0, f = 1.0; i < ScaleSteps.w; ++i, f *= 0.5)\n"
568 "               RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * f - 0.5 * f);\n"
569 "       return RT.xy;\n"
570 "#else\n"
571 "       // 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits)\n"
572 "       //float2 OffsetVector = float2(EyeVector.xy * ((1.0 / EyeVector.z) * ScaleSteps.x) * float2(-1, 1));\n"
573 "       //float2 OffsetVector = float2(normalize(EyeVector.xy) * ScaleSteps.x * float2(-1, 1));\n"
574 "       float2 OffsetVector = float2(normalize(EyeVector).xy * ScaleSteps.x * float2(-1, 1));\n"
575 "       OffsetVector *= ScaleSteps.z;\n"
576 "       for(i = 0.0; i < ScaleSteps.y; ++i)\n"
577 "               TexCoord += OffsetVector * ((1.0 - OffsetMapping_Bias) - tex2Dgrad(Texture_Normal, TexCoord, dPdx, dPdy).a);\n"
578 "       return TexCoord;\n"
579 "#endif\n"
580 "}\n"
581 "#endif // USEOFFSETMAPPING\n"
582 "\n"
583 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n"
584 "#if defined(USESHADOWMAP2D)\n"
585 "# ifdef USESHADOWMAPORTHO\n"
586 "#  define GetShadowMapTC2D(dir, ShadowMap_Parameters) (min(dir, ShadowMap_Parameters.xyz))\n"
587 "# else\n"
588 "#  ifdef USESHADOWMAPVSDCT\n"
589 "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters, samplerCUBE Texture_CubeProjection)\n"
590 "{\n"
591 "       float3 adir = abs(dir);\n"
592 "       float2 aparams = ShadowMap_Parameters.xy / max(max(adir.x, adir.y), adir.z);\n"
593 "       float4 proj = texCUBE(Texture_CubeProjection, dir);\n"
594 "       return float3(lerp(dir.xy, dir.zz, proj.xy) * aparams.x + proj.zw * ShadowMap_Parameters.z, aparams.y + ShadowMap_Parameters.w);\n"
595 "}\n"
596 "#  else\n"
597 "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters)\n"
598 "{\n"
599 "       float3 adir = abs(dir);\n"
600 "       float ma = adir.z;\n"
601 "       float4 proj = float4(dir, 2.5);\n"
602 "       if (adir.x > ma) { ma = adir.x; proj = float4(dir.zyx, 0.5); }\n"
603 "       if (adir.y > ma) { ma = adir.y; proj = float4(dir.xzy, 1.5); }\n"
604 "#ifdef HLSL\n"
605 "       return float3(proj.xy * ShadowMap_Parameters.x / ma + float2(0.5,0.5) + float2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, ma + 64 * ShadowMap_Parameters.w);\n"
606 "#else\n"
607 "       float2 aparams = ShadowMap_Parameters.xy / ma;\n"
608 "       return float3(proj.xy * aparams.x + float2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, aparams.y + ShadowMap_Parameters.w);\n"
609 "#endif\n"
610 "}\n"
611 "#  endif\n"
612 "# endif\n"
613 "#endif // defined(USESHADOWMAP2D)\n"
614 "\n"
615 "# ifdef USESHADOWMAP2D\n"
616 "#ifdef USESHADOWMAPVSDCT\n"
617 "float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale, samplerCUBE Texture_CubeProjection)\n"
618 "#else\n"
619 "float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale)\n"
620 "#endif\n"
621 "{\n"
622 "#ifdef USESHADOWMAPVSDCT\n"
623 "       float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters, Texture_CubeProjection);\n"
624 "#else\n"
625 "       float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters);\n"
626 "#endif\n"
627 "       float f;\n"
628 "\n"
629 "#  ifdef USESHADOWSAMPLER\n"
630 "#    ifdef USESHADOWMAPPCF\n"
631 "#      define texval(x, y) tex2Dproj(Texture_ShadowMap2D, float4(center + float2(x, y)*ShadowMap_TextureScale, shadowmaptc.z, 1.0)).r  \n"
632 "       float2 center = shadowmaptc.xy*ShadowMap_TextureScale;\n"
633 "       f = dot(float4(0.25,0.25,0.25,0.25), float4(texval(-0.4, 1.0), texval(-1.0, -0.4), texval(0.4, -1.0), texval(1.0, 0.4)));\n"
634 "#    else\n"
635 "       f = tex2Dproj(Texture_ShadowMap2D, float4(shadowmaptc.xy*ShadowMap_TextureScale, shadowmaptc.z, 1.0)).r;\n"
636 "#    endif\n"
637 "#  else\n"
638 "#    ifdef USESHADOWMAPPCF\n"
639 "#     if defined(GL_ARB_texture_gather) || defined(GL_AMD_texture_texture4)\n"
640 "#      ifdef GL_ARB_texture_gather\n"
641 "#        define texval(x, y) textureGatherOffset(Texture_ShadowMap2D, center, int2(x, y))\n"
642 "#      else\n"
643 "#        define texval(x, y) texture4(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale)\n"
644 "#      endif\n"
645 "       float2 offset = frac(shadowmaptc.xy - 0.5), center = (shadowmaptc.xy - offset)*ShadowMap_TextureScale;\n"
646 "#      if USESHADOWMAPPCF > 1\n"
647 "       float4 group1 = step(shadowmaptc.z, texval(-2.0, -2.0));\n"
648 "       float4 group2 = step(shadowmaptc.z, texval( 0.0, -2.0));\n"
649 "       float4 group3 = step(shadowmaptc.z, texval( 2.0, -2.0));\n"
650 "       float4 group4 = step(shadowmaptc.z, texval(-2.0,  0.0));\n"
651 "       float4 group5 = step(shadowmaptc.z, texval( 0.0,  0.0));\n"
652 "       float4 group6 = step(shadowmaptc.z, texval( 2.0,  0.0));\n"
653 "       float4 group7 = step(shadowmaptc.z, texval(-2.0,  2.0));\n"
654 "       float4 group8 = step(shadowmaptc.z, texval( 0.0,  2.0));\n"
655 "       float4 group9 = step(shadowmaptc.z, texval( 2.0,  2.0));\n"
656 "       float4 locols = float4(group1.ab, group3.ab);\n"
657 "       float4 hicols = float4(group7.rg, group9.rg);\n"
658 "       locols.yz += group2.ab;\n"
659 "       hicols.yz += group8.rg;\n"
660 "       float4 midcols = float4(group1.rg, group3.rg) + float4(group7.ab, group9.ab) +\n"
661 "                               float4(group4.rg, group6.rg) + float4(group4.ab, group6.ab) +\n"
662 "                               lerp(locols, hicols, offset.y);\n"
663 "       float4 cols = group5 + float4(group2.rg, group8.ab);\n"
664 "       cols.xyz += lerp(midcols.xyz, midcols.yzw, offset.x);\n"
665 "       f = dot(cols, float4(1.0/25.0));\n"
666 "#      else\n"
667 "       float4 group1 = step(shadowmaptc.z, texval(-1.0, -1.0));\n"
668 "       float4 group2 = step(shadowmaptc.z, texval( 1.0, -1.0));\n"
669 "       float4 group3 = step(shadowmaptc.z, texval(-1.0,  1.0));\n"
670 "       float4 group4 = step(shadowmaptc.z, texval( 1.0,  1.0));\n"
671 "       float4 cols = float4(group1.rg, group2.rg) + float4(group3.ab, group4.ab) +\n"
672 "                               lerp(float4(group1.ab, group2.ab), float4(group3.rg, group4.rg), offset.y);\n"
673 "       f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n"
674 "#      endif\n"
675 "#     else\n"
676 "#      ifdef GL_EXT_gpu_shader4\n"
677 "#        define texval(x, y) tex2DOffset(Texture_ShadowMap2D, center, int2(x, y)).r\n"
678 "#      else\n"
679 "#        define texval(x, y) texDepth2D(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale).r  \n"
680 "#      endif\n"
681 "#      if USESHADOWMAPPCF > 1\n"
682 "       float2 center = shadowmaptc.xy - 0.5, offset = frac(center);\n"
683 "       center *= ShadowMap_TextureScale;\n"
684 "       float4 row1 = step(shadowmaptc.z, float4(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0), texval( 2.0, -1.0)));\n"
685 "       float4 row2 = step(shadowmaptc.z, float4(texval(-1.0,  0.0), texval( 0.0,  0.0), texval( 1.0,  0.0), texval( 2.0,  0.0)));\n"
686 "       float4 row3 = step(shadowmaptc.z, float4(texval(-1.0,  1.0), texval( 0.0,  1.0), texval( 1.0,  1.0), texval( 2.0,  1.0)));\n"
687 "       float4 row4 = step(shadowmaptc.z, float4(texval(-1.0,  2.0), texval( 0.0,  2.0), texval( 1.0,  2.0), texval( 2.0,  2.0)));\n"
688 "       float4 cols = row2 + row3 + lerp(row1, row4, offset.y);\n"
689 "       f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n"
690 "#      else\n"
691 "       float2 center = shadowmaptc.xy*ShadowMap_TextureScale, offset = frac(shadowmaptc.xy);\n"
692 "       float3 row1 = step(shadowmaptc.z, float3(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0)));\n"
693 "       float3 row2 = step(shadowmaptc.z, float3(texval(-1.0,  0.0), texval( 0.0,  0.0), texval( 1.0,  0.0)));\n"
694 "       float3 row3 = step(shadowmaptc.z, float3(texval(-1.0,  1.0), texval( 0.0,  1.0), texval( 1.0,  1.0)));\n"
695 "       float3 cols = row2 + lerp(row1, row3, offset.y);\n"
696 "       f = dot(lerp(cols.xy, cols.yz, offset.x), float2(0.25,0.25));\n"
697 "#      endif\n"
698 "#     endif\n"
699 "#    else\n"
700 "       f = step(shadowmaptc.z, tex2D(Texture_ShadowMap2D, shadowmaptc.xy*ShadowMap_TextureScale).r);\n"
701 "#    endif\n"
702 "#  endif\n"
703 "#  ifdef USESHADOWMAPORTHO\n"
704 "       return lerp(ShadowMap_Parameters.w, 1.0, f);\n"
705 "#  else\n"
706 "       return f;\n"
707 "#  endif\n"
708 "}\n"
709 "# endif\n"
710 "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n"
711 "#endif // FRAGMENT_SHADER\n"
712 "\n"
713 "\n"
714 "\n"
715 "\n"
716 "#ifdef MODE_DEFERREDGEOMETRY\n"
717 "#ifdef VERTEX_SHADER\n"
718 "void main\n"
719 "(\n"
720 "float4 gl_Vertex : POSITION,\n"
721 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
722 "#ifdef USEVERTEXTEXTUREBLEND\n"
723 "float4 gl_Color : COLOR0,\n"
724 "#endif\n"
725 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
726 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n"
727 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n"
728 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n"
729 "uniform float4x4 TexMatrix : register(c0),\n"
730 "#ifdef USEVERTEXTEXTUREBLEND\n"
731 "uniform float4x4 BackgroundTexMatrix : register(c4),\n"
732 "#endif\n"
733 "uniform float4x4 ModelViewMatrix : register(c12),\n"
734 "#ifdef USEOFFSETMAPPING\n"
735 "uniform float3 EyePosition : register(c24),\n"
736 "#endif\n"
737 "out float4 gl_Position : POSITION,\n"
738 "#ifdef USEVERTEXTEXTUREBLEND\n"
739 "out float4 gl_FrontColor : COLOR,\n"
740 "#endif\n"
741 "out float4 TexCoordBoth : TEXCOORD0,\n"
742 "#ifdef USEOFFSETMAPPING\n"
743 "out float3 EyeVector : TEXCOORD2,\n"
744 "#endif\n"
745 "out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
746 "out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
747 "out float4 VectorR : TEXCOORD7 // direction of R texcoord (surface normal), Depth value\n"
748 ")\n"
749 "{\n"
750 "       TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n"
751 "#ifdef USEVERTEXTEXTUREBLEND\n"
752 "       gl_FrontColor = gl_Color;\n"
753 "       TexCoordBoth.zw = float2(Backgroundmul(TexMatrix, gl_MultiTexCoord0));\n"
754 "#endif\n"
755 "\n"
756 "       // transform unnormalized eye direction into tangent space\n"
757 "#ifdef USEOFFSETMAPPING\n"
758 "       float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n"
759 "       EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n"
760 "#endif\n"
761 "\n"
762 "       VectorS = mul(ModelViewMatrix, float4(gl_MultiTexCoord1.xyz, 0)).xyz;\n"
763 "       VectorT = mul(ModelViewMatrix, float4(gl_MultiTexCoord2.xyz, 0)).xyz;\n"
764 "       VectorR.xyz = mul(ModelViewMatrix, float4(gl_MultiTexCoord3.xyz, 0)).xyz;\n"
765 "       gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
766 "#ifdef USETRIPPY\n"
767 "       gl_Position = TrippyVertex(gl_Position);\n"
768 "#endif\n"
769 "       VectorR.w = gl_Position.z;\n"
770 "}\n"
771 "#endif // VERTEX_SHADER\n"
772 "\n"
773 "#ifdef FRAGMENT_SHADER\n"
774 "void main\n"
775 "(\n"
776 "float4 TexCoordBoth : TEXCOORD0,\n"
777 "float3 EyeVector : TEXCOORD2,\n"
778 "float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
779 "float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
780 "float4 VectorR : TEXCOORD7, // direction of R texcoord (surface normal), Depth value\n"
781 "uniform sampler Texture_Normal : register(s0),\n"
782 "#ifdef USEALPHAKILL\n"
783 "uniform sampler Texture_Color : register(s1),\n"
784 "#endif\n"
785 "uniform sampler Texture_Gloss : register(s2),\n"
786 "#ifdef USEVERTEXTEXTUREBLEND\n"
787 "uniform sampler Texture_SecondaryNormal : register(s4),\n"
788 "uniform sampler Texture_SecondaryGloss : register(s6),\n"
789 "#endif\n"
790 "#ifdef USEOFFSETMAPPING\n"
791 "uniform float4 OffsetMapping_ScaleSteps : register(c24),\n"
792 "uniform float4 OffsetMapping_LodDistance : register(c53),\n"
793 "uniform float OffsetMapping_Bias : register(c54),\n"
794 "#endif\n"
795 "uniform half SpecularPower : register(c36),\n"
796 "#ifdef HLSL\n"
797 "out float4 gl_FragData0 : COLOR0,\n"
798 "out float4 gl_FragData1 : COLOR1\n"
799 "#else\n"
800 "out float4 gl_FragColor : COLOR\n"
801 "#endif\n"
802 ")\n"
803 "{\n"
804 "       float2 TexCoord = TexCoordBoth.xy;\n"
805 "#ifdef USEOFFSETMAPPING\n"
806 "       // apply offsetmapping\n"
807 "       float2 dPdx = ddx(TexCoord);\n"
808 "       float2 dPdy = ddy(TexCoord);\n"
809 "       float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, OffsetMapping_Bias, OffsetMapping_LodDistance, EyeVector, Texture_Normal, dPdx, dPdy);\n"
810 "# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n"
811 "#else\n"
812 "# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n"
813 "#endif\n"
814 "\n"
815 "#ifdef USEALPHAKILL\n"
816 "       if (offsetMappedTexture2D(Texture_Color).a < 0.5)\n"
817 "               discard;\n"
818 "#endif\n"
819 "\n"
820 "#ifdef USEVERTEXTEXTUREBLEND\n"
821 "       float alpha = offsetMappedTexture2D(Texture_Color).a;\n"
822 "       float terrainblend = clamp(float(gl_FrontColor.a) * alpha * 2.0 - 0.5, float(0.0), float(1.0));\n"
823 "       //float terrainblend = min(float(gl_FrontColor.a) * alpha * 2.0, float(1.0));\n"
824 "       //float terrainblend = float(gl_FrontColor.a) * alpha > 0.5;\n"
825 "#endif\n"
826 "\n"
827 "#ifdef USEVERTEXTEXTUREBLEND\n"
828 "       float3 surfacenormal = lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, offsetMappedTexture2D(Texture_Normal).rgb, terrainblend) - float3(0.5, 0.5, 0.5);\n"
829 "       float a = lerp(tex2D(Texture_SecondaryGloss, TexCoord2).a, offsetMappedTexture2D(Texture_Gloss).a, terrainblend);\n"
830 "#else\n"
831 "       float3 surfacenormal = offsetMappedTexture2D(Texture_Normal).rgb - float3(0.5, 0.5, 0.5);\n"
832 "       float a = offsetMappedTexture2D(Texture_Gloss).a;\n"
833 "#endif\n"
834 "\n"
835 "#ifdef HLSL\n"
836 "       gl_FragData0 = float4(normalize(surfacenormal.x * VectorS + surfacenormal.y * VectorT + surfacenormal.z * VectorR.xyz) * 0.5 + float3(0.5, 0.5, 0.5), a);\n"
837 "       float Depth = VectorR.w / 256.0;\n"
838 "       float4 depthcolor = float4(Depth,Depth*65536.0/255.0,Depth*16777216.0/255.0,0.0);\n"
839 "//     float4 depthcolor = float4(Depth,Depth*256.0,Depth*65536.0,0.0);\n"
840 "       depthcolor.yz -= floor(depthcolor.yz);\n"
841 "       gl_FragData1 = depthcolor;\n"
842 "#else\n"
843 "       gl_FragColor = float4(normalize(surfacenormal.x * VectorS + surfacenormal.y * VectorT + surfacenormal.z * VectorR) * 0.5 + float3(0.5, 0.5, 0.5), a);\n"
844 "#endif\n"
845 "}\n"
846 "#endif // FRAGMENT_SHADER\n"
847 "#else // !MODE_DEFERREDGEOMETRY\n"
848 "\n"
849 "\n"
850 "\n"
851 "\n"
852 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
853 "#ifdef VERTEX_SHADER\n"
854 "void main\n"
855 "(\n"
856 "float4 gl_Vertex : POSITION,\n"
857 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
858 "uniform float4x4 ModelViewMatrix : register(c12),\n"
859 "out float4 gl_Position : POSITION,\n"
860 "out float4 ModelViewPosition : TEXCOORD0\n"
861 ")\n"
862 "{\n"
863 "       ModelViewPosition = mul(ModelViewMatrix, gl_Vertex);\n"
864 "       gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
865 "}\n"
866 "#endif // VERTEX_SHADER\n"
867 "\n"
868 "#ifdef FRAGMENT_SHADER\n"
869 "void main\n"
870 "(\n"
871 "#ifdef HLSL\n"
872 "float2 Pixel : VPOS,\n"
873 "#else\n"
874 "float2 Pixel : WPOS,\n"
875 "#endif\n"
876 "float4 ModelViewPosition : TEXCOORD0,\n"
877 "uniform float4x4 ViewToLight : register(c44),\n"
878 "uniform float2 ScreenToDepth : register(c33), // ScreenToDepth = float2(Far / (Far - Near), Far * Near / (Near - Far));\n"
879 "uniform float3 LightPosition : register(c23),\n"
880 "uniform half2 PixelToScreenTexCoord : register(c42),\n"
881 "uniform half3 DeferredColor_Ambient : register(c9),\n"
882 "uniform half3 DeferredColor_Diffuse : register(c10),\n"
883 "#ifdef USESPECULAR\n"
884 "uniform half3 DeferredColor_Specular : register(c11),\n"
885 "uniform half SpecularPower : register(c36),\n"
886 "#endif\n"
887 "uniform sampler Texture_Attenuation : register(s9),\n"
888 "uniform sampler Texture_ScreenDepth : register(s13),\n"
889 "uniform sampler Texture_ScreenNormalMap : register(s14),\n"
890 "\n"
891 "#ifdef USECUBEFILTER\n"
892 "uniform samplerCUBE Texture_Cube : register(s10),\n"
893 "#endif\n"
894 "\n"
895 "#ifdef USESHADOWMAP2D\n"
896 "# ifdef USESHADOWSAMPLER\n"
897 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
898 "# else\n"
899 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
900 "# endif\n"
901 "#endif\n"
902 "\n"
903 "#ifdef USESHADOWMAPVSDCT\n"
904 "uniform samplerCUBE Texture_CubeProjection : register(s12),\n"
905 "#endif\n"
906 "\n"
907 "#if defined(USESHADOWMAP2D)\n"
908 "uniform float2 ShadowMap_TextureScale : register(c35),\n"
909 "uniform float4 ShadowMap_Parameters : register(c34),\n"
910 "#endif\n"
911 "\n"
912 "out float4 gl_FragData0 : COLOR0,\n"
913 "out float4 gl_FragData1 : COLOR1\n"
914 ")\n"
915 "{\n"
916 "       // calculate viewspace pixel position\n"
917 "       float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n"
918 "       //ScreenTexCoord.y = ScreenTexCoord.y * -1 + 1; // Cg is opposite?\n"
919 "       float3 position;\n"
920 "#ifdef HLSL\n"
921 "       position.z = texDepth2D(Texture_ScreenDepth, ScreenTexCoord) * 256.0;\n"
922 "#else\n"
923 "       position.z = ScreenToDepth.y / (texDepth2D(Texture_ScreenDepth, ScreenTexCoord) + ScreenToDepth.x);\n"
924 "#endif\n"
925 "       position.xy = ModelViewPosition.xy * (position.z / ModelViewPosition.z);\n"
926 "       // decode viewspace pixel normal\n"
927 "       half4 normalmap = half4(tex2D(Texture_ScreenNormalMap, ScreenTexCoord));\n"
928 "       half3 surfacenormal = half3(normalize(normalmap.rgb - half3(0.5,0.5,0.5)));\n"
929 "       // surfacenormal = pixel normal in viewspace\n"
930 "       // LightVector = pixel to light in viewspace\n"
931 "       // CubeVector = position in lightspace\n"
932 "       // eyevector = pixel to view in viewspace\n"
933 "       float3 CubeVector = mul(ViewToLight, float4(position,1)).xyz;\n"
934 "       half fade = half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n"
935 "#ifdef USEDIFFUSE\n"
936 "       // calculate diffuse shading\n"
937 "       half3 lightnormal = half3(normalize(LightPosition - position));\n"
938 "       half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n"
939 "#endif\n"
940 "#ifdef USESPECULAR\n"
941 "       // calculate directional shading\n"
942 "       float3 eyevector = position * -1.0;\n"
943 "#  ifdef USEEXACTSPECULARMATH\n"
944 "       half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(eyevector)))*-1.0, 0.0)), 1.0 + SpecularPower * normalmap.a));\n"
945 "#  else\n"
946 "       half3 specularnormal = half3(normalize(lightnormal + half3(normalize(eyevector))));\n"
947 "       half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * normalmap.a));\n"
948 "#  endif\n"
949 "#endif\n"
950 "\n"
951 "#if defined(USESHADOWMAP2D)\n"
952 "       fade *= half(ShadowMapCompare(CubeVector, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n"
953 "#ifdef USESHADOWMAPVSDCT\n"
954 ", Texture_CubeProjection\n"
955 "#endif\n"
956 "       ));\n"
957 "#endif\n"
958 "\n"
959 "#ifdef USEDIFFUSE\n"
960 "       gl_FragData0 = float4((DeferredColor_Ambient + DeferredColor_Diffuse * diffuse) * fade, 1.0);\n"
961 "#else\n"
962 "       gl_FragData0 = float4(DeferredColor_Ambient * fade, 1.0);\n"
963 "#endif\n"
964 "#ifdef USESPECULAR\n"
965 "       gl_FragData1 = float4(DeferredColor_Specular * (specular * fade), 1.0);\n"
966 "#else\n"
967 "       gl_FragData1 = float4(0.0, 0.0, 0.0, 1.0);\n"
968 "#endif\n"
969 "\n"
970 "# ifdef USECUBEFILTER\n"
971 "       float3 cubecolor = texCUBE(Texture_Cube, CubeVector).rgb;\n"
972 "       gl_FragData0.rgb *= cubecolor;\n"
973 "       gl_FragData1.rgb *= cubecolor;\n"
974 "# endif\n"
975 "}\n"
976 "#endif // FRAGMENT_SHADER\n"
977 "#else // !MODE_DEFERREDLIGHTSOURCE\n"
978 "\n"
979 "\n"
980 "\n"
981 "\n"
982 "#ifdef VERTEX_SHADER\n"
983 "void main\n"
984 "(\n"
985 "float4 gl_Vertex : POSITION,\n"
986 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
987 "#if defined(USEVERTEXTEXTUREBLEND) || defined(MODE_VERTEXCOLOR) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n"
988 "float4 gl_Color : COLOR0,\n"
989 "#endif\n"
990 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
991 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n"
992 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n"
993 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n"
994 "float4 gl_MultiTexCoord4 : TEXCOORD4,\n"
995 "\n"
996 "uniform float3 EyePosition : register(c24),\n"
997 "uniform float4x4 TexMatrix : register(c0),\n"
998 "#ifdef USEVERTEXTEXTUREBLEND\n"
999 "uniform float4x4 BackgroundTexMatrix : register(c4),\n"
1000 "#endif\n"
1001 "#ifdef MODE_LIGHTSOURCE\n"
1002 "uniform float4x4 ModelToLight : register(c20),\n"
1003 "#endif\n"
1004 "#ifdef MODE_LIGHTSOURCE\n"
1005 "uniform float3 LightPosition : register(c27),\n"
1006 "#endif\n"
1007 "#ifdef MODE_LIGHTDIRECTION\n"
1008 "uniform float3 LightDir : register(c26),\n"
1009 "#endif\n"
1010 "uniform float4 FogPlane : register(c25),\n"
1011 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
1012 "uniform float3 LightPosition : register(c27),\n"
1013 "#endif\n"
1014 "#ifdef USESHADOWMAPORTHO\n"
1015 "uniform float4x4 ShadowMapMatrix : register(c16),\n"
1016 "#endif\n"
1017 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND)\n"
1018 "out float4 gl_FrontColor : COLOR,\n"
1019 "#endif\n"
1020 "out float4 TexCoordBoth : TEXCOORD0,\n"
1021 "#ifdef USELIGHTMAP\n"
1022 "out float2 TexCoordLightmap : TEXCOORD1,\n"
1023 "#endif\n"
1024 "#ifdef USEEYEVECTOR\n"
1025 "out float3 EyeVector : TEXCOORD2,\n"
1026 "#endif\n"
1027 "#ifdef USEREFLECTION\n"
1028 "out float4 ModelViewProjectionPosition : TEXCOORD3,\n"
1029 "#endif\n"
1030 "#ifdef USEFOG\n"
1031 "out float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n"
1032 "#endif\n"
1033 "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE) || defined(USEDIFFUSE)\n"
1034 "out float3 LightVector : TEXCOORD1,\n"
1035 "#endif\n"
1036 "#ifdef MODE_LIGHTSOURCE\n"
1037 "out float3 CubeVector : TEXCOORD3,\n"
1038 "#endif\n"
1039 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n"
1040 "out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
1041 "out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
1042 "out float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n"
1043 "#endif\n"
1044 "#ifdef USESHADOWMAPORTHO\n"
1045 "out float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n"
1046 "#endif\n"
1047 "out float4 gl_Position : POSITION\n"
1048 ")\n"
1049 "{\n"
1050 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND)\n"
1051 "       gl_FrontColor = gl_Color;\n"
1052 "#endif\n"
1053 "       // copy the surface texcoord\n"
1054 "       TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n"
1055 "#ifdef USEVERTEXTEXTUREBLEND\n"
1056 "       TexCoordBoth.zw = mul(BackgroundTexMatrix, gl_MultiTexCoord0).xy;\n"
1057 "#endif\n"
1058 "#ifdef USELIGHTMAP\n"
1059 "       TexCoordLightmap = gl_MultiTexCoord4.xy;\n"
1060 "#endif\n"
1061 "\n"
1062 "#ifdef MODE_LIGHTSOURCE\n"
1063 "       // transform vertex position into light attenuation/cubemap space\n"
1064 "       // (-1 to +1 across the light box)\n"
1065 "       CubeVector = mul(ModelToLight, gl_Vertex).xyz;\n"
1066 "\n"
1067 "# ifdef USEDIFFUSE\n"
1068 "       // transform unnormalized light direction into tangent space\n"
1069 "       // (we use unnormalized to ensure that it interpolates correctly and then\n"
1070 "       //  normalize it per pixel)\n"
1071 "       float3 lightminusvertex = LightPosition - gl_Vertex.xyz;\n"
1072 "       LightVector = float3(dot(lightminusvertex, gl_MultiTexCoord1.xyz), dot(lightminusvertex, gl_MultiTexCoord2.xyz), dot(lightminusvertex, gl_MultiTexCoord3.xyz));\n"
1073 "# endif\n"
1074 "#endif\n"
1075 "\n"
1076 "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE)\n"
1077 "       LightVector = float3(dot(LightDir, gl_MultiTexCoord1.xyz), dot(LightDir, gl_MultiTexCoord2.xyz), dot(LightDir, gl_MultiTexCoord3.xyz));\n"
1078 "#endif\n"
1079 "\n"
1080 "       // transform unnormalized eye direction into tangent space\n"
1081 "#ifdef USEEYEVECTOR\n"
1082 "       float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n"
1083 "       EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n"
1084 "#endif\n"
1085 "\n"
1086 "#ifdef USEFOG\n"
1087 "       EyeVectorModelSpaceFogPlaneVertexDist.xyz = EyePosition - gl_Vertex.xyz;\n"
1088 "       EyeVectorModelSpaceFogPlaneVertexDist.w = dot(FogPlane, gl_Vertex);\n"
1089 "#endif\n"
1090 "\n"
1091 "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n"
1092 "       VectorS = gl_MultiTexCoord1.xyz;\n"
1093 "       VectorT = gl_MultiTexCoord2.xyz;\n"
1094 "       VectorR = gl_MultiTexCoord3.xyz;\n"
1095 "#endif\n"
1096 "\n"
1097 "       // transform vertex to camera space, using ftransform to match non-VS rendering\n"
1098 "       gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
1099 "\n"
1100 "#ifdef USESHADOWMAPORTHO\n"
1101 "       ShadowMapTC = mul(ShadowMapMatrix, gl_Position).xyz;\n"
1102 "#endif\n"
1103 "\n"
1104 "#ifdef USEREFLECTION\n"
1105 "       ModelViewProjectionPosition = gl_Position;\n"
1106 "#endif\n"
1107 "#ifdef USETRIPPY\n"
1108 "       gl_Position = TrippyVertex(gl_Position);\n"
1109 "#endif\n"
1110 "}\n"
1111 "#endif // VERTEX_SHADER\n"
1112 "\n"
1113 "\n"
1114 "\n"
1115 "\n"
1116 "#ifdef FRAGMENT_SHADER\n"
1117 "void main\n"
1118 "(\n"
1119 "#ifdef USEDEFERREDLIGHTMAP\n"
1120 "#ifdef HLSL\n"
1121 "float2 Pixel : VPOS,\n"
1122 "#else\n"
1123 "float2 Pixel : WPOS,\n"
1124 "#endif\n"
1125 "#endif\n"
1126 "float4 gl_FrontColor : COLOR,\n"
1127 "float4 TexCoordBoth : TEXCOORD0,\n"
1128 "#ifdef USELIGHTMAP\n"
1129 "float2 TexCoordLightmap : TEXCOORD1,\n"
1130 "#endif\n"
1131 "#ifdef USEEYEVECTOR\n"
1132 "float3 EyeVector : TEXCOORD2,\n"
1133 "#endif\n"
1134 "#ifdef USEREFLECTION\n"
1135 "float4 ModelViewProjectionPosition : TEXCOORD3,\n"
1136 "#endif\n"
1137 "#ifdef USEFOG\n"
1138 "float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n"
1139 "#endif\n"
1140 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_LIGHTDIRECTION)\n"
1141 "float3 LightVector : TEXCOORD1,\n"
1142 "#endif\n"
1143 "#ifdef MODE_LIGHTSOURCE\n"
1144 "float3 CubeVector : TEXCOORD3,\n"
1145 "#endif\n"
1146 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
1147 "float4 ModelViewPosition : TEXCOORD0,\n"
1148 "#endif\n"
1149 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n"
1150 "float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
1151 "float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
1152 "float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n"
1153 "#endif\n"
1154 "#ifdef USESHADOWMAPORTHO\n"
1155 "float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n"
1156 "#endif\n"
1157 "\n"
1158 "uniform sampler Texture_Normal : register(s0),\n"
1159 "uniform sampler Texture_Color : register(s1),\n"
1160 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n"
1161 "uniform sampler Texture_Gloss : register(s2),\n"
1162 "#endif\n"
1163 "#ifdef USEGLOW\n"
1164 "uniform sampler Texture_Glow : register(s3),\n"
1165 "#endif\n"
1166 "#ifdef USEVERTEXTEXTUREBLEND\n"
1167 "uniform sampler Texture_SecondaryNormal : register(s4),\n"
1168 "uniform sampler Texture_SecondaryColor : register(s5),\n"
1169 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n"
1170 "uniform sampler Texture_SecondaryGloss : register(s6),\n"
1171 "#endif\n"
1172 "#ifdef USEGLOW\n"
1173 "uniform sampler Texture_SecondaryGlow : register(s7),\n"
1174 "#endif\n"
1175 "#endif\n"
1176 "#ifdef USECOLORMAPPING\n"
1177 "uniform sampler Texture_Pants : register(s4),\n"
1178 "uniform sampler Texture_Shirt : register(s7),\n"
1179 "#endif\n"
1180 "#ifdef USEFOG\n"
1181 "uniform sampler Texture_FogHeightTexture : register(s14),\n"
1182 "uniform sampler Texture_FogMask : register(s8),\n"
1183 "#endif\n"
1184 "#ifdef USELIGHTMAP\n"
1185 "uniform sampler Texture_Lightmap : register(s9),\n"
1186 "#endif\n"
1187 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE)\n"
1188 "uniform sampler Texture_Deluxemap : register(s10),\n"
1189 "#endif\n"
1190 "#ifdef USEREFLECTION\n"
1191 "uniform sampler Texture_Reflection : register(s7),\n"
1192 "#endif\n"
1193 "\n"
1194 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
1195 "uniform sampler Texture_ScreenDepth : register(s13),\n"
1196 "uniform sampler Texture_ScreenNormalMap : register(s14),\n"
1197 "#endif\n"
1198 "#ifdef USEDEFERREDLIGHTMAP\n"
1199 "uniform sampler Texture_ScreenDepth : register(s13),\n"
1200 "uniform sampler Texture_ScreenNormalMap : register(s14),\n"
1201 "uniform sampler Texture_ScreenDiffuse : register(s11),\n"
1202 "uniform sampler Texture_ScreenSpecular : register(s12),\n"
1203 "#endif\n"
1204 "\n"
1205 "#ifdef USECOLORMAPPING\n"
1206 "uniform half3 Color_Pants : register(c7),\n"
1207 "uniform half3 Color_Shirt : register(c8),\n"
1208 "#endif\n"
1209 "#ifdef USEFOG\n"
1210 "uniform float3 FogColor : register(c16),\n"
1211 "uniform float FogRangeRecip : register(c20),\n"
1212 "uniform float FogPlaneViewDist : register(c19),\n"
1213 "uniform float FogHeightFade : register(c17),\n"
1214 "#endif\n"
1215 "\n"
1216 "#ifdef USEOFFSETMAPPING\n"
1217 "uniform float4 OffsetMapping_ScaleSteps : register(c24),\n"
1218 "uniform float OffsetMapping_Bias : register(c54),\n"
1219 "#endif\n"
1220 "\n"
1221 "#ifdef USEDEFERREDLIGHTMAP\n"
1222 "uniform half2 PixelToScreenTexCoord : register(c42),\n"
1223 "uniform half3 DeferredMod_Diffuse : register(c12),\n"
1224 "uniform half3 DeferredMod_Specular : register(c13),\n"
1225 "#endif\n"
1226 "uniform half3 Color_Ambient : register(c3),\n"
1227 "uniform half3 Color_Diffuse : register(c4),\n"
1228 "uniform half3 Color_Specular : register(c5),\n"
1229 "uniform half SpecularPower : register(c36),\n"
1230 "#ifdef USEGLOW\n"
1231 "uniform half3 Color_Glow : register(c6),\n"
1232 "#endif\n"
1233 "uniform half Alpha : register(c0),\n"
1234 "#ifdef USEREFLECTION\n"
1235 "uniform float4 DistortScaleRefractReflect : register(c14),\n"
1236 "uniform float4 ScreenScaleRefractReflect : register(c32),\n"
1237 "uniform float4 ScreenCenterRefractReflect : register(c31),\n"
1238 "uniform half4 ReflectColor : register(c26),\n"
1239 "#endif\n"
1240 "#ifdef USEREFLECTCUBE\n"
1241 "uniform float4x4 ModelToReflectCube : register(c48),\n"
1242 "uniform sampler Texture_ReflectMask : register(s5),\n"
1243 "uniform samplerCUBE Texture_ReflectCube : register(s6),\n"
1244 "#endif\n"
1245 "#ifdef MODE_LIGHTDIRECTION\n"
1246 "uniform half3 LightColor : register(c21),\n"
1247 "#endif\n"
1248 "#ifdef MODE_LIGHTSOURCE\n"
1249 "uniform half3 LightColor : register(c21),\n"
1250 "#endif\n"
1251 "\n"
1252 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE)\n"
1253 "uniform sampler Texture_Attenuation : register(s9),\n"
1254 "uniform samplerCUBE Texture_Cube : register(s10),\n"
1255 "#endif\n"
1256 "\n"
1257 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n"
1258 "\n"
1259 "#ifdef USESHADOWMAP2D\n"
1260 "# ifdef USESHADOWSAMPLER\n"
1261 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
1262 "# else\n"
1263 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
1264 "# endif\n"
1265 "#endif\n"
1266 "\n"
1267 "#ifdef USESHADOWMAPVSDCT\n"
1268 "uniform samplerCUBE Texture_CubeProjection : register(s12),\n"
1269 "#endif\n"
1270 "\n"
1271 "#if defined(USESHADOWMAP2D)\n"
1272 "uniform float2 ShadowMap_TextureScale : register(c35),\n"
1273 "uniform float4 ShadowMap_Parameters : register(c34),\n"
1274 "#endif\n"
1275 "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n"
1276 "\n"
1277 "out float4 gl_FragColor : COLOR\n"
1278 ")\n"
1279 "{\n"
1280 "       float2 TexCoord = TexCoordBoth.xy;\n"
1281 "#ifdef USEVERTEXTEXTUREBLEND\n"
1282 "       float2 TexCoord2 = TexCoordBoth.zw;\n"
1283 "#endif\n"
1284 "#ifdef USEOFFSETMAPPING\n"
1285 "       // apply offsetmapping\n"
1286 "       float2 dPdx = ddx(TexCoord);\n"
1287 "       float2 dPdy = ddy(TexCoord);\n"
1288 "       float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, OffsetMapping_Bias, OffsetMapping_LodDistance, EyeVector, Texture_Normal, dPdx, dPdy);\n"
1289 "# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n"
1290 "#else\n"
1291 "# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n"
1292 "#endif\n"
1293 "\n"
1294 "       // combine the diffuse textures (base, pants, shirt)\n"
1295 "       half4 color = half4(offsetMappedTexture2D(Texture_Color));\n"
1296 "#ifdef USEALPHAKILL\n"
1297 "       if (color.a < 0.5)\n"
1298 "               discard;\n"
1299 "#endif\n"
1300 "       color.a *= Alpha;\n"
1301 "#ifdef USECOLORMAPPING\n"
1302 "       color.rgb += half3(offsetMappedTexture2D(Texture_Pants).rgb) * Color_Pants + half3(offsetMappedTexture2D(Texture_Shirt).rgb) * Color_Shirt;\n"
1303 "#endif\n"
1304 "#ifdef USEVERTEXTEXTUREBLEND\n"
1305 "#ifdef USEBOTHALPHAS\n"
1306 "       half4 color2 = half4(tex2D(Texture_SecondaryColor, TexCoord2));\n"
1307 "       half terrainblend = clamp(half(gl_FrontColor.a) * color.a, half(1.0 - color2.a), half(1.0));\n"
1308 "       color.rgb = lerp(color2.rgb, color.rgb, terrainblend);\n"
1309 "#else\n"
1310 "       half terrainblend = clamp(half(gl_FrontColor.a) * color.a * 2.0 - 0.5, half(0.0), half(1.0));\n"
1311 "       //half terrainblend = min(half(gl_FrontColor.a) * color.a * 2.0, half(1.0));\n"
1312 "       //half terrainblend = half(gl_FrontColor.a) * color.a > 0.5;\n"
1313 "       color.rgb = half3(lerp(tex2D(Texture_SecondaryColor, TexCoord2).rgb, float3(color.rgb), terrainblend));\n"
1314 "       color.a = 1.0;\n"
1315 "       //color = half4(lerp(float4(1, 0, 0, 1), color, terrainblend));\n"
1316 "#endif\n"
1317 "#endif\n"
1318 "\n"
1319 "       // get the surface normal\n"
1320 "#ifdef USEVERTEXTEXTUREBLEND\n"
1321 "       half3 surfacenormal = normalize(half3(lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, offsetMappedTexture2D(Texture_Normal).rgb, terrainblend)) - half3(0.5, 0.5, 0.5));\n"
1322 "#else\n"
1323 "       half3 surfacenormal = half3(normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5, 0.5, 0.5)));\n"
1324 "#endif\n"
1325 "\n"
1326 "       // get the material colors\n"
1327 "       half3 diffusetex = color.rgb;\n"
1328 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n"
1329 "# ifdef USEVERTEXTEXTUREBLEND\n"
1330 "       half4 glosstex = half4(lerp(tex2D(Texture_SecondaryGloss, TexCoord2), offsetMappedTexture2D(Texture_Gloss), terrainblend));\n"
1331 "# else\n"
1332 "       half4 glosstex = half4(offsetMappedTexture2D(Texture_Gloss));\n"
1333 "# endif\n"
1334 "#endif\n"
1335 "\n"
1336 "#ifdef USEREFLECTCUBE\n"
1337 "       float3 TangentReflectVector = reflect(-EyeVector, surfacenormal);\n"
1338 "       float3 ModelReflectVector = TangentReflectVector.x * VectorS + TangentReflectVector.y * VectorT + TangentReflectVector.z * VectorR;\n"
1339 "       float3 ReflectCubeTexCoord = mul(ModelToReflectCube, float4(ModelReflectVector, 0)).xyz;\n"
1340 "       diffusetex += half3(offsetMappedTexture2D(Texture_ReflectMask).rgb) * half3(texCUBE(Texture_ReflectCube, ReflectCubeTexCoord).rgb);\n"
1341 "#endif\n"
1342 "\n"
1343 "\n"
1344 "\n"
1345 "\n"
1346 "#ifdef MODE_LIGHTSOURCE\n"
1347 "       // light source\n"
1348 "#ifdef USEDIFFUSE\n"
1349 "       half3 lightnormal = half3(normalize(LightVector));\n"
1350 "       half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n"
1351 "       color.rgb = diffusetex * (Color_Ambient + diffuse * Color_Diffuse);\n"
1352 "#ifdef USESPECULAR\n"
1353 "#ifdef USEEXACTSPECULARMATH\n"
1354 "       half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), 1.0 + SpecularPower * glosstex.a));\n"
1355 "#else\n"
1356 "       half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n"
1357 "       half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * glosstex.a));\n"
1358 "#endif\n"
1359 "       color.rgb += glosstex.rgb * (specular * Color_Specular);\n"
1360 "#endif\n"
1361 "#else\n"
1362 "       color.rgb = diffusetex * Color_Ambient;\n"
1363 "#endif\n"
1364 "       color.rgb *= LightColor;\n"
1365 "       color.rgb *= half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n"
1366 "#if defined(USESHADOWMAP2D)\n"
1367 "       color.rgb *= half(ShadowMapCompare(CubeVector, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n"
1368 "#ifdef USESHADOWMAPVSDCT\n"
1369 ", Texture_CubeProjection\n"
1370 "#endif\n"
1371 "       ));\n"
1372 "\n"
1373 "#endif\n"
1374 "# ifdef USECUBEFILTER\n"
1375 "       color.rgb *= half3(texCUBE(Texture_Cube, CubeVector).rgb);\n"
1376 "# endif\n"
1377 "\n"
1378 "#ifdef USESHADOWMAP2D\n"
1379 "#ifdef USESHADOWMAPVSDCT\n"
1380 "//     float3 shadowmaptc = GetShadowMapTC2D(CubeVector, ShadowMap_Parameters, Texture_CubeProjection);\n"
1381 "#else\n"
1382 "//     float3 shadowmaptc = GetShadowMapTC2D(CubeVector, ShadowMap_Parameters);\n"
1383 "#endif\n"
1384 "//     color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n"
1385 "//     color.rgb = half3(tex2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale).rgb);\n"
1386 "//     color.rgb = half3(shadowmaptc.xyz * float3(ShadowMap_TextureScale,1.0));\n"
1387 "//     color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n"
1388 "//     color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n"
1389 "//     color.rgb = half3(tex2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale).rgb);\n"
1390 "//     color.rgb = half3(shadowmaptc.xyz * float3(ShadowMap_TextureScale,1.0));\n"
1391 "//     color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n"
1392 "//     color.r = half(shadowmaptc.z - texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n"
1393 "//     color.r = half(shadowmaptc.z);\n"
1394 "//     color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n"
1395 "//     color.r = half(shadowmaptc.z);\n"
1396 "//     color.r = 1;\n"
1397 "//     color.rgb = abs(CubeVector);\n"
1398 "#endif\n"
1399 "//     color.rgb = half3(1,1,1);\n"
1400 "#endif // MODE_LIGHTSOURCE\n"
1401 "\n"
1402 "\n"
1403 "\n"
1404 "\n"
1405 "#ifdef MODE_LIGHTDIRECTION\n"
1406 "       #define SHADING\n"
1407 "       #ifdef USEDIFFUSE\n"
1408 "               half3 lightnormal = half3(normalize(LightVector));\n"
1409 "       #endif\n"
1410 "       #define lightcolor LightColor\n"
1411 "#endif // MODE_LIGHTDIRECTION\n"
1412 "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n"
1413 "       #define SHADING\n"
1414 "       // deluxemap lightmapping using light vectors in modelspace (q3map2 -light -deluxe)\n"
1415 "       half3 lightnormal_modelspace = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n"
1416 "       half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n"
1417 "       // convert modelspace light vector to tangentspace\n"
1418 "       half3 lightnormal = half3(dot(lightnormal_modelspace, half3(VectorS)), dot(lightnormal_modelspace, half3(VectorT)), dot(lightnormal_modelspace, half3(VectorR)));\n"
1419 "       // calculate directional shading (and undoing the existing angle attenuation on the lightmap by the division)\n"
1420 "       // note that q3map2 is too stupid to calculate proper surface normals when q3map_nonplanar\n"
1421 "       // is used (the lightmap and deluxemap coords correspond to virtually random coordinates\n"
1422 "       // on that luxel, and NOT to its center, because recursive triangle subdivision is used\n"
1423 "       // to map the luxels to coordinates on the draw surfaces), which also causes\n"
1424 "       // deluxemaps to be wrong because light contributions from the wrong side of the surface\n"
1425 "       // are added up. To prevent divisions by zero or strong exaggerations, a max()\n"
1426 "       // nudge is done here at expense of some additional fps. This is ONLY needed for\n"
1427 "       // deluxemaps, tangentspace deluxemap avoid this problem by design.\n"
1428 "       lightcolor *= 1.0 / max(0.25, lightnormal.z);\n"
1429 "#endif // MODE_LIGHTDIRECTIONMAP_MODELSPACE\n"
1430 "#ifdef MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n"
1431 "       #define SHADING\n"
1432 "       // deluxemap lightmapping using light vectors in tangentspace (hmap2 -light)\n"
1433 "       half3 lightnormal = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n"
1434 "       half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n"
1435 "#endif\n"
1436 "#if defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n"
1437 "       #define SHADING\n"
1438 "       // forced deluxemap on lightmapped/vertexlit surfaces\n"
1439 "       half3 lightnormal = half3(0.0, 0.0, 1.0);\n"
1440 "   #ifdef USELIGHTMAP\n"
1441 "               half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n"
1442 "   #else\n"
1443 "               half3 lightcolor = half3(gl_FrontColor.rgb);\n"
1444 "   #endif\n"
1445 "#endif\n"
1446 "#ifdef MODE_FAKELIGHT\n"
1447 "       #define SHADING\n"
1448 "       half3 lightnormal = half3(normalize(EyeVector));\n"
1449 "       half3 lightcolor = half3(1.0,1.0,1.0);\n"
1450 "#endif // MODE_FAKELIGHT\n"
1451 "\n"
1452 "\n"
1453 "\n"
1454 "\n"
1455 "#ifdef MODE_LIGHTMAP\n"
1456 "       color.rgb = diffusetex * (Color_Ambient + half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb) * Color_Diffuse);\n"
1457 "#endif // MODE_LIGHTMAP\n"
1458 "#ifdef MODE_VERTEXCOLOR\n"
1459 "       color.rgb = diffusetex * (Color_Ambient + half3(gl_FrontColor.rgb) * Color_Diffuse);\n"
1460 "#endif // MODE_VERTEXCOLOR\n"
1461 "#ifdef MODE_FLATCOLOR\n"
1462 "       color.rgb = diffusetex * Color_Ambient;\n"
1463 "#endif // MODE_FLATCOLOR\n"
1464 "\n"
1465 "\n"
1466 "\n"
1467 "\n"
1468 "#ifdef SHADING\n"
1469 "# ifdef USEDIFFUSE\n"
1470 "       half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n"
1471 "#  ifdef USESPECULAR\n"
1472 "#   ifdef USEEXACTSPECULARMATH\n"
1473 "       half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), 1.0 + SpecularPower * glosstex.a));\n"
1474 "#   else\n"
1475 "       half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n"
1476 "       half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * glosstex.a));\n"
1477 "#   endif\n"
1478 "       color.rgb = diffusetex * Color_Ambient + (diffusetex * Color_Diffuse * diffuse + glosstex.rgb * Color_Specular * specular) * lightcolor;\n"
1479 "#  else\n"
1480 "       color.rgb = diffusetex * (Color_Ambient + Color_Diffuse * diffuse * lightcolor);\n"
1481 "#  endif\n"
1482 "# else\n"
1483 "       color.rgb = diffusetex * Color_Ambient;\n"
1484 "# endif\n"
1485 "#endif\n"
1486 "\n"
1487 "#ifdef USESHADOWMAPORTHO\n"
1488 "       color.rgb *= half(ShadowMapCompare(ShadowMapTC, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale));\n"
1489 "#endif\n"
1490 "\n"
1491 "#ifdef USEDEFERREDLIGHTMAP\n"
1492 "       float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n"
1493 "       color.rgb += diffusetex * half3(tex2D(Texture_ScreenDiffuse, ScreenTexCoord).rgb) * DeferredMod_Diffuse;\n"
1494 "       color.rgb += glosstex.rgb * half3(tex2D(Texture_ScreenSpecular, ScreenTexCoord).rgb) * DeferredMod_Specular;\n"
1495 "//     color.rgb = half3(tex2D(Texture_ScreenDepth, ScreenTexCoord).rgb);\n"
1496 "//     color.r = half(texDepth2D(Texture_ScreenDepth, ScreenTexCoord)) * 1.0;\n"
1497 "#endif\n"
1498 "\n"
1499 "#ifdef USEGLOW\n"
1500 "#ifdef USEVERTEXTEXTUREBLEND\n"
1501 "       color.rgb += half3(lerp(tex2D(Texture_SecondaryGlow, TexCoord2).rgb, offsetMappedTexture2D(Texture_Glow).rgb, terrainblend)) * Color_Glow;\n"
1502 "#else\n"
1503 "       color.rgb += half3(offsetMappedTexture2D(Texture_Glow).rgb) * Color_Glow;\n"
1504 "#endif\n"
1505 "#endif\n"
1506 "\n"
1507 "#ifdef USEFOG\n"
1508 "       color.rgb = half3(FogVertex(color, FogColor, EyeVectorModelSpaceFogPlaneVertexDist.xyz, EyeVectorModelSpaceFogPlaneVertexDist.w, FogRangeRecip, FogPlaneViewDist, FogHeightFade, Texture_FogMask, Texture_FogHeightTexture));\n"
1509 "#endif\n"
1510 "\n"
1511 "       // 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"
1512 "#ifdef USEREFLECTION\n"
1513 "       float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n"
1514 "       //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n"
1515 "       float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW.zw + ScreenCenterRefractReflect.zw;\n"
1516 "       float2 ScreenTexCoord = SafeScreenTexCoord + float3(normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5,0.5,0.5))).xy * DistortScaleRefractReflect.zw;\n"
1517 "       // FIXME temporary hack to detect the case that the reflection\n"
1518 "       // gets blackened at edges due to leaving the area that contains actual\n"
1519 "       // content.\n"
1520 "       // Remove this 'ack once we have a better way to stop this thing from\n"
1521 "       // 'appening.\n"
1522 "       float f = min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(0.01, 0.01)).rgb) / 0.05);\n"
1523 "       f      *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(0.01, -0.01)).rgb) / 0.05);\n"
1524 "       f      *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, 0.01)).rgb) / 0.05);\n"
1525 "       f      *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, -0.01)).rgb) / 0.05);\n"
1526 "       ScreenTexCoord = lerp(SafeScreenTexCoord, ScreenTexCoord, f);\n"
1527 "       color.rgb = lerp(color.rgb, half3(tex2D(Texture_Reflection, ScreenTexCoord).rgb) * ReflectColor.rgb, ReflectColor.a);\n"
1528 "#endif\n"
1529 "\n"
1530 "       gl_FragColor = float4(color);\n"
1531 "}\n"
1532 "#endif // FRAGMENT_SHADER\n"
1533 "\n"
1534 "#endif // !MODE_DEFERREDLIGHTSOURCE\n"
1535 "#endif // !MODE_DEFERREDGEOMETRY\n"
1536 "#endif // !MODE_WATER\n"
1537 "#endif // !MODE_REFRACTION\n"
1538 "#endif // !MODE_BLOOMBLUR\n"
1539 "#endif // !MODE_GENERIC\n"
1540 "#endif // !MODE_POSTPROCESS\n"
1541 "#endif // !MODE_SHOWDEPTH\n"
1542 "#endif // !MODE_DEPTH_OR_SHADOW\n"