]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - shader_hlsl.h
remove CRLFs added by last commit
[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, float3 OffsetMapping_ScaleSteps, float3 EyeVector, sampler Texture_Normal, float2 dPdx, float2 dPdy)\n"
499 "{\n"
500 "       float i;\n"
501 "#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n"
502 "       // 14 sample relief mapping: linear search and then binary search\n"
503 "       // this basically steps forward a small amount repeatedly until it finds\n"
504 "       // itself inside solid, then jitters forward and back using decreasing\n"
505 "       // amounts to find the impact\n"
506 "       //float3 OffsetVector = float3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMapping_ScaleSteps.x) * float2(-1, 1), -1);\n"
507 "       //float3 OffsetVector = float3(normalize(EyeVector.xy) * OffsetMapping_ScaleSteps.x * float2(-1, 1), -1);\n"
508 "       float3 OffsetVector = float3(normalize(EyeVector).xy * OffsetMapping_ScaleSteps.x * float2(-1, 1), -1);\n"
509 "       float3 RT = float3(TexCoord, 1);\n"
510 "       OffsetVector *= OffsetMapping_ScaleSteps.z;\n"
511 "       for(i = 1.0; i < OffsetMapping_ScaleSteps.y; ++i)\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)          - 0.5);\n"
514 "       RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * 0.5    - 0.25);\n"
515 "       RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * 0.25   - 0.125);\n"
516 "       RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * 0.125  - 0.0625);\n"
517 "       RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * 0.0625 - 0.03125);\n"
518 "       return RT.xy;\n"
519 "#else\n"
520 "       // 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits)\n"
521 "       //float2 OffsetVector = float2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMapping_ScaleSteps.x) * float2(-1, 1));\n"
522 "       //float2 OffsetVector = float2(normalize(EyeVector.xy) * OffsetMapping_ScaleSteps.x * float2(-1, 1));\n"
523 "       float2 OffsetVector = float2(normalize(EyeVector).xy * OffsetMapping_ScaleSteps.x * float2(-1, 1));\n"
524 "       OffsetVector *= OffsetMapping_ScaleSteps.z;\n"
525 "       for(i = 0.0; i < OffsetMapping_ScaleSteps.y; ++i)\n"
526 "               TexCoord += OffsetVector * (1.0 - tex2Dgrad(Texture_Normal, TexCoord, dPdx, dPdy).a);\n"
527 "       return TexCoord;\n"
528 "#endif\n"
529 "}\n"
530 "#endif // USEOFFSETMAPPING\n"
531 "\n"
532 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n"
533 "#if defined(USESHADOWMAP2D)\n"
534 "# ifdef USESHADOWMAPORTHO\n"
535 "#  define GetShadowMapTC2D(dir, ShadowMap_Parameters) (min(dir, ShadowMap_Parameters.xyz))\n"
536 "# else\n"
537 "#  ifdef USESHADOWMAPVSDCT\n"
538 "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters, samplerCUBE Texture_CubeProjection)\n"
539 "{\n"
540 "       float3 adir = abs(dir);\n"
541 "       float2 aparams = ShadowMap_Parameters.xy / max(max(adir.x, adir.y), adir.z);\n"
542 "       float4 proj = texCUBE(Texture_CubeProjection, dir);\n"
543 "       return float3(lerp(dir.xy, dir.zz, proj.xy) * aparams.x + proj.zw * ShadowMap_Parameters.z, aparams.y + ShadowMap_Parameters.w);\n"
544 "}\n"
545 "#  else\n"
546 "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters)\n"
547 "{\n"
548 "       float3 adir = abs(dir);\n"
549 "       float ma = adir.z;\n"
550 "       float4 proj = float4(dir, 2.5);\n"
551 "       if (adir.x > ma) { ma = adir.x; proj = float4(dir.zyx, 0.5); }\n"
552 "       if (adir.y > ma) { ma = adir.y; proj = float4(dir.xzy, 1.5); }\n"
553 "#ifdef HLSL\n"
554 "       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"
555 "#else\n"
556 "       float2 aparams = ShadowMap_Parameters.xy / ma;\n"
557 "       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"
558 "#endif\n"
559 "}\n"
560 "#  endif\n"
561 "# endif\n"
562 "#endif // defined(USESHADOWMAP2D)\n"
563 "\n"
564 "# ifdef USESHADOWMAP2D\n"
565 "#ifdef USESHADOWMAPVSDCT\n"
566 "float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale, samplerCUBE Texture_CubeProjection)\n"
567 "#else\n"
568 "float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale)\n"
569 "#endif\n"
570 "{\n"
571 "#ifdef USESHADOWMAPVSDCT\n"
572 "       float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters, Texture_CubeProjection);\n"
573 "#else\n"
574 "       float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters);\n"
575 "#endif\n"
576 "       float f;\n"
577 "\n"
578 "#  ifdef USESHADOWSAMPLER\n"
579 "#    ifdef USESHADOWMAPPCF\n"
580 "#      define texval(x, y) tex2Dproj(Texture_ShadowMap2D, float4(center + float2(x, y)*ShadowMap_TextureScale, shadowmaptc.z, 1.0)).r  \n"
581 "       float2 center = shadowmaptc.xy*ShadowMap_TextureScale;\n"
582 "       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"
583 "#    else\n"
584 "       f = tex2Dproj(Texture_ShadowMap2D, float4(shadowmaptc.xy*ShadowMap_TextureScale, shadowmaptc.z, 1.0)).r;\n"
585 "#    endif\n"
586 "#  else\n"
587 "#    ifdef USESHADOWMAPPCF\n"
588 "#     if defined(GL_ARB_texture_gather) || defined(GL_AMD_texture_texture4)\n"
589 "#      ifdef GL_ARB_texture_gather\n"
590 "#        define texval(x, y) textureGatherOffset(Texture_ShadowMap2D, center, int2(x, y))\n"
591 "#      else\n"
592 "#        define texval(x, y) texture4(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale)\n"
593 "#      endif\n"
594 "       float2 offset = frac(shadowmaptc.xy - 0.5), center = (shadowmaptc.xy - offset)*ShadowMap_TextureScale;\n"
595 "#      if USESHADOWMAPPCF > 1\n"
596 "       float4 group1 = step(shadowmaptc.z, texval(-2.0, -2.0));\n"
597 "       float4 group2 = step(shadowmaptc.z, texval( 0.0, -2.0));\n"
598 "       float4 group3 = step(shadowmaptc.z, texval( 2.0, -2.0));\n"
599 "       float4 group4 = step(shadowmaptc.z, texval(-2.0,  0.0));\n"
600 "       float4 group5 = step(shadowmaptc.z, texval( 0.0,  0.0));\n"
601 "       float4 group6 = step(shadowmaptc.z, texval( 2.0,  0.0));\n"
602 "       float4 group7 = step(shadowmaptc.z, texval(-2.0,  2.0));\n"
603 "       float4 group8 = step(shadowmaptc.z, texval( 0.0,  2.0));\n"
604 "       float4 group9 = step(shadowmaptc.z, texval( 2.0,  2.0));\n"
605 "       float4 locols = float4(group1.ab, group3.ab);\n"
606 "       float4 hicols = float4(group7.rg, group9.rg);\n"
607 "       locols.yz += group2.ab;\n"
608 "       hicols.yz += group8.rg;\n"
609 "       float4 midcols = float4(group1.rg, group3.rg) + float4(group7.ab, group9.ab) +\n"
610 "                               float4(group4.rg, group6.rg) + float4(group4.ab, group6.ab) +\n"
611 "                               lerp(locols, hicols, offset.y);\n"
612 "       float4 cols = group5 + float4(group2.rg, group8.ab);\n"
613 "       cols.xyz += lerp(midcols.xyz, midcols.yzw, offset.x);\n"
614 "       f = dot(cols, float4(1.0/25.0));\n"
615 "#      else\n"
616 "       float4 group1 = step(shadowmaptc.z, texval(-1.0, -1.0));\n"
617 "       float4 group2 = step(shadowmaptc.z, texval( 1.0, -1.0));\n"
618 "       float4 group3 = step(shadowmaptc.z, texval(-1.0,  1.0));\n"
619 "       float4 group4 = step(shadowmaptc.z, texval( 1.0,  1.0));\n"
620 "       float4 cols = float4(group1.rg, group2.rg) + float4(group3.ab, group4.ab) +\n"
621 "                               lerp(float4(group1.ab, group2.ab), float4(group3.rg, group4.rg), offset.y);\n"
622 "       f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n"
623 "#      endif\n"
624 "#     else\n"
625 "#      ifdef GL_EXT_gpu_shader4\n"
626 "#        define texval(x, y) tex2DOffset(Texture_ShadowMap2D, center, int2(x, y)).r\n"
627 "#      else\n"
628 "#        define texval(x, y) texDepth2D(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale).r  \n"
629 "#      endif\n"
630 "#      if USESHADOWMAPPCF > 1\n"
631 "       float2 center = shadowmaptc.xy - 0.5, offset = frac(center);\n"
632 "       center *= ShadowMap_TextureScale;\n"
633 "       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"
634 "       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"
635 "       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"
636 "       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"
637 "       float4 cols = row2 + row3 + lerp(row1, row4, offset.y);\n"
638 "       f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n"
639 "#      else\n"
640 "       float2 center = shadowmaptc.xy*ShadowMap_TextureScale, offset = frac(shadowmaptc.xy);\n"
641 "       float3 row1 = step(shadowmaptc.z, float3(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0)));\n"
642 "       float3 row2 = step(shadowmaptc.z, float3(texval(-1.0,  0.0), texval( 0.0,  0.0), texval( 1.0,  0.0)));\n"
643 "       float3 row3 = step(shadowmaptc.z, float3(texval(-1.0,  1.0), texval( 0.0,  1.0), texval( 1.0,  1.0)));\n"
644 "       float3 cols = row2 + lerp(row1, row3, offset.y);\n"
645 "       f = dot(lerp(cols.xy, cols.yz, offset.x), float2(0.25,0.25));\n"
646 "#      endif\n"
647 "#     endif\n"
648 "#    else\n"
649 "       f = step(shadowmaptc.z, tex2D(Texture_ShadowMap2D, shadowmaptc.xy*ShadowMap_TextureScale).r);\n"
650 "#    endif\n"
651 "#  endif\n"
652 "#  ifdef USESHADOWMAPORTHO\n"
653 "       return lerp(ShadowMap_Parameters.w, 1.0, f);\n"
654 "#  else\n"
655 "       return f;\n"
656 "#  endif\n"
657 "}\n"
658 "# endif\n"
659 "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n"
660 "#endif // FRAGMENT_SHADER\n"
661 "\n"
662 "\n"
663 "\n"
664 "\n"
665 "#ifdef MODE_DEFERREDGEOMETRY\n"
666 "#ifdef VERTEX_SHADER\n"
667 "void main\n"
668 "(\n"
669 "float4 gl_Vertex : POSITION,\n"
670 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
671 "#ifdef USEVERTEXTEXTUREBLEND\n"
672 "float4 gl_Color : COLOR0,\n"
673 "#endif\n"
674 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
675 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n"
676 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n"
677 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n"
678 "uniform float4x4 TexMatrix : register(c0),\n"
679 "#ifdef USEVERTEXTEXTUREBLEND\n"
680 "uniform float4x4 BackgroundTexMatrix : register(c4),\n"
681 "#endif\n"
682 "uniform float4x4 ModelViewMatrix : register(c12),\n"
683 "#ifdef USEOFFSETMAPPING\n"
684 "uniform float3 EyePosition : register(c24),\n"
685 "#endif\n"
686 "out float4 gl_Position : POSITION,\n"
687 "#ifdef USEVERTEXTEXTUREBLEND\n"
688 "out float4 gl_FrontColor : COLOR,\n"
689 "#endif\n"
690 "out float4 TexCoordBoth : TEXCOORD0,\n"
691 "#ifdef USEOFFSETMAPPING\n"
692 "out float3 EyeVector : TEXCOORD2,\n"
693 "#endif\n"
694 "out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
695 "out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
696 "out float4 VectorR : TEXCOORD7 // direction of R texcoord (surface normal), Depth value\n"
697 ")\n"
698 "{\n"
699 "       TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n"
700 "#ifdef USEVERTEXTEXTUREBLEND\n"
701 "       gl_FrontColor = gl_Color;\n"
702 "       TexCoordBoth.zw = float2(Backgroundmul(TexMatrix, gl_MultiTexCoord0));\n"
703 "#endif\n"
704 "\n"
705 "       // transform unnormalized eye direction into tangent space\n"
706 "#ifdef USEOFFSETMAPPING\n"
707 "       float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n"
708 "       EyeVector.x = dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz);\n"
709 "       EyeVector.y = dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz);\n"
710 "       EyeVector.z = dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz);\n"
711 "#endif\n"
712 "\n"
713 "       VectorS = mul(ModelViewMatrix, float4(gl_MultiTexCoord1.xyz, 0)).xyz;\n"
714 "       VectorT = mul(ModelViewMatrix, float4(gl_MultiTexCoord2.xyz, 0)).xyz;\n"
715 "       VectorR.xyz = mul(ModelViewMatrix, float4(gl_MultiTexCoord3.xyz, 0)).xyz;\n"
716 "       gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
717 "       VectorR.w = gl_Position.z;\n"
718 "}\n"
719 "#endif // VERTEX_SHADER\n"
720 "\n"
721 "#ifdef FRAGMENT_SHADER\n"
722 "void main\n"
723 "(\n"
724 "float4 TexCoordBoth : TEXCOORD0,\n"
725 "float3 EyeVector : TEXCOORD2,\n"
726 "float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
727 "float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
728 "float4 VectorR : TEXCOORD7, // direction of R texcoord (surface normal), Depth value\n"
729 "uniform sampler Texture_Normal : register(s0),\n"
730 "#ifdef USEALPHAKILL\n"
731 "uniform sampler Texture_Color : register(s1),\n"
732 "#endif\n"
733 "uniform sampler Texture_Gloss : register(s2),\n"
734 "#ifdef USEVERTEXTEXTUREBLEND\n"
735 "uniform sampler Texture_SecondaryNormal : register(s4),\n"
736 "uniform sampler Texture_SecondaryGloss : register(s6),\n"
737 "#endif\n"
738 "#ifdef USEOFFSETMAPPING\n"
739 "uniform float3 OffsetMapping_ScaleSteps : register(c24),\n"
740 "#endif\n"
741 "uniform half SpecularPower : register(c36),\n"
742 "#ifdef HLSL\n"
743 "out float4 gl_FragData0 : COLOR0,\n"
744 "out float4 gl_FragData1 : COLOR1\n"
745 "#else\n"
746 "out float4 gl_FragColor : COLOR\n"
747 "#endif\n"
748 ")\n"
749 "{\n"
750 "       float2 TexCoord = TexCoordBoth.xy;\n"
751 "#ifdef USEOFFSETMAPPING\n"
752 "       // apply offsetmapping\n"
753 "       float2 dPdx = ddx(TexCoord);\n"
754 "       float2 dPdy = ddy(TexCoord);\n"
755 "       float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, EyeVector, Texture_Normal, dPdx, dPdy);\n"
756 "# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n"
757 "#else\n"
758 "# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n"
759 "#endif\n"
760 "\n"
761 "#ifdef USEALPHAKILL\n"
762 "       if (offsetMappedTexture2D(Texture_Color).a < 0.5)\n"
763 "               discard;\n"
764 "#endif\n"
765 "\n"
766 "#ifdef USEVERTEXTEXTUREBLEND\n"
767 "       float alpha = offsetMappedTexture2D(Texture_Color).a;\n"
768 "       float terrainblend = clamp(float(gl_FrontColor.a) * alpha * 2.0 - 0.5, float(0.0), float(1.0));\n"
769 "       //float terrainblend = min(float(gl_FrontColor.a) * alpha * 2.0, float(1.0));\n"
770 "       //float terrainblend = float(gl_FrontColor.a) * alpha > 0.5;\n"
771 "#endif\n"
772 "\n"
773 "#ifdef USEVERTEXTEXTUREBLEND\n"
774 "       float3 surfacenormal = lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, offsetMappedTexture2D(Texture_Normal).rgb, terrainblend) - float3(0.5, 0.5, 0.5);\n"
775 "       float a = lerp(tex2D(Texture_SecondaryGloss, TexCoord2).a, offsetMappedTexture2D(Texture_Gloss).a, terrainblend);\n"
776 "#else\n"
777 "       float3 surfacenormal = offsetMappedTexture2D(Texture_Normal).rgb - float3(0.5, 0.5, 0.5);\n"
778 "       float a = offsetMappedTexture2D(Texture_Gloss).a;\n"
779 "#endif\n"
780 "\n"
781 "#ifdef HLSL\n"
782 "       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"
783 "       float Depth = VectorR.w / 256.0;\n"
784 "       float4 depthcolor = float4(Depth,Depth*65536.0/255.0,Depth*16777216.0/255.0,0.0);\n"
785 "//     float4 depthcolor = float4(Depth,Depth*256.0,Depth*65536.0,0.0);\n"
786 "       depthcolor.yz -= floor(depthcolor.yz);\n"
787 "       gl_FragData1 = depthcolor;\n"
788 "#else\n"
789 "       gl_FragColor = float4(normalize(surfacenormal.x * VectorS + surfacenormal.y * VectorT + surfacenormal.z * VectorR) * 0.5 + float3(0.5, 0.5, 0.5), a);\n"
790 "#endif\n"
791 "}\n"
792 "#endif // FRAGMENT_SHADER\n"
793 "#else // !MODE_DEFERREDGEOMETRY\n"
794 "\n"
795 "\n"
796 "\n"
797 "\n"
798 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
799 "#ifdef VERTEX_SHADER\n"
800 "void main\n"
801 "(\n"
802 "float4 gl_Vertex : POSITION,\n"
803 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
804 "uniform float4x4 ModelViewMatrix : register(c12),\n"
805 "out float4 gl_Position : POSITION,\n"
806 "out float4 ModelViewPosition : TEXCOORD0\n"
807 ")\n"
808 "{\n"
809 "       ModelViewPosition = mul(ModelViewMatrix, gl_Vertex);\n"
810 "       gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
811 "}\n"
812 "#endif // VERTEX_SHADER\n"
813 "\n"
814 "#ifdef FRAGMENT_SHADER\n"
815 "void main\n"
816 "(\n"
817 "#ifdef HLSL\n"
818 "float2 Pixel : VPOS,\n"
819 "#else\n"
820 "float2 Pixel : WPOS,\n"
821 "#endif\n"
822 "float4 ModelViewPosition : TEXCOORD0,\n"
823 "uniform float4x4 ViewToLight : register(c44),\n"
824 "uniform float2 ScreenToDepth : register(c33), // ScreenToDepth = float2(Far / (Far - Near), Far * Near / (Near - Far));\n"
825 "uniform float3 LightPosition : register(c23),\n"
826 "uniform half2 PixelToScreenTexCoord : register(c42),\n"
827 "uniform half3 DeferredColor_Ambient : register(c9),\n"
828 "uniform half3 DeferredColor_Diffuse : register(c10),\n"
829 "#ifdef USESPECULAR\n"
830 "uniform half3 DeferredColor_Specular : register(c11),\n"
831 "uniform half SpecularPower : register(c36),\n"
832 "#endif\n"
833 "uniform sampler Texture_Attenuation : register(s9),\n"
834 "uniform sampler Texture_ScreenDepth : register(s13),\n"
835 "uniform sampler Texture_ScreenNormalMap : register(s14),\n"
836 "\n"
837 "#ifdef USECUBEFILTER\n"
838 "uniform samplerCUBE Texture_Cube : register(s10),\n"
839 "#endif\n"
840 "\n"
841 "#ifdef USESHADOWMAP2D\n"
842 "# ifdef USESHADOWSAMPLER\n"
843 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
844 "# else\n"
845 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
846 "# endif\n"
847 "#endif\n"
848 "\n"
849 "#ifdef USESHADOWMAPVSDCT\n"
850 "uniform samplerCUBE Texture_CubeProjection : register(s12),\n"
851 "#endif\n"
852 "\n"
853 "#if defined(USESHADOWMAP2D)\n"
854 "uniform float2 ShadowMap_TextureScale : register(c35),\n"
855 "uniform float4 ShadowMap_Parameters : register(c34),\n"
856 "#endif\n"
857 "\n"
858 "out float4 gl_FragData0 : COLOR0,\n"
859 "out float4 gl_FragData1 : COLOR1\n"
860 ")\n"
861 "{\n"
862 "       // calculate viewspace pixel position\n"
863 "       float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n"
864 "       //ScreenTexCoord.y = ScreenTexCoord.y * -1 + 1; // Cg is opposite?\n"
865 "       float3 position;\n"
866 "#ifdef HLSL\n"
867 "       position.z = texDepth2D(Texture_ScreenDepth, ScreenTexCoord) * 256.0;\n"
868 "#else\n"
869 "       position.z = ScreenToDepth.y / (texDepth2D(Texture_ScreenDepth, ScreenTexCoord) + ScreenToDepth.x);\n"
870 "#endif\n"
871 "       position.xy = ModelViewPosition.xy * (position.z / ModelViewPosition.z);\n"
872 "       // decode viewspace pixel normal\n"
873 "       half4 normalmap = half4(tex2D(Texture_ScreenNormalMap, ScreenTexCoord));\n"
874 "       half3 surfacenormal = half3(normalize(normalmap.rgb - half3(0.5,0.5,0.5)));\n"
875 "       // surfacenormal = pixel normal in viewspace\n"
876 "       // LightVector = pixel to light in viewspace\n"
877 "       // CubeVector = position in lightspace\n"
878 "       // eyevector = pixel to view in viewspace\n"
879 "       float3 CubeVector = mul(ViewToLight, float4(position,1)).xyz;\n"
880 "       half fade = half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n"
881 "#ifdef USEDIFFUSE\n"
882 "       // calculate diffuse shading\n"
883 "       half3 lightnormal = half3(normalize(LightPosition - position));\n"
884 "       half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n"
885 "#endif\n"
886 "#ifdef USESPECULAR\n"
887 "       // calculate directional shading\n"
888 "       float3 eyevector = position * -1.0;\n"
889 "#  ifdef USEEXACTSPECULARMATH\n"
890 "       half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(eyevector)))*-1.0, 0.0)), SpecularPower * normalmap.a));\n"
891 "#  else\n"
892 "       half3 specularnormal = half3(normalize(lightnormal + half3(normalize(eyevector))));\n"
893 "       half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * normalmap.a));\n"
894 "#  endif\n"
895 "#endif\n"
896 "\n"
897 "#if defined(USESHADOWMAP2D)\n"
898 "       fade *= half(ShadowMapCompare(CubeVector, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n"
899 "#ifdef USESHADOWMAPVSDCT\n"
900 ", Texture_CubeProjection\n"
901 "#endif\n"
902 "       ));\n"
903 "#endif\n"
904 "\n"
905 "#ifdef USEDIFFUSE\n"
906 "       gl_FragData0 = float4((DeferredColor_Ambient + DeferredColor_Diffuse * diffuse) * fade, 1.0);\n"
907 "#else\n"
908 "       gl_FragData0 = float4(DeferredColor_Ambient * fade, 1.0);\n"
909 "#endif\n"
910 "#ifdef USESPECULAR\n"
911 "       gl_FragData1 = float4(DeferredColor_Specular * (specular * fade), 1.0);\n"
912 "#else\n"
913 "       gl_FragData1 = float4(0.0, 0.0, 0.0, 1.0);\n"
914 "#endif\n"
915 "\n"
916 "# ifdef USECUBEFILTER\n"
917 "       float3 cubecolor = texCUBE(Texture_Cube, CubeVector).rgb;\n"
918 "       gl_FragData0.rgb *= cubecolor;\n"
919 "       gl_FragData1.rgb *= cubecolor;\n"
920 "# endif\n"
921 "}\n"
922 "#endif // FRAGMENT_SHADER\n"
923 "#else // !MODE_DEFERREDLIGHTSOURCE\n"
924 "\n"
925 "\n"
926 "\n"
927 "\n"
928 "#ifdef VERTEX_SHADER\n"
929 "void main\n"
930 "(\n"
931 "float4 gl_Vertex : POSITION,\n"
932 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
933 "#if defined(USEVERTEXTEXTUREBLEND) || defined(MODE_VERTEXCOLOR)\n"
934 "float4 gl_Color : COLOR0,\n"
935 "#endif\n"
936 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
937 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n"
938 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n"
939 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n"
940 "float4 gl_MultiTexCoord4 : TEXCOORD4,\n"
941 "\n"
942 "uniform float3 EyePosition : register(c24),\n"
943 "uniform float4x4 TexMatrix : register(c0),\n"
944 "#ifdef USEVERTEXTEXTUREBLEND\n"
945 "uniform float4x4 BackgroundTexMatrix : register(c4),\n"
946 "#endif\n"
947 "#ifdef MODE_LIGHTSOURCE\n"
948 "uniform float4x4 ModelToLight : register(c20),\n"
949 "#endif\n"
950 "#ifdef MODE_LIGHTSOURCE\n"
951 "uniform float3 LightPosition : register(c27),\n"
952 "#endif\n"
953 "#ifdef MODE_LIGHTDIRECTION\n"
954 "uniform float3 LightDir : register(c26),\n"
955 "#endif\n"
956 "uniform float4 FogPlane : register(c25),\n"
957 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
958 "uniform float3 LightPosition : register(c27),\n"
959 "#endif\n"
960 "#ifdef USESHADOWMAPORTHO\n"
961 "uniform float4x4 ShadowMapMatrix : register(c16),\n"
962 "#endif\n"
963 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND)\n"
964 "out float4 gl_FrontColor : COLOR,\n"
965 "#endif\n"
966 "out float4 TexCoordBoth : TEXCOORD0,\n"
967 "#ifdef USELIGHTMAP\n"
968 "out float2 TexCoordLightmap : TEXCOORD1,\n"
969 "#endif\n"
970 "#ifdef USEEYEVECTOR\n"
971 "out float3 EyeVector : TEXCOORD2,\n"
972 "#endif\n"
973 "#ifdef USEREFLECTION\n"
974 "out float4 ModelViewProjectionPosition : TEXCOORD3,\n"
975 "#endif\n"
976 "#ifdef USEFOG\n"
977 "out float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n"
978 "#endif\n"
979 "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE) || defined(USEDIFFUSE)\n"
980 "out float3 LightVector : TEXCOORD1,\n"
981 "#endif\n"
982 "#ifdef MODE_LIGHTSOURCE\n"
983 "out float3 CubeVector : TEXCOORD3,\n"
984 "#endif\n"
985 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n"
986 "out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
987 "out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
988 "out float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n"
989 "#endif\n"
990 "#ifdef USESHADOWMAPORTHO\n"
991 "out float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n"
992 "#endif\n"
993 "out float4 gl_Position : POSITION\n"
994 ")\n"
995 "{\n"
996 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND)\n"
997 "       gl_FrontColor = gl_Color;\n"
998 "#endif\n"
999 "       // copy the surface texcoord\n"
1000 "       TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n"
1001 "#ifdef USEVERTEXTEXTUREBLEND\n"
1002 "       TexCoordBoth.zw = mul(BackgroundTexMatrix, gl_MultiTexCoord0).xy;\n"
1003 "#endif\n"
1004 "#ifdef USELIGHTMAP\n"
1005 "       TexCoordLightmap = gl_MultiTexCoord4.xy;\n"
1006 "#endif\n"
1007 "\n"
1008 "#ifdef MODE_LIGHTSOURCE\n"
1009 "       // transform vertex position into light attenuation/cubemap space\n"
1010 "       // (-1 to +1 across the light box)\n"
1011 "       CubeVector = mul(ModelToLight, gl_Vertex).xyz;\n"
1012 "\n"
1013 "# ifdef USEDIFFUSE\n"
1014 "       // transform unnormalized light direction into tangent space\n"
1015 "       // (we use unnormalized to ensure that it interpolates correctly and then\n"
1016 "       //  normalize it per pixel)\n"
1017 "       float3 lightminusvertex = LightPosition - gl_Vertex.xyz;\n"
1018 "       LightVector.x = dot(lightminusvertex, gl_MultiTexCoord1.xyz);\n"
1019 "       LightVector.y = dot(lightminusvertex, gl_MultiTexCoord2.xyz);\n"
1020 "       LightVector.z = dot(lightminusvertex, gl_MultiTexCoord3.xyz);\n"
1021 "# endif\n"
1022 "#endif\n"
1023 "\n"
1024 "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE)\n"
1025 "       LightVector.x = dot(LightDir, gl_MultiTexCoord1.xyz);\n"
1026 "       LightVector.y = dot(LightDir, gl_MultiTexCoord2.xyz);\n"
1027 "       LightVector.z = dot(LightDir, gl_MultiTexCoord3.xyz);\n"
1028 "#endif\n"
1029 "\n"
1030 "       // transform unnormalized eye direction into tangent space\n"
1031 "#ifdef USEEYEVECTOR\n"
1032 "       float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n"
1033 "       EyeVector.x = dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz);\n"
1034 "       EyeVector.y = dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz);\n"
1035 "       EyeVector.z = dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz);\n"
1036 "#endif\n"
1037 "\n"
1038 "#ifdef USEFOG\n"
1039 "       EyeVectorModelSpaceFogPlaneVertexDist.xyz = EyePosition - gl_Vertex.xyz;\n"
1040 "       EyeVectorModelSpaceFogPlaneVertexDist.w = dot(FogPlane, gl_Vertex);\n"
1041 "#endif\n"
1042 "\n"
1043 "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n"
1044 "       VectorS = gl_MultiTexCoord1.xyz;\n"
1045 "       VectorT = gl_MultiTexCoord2.xyz;\n"
1046 "       VectorR = gl_MultiTexCoord3.xyz;\n"
1047 "#endif\n"
1048 "\n"
1049 "       // transform vertex to camera space, using ftransform to match non-VS rendering\n"
1050 "       gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
1051 "\n"
1052 "#ifdef USESHADOWMAPORTHO\n"
1053 "       ShadowMapTC = mul(ShadowMapMatrix, gl_Position).xyz;\n"
1054 "#endif\n"
1055 "\n"
1056 "#ifdef USEREFLECTION\n"
1057 "       ModelViewProjectionPosition = gl_Position;\n"
1058 "#endif\n"
1059 "}\n"
1060 "#endif // VERTEX_SHADER\n"
1061 "\n"
1062 "\n"
1063 "\n"
1064 "\n"
1065 "#ifdef FRAGMENT_SHADER\n"
1066 "void main\n"
1067 "(\n"
1068 "#ifdef USEDEFERREDLIGHTMAP\n"
1069 "#ifdef HLSL\n"
1070 "float2 Pixel : VPOS,\n"
1071 "#else\n"
1072 "float2 Pixel : WPOS,\n"
1073 "#endif\n"
1074 "#endif\n"
1075 "float4 gl_FrontColor : COLOR,\n"
1076 "float4 TexCoordBoth : TEXCOORD0,\n"
1077 "#ifdef USELIGHTMAP\n"
1078 "float2 TexCoordLightmap : TEXCOORD1,\n"
1079 "#endif\n"
1080 "#ifdef USEEYEVECTOR\n"
1081 "float3 EyeVector : TEXCOORD2,\n"
1082 "#endif\n"
1083 "#ifdef USEREFLECTION\n"
1084 "float4 ModelViewProjectionPosition : TEXCOORD3,\n"
1085 "#endif\n"
1086 "#ifdef USEFOG\n"
1087 "float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n"
1088 "#endif\n"
1089 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_LIGHTDIRECTION)\n"
1090 "float3 LightVector : TEXCOORD1,\n"
1091 "#endif\n"
1092 "#ifdef MODE_LIGHTSOURCE\n"
1093 "float3 CubeVector : TEXCOORD3,\n"
1094 "#endif\n"
1095 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
1096 "float4 ModelViewPosition : TEXCOORD0,\n"
1097 "#endif\n"
1098 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n"
1099 "float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
1100 "float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
1101 "float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n"
1102 "#endif\n"
1103 "#ifdef USESHADOWMAPORTHO\n"
1104 "float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n"
1105 "#endif\n"
1106 "\n"
1107 "uniform sampler Texture_Normal : register(s0),\n"
1108 "uniform sampler Texture_Color : register(s1),\n"
1109 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n"
1110 "uniform sampler Texture_Gloss : register(s2),\n"
1111 "#endif\n"
1112 "#ifdef USEGLOW\n"
1113 "uniform sampler Texture_Glow : register(s3),\n"
1114 "#endif\n"
1115 "#ifdef USEVERTEXTEXTUREBLEND\n"
1116 "uniform sampler Texture_SecondaryNormal : register(s4),\n"
1117 "uniform sampler Texture_SecondaryColor : register(s5),\n"
1118 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n"
1119 "uniform sampler Texture_SecondaryGloss : register(s6),\n"
1120 "#endif\n"
1121 "#ifdef USEGLOW\n"
1122 "uniform sampler Texture_SecondaryGlow : register(s7),\n"
1123 "#endif\n"
1124 "#endif\n"
1125 "#ifdef USECOLORMAPPING\n"
1126 "uniform sampler Texture_Pants : register(s4),\n"
1127 "uniform sampler Texture_Shirt : register(s7),\n"
1128 "#endif\n"
1129 "#ifdef USEFOG\n"
1130 "uniform sampler Texture_FogHeightTexture : register(s14),\n"
1131 "uniform sampler Texture_FogMask : register(s8),\n"
1132 "#endif\n"
1133 "#ifdef USELIGHTMAP\n"
1134 "uniform sampler Texture_Lightmap : register(s9),\n"
1135 "#endif\n"
1136 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE)\n"
1137 "uniform sampler Texture_Deluxemap : register(s10),\n"
1138 "#endif\n"
1139 "#ifdef USEREFLECTION\n"
1140 "uniform sampler Texture_Reflection : register(s7),\n"
1141 "#endif\n"
1142 "\n"
1143 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
1144 "uniform sampler Texture_ScreenDepth : register(s13),\n"
1145 "uniform sampler Texture_ScreenNormalMap : register(s14),\n"
1146 "#endif\n"
1147 "#ifdef USEDEFERREDLIGHTMAP\n"
1148 "uniform sampler Texture_ScreenDepth : register(s13),\n"
1149 "uniform sampler Texture_ScreenNormalMap : register(s14),\n"
1150 "uniform sampler Texture_ScreenDiffuse : register(s11),\n"
1151 "uniform sampler Texture_ScreenSpecular : register(s12),\n"
1152 "#endif\n"
1153 "\n"
1154 "#ifdef USECOLORMAPPING\n"
1155 "uniform half3 Color_Pants : register(c7),\n"
1156 "uniform half3 Color_Shirt : register(c8),\n"
1157 "#endif\n"
1158 "#ifdef USEFOG\n"
1159 "uniform float3 FogColor : register(c16),\n"
1160 "uniform float FogRangeRecip : register(c20),\n"
1161 "uniform float FogPlaneViewDist : register(c19),\n"
1162 "uniform float FogHeightFade : register(c17),\n"
1163 "#endif\n"
1164 "\n"
1165 "#ifdef USEOFFSETMAPPING\n"
1166 "uniform float3 OffsetMapping_ScaleSteps : register(c24),\n"
1167 "#endif\n"
1168 "\n"
1169 "#ifdef USEDEFERREDLIGHTMAP\n"
1170 "uniform half2 PixelToScreenTexCoord : register(c42),\n"
1171 "uniform half3 DeferredMod_Diffuse : register(c12),\n"
1172 "uniform half3 DeferredMod_Specular : register(c13),\n"
1173 "#endif\n"
1174 "uniform half3 Color_Ambient : register(c3),\n"
1175 "uniform half3 Color_Diffuse : register(c4),\n"
1176 "uniform half3 Color_Specular : register(c5),\n"
1177 "uniform half SpecularPower : register(c36),\n"
1178 "#ifdef USEGLOW\n"
1179 "uniform half3 Color_Glow : register(c6),\n"
1180 "#endif\n"
1181 "uniform half Alpha : register(c0),\n"
1182 "#ifdef USEREFLECTION\n"
1183 "uniform float4 DistortScaleRefractReflect : register(c14),\n"
1184 "uniform float4 ScreenScaleRefractReflect : register(c32),\n"
1185 "uniform float4 ScreenCenterRefractReflect : register(c31),\n"
1186 "uniform half4 ReflectColor : register(c26),\n"
1187 "#endif\n"
1188 "#ifdef USEREFLECTCUBE\n"
1189 "uniform float4x4 ModelToReflectCube : register(c48),\n"
1190 "uniform sampler Texture_ReflectMask : register(s5),\n"
1191 "uniform samplerCUBE Texture_ReflectCube : register(s6),\n"
1192 "#endif\n"
1193 "#ifdef MODE_LIGHTDIRECTION\n"
1194 "uniform half3 LightColor : register(c21),\n"
1195 "#endif\n"
1196 "#ifdef MODE_LIGHTSOURCE\n"
1197 "uniform half3 LightColor : register(c21),\n"
1198 "#endif\n"
1199 "\n"
1200 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE)\n"
1201 "uniform sampler Texture_Attenuation : register(s9),\n"
1202 "uniform samplerCUBE Texture_Cube : register(s10),\n"
1203 "#endif\n"
1204 "\n"
1205 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n"
1206 "\n"
1207 "#ifdef USESHADOWMAP2D\n"
1208 "# ifdef USESHADOWSAMPLER\n"
1209 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
1210 "# else\n"
1211 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
1212 "# endif\n"
1213 "#endif\n"
1214 "\n"
1215 "#ifdef USESHADOWMAPVSDCT\n"
1216 "uniform samplerCUBE Texture_CubeProjection : register(s12),\n"
1217 "#endif\n"
1218 "\n"
1219 "#if defined(USESHADOWMAP2D)\n"
1220 "uniform float2 ShadowMap_TextureScale : register(c35),\n"
1221 "uniform float4 ShadowMap_Parameters : register(c34),\n"
1222 "#endif\n"
1223 "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n"
1224 "\n"
1225 "out float4 gl_FragColor : COLOR\n"
1226 ")\n"
1227 "{\n"
1228 "       float2 TexCoord = TexCoordBoth.xy;\n"
1229 "#ifdef USEVERTEXTEXTUREBLEND\n"
1230 "       float2 TexCoord2 = TexCoordBoth.zw;\n"
1231 "#endif\n"
1232 "#ifdef USEOFFSETMAPPING\n"
1233 "       // apply offsetmapping\n"
1234 "       float2 dPdx = ddx(TexCoord);\n"
1235 "       float2 dPdy = ddy(TexCoord);\n"
1236 "       float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, EyeVector, Texture_Normal, dPdx, dPdy);\n"
1237 "# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n"
1238 "#else\n"
1239 "# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n"
1240 "#endif\n"
1241 "\n"
1242 "       // combine the diffuse textures (base, pants, shirt)\n"
1243 "       half4 color = half4(offsetMappedTexture2D(Texture_Color));\n"
1244 "#ifdef USEALPHAKILL\n"
1245 "       if (color.a < 0.5)\n"
1246 "               discard;\n"
1247 "#endif\n"
1248 "       color.a *= Alpha;\n"
1249 "#ifdef USECOLORMAPPING\n"
1250 "       color.rgb += half3(offsetMappedTexture2D(Texture_Pants).rgb) * Color_Pants + half3(offsetMappedTexture2D(Texture_Shirt).rgb) * Color_Shirt;\n"
1251 "#endif\n"
1252 "#ifdef USEVERTEXTEXTUREBLEND\n"
1253 "#ifdef USEBOTHALPHAS\n"
1254 "       half4 color2 = half4(tex2D(Texture_SecondaryColor, TexCoord2));\n"
1255 "       half terrainblend = clamp(half(gl_FrontColor.a) * color.a, half(1.0 - color2.a), half(1.0));\n"
1256 "       color.rgb = lerp(color2.rgb, color.rgb, terrainblend);\n"
1257 "#else\n"
1258 "       half terrainblend = clamp(half(gl_FrontColor.a) * color.a * 2.0 - 0.5, half(0.0), half(1.0));\n"
1259 "       //half terrainblend = min(half(gl_FrontColor.a) * color.a * 2.0, half(1.0));\n"
1260 "       //half terrainblend = half(gl_FrontColor.a) * color.a > 0.5;\n"
1261 "       color.rgb = half3(lerp(tex2D(Texture_SecondaryColor, TexCoord2).rgb, float3(color.rgb), terrainblend));\n"
1262 "       color.a = 1.0;\n"
1263 "       //color = half4(lerp(float4(1, 0, 0, 1), color, terrainblend));\n"
1264 "#endif\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 = half3(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"