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