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"
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"
10 "#if defined(USEFOGINSIDE) || defined(USEFOGOUTSIDE) || defined(USEFOGHEIGHTTEXTURE)\n"
13 "#if defined(MODE_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE)\n"
14 "#define USELIGHTMAP\n"
16 "#if defined(USESPECULAR) || defined(USEOFFSETMAPPING) || defined(USEREFLECTCUBE) || defined(MODE_FAKELIGHT)\n"
17 "#define USEEYEVECTOR\n"
20 "#ifdef FRAGMENT_SHADER\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"
26 "#define texDepth2D(tex,texcoord) tex2D(tex,texcoord).r\n"
30 "#ifdef MODE_DEPTH_OR_SHADOW\n"
31 "#ifdef VERTEX_SHADER\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"
40 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
41 " Depth = gl_Position.z;\n"
45 "#ifdef FRAGMENT_SHADER\n"
48 "float Depth : TEXCOORD0,\n"
49 "out float4 gl_FragColor : COLOR\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"
59 "#else // !MODE_DEPTH_ORSHADOW\n"
64 "#ifdef MODE_SHOWDEPTH\n"
65 "#ifdef VERTEX_SHADER\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"
74 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
75 " gl_FrontColor = float4(gl_Position.z, gl_Position.z, gl_Position.z, 1.0);\n"
79 "#ifdef FRAGMENT_SHADER\n"
82 "float4 gl_FrontColor : COLOR0,\n"
83 "out float4 gl_FragColor : COLOR\n"
86 " gl_FragColor = gl_FrontColor;\n"
89 "#else // !MODE_SHOWDEPTH\n"
94 "#ifdef MODE_POSTPROCESS\n"
96 "#ifdef VERTEX_SHADER\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"
108 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
109 " TexCoord1 = gl_MultiTexCoord0.xy;\n"
111 " TexCoord2 = gl_MultiTexCoord4.xy;\n"
116 "#ifdef FRAGMENT_SHADER\n"
119 "float2 TexCoord1 : TEXCOORD0,\n"
120 "float2 TexCoord2 : TEXCOORD1,\n"
121 "uniform sampler Texture_First : register(s0),\n"
123 "uniform sampler Texture_Second : register(s1),\n"
125 "#ifdef USEGAMMARAMPS\n"
126 "uniform sampler Texture_GammaRamps : register(s2),\n"
128 "#ifdef USESATURATION\n"
129 "uniform float Saturation : register(c30),\n"
131 "#ifdef USEVIEWTINT\n"
132 "uniform float4 ViewTintColor : register(c41),\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"
144 " gl_FragColor = tex2D(Texture_First, TexCoord1);\n"
146 " gl_FragColor += max(float4(0,0,0,0), tex2D(Texture_Second, TexCoord2) - BloomColorSubtract);\n"
148 "#ifdef USEVIEWTINT\n"
149 " gl_FragColor = lerp(gl_FragColor, ViewTintColor, ViewTintColor.a);\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"
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"
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"
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"
215 "#else // !MODE_POSTPROCESS\n"
220 "#ifdef MODE_GENERIC\n"
221 "#ifdef VERTEX_SHADER\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"
233 "#ifdef USESPECULAR\n"
234 "out float2 TexCoord2 : TEXCOORD1,\n"
236 "out float4 gl_FrontColor : COLOR\n"
239 " gl_FrontColor = gl_Color;\n"
240 "#ifdef USEDIFFUSE\n"
241 " TexCoord1 = gl_MultiTexCoord0.xy;\n"
243 "#ifdef USESPECULAR\n"
244 " TexCoord2 = gl_MultiTexCoord1.xy;\n"
246 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
250 "#ifdef FRAGMENT_SHADER\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"
260 "#ifdef USESPECULAR\n"
261 "uniform sampler Texture_Second : register(s1),\n"
263 "out float4 gl_FragColor : COLOR\n"
266 "#ifdef USEVIEWTINT\n"
267 " gl_FragColor = gl_FrontColor;\n"
269 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
271 "#ifdef USEDIFFUSE\n"
272 " gl_FragColor *= tex2D(Texture_First, TexCoord1);\n"
275 "#ifdef USESPECULAR\n"
276 " float4 tex2 = tex2D(Texture_Second, TexCoord2);\n"
277 "# ifdef USECOLORMAPPING\n"
278 " gl_FragColor *= tex2;\n"
281 " gl_FragColor += tex2;\n"
283 "# ifdef USEVERTEXTEXTUREBLEND\n"
284 " gl_FragColor = lerp(gl_FragColor, tex2, tex2.a);\n"
289 "#else // !MODE_GENERIC\n"
294 "#ifdef MODE_BLOOMBLUR\n"
295 "#ifdef VERTEX_SHADER\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"
305 " TexCoord = gl_MultiTexCoord0.xy;\n"
306 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
310 "#ifdef FRAGMENT_SHADER\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"
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"
326 " color += tex2D(Texture_First, tc).rgb;\n"
327 " tc += BloomBlur_Parameters.xy;\n"
329 " gl_FragColor = float4(color * BloomBlur_Parameters.z + float3(BloomBlur_Parameters.w), 1);\n"
332 "#else // !MODE_BLOOMBLUR\n"
333 "#ifdef MODE_REFRACTION\n"
334 "#ifdef VERTEX_SHADER\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"
348 " TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n"
349 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
350 " ModelViewProjectionPosition = gl_Position;\n"
354 "#ifdef FRAGMENT_SHADER\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"
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"
377 " // Remove this 'ack once we have a better way to stop this thing from\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"
387 "#else // !MODE_REFRACTION\n"
392 "#ifdef MODE_WATER\n"
393 "#ifdef VERTEX_SHADER\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"
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"
421 "#ifdef FRAGMENT_SHADER\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"
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"
448 " // Remove this 'ack once we have a better way to stop this thing from\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"
464 "#else // !MODE_WATER\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"
471 "// fragment shader specific:\n"
472 "#ifdef FRAGMENT_SHADER\n"
475 "float3 FogVertex(float3 surfacecolor, float3 FogColor, float3 EyeVectorModelSpace, float FogPlaneVertexDist, float FogRangeRecip, float FogPlaneViewDist, float FogHeightFade, sampler Texture_FogMask, sampler Texture_FogHeightTexture)\n"
478 "#ifdef USEFOGHEIGHTTEXTURE\n"
479 " float4 fogheightpixel = tex2D(Texture_FogHeightTexture, float2(1,1) + float2(FogPlaneVertexDist, FogPlaneViewDist) * (-2.0 * FogHeightFade));\n"
480 " fogfrac = fogheightpixel.a;\n"
481 " return lerp(fogheightpixel.rgb * FogColor, surfacecolor, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n"
483 "# ifdef USEFOGOUTSIDE\n"
484 " fogfrac = min(0.0, FogPlaneVertexDist) / (FogPlaneVertexDist - FogPlaneViewDist) * min(1.0, min(0.0, FogPlaneVertexDist) * FogHeightFade);\n"
486 " fogfrac = FogPlaneViewDist / (FogPlaneViewDist - max(0.0, FogPlaneVertexDist)) * min(1.0, (min(0.0, FogPlaneVertexDist) + FogPlaneViewDist) * FogHeightFade);\n"
488 " return lerp(FogColor, surfacecolor, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n"
493 "#ifdef USEOFFSETMAPPING\n"
494 "float2 OffsetMapping(float2 TexCoord, float OffsetMapping_Scale, float3 EyeVector, sampler Texture_Normal)\n"
496 "#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n"
497 " // 14 sample relief mapping: linear search and then binary search\n"
498 " // this basically steps forward a small amount repeatedly until it finds\n"
499 " // itself inside solid, then jitters forward and back using decreasing\n"
500 " // amounts to find the impact\n"
501 " //float3 OffsetVector = float3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMapping_Scale) * float2(-1, 1), -1);\n"
502 " //float3 OffsetVector = float3(normalize(EyeVector.xy) * OffsetMapping_Scale * float2(-1, 1), -1);\n"
503 " float3 OffsetVector = float3(normalize(EyeVector).xy * OffsetMapping_Scale * float2(-1, 1), -1);\n"
504 " float3 RT = float3(TexCoord, 1);\n"
505 " OffsetVector *= 0.1;\n"
506 " RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n"
507 " RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n"
508 " RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n"
509 " RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n"
510 " RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n"
511 " RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n"
512 " RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n"
513 " RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n"
514 " RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n"
515 " RT += OffsetVector * (step(tex2D(Texture_Normal, RT.xy).a, RT.z) - 0.5);\n"
516 " RT += OffsetVector * (step(tex2D(Texture_Normal, RT.xy).a, RT.z) * 0.5 - 0.25);\n"
517 " RT += OffsetVector * (step(tex2D(Texture_Normal, RT.xy).a, RT.z) * 0.25 - 0.125);\n"
518 " RT += OffsetVector * (step(tex2D(Texture_Normal, RT.xy).a, RT.z) * 0.125 - 0.0625);\n"
519 " RT += OffsetVector * (step(tex2D(Texture_Normal, RT.xy).a, RT.z) * 0.0625 - 0.03125);\n"
522 " // 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits)\n"
523 " //float2 OffsetVector = float2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMapping_Scale) * float2(-1, 1));\n"
524 " //float2 OffsetVector = float2(normalize(EyeVector.xy) * OffsetMapping_Scale * float2(-1, 1));\n"
525 " float2 OffsetVector = float2(normalize(EyeVector).xy * OffsetMapping_Scale * float2(-1, 1));\n"
526 " OffsetVector *= 0.5;\n"
527 " TexCoord += OffsetVector * (1.0 - tex2D(Texture_Normal, TexCoord).a);\n"
528 " TexCoord += OffsetVector * (1.0 - tex2D(Texture_Normal, TexCoord).a);\n"
529 " return TexCoord;\n"
532 "#endif // USEOFFSETMAPPING\n"
534 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n"
535 "#if defined(USESHADOWMAP2D)\n"
536 "# ifdef USESHADOWMAPORTHO\n"
537 "# define GetShadowMapTC2D(dir, ShadowMap_Parameters) (min(dir, ShadowMap_Parameters.xyz))\n"
539 "# ifdef USESHADOWMAPVSDCT\n"
540 "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters, samplerCUBE Texture_CubeProjection)\n"
542 " float3 adir = abs(dir);\n"
543 " float2 aparams = ShadowMap_Parameters.xy / max(max(adir.x, adir.y), adir.z);\n"
544 " float4 proj = texCUBE(Texture_CubeProjection, dir);\n"
545 " return float3(lerp(dir.xy, dir.zz, proj.xy) * aparams.x + proj.zw * ShadowMap_Parameters.z, aparams.y + ShadowMap_Parameters.w);\n"
548 "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters)\n"
550 " float3 adir = abs(dir);\n"
551 " float ma = adir.z;\n"
552 " float4 proj = float4(dir, 2.5);\n"
553 " if (adir.x > ma) { ma = adir.x; proj = float4(dir.zyx, 0.5); }\n"
554 " if (adir.y > ma) { ma = adir.y; proj = float4(dir.xzy, 1.5); }\n"
556 " 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"
558 " float2 aparams = ShadowMap_Parameters.xy / ma;\n"
559 " 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 // defined(USESHADOWMAP2D)\n"
566 "# ifdef USESHADOWMAP2D\n"
567 "#ifdef USESHADOWMAPVSDCT\n"
568 "float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale, samplerCUBE Texture_CubeProjection)\n"
570 "float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale)\n"
573 "#ifdef USESHADOWMAPVSDCT\n"
574 " float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters, Texture_CubeProjection);\n"
576 " float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters);\n"
580 "# ifdef USESHADOWSAMPLER\n"
581 "# ifdef USESHADOWMAPPCF\n"
582 "# define texval(x, y) tex2Dproj(Texture_ShadowMap2D, float4(center + float2(x, y)*ShadowMap_TextureScale, shadowmaptc.z, 1.0)).r \n"
583 " float2 center = shadowmaptc.xy*ShadowMap_TextureScale;\n"
584 " 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"
586 " f = tex2Dproj(Texture_ShadowMap2D, float4(shadowmaptc.xy*ShadowMap_TextureScale, shadowmaptc.z, 1.0)).r;\n"
589 "# ifdef USESHADOWMAPPCF\n"
590 "# if defined(GL_ARB_texture_gather) || defined(GL_AMD_texture_texture4)\n"
591 "# ifdef GL_ARB_texture_gather\n"
592 "# define texval(x, y) textureGatherOffset(Texture_ShadowMap2D, center, int2(x, y))\n"
594 "# define texval(x, y) texture4(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale)\n"
596 " float2 offset = frac(shadowmaptc.xy - 0.5), center = (shadowmaptc.xy - offset)*ShadowMap_TextureScale;\n"
597 "# if USESHADOWMAPPCF > 1\n"
598 " float4 group1 = step(shadowmaptc.z, texval(-2.0, -2.0));\n"
599 " float4 group2 = step(shadowmaptc.z, texval( 0.0, -2.0));\n"
600 " float4 group3 = step(shadowmaptc.z, texval( 2.0, -2.0));\n"
601 " float4 group4 = step(shadowmaptc.z, texval(-2.0, 0.0));\n"
602 " float4 group5 = step(shadowmaptc.z, texval( 0.0, 0.0));\n"
603 " float4 group6 = step(shadowmaptc.z, texval( 2.0, 0.0));\n"
604 " float4 group7 = step(shadowmaptc.z, texval(-2.0, 2.0));\n"
605 " float4 group8 = step(shadowmaptc.z, texval( 0.0, 2.0));\n"
606 " float4 group9 = step(shadowmaptc.z, texval( 2.0, 2.0));\n"
607 " float4 locols = float4(group1.ab, group3.ab);\n"
608 " float4 hicols = float4(group7.rg, group9.rg);\n"
609 " locols.yz += group2.ab;\n"
610 " hicols.yz += group8.rg;\n"
611 " float4 midcols = float4(group1.rg, group3.rg) + float4(group7.ab, group9.ab) +\n"
612 " float4(group4.rg, group6.rg) + float4(group4.ab, group6.ab) +\n"
613 " lerp(locols, hicols, offset.y);\n"
614 " float4 cols = group5 + float4(group2.rg, group8.ab);\n"
615 " cols.xyz += lerp(midcols.xyz, midcols.yzw, offset.x);\n"
616 " f = dot(cols, float4(1.0/25.0));\n"
618 " float4 group1 = step(shadowmaptc.z, texval(-1.0, -1.0));\n"
619 " float4 group2 = step(shadowmaptc.z, texval( 1.0, -1.0));\n"
620 " float4 group3 = step(shadowmaptc.z, texval(-1.0, 1.0));\n"
621 " float4 group4 = step(shadowmaptc.z, texval( 1.0, 1.0));\n"
622 " float4 cols = float4(group1.rg, group2.rg) + float4(group3.ab, group4.ab) +\n"
623 " lerp(float4(group1.ab, group2.ab), float4(group3.rg, group4.rg), offset.y);\n"
624 " f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n"
627 "# ifdef GL_EXT_gpu_shader4\n"
628 "# define texval(x, y) tex2DOffset(Texture_ShadowMap2D, center, int2(x, y)).r\n"
630 "# define texval(x, y) texDepth2D(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale).r \n"
632 "# if USESHADOWMAPPCF > 1\n"
633 " float2 center = shadowmaptc.xy - 0.5, offset = frac(center);\n"
634 " center *= ShadowMap_TextureScale;\n"
635 " 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"
636 " 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"
637 " 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"
638 " 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"
639 " float4 cols = row2 + row3 + lerp(row1, row4, offset.y);\n"
640 " f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n"
642 " float2 center = shadowmaptc.xy*ShadowMap_TextureScale, offset = frac(shadowmaptc.xy);\n"
643 " float3 row1 = step(shadowmaptc.z, float3(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0)));\n"
644 " float3 row2 = step(shadowmaptc.z, float3(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0)));\n"
645 " float3 row3 = step(shadowmaptc.z, float3(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0)));\n"
646 " float3 cols = row2 + lerp(row1, row3, offset.y);\n"
647 " f = dot(lerp(cols.xy, cols.yz, offset.x), float2(0.25,0.25));\n"
651 " f = step(shadowmaptc.z, tex2D(Texture_ShadowMap2D, shadowmaptc.xy*ShadowMap_TextureScale).r);\n"
654 "# ifdef USESHADOWMAPORTHO\n"
655 " return lerp(ShadowMap_Parameters.w, 1.0, f);\n"
661 "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n"
662 "#endif // FRAGMENT_SHADER\n"
667 "#ifdef MODE_DEFERREDGEOMETRY\n"
668 "#ifdef VERTEX_SHADER\n"
671 "float4 gl_Vertex : POSITION,\n"
672 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
673 "#ifdef USEVERTEXTEXTUREBLEND\n"
674 "float4 gl_Color : COLOR0,\n"
676 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
677 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n"
678 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n"
679 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n"
680 "uniform float4x4 TexMatrix : register(c0),\n"
681 "#ifdef USEVERTEXTEXTUREBLEND\n"
682 "uniform float4x4 BackgroundTexMatrix : register(c4),\n"
684 "uniform float4x4 ModelViewMatrix : register(c12),\n"
685 "#ifdef USEOFFSETMAPPING\n"
686 "uniform float3 EyePosition : register(c24),\n"
688 "out float4 gl_Position : POSITION,\n"
689 "#ifdef USEVERTEXTEXTUREBLEND\n"
690 "out float4 gl_FrontColor : COLOR,\n"
692 "out float4 TexCoordBoth : TEXCOORD0,\n"
693 "#ifdef USEOFFSETMAPPING\n"
694 "out float3 EyeVector : TEXCOORD2,\n"
696 "out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
697 "out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
698 "out float4 VectorR : TEXCOORD7 // direction of R texcoord (surface normal), Depth value\n"
701 " TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n"
702 "#ifdef USEVERTEXTEXTUREBLEND\n"
703 " gl_FrontColor = gl_Color;\n"
704 " TexCoordBoth.zw = float2(Backgroundmul(TexMatrix, gl_MultiTexCoord0));\n"
707 " // transform unnormalized eye direction into tangent space\n"
708 "#ifdef USEOFFSETMAPPING\n"
709 " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n"
710 " EyeVector.x = dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz);\n"
711 " EyeVector.y = dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz);\n"
712 " EyeVector.z = dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz);\n"
715 " VectorS = mul(ModelViewMatrix, float4(gl_MultiTexCoord1.xyz, 0)).xyz;\n"
716 " VectorT = mul(ModelViewMatrix, float4(gl_MultiTexCoord2.xyz, 0)).xyz;\n"
717 " VectorR.xyz = mul(ModelViewMatrix, float4(gl_MultiTexCoord3.xyz, 0)).xyz;\n"
718 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
719 " VectorR.w = gl_Position.z;\n"
721 "#endif // VERTEX_SHADER\n"
723 "#ifdef FRAGMENT_SHADER\n"
726 "float4 TexCoordBoth : TEXCOORD0,\n"
727 "float3 EyeVector : TEXCOORD2,\n"
728 "float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
729 "float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
730 "float4 VectorR : TEXCOORD7, // direction of R texcoord (surface normal), Depth value\n"
731 "uniform sampler Texture_Normal : register(s0),\n"
732 "#ifdef USEALPHAKILL\n"
733 "uniform sampler Texture_Color : register(s1),\n"
735 "uniform sampler Texture_Gloss : register(s2),\n"
736 "#ifdef USEVERTEXTEXTUREBLEND\n"
737 "uniform sampler Texture_SecondaryNormal : register(s4),\n"
738 "uniform sampler Texture_SecondaryGloss : register(s6),\n"
740 "#ifdef USEOFFSETMAPPING\n"
741 "uniform float OffsetMapping_Scale : register(c24),\n"
743 "uniform half SpecularPower : register(c36),\n"
745 "out float4 gl_FragData0 : COLOR0,\n"
746 "out float4 gl_FragData1 : COLOR1\n"
748 "out float4 gl_FragColor : COLOR\n"
752 " float2 TexCoord = TexCoordBoth.xy;\n"
753 "#ifdef USEOFFSETMAPPING\n"
754 " // apply offsetmapping\n"
755 " float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_Scale, EyeVector, Texture_Normal);\n"
756 "#define TexCoord TexCoordOffset\n"
759 "#ifdef USEALPHAKILL\n"
760 " if (tex2D(Texture_Color, TexCoord).a < 0.5)\n"
764 "#ifdef USEVERTEXTEXTUREBLEND\n"
765 " float alpha = tex2D(Texture_Color, TexCoord).a;\n"
766 " float terrainblend = clamp(float(gl_FrontColor.a) * alpha * 2.0 - 0.5, float(0.0), float(1.0));\n"
767 " //float terrainblend = min(float(gl_FrontColor.a) * alpha * 2.0, float(1.0));\n"
768 " //float terrainblend = float(gl_FrontColor.a) * alpha > 0.5;\n"
771 "#ifdef USEVERTEXTEXTUREBLEND\n"
772 " float3 surfacenormal = lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, tex2D(Texture_Normal, TexCoord).rgb, terrainblend) - float3(0.5, 0.5, 0.5);\n"
773 " float a = lerp(tex2D(Texture_SecondaryGloss, TexCoord2).a, tex2D(Texture_Gloss, TexCoord).a, terrainblend);\n"
775 " float3 surfacenormal = tex2D(Texture_Normal, TexCoord).rgb - float3(0.5, 0.5, 0.5);\n"
776 " float a = tex2D(Texture_Gloss, TexCoord).a;\n"
780 " 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"
781 " float Depth = VectorR.w / 256.0;\n"
782 " float4 depthcolor = float4(Depth,Depth*65536.0/255.0,Depth*16777216.0/255.0,0.0);\n"
783 "// float4 depthcolor = float4(Depth,Depth*256.0,Depth*65536.0,0.0);\n"
784 " depthcolor.yz -= floor(depthcolor.yz);\n"
785 " gl_FragData1 = depthcolor;\n"
787 " 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 // FRAGMENT_SHADER\n"
791 "#else // !MODE_DEFERREDGEOMETRY\n"
796 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
797 "#ifdef VERTEX_SHADER\n"
800 "float4 gl_Vertex : POSITION,\n"
801 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
802 "uniform float4x4 ModelViewMatrix : register(c12),\n"
803 "out float4 gl_Position : POSITION,\n"
804 "out float4 ModelViewPosition : TEXCOORD0\n"
807 " ModelViewPosition = mul(ModelViewMatrix, gl_Vertex);\n"
808 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
810 "#endif // VERTEX_SHADER\n"
812 "#ifdef FRAGMENT_SHADER\n"
816 "float2 Pixel : VPOS,\n"
818 "float2 Pixel : WPOS,\n"
820 "float4 ModelViewPosition : TEXCOORD0,\n"
821 "uniform float4x4 ViewToLight : register(c44),\n"
822 "uniform float2 ScreenToDepth : register(c33), // ScreenToDepth = float2(Far / (Far - Near), Far * Near / (Near - Far));\n"
823 "uniform float3 LightPosition : register(c23),\n"
824 "uniform half2 PixelToScreenTexCoord : register(c42),\n"
825 "uniform half3 DeferredColor_Ambient : register(c9),\n"
826 "uniform half3 DeferredColor_Diffuse : register(c10),\n"
827 "#ifdef USESPECULAR\n"
828 "uniform half3 DeferredColor_Specular : register(c11),\n"
829 "uniform half SpecularPower : register(c36),\n"
831 "uniform sampler Texture_Attenuation : register(s9),\n"
832 "uniform sampler Texture_ScreenDepth : register(s13),\n"
833 "uniform sampler Texture_ScreenNormalMap : register(s14),\n"
835 "#ifdef USECUBEFILTER\n"
836 "uniform samplerCUBE Texture_Cube : register(s10),\n"
839 "#ifdef USESHADOWMAP2D\n"
840 "# ifdef USESHADOWSAMPLER\n"
841 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
843 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
847 "#ifdef USESHADOWMAPVSDCT\n"
848 "uniform samplerCUBE Texture_CubeProjection : register(s12),\n"
851 "#if defined(USESHADOWMAP2D)\n"
852 "uniform float2 ShadowMap_TextureScale : register(c35),\n"
853 "uniform float4 ShadowMap_Parameters : register(c34),\n"
856 "out float4 gl_FragData0 : COLOR0,\n"
857 "out float4 gl_FragData1 : COLOR1\n"
860 " // calculate viewspace pixel position\n"
861 " float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n"
862 " //ScreenTexCoord.y = ScreenTexCoord.y * -1 + 1; // Cg is opposite?\n"
863 " float3 position;\n"
865 " position.z = texDepth2D(Texture_ScreenDepth, ScreenTexCoord) * 256.0;\n"
867 " position.z = ScreenToDepth.y / (texDepth2D(Texture_ScreenDepth, ScreenTexCoord) + ScreenToDepth.x);\n"
869 " position.xy = ModelViewPosition.xy * (position.z / ModelViewPosition.z);\n"
870 " // decode viewspace pixel normal\n"
871 " half4 normalmap = half4(tex2D(Texture_ScreenNormalMap, ScreenTexCoord));\n"
872 " half3 surfacenormal = half3(normalize(normalmap.rgb - half3(0.5,0.5,0.5)));\n"
873 " // surfacenormal = pixel normal in viewspace\n"
874 " // LightVector = pixel to light in viewspace\n"
875 " // CubeVector = position in lightspace\n"
876 " // eyevector = pixel to view in viewspace\n"
877 " float3 CubeVector = mul(ViewToLight, float4(position,1)).xyz;\n"
878 " half fade = half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n"
879 "#ifdef USEDIFFUSE\n"
880 " // calculate diffuse shading\n"
881 " half3 lightnormal = half3(normalize(LightPosition - position));\n"
882 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n"
884 "#ifdef USESPECULAR\n"
885 " // calculate directional shading\n"
886 " float3 eyevector = position * -1.0;\n"
887 "# ifdef USEEXACTSPECULARMATH\n"
888 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(eyevector)))*-1.0, 0.0)), SpecularPower * normalmap.a));\n"
890 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(eyevector))));\n"
891 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * normalmap.a));\n"
895 "#if defined(USESHADOWMAP2D)\n"
896 " fade *= half(ShadowMapCompare(CubeVector, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n"
897 "#ifdef USESHADOWMAPVSDCT\n"
898 ", Texture_CubeProjection\n"
903 "#ifdef USEDIFFUSE\n"
904 " gl_FragData0 = float4((DeferredColor_Ambient + DeferredColor_Diffuse * diffuse) * fade, 1.0);\n"
906 " gl_FragData0 = float4(DeferredColor_Ambient * fade, 1.0);\n"
908 "#ifdef USESPECULAR\n"
909 " gl_FragData1 = float4(DeferredColor_Specular * (specular * fade), 1.0);\n"
911 " gl_FragData1 = float4(0.0, 0.0, 0.0, 1.0);\n"
914 "# ifdef USECUBEFILTER\n"
915 " float3 cubecolor = texCUBE(Texture_Cube, CubeVector).rgb;\n"
916 " gl_FragData0.rgb *= cubecolor;\n"
917 " gl_FragData1.rgb *= cubecolor;\n"
920 "#endif // FRAGMENT_SHADER\n"
921 "#else // !MODE_DEFERREDLIGHTSOURCE\n"
926 "#ifdef VERTEX_SHADER\n"
929 "float4 gl_Vertex : POSITION,\n"
930 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
931 "#if defined(USEVERTEXTEXTUREBLEND) || defined(MODE_VERTEXCOLOR)\n"
932 "float4 gl_Color : COLOR0,\n"
934 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
935 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n"
936 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n"
937 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n"
938 "float4 gl_MultiTexCoord4 : TEXCOORD4,\n"
940 "uniform float3 EyePosition : register(c24),\n"
941 "uniform float4x4 TexMatrix : register(c0),\n"
942 "#ifdef USEVERTEXTEXTUREBLEND\n"
943 "uniform float4x4 BackgroundTexMatrix : register(c4),\n"
945 "#ifdef MODE_LIGHTSOURCE\n"
946 "uniform float4x4 ModelToLight : register(c20),\n"
948 "#ifdef MODE_LIGHTSOURCE\n"
949 "uniform float3 LightPosition : register(c27),\n"
951 "#ifdef MODE_LIGHTDIRECTION\n"
952 "uniform float3 LightDir : register(c26),\n"
954 "uniform float4 FogPlane : register(c25),\n"
955 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
956 "uniform float3 LightPosition : register(c27),\n"
958 "#ifdef USESHADOWMAPORTHO\n"
959 "uniform float4x4 ShadowMapMatrix : register(c16),\n"
961 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND)\n"
962 "out float4 gl_FrontColor : COLOR,\n"
964 "out float4 TexCoordBoth : TEXCOORD0,\n"
965 "#ifdef USELIGHTMAP\n"
966 "out float2 TexCoordLightmap : TEXCOORD1,\n"
968 "#ifdef USEEYEVECTOR\n"
969 "out float3 EyeVector : TEXCOORD2,\n"
971 "#ifdef USEREFLECTION\n"
972 "out float4 ModelViewProjectionPosition : TEXCOORD3,\n"
975 "out float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n"
977 "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE) || defined(USEDIFFUSE)\n"
978 "out float3 LightVector : TEXCOORD1,\n"
980 "#ifdef MODE_LIGHTSOURCE\n"
981 "out float3 CubeVector : TEXCOORD3,\n"
983 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n"
984 "out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
985 "out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
986 "out float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n"
988 "#ifdef USESHADOWMAPORTHO\n"
989 "out float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n"
991 "out float4 gl_Position : POSITION\n"
994 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND)\n"
995 " gl_FrontColor = gl_Color;\n"
997 " // copy the surface texcoord\n"
998 " TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n"
999 "#ifdef USEVERTEXTEXTUREBLEND\n"
1000 " TexCoordBoth.zw = mul(BackgroundTexMatrix, gl_MultiTexCoord0).xy;\n"
1002 "#ifdef USELIGHTMAP\n"
1003 " TexCoordLightmap = gl_MultiTexCoord4.xy;\n"
1006 "#ifdef MODE_LIGHTSOURCE\n"
1007 " // transform vertex position into light attenuation/cubemap space\n"
1008 " // (-1 to +1 across the light box)\n"
1009 " CubeVector = mul(ModelToLight, gl_Vertex).xyz;\n"
1011 "# ifdef USEDIFFUSE\n"
1012 " // transform unnormalized light direction into tangent space\n"
1013 " // (we use unnormalized to ensure that it interpolates correctly and then\n"
1014 " // normalize it per pixel)\n"
1015 " float3 lightminusvertex = LightPosition - gl_Vertex.xyz;\n"
1016 " LightVector.x = dot(lightminusvertex, gl_MultiTexCoord1.xyz);\n"
1017 " LightVector.y = dot(lightminusvertex, gl_MultiTexCoord2.xyz);\n"
1018 " LightVector.z = dot(lightminusvertex, gl_MultiTexCoord3.xyz);\n"
1022 "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE)\n"
1023 " LightVector.x = dot(LightDir, gl_MultiTexCoord1.xyz);\n"
1024 " LightVector.y = dot(LightDir, gl_MultiTexCoord2.xyz);\n"
1025 " LightVector.z = dot(LightDir, gl_MultiTexCoord3.xyz);\n"
1028 " // transform unnormalized eye direction into tangent space\n"
1029 "#ifdef USEEYEVECTOR\n"
1030 " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n"
1031 " EyeVector.x = dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz);\n"
1032 " EyeVector.y = dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz);\n"
1033 " EyeVector.z = dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz);\n"
1037 " EyeVectorModelSpaceFogPlaneVertexDist.xyz = EyePosition - gl_Vertex.xyz;\n"
1038 " EyeVectorModelSpaceFogPlaneVertexDist.w = dot(FogPlane, gl_Vertex);\n"
1041 "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n"
1042 " VectorS = gl_MultiTexCoord1.xyz;\n"
1043 " VectorT = gl_MultiTexCoord2.xyz;\n"
1044 " VectorR = gl_MultiTexCoord3.xyz;\n"
1047 " // transform vertex to camera space, using ftransform to match non-VS rendering\n"
1048 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
1050 "#ifdef USESHADOWMAPORTHO\n"
1051 " ShadowMapTC = mul(ShadowMapMatrix, gl_Position).xyz;\n"
1054 "#ifdef USEREFLECTION\n"
1055 " ModelViewProjectionPosition = gl_Position;\n"
1058 "#endif // VERTEX_SHADER\n"
1063 "#ifdef FRAGMENT_SHADER\n"
1066 "#ifdef USEDEFERREDLIGHTMAP\n"
1068 "float2 Pixel : VPOS,\n"
1070 "float2 Pixel : WPOS,\n"
1073 "float4 gl_FrontColor : COLOR,\n"
1074 "float4 TexCoordBoth : TEXCOORD0,\n"
1075 "#ifdef USELIGHTMAP\n"
1076 "float2 TexCoordLightmap : TEXCOORD1,\n"
1078 "#ifdef USEEYEVECTOR\n"
1079 "float3 EyeVector : TEXCOORD2,\n"
1081 "#ifdef USEREFLECTION\n"
1082 "float4 ModelViewProjectionPosition : TEXCOORD3,\n"
1085 "float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n"
1087 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_LIGHTDIRECTION)\n"
1088 "float3 LightVector : TEXCOORD1,\n"
1090 "#ifdef MODE_LIGHTSOURCE\n"
1091 "float3 CubeVector : TEXCOORD3,\n"
1093 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
1094 "float4 ModelViewPosition : TEXCOORD0,\n"
1096 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n"
1097 "float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
1098 "float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
1099 "float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n"
1101 "#ifdef USESHADOWMAPORTHO\n"
1102 "float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n"
1105 "uniform sampler Texture_Normal : register(s0),\n"
1106 "uniform sampler Texture_Color : register(s1),\n"
1107 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n"
1108 "uniform sampler Texture_Gloss : register(s2),\n"
1111 "uniform sampler Texture_Glow : register(s3),\n"
1113 "#ifdef USEVERTEXTEXTUREBLEND\n"
1114 "uniform sampler Texture_SecondaryNormal : register(s4),\n"
1115 "uniform sampler Texture_SecondaryColor : register(s5),\n"
1116 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n"
1117 "uniform sampler Texture_SecondaryGloss : register(s6),\n"
1120 "uniform sampler Texture_SecondaryGlow : register(s7),\n"
1123 "#ifdef USECOLORMAPPING\n"
1124 "uniform sampler Texture_Pants : register(s4),\n"
1125 "uniform sampler Texture_Shirt : register(s7),\n"
1128 "uniform sampler Texture_FogHeightTexture : register(s14),\n"
1129 "uniform sampler Texture_FogMask : register(s8),\n"
1131 "#ifdef USELIGHTMAP\n"
1132 "uniform sampler Texture_Lightmap : register(s9),\n"
1134 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE)\n"
1135 "uniform sampler Texture_Deluxemap : register(s10),\n"
1137 "#ifdef USEREFLECTION\n"
1138 "uniform sampler Texture_Reflection : register(s7),\n"
1141 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
1142 "uniform sampler Texture_ScreenDepth : register(s13),\n"
1143 "uniform sampler Texture_ScreenNormalMap : register(s14),\n"
1145 "#ifdef USEDEFERREDLIGHTMAP\n"
1146 "uniform sampler Texture_ScreenDepth : register(s13),\n"
1147 "uniform sampler Texture_ScreenNormalMap : register(s14),\n"
1148 "uniform sampler Texture_ScreenDiffuse : register(s11),\n"
1149 "uniform sampler Texture_ScreenSpecular : register(s12),\n"
1152 "#ifdef USECOLORMAPPING\n"
1153 "uniform half3 Color_Pants : register(c7),\n"
1154 "uniform half3 Color_Shirt : register(c8),\n"
1157 "uniform float3 FogColor : register(c16),\n"
1158 "uniform float FogRangeRecip : register(c20),\n"
1159 "uniform float FogPlaneViewDist : register(c19),\n"
1160 "uniform float FogHeightFade : register(c17),\n"
1163 "#ifdef USEOFFSETMAPPING\n"
1164 "uniform float OffsetMapping_Scale : register(c24),\n"
1167 "#ifdef USEDEFERREDLIGHTMAP\n"
1168 "uniform half2 PixelToScreenTexCoord : register(c42),\n"
1169 "uniform half3 DeferredMod_Diffuse : register(c12),\n"
1170 "uniform half3 DeferredMod_Specular : register(c13),\n"
1172 "uniform half3 Color_Ambient : register(c3),\n"
1173 "uniform half3 Color_Diffuse : register(c4),\n"
1174 "uniform half3 Color_Specular : register(c5),\n"
1175 "uniform half SpecularPower : register(c36),\n"
1177 "uniform half3 Color_Glow : register(c6),\n"
1179 "uniform half Alpha : register(c0),\n"
1180 "#ifdef USEREFLECTION\n"
1181 "uniform float4 DistortScaleRefractReflect : register(c14),\n"
1182 "uniform float4 ScreenScaleRefractReflect : register(c32),\n"
1183 "uniform float4 ScreenCenterRefractReflect : register(c31),\n"
1184 "uniform half4 ReflectColor : register(c26),\n"
1186 "#ifdef USEREFLECTCUBE\n"
1187 "uniform float4x4 ModelToReflectCube : register(c48),\n"
1188 "uniform sampler Texture_ReflectMask : register(s5),\n"
1189 "uniform samplerCUBE Texture_ReflectCube : register(s6),\n"
1191 "#ifdef MODE_LIGHTDIRECTION\n"
1192 "uniform half3 LightColor : register(c21),\n"
1194 "#ifdef MODE_LIGHTSOURCE\n"
1195 "uniform half3 LightColor : register(c21),\n"
1198 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE)\n"
1199 "uniform sampler Texture_Attenuation : register(s9),\n"
1200 "uniform samplerCUBE Texture_Cube : register(s10),\n"
1203 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n"
1205 "#ifdef USESHADOWMAP2D\n"
1206 "# ifdef USESHADOWSAMPLER\n"
1207 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
1209 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
1213 "#ifdef USESHADOWMAPVSDCT\n"
1214 "uniform samplerCUBE Texture_CubeProjection : register(s12),\n"
1217 "#if defined(USESHADOWMAP2D)\n"
1218 "uniform float2 ShadowMap_TextureScale : register(c35),\n"
1219 "uniform float4 ShadowMap_Parameters : register(c34),\n"
1221 "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n"
1223 "out float4 gl_FragColor : COLOR\n"
1226 " float2 TexCoord = TexCoordBoth.xy;\n"
1227 "#ifdef USEVERTEXTEXTUREBLEND\n"
1228 " float2 TexCoord2 = TexCoordBoth.zw;\n"
1230 "#ifdef USEOFFSETMAPPING\n"
1231 " // apply offsetmapping\n"
1232 " float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_Scale, EyeVector, Texture_Normal);\n"
1233 "#define TexCoord TexCoordOffset\n"
1236 " // combine the diffuse textures (base, pants, shirt)\n"
1237 " half4 color = half4(tex2D(Texture_Color, TexCoord));\n"
1238 "#ifdef USEALPHAKILL\n"
1239 " if (color.a < 0.5)\n"
1242 " color.a *= Alpha;\n"
1243 "#ifdef USECOLORMAPPING\n"
1244 " color.rgb += half3(tex2D(Texture_Pants, TexCoord).rgb) * Color_Pants + half3(tex2D(Texture_Shirt, TexCoord).rgb) * Color_Shirt;\n"
1246 "#ifdef USEVERTEXTEXTUREBLEND\n"
1247 " half terrainblend = clamp(half(gl_FrontColor.a) * color.a * 2.0 - 0.5, half(0.0), half(1.0));\n"
1248 " //half terrainblend = min(half(gl_FrontColor.a) * color.a * 2.0, half(1.0));\n"
1249 " //half terrainblend = half(gl_FrontColor.a) * color.a > 0.5;\n"
1250 " color.rgb = half3(lerp(tex2D(Texture_SecondaryColor, TexCoord2).rgb, float3(color.rgb), terrainblend));\n"
1252 " //color = half4(lerp(float4(1, 0, 0, 1), color, terrainblend));\n"
1255 " // get the surface normal\n"
1256 "#ifdef USEVERTEXTEXTUREBLEND\n"
1257 " half3 surfacenormal = normalize(half3(lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, tex2D(Texture_Normal, TexCoord).rgb, terrainblend)) - half3(0.5, 0.5, 0.5));\n"
1259 " half3 surfacenormal = half3(normalize(half3(tex2D(Texture_Normal, TexCoord).rgb) - half3(0.5, 0.5, 0.5)));\n"
1262 " // get the material colors\n"
1263 " half3 diffusetex = color.rgb;\n"
1264 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n"
1265 "# ifdef USEVERTEXTEXTUREBLEND\n"
1266 " half4 glosstex = half4(lerp(tex2D(Texture_SecondaryGloss, TexCoord2), tex2D(Texture_Gloss, TexCoord), terrainblend));\n"
1268 " half4 glosstex = half4(tex2D(Texture_Gloss, TexCoord));\n"
1272 "#ifdef USEREFLECTCUBE\n"
1273 " float3 TangentReflectVector = reflect(-EyeVector, surfacenormal);\n"
1274 " float3 ModelReflectVector = TangentReflectVector.x * VectorS + TangentReflectVector.y * VectorT + TangentReflectVector.z * VectorR;\n"
1275 " float3 ReflectCubeTexCoord = mul(ModelToReflectCube, float4(ModelReflectVector, 0)).xyz;\n"
1276 " diffusetex += half3(tex2D(Texture_ReflectMask, TexCoord).rgb) * half3(texCUBE(Texture_ReflectCube, ReflectCubeTexCoord).rgb);\n"
1282 "#ifdef MODE_LIGHTSOURCE\n"
1283 " // light source\n"
1284 "#ifdef USEDIFFUSE\n"
1285 " half3 lightnormal = half3(normalize(LightVector));\n"
1286 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n"
1287 " color.rgb = diffusetex * (Color_Ambient + diffuse * Color_Diffuse);\n"
1288 "#ifdef USESPECULAR\n"
1289 "#ifdef USEEXACTSPECULARMATH\n"
1290 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower * glosstex.a));\n"
1292 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n"
1293 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * glosstex.a));\n"
1295 " color.rgb += glosstex.rgb * (specular * Color_Specular);\n"
1298 " color.rgb = diffusetex * Color_Ambient;\n"
1300 " color.rgb *= LightColor;\n"
1301 " color.rgb *= half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n"
1302 "#if defined(USESHADOWMAP2D)\n"
1303 " color.rgb *= half(ShadowMapCompare(CubeVector, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n"
1304 "#ifdef USESHADOWMAPVSDCT\n"
1305 ", Texture_CubeProjection\n"
1310 "# ifdef USECUBEFILTER\n"
1311 " color.rgb *= half3(texCUBE(Texture_Cube, CubeVector).rgb);\n"
1314 "#ifdef USESHADOWMAP2D\n"
1315 "#ifdef USESHADOWMAPVSDCT\n"
1316 "// float3 shadowmaptc = GetShadowMapTC2D(CubeVector, ShadowMap_Parameters, Texture_CubeProjection);\n"
1318 "// float3 shadowmaptc = GetShadowMapTC2D(CubeVector, ShadowMap_Parameters);\n"
1320 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n"
1321 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale).rgb);\n"
1322 "// color.rgb = half3(shadowmaptc.xyz * float3(ShadowMap_TextureScale,1.0));\n"
1323 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n"
1324 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n"
1325 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale).rgb);\n"
1326 "// color.rgb = half3(shadowmaptc.xyz * float3(ShadowMap_TextureScale,1.0));\n"
1327 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n"
1328 "// color.r = half(shadowmaptc.z - texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n"
1329 "// color.r = half(shadowmaptc.z);\n"
1330 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n"
1331 "// color.r = half(shadowmaptc.z);\n"
1333 "// color.rgb = abs(CubeVector);\n"
1335 "// color.rgb = half3(1,1,1);\n"
1336 "#endif // MODE_LIGHTSOURCE\n"
1341 "#ifdef MODE_LIGHTDIRECTION\n"
1343 "#ifdef USEDIFFUSE\n"
1344 " half3 lightnormal = half3(normalize(LightVector));\n"
1346 "#define lightcolor LightColor\n"
1347 "#endif // MODE_LIGHTDIRECTION\n"
1348 "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n"
1350 " // deluxemap lightmapping using light vectors in modelspace (q3map2 -light -deluxe)\n"
1351 " half3 lightnormal_modelspace = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n"
1352 " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n"
1353 " // convert modelspace light vector to tangentspace\n"
1354 " half3 lightnormal;\n"
1355 " lightnormal.x = dot(lightnormal_modelspace, half3(VectorS));\n"
1356 " lightnormal.y = dot(lightnormal_modelspace, half3(VectorT));\n"
1357 " lightnormal.z = dot(lightnormal_modelspace, half3(VectorR));\n"
1358 " // calculate directional shading (and undoing the existing angle attenuation on the lightmap by the division)\n"
1359 " // note that q3map2 is too stupid to calculate proper surface normals when q3map_nonplanar\n"
1360 " // is used (the lightmap and deluxemap coords correspond to virtually random coordinates\n"
1361 " // on that luxel, and NOT to its center, because recursive triangle subdivision is used\n"
1362 " // to map the luxels to coordinates on the draw surfaces), which also causes\n"
1363 " // deluxemaps to be wrong because light contributions from the wrong side of the surface\n"
1364 " // are added up. To prevent divisions by zero or strong exaggerations, a max()\n"
1365 " // nudge is done here at expense of some additional fps. This is ONLY needed for\n"
1366 " // deluxemaps, tangentspace deluxemap avoid this problem by design.\n"
1367 " lightcolor *= 1.0 / max(0.25, lightnormal.z);\n"
1368 "#endif // MODE_LIGHTDIRECTIONMAP_MODELSPACE\n"
1369 "#ifdef MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n"
1371 " // deluxemap lightmapping using light vectors in tangentspace (hmap2 -light)\n"
1372 " half3 lightnormal = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n"
1373 " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n"
1379 "#ifdef MODE_FAKELIGHT\n"
1381 "half3 lightnormal = half3(normalize(EyeVector));\n"
1382 "half3 lightcolor = half3(1.0,1.0,1.0);\n"
1383 "#endif // MODE_FAKELIGHT\n"
1388 "#ifdef MODE_LIGHTMAP\n"
1389 " color.rgb = diffusetex * (Color_Ambient + half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb) * Color_Diffuse);\n"
1390 "#endif // MODE_LIGHTMAP\n"
1391 "#ifdef MODE_VERTEXCOLOR\n"
1392 " color.rgb = diffusetex * (Color_Ambient + half3(gl_FrontColor.rgb) * Color_Diffuse);\n"
1393 "#endif // MODE_VERTEXCOLOR\n"
1394 "#ifdef MODE_FLATCOLOR\n"
1395 " color.rgb = diffusetex * Color_Ambient;\n"
1396 "#endif // MODE_FLATCOLOR\n"
1402 "# ifdef USEDIFFUSE\n"
1403 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n"
1404 "# ifdef USESPECULAR\n"
1405 "# ifdef USEEXACTSPECULARMATH\n"
1406 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower * glosstex.a));\n"
1408 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n"
1409 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * glosstex.a));\n"
1411 " color.rgb = diffusetex * Color_Ambient + (diffusetex * Color_Diffuse * diffuse + glosstex.rgb * Color_Specular * specular) * lightcolor;\n"
1413 " color.rgb = diffusetex * (Color_Ambient + Color_Diffuse * diffuse * lightcolor);\n"
1416 " color.rgb = diffusetex * Color_Ambient;\n"
1420 "#ifdef USESHADOWMAPORTHO\n"
1421 " color.rgb *= half(ShadowMapCompare(ShadowMapTC, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale));\n"
1424 "#ifdef USEDEFERREDLIGHTMAP\n"
1425 " float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n"
1426 " color.rgb += diffusetex * half3(tex2D(Texture_ScreenDiffuse, ScreenTexCoord).rgb) * DeferredMod_Diffuse;\n"
1427 " color.rgb += glosstex.rgb * half3(tex2D(Texture_ScreenSpecular, ScreenTexCoord).rgb) * DeferredMod_Specular;\n"
1428 "// color.rgb = half3(tex2D(Texture_ScreenDepth, ScreenTexCoord).rgb);\n"
1429 "// color.r = half(texDepth2D(Texture_ScreenDepth, ScreenTexCoord)) * 1.0;\n"
1433 "#ifdef USEVERTEXTEXTUREBLEND\n"
1434 " color.rgb += half3(lerp(tex2D(Texture_SecondaryGlow, TexCoord2).rgb, tex2D(Texture_Glow, TexCoord).rgb, terrainblend)) * Color_Glow;\n"
1436 " color.rgb += half3(tex2D(Texture_Glow, TexCoord).rgb) * Color_Glow;\n"
1441 " color.rgb = FogVertex(color.rgb, FogColor, EyeVectorModelSpaceFogPlaneVertexDist.xyz, EyeVectorModelSpaceFogPlaneVertexDist.w, FogRangeRecip, FogPlaneViewDist, FogHeightFade, Texture_FogMask, Texture_FogHeightTexture);\n"
1444 " // 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"
1445 "#ifdef USEREFLECTION\n"
1446 " float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n"
1447 " //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(half3(tex2D(Texture_Normal, TexCoord).rgb) - half3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n"
1448 " float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW.zw + ScreenCenterRefractReflect.zw;\n"
1449 " float2 ScreenTexCoord = SafeScreenTexCoord + float3(normalize(half3(tex2D(Texture_Normal, TexCoord).rgb) - half3(0.5,0.5,0.5))).xy * DistortScaleRefractReflect.zw;\n"
1450 " // FIXME temporary hack to detect the case that the reflection\n"
1451 " // gets blackened at edges due to leaving the area that contains actual\n"
1453 " // Remove this 'ack once we have a better way to stop this thing from\n"
1455 " float f = min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(0.01, 0.01)).rgb) / 0.05);\n"
1456 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(0.01, -0.01)).rgb) / 0.05);\n"
1457 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, 0.01)).rgb) / 0.05);\n"
1458 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, -0.01)).rgb) / 0.05);\n"
1459 " ScreenTexCoord = lerp(SafeScreenTexCoord, ScreenTexCoord, f);\n"
1460 " color.rgb = lerp(color.rgb, half3(tex2D(Texture_Reflection, ScreenTexCoord).rgb) * ReflectColor.rgb, ReflectColor.a);\n"
1463 " gl_FragColor = float4(color);\n"
1465 "#endif // FRAGMENT_SHADER\n"
1467 "#endif // !MODE_DEFERREDLIGHTSOURCE\n"
1468 "#endif // !MODE_DEFERREDGEOMETRY\n"
1469 "#endif // !MODE_WATER\n"
1470 "#endif // !MODE_REFRACTION\n"
1471 "#endif // !MODE_BLOOMBLUR\n"
1472 "#endif // !MODE_GENERIC\n"
1473 "#endif // !MODE_POSTPROCESS\n"
1474 "#endif // !MODE_SHOWDEPTH\n"
1475 "#endif // !MODE_DEPTH_OR_SHADOW\n"