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) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP)\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 VERTEX_SHADER\n"
32 "// LordHavoc: based on shader code linked at: http://www.youtube.com/watch?v=JpksyojwqzE\n"
34 "float4 TrippyVertex(float4 position)\n"
36 "uniform float ClientTime : register(c2)\n"
39 " float worldTime = ClientTime;\n"
40 " // tweaked for Quake\n"
41 " worldTime *= 10.0;\n"
42 " position *= 0.125;\n"
43 " //~tweaked for Quake\n"
44 " float distanceSquared = (position.x * position.x + position.z * position.z);\n"
45 " position.y += 5.0*sin(distanceSquared*sin(worldTime/143.0)/1000.0);\n"
46 " float y = position.y;\n"
47 " float x = position.x;\n"
48 " float om = sin(distanceSquared*sin(worldTime/256.0)/5000.0) * sin(worldTime/200.0);\n"
49 " position.y = x*sin(om)+y*cos(om);\n"
50 " position.x = x*cos(om)-y*sin(om);\n"
56 "#ifdef MODE_DEPTH_OR_SHADOW\n"
57 "#ifdef VERTEX_SHADER\n"
60 "float4 gl_Vertex : POSITION,\n"
61 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
62 "out float4 gl_Position : POSITION,\n"
63 "out float Depth : TEXCOORD0\n"
66 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
68 " gl_Position = TrippyVertex(gl_Position);\n"
70 " Depth = gl_Position.z;\n"
74 "#ifdef FRAGMENT_SHADER\n"
77 "float Depth : TEXCOORD0,\n"
78 "out float4 dp_FragColor : COLOR\n"
81 "// float4 temp = float4(Depth,Depth*(65536.0/255.0),Depth*(16777216.0/255.0),0.0);\n"
82 " float4 temp = float4(Depth,Depth*256.0,Depth*65536.0,0.0);\n"
83 " temp.yz -= floor(temp.yz);\n"
84 " dp_FragColor = temp;\n"
85 "// dp_FragColor = float4(Depth,0,0,0);\n"
88 "#else // !MODE_DEPTH_OR_SHADOW\n"
93 "#ifdef MODE_SHOWDEPTH\n"
94 "#ifdef VERTEX_SHADER\n"
97 "float4 gl_Vertex : POSITION,\n"
98 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
99 "out float4 gl_Position : POSITION,\n"
100 "out float4 gl_FrontColor : COLOR0\n"
103 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
105 " gl_Position = TrippyVertex(gl_Position);\n"
107 " gl_FrontColor = float4(gl_Position.z, gl_Position.z, gl_Position.z, 1.0);\n"
111 "#ifdef FRAGMENT_SHADER\n"
114 "float4 gl_FrontColor : COLOR0,\n"
115 "out float4 dp_FragColor : COLOR\n"
118 " dp_FragColor = gl_FrontColor;\n"
121 "#else // !MODE_SHOWDEPTH\n"
126 "#ifdef MODE_POSTPROCESS\n"
128 "#ifdef VERTEX_SHADER\n"
131 "float4 gl_Vertex : POSITION,\n"
132 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
133 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
134 "float4 gl_MultiTexCoord4 : TEXCOORD4,\n"
135 "out float4 gl_Position : POSITION,\n"
136 "out float2 TexCoord1 : TEXCOORD0,\n"
137 "out float2 TexCoord2 : TEXCOORD1\n"
140 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
141 " TexCoord1 = gl_MultiTexCoord0.xy;\n"
143 " TexCoord2 = gl_MultiTexCoord4.xy;\n"
148 "#ifdef FRAGMENT_SHADER\n"
151 "float2 TexCoord1 : TEXCOORD0,\n"
152 "float2 TexCoord2 : TEXCOORD1,\n"
153 "uniform sampler Texture_First : register(s0),\n"
155 "uniform sampler Texture_Second : register(s1),\n"
157 "#ifdef USEGAMMARAMPS\n"
158 "uniform sampler Texture_GammaRamps : register(s2),\n"
160 "#ifdef USESATURATION\n"
161 "uniform float Saturation : register(c30),\n"
163 "#ifdef USEVIEWTINT\n"
164 "uniform float4 ViewTintColor : register(c41),\n"
166 "uniform float4 UserVec1 : register(c37),\n"
167 "uniform float4 UserVec2 : register(c38),\n"
168 "uniform float4 UserVec3 : register(c39),\n"
169 "uniform float4 UserVec4 : register(c40),\n"
170 "uniform float ClientTime : register(c2),\n"
171 "uniform float2 PixelSize : register(c25),\n"
172 "uniform float4 BloomColorSubtract : register(c43),\n"
173 "out float4 dp_FragColor : COLOR\n"
176 " dp_FragColor = tex2D(Texture_First, TexCoord1);\n"
178 " dp_FragColor += max(float4(0,0,0,0), tex2D(Texture_Second, TexCoord2) - BloomColorSubtract);\n"
180 "#ifdef USEVIEWTINT\n"
181 " dp_FragColor = lerp(dp_FragColor, ViewTintColor, ViewTintColor.a);\n"
184 "#ifdef USEPOSTPROCESSING\n"
185 "// do r_glsl_dumpshader, edit glsl/default.glsl, and replace this by your own postprocessing if you want\n"
186 "// this code does a blur with the radius specified in the first component of r_glsl_postprocess_uservec1 and blends it using the second component\n"
187 " float sobel = 1.0;\n"
188 " // float2 ts = textureSize(Texture_First, 0);\n"
189 " // float2 px = float2(1/ts.x, 1/ts.y);\n"
190 " float2 px = PixelSize;\n"
191 " float3 x1 = tex2D(Texture_First, TexCoord1 + float2(-px.x, px.y)).rgb;\n"
192 " float3 x2 = tex2D(Texture_First, TexCoord1 + float2(-px.x, 0.0)).rgb;\n"
193 " float3 x3 = tex2D(Texture_First, TexCoord1 + float2(-px.x,-px.y)).rgb;\n"
194 " float3 x4 = tex2D(Texture_First, TexCoord1 + float2( px.x, px.y)).rgb;\n"
195 " float3 x5 = tex2D(Texture_First, TexCoord1 + float2( px.x, 0.0)).rgb;\n"
196 " float3 x6 = tex2D(Texture_First, TexCoord1 + float2( px.x,-px.y)).rgb;\n"
197 " float3 y1 = tex2D(Texture_First, TexCoord1 + float2( px.x,-px.y)).rgb;\n"
198 " float3 y2 = tex2D(Texture_First, TexCoord1 + float2( 0.0,-px.y)).rgb;\n"
199 " float3 y3 = tex2D(Texture_First, TexCoord1 + float2(-px.x,-px.y)).rgb;\n"
200 " float3 y4 = tex2D(Texture_First, TexCoord1 + float2( px.x, px.y)).rgb;\n"
201 " float3 y5 = tex2D(Texture_First, TexCoord1 + float2( 0.0, px.y)).rgb;\n"
202 " float3 y6 = tex2D(Texture_First, TexCoord1 + float2(-px.x, px.y)).rgb;\n"
203 " float px1 = -1.0 * dot(float3(0.3, 0.59, 0.11), x1);\n"
204 " float px2 = -2.0 * dot(float3(0.3, 0.59, 0.11), x2);\n"
205 " float px3 = -1.0 * dot(float3(0.3, 0.59, 0.11), x3);\n"
206 " float px4 = 1.0 * dot(float3(0.3, 0.59, 0.11), x4);\n"
207 " float px5 = 2.0 * dot(float3(0.3, 0.59, 0.11), x5);\n"
208 " float px6 = 1.0 * dot(float3(0.3, 0.59, 0.11), x6);\n"
209 " float py1 = -1.0 * dot(float3(0.3, 0.59, 0.11), y1);\n"
210 " float py2 = -2.0 * dot(float3(0.3, 0.59, 0.11), y2);\n"
211 " float py3 = -1.0 * dot(float3(0.3, 0.59, 0.11), y3);\n"
212 " float py4 = 1.0 * dot(float3(0.3, 0.59, 0.11), y4);\n"
213 " float py5 = 2.0 * dot(float3(0.3, 0.59, 0.11), y5);\n"
214 " float py6 = 1.0 * dot(float3(0.3, 0.59, 0.11), y6);\n"
215 " sobel = 0.25 * abs(px1 + px2 + px3 + px4 + px5 + px6) + 0.25 * abs(py1 + py2 + py3 + py4 + py5 + py6);\n"
216 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.987688, -0.156434)) * UserVec1.y;\n"
217 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.156434, -0.891007)) * UserVec1.y;\n"
218 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2( 0.891007, -0.453990)) * UserVec1.y;\n"
219 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2( 0.707107, 0.707107)) * UserVec1.y;\n"
220 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.453990, 0.891007)) * UserVec1.y;\n"
221 " dp_FragColor /= (1.0 + 5.0 * UserVec1.y);\n"
222 " dp_FragColor.rgb = dp_FragColor.rgb * (1.0 + UserVec2.x) + float3(1,1,1)*max(0.0, sobel - UserVec2.z)*UserVec2.y;\n"
225 "#ifdef USESATURATION\n"
226 " //apply saturation BEFORE gamma ramps, so v_glslgamma value does not matter\n"
227 " float y = dot(dp_FragColor.rgb, float3(0.299, 0.587, 0.114));\n"
228 " // 'vampire sight' effect, wheres red is compensated\n"
229 " #ifdef SATURATION_REDCOMPENSATE\n"
230 " float rboost = max(0.0, (dp_FragColor.r - max(dp_FragColor.g, dp_FragColor.b))*(1.0 - Saturation));\n"
231 " dp_FragColor.rgb = lerp(float3(y,y,y), dp_FragColor.rgb, Saturation);\n"
232 " dp_FragColor.r += r;\n"
234 " // normal desaturation\n"
235 " //dp_FragColor = float3(y,y,y) + (dp_FragColor.rgb - float3(y)) * Saturation;\n"
236 " dp_FragColor.rgb = lerp(float3(y,y,y), dp_FragColor.rgb, Saturation);\n"
240 "#ifdef USEGAMMARAMPS\n"
241 " dp_FragColor.r = tex2D(Texture_GammaRamps, float2(dp_FragColor.r, 0)).r;\n"
242 " dp_FragColor.g = tex2D(Texture_GammaRamps, float2(dp_FragColor.g, 0)).g;\n"
243 " dp_FragColor.b = tex2D(Texture_GammaRamps, float2(dp_FragColor.b, 0)).b;\n"
247 "#else // !MODE_POSTPROCESS\n"
252 "#ifdef MODE_GENERIC\n"
253 "#ifdef VERTEX_SHADER\n"
256 "float4 gl_Vertex : POSITION,\n"
257 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
258 "float4 gl_Color : COLOR0,\n"
259 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
260 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n"
261 "out float4 gl_Position : POSITION,\n"
262 "#ifdef USEDIFFUSE\n"
263 "out float2 TexCoord1 : TEXCOORD0,\n"
265 "#ifdef USESPECULAR\n"
266 "out float2 TexCoord2 : TEXCOORD1,\n"
268 "out float4 gl_FrontColor : COLOR\n"
271 " gl_FrontColor = gl_Color;\n"
272 "#ifdef USEDIFFUSE\n"
273 " TexCoord1 = gl_MultiTexCoord0.xy;\n"
275 "#ifdef USESPECULAR\n"
276 " TexCoord2 = gl_MultiTexCoord1.xy;\n"
278 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
280 " gl_Position = TrippyVertex(gl_Position);\n"
285 "#ifdef FRAGMENT_SHADER\n"
289 "float4 gl_FrontColor : COLOR0,\n"
290 "float2 TexCoord1 : TEXCOORD0,\n"
291 "float2 TexCoord2 : TEXCOORD1,\n"
292 "#ifdef USEDIFFUSE\n"
293 "uniform sampler Texture_First : register(s0),\n"
295 "#ifdef USESPECULAR\n"
296 "uniform sampler Texture_Second : register(s1),\n"
298 "#ifdef USEGAMMARAMPS\n"
299 "uniform sampler Texture_GammaRamps : register(s2),\n"
301 "out float4 dp_FragColor : COLOR\n"
304 "#ifdef USEVIEWTINT\n"
305 " dp_FragColor = gl_FrontColor;\n"
307 " dp_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
309 "#ifdef USEDIFFUSE\n"
310 "# ifdef USEREFLECTCUBE\n"
311 " // suppress texture alpha\n"
312 " dp_FragColor.rgb *= tex2D(Texture_First, TexCoord1).rgb;\n"
314 " dp_FragColor *= tex2D(Texture_First, TexCoord1);\n"
318 "#ifdef USESPECULAR\n"
319 " float4 tex2 = tex2D(Texture_Second, TexCoord2);\n"
320 "# ifdef USECOLORMAPPING\n"
321 " dp_FragColor *= tex2;\n"
324 " dp_FragColor += tex2;\n"
326 "# ifdef USEVERTEXTEXTUREBLEND\n"
327 " dp_FragColor = lerp(dp_FragColor, tex2, tex2.a);\n"
330 "#ifdef USEGAMMARAMPS\n"
331 " dp_FragColor.r = tex2D(Texture_GammaRamps, vec2(dp_FragColor.r, 0)).r;\n"
332 " dp_FragColor.g = tex2D(Texture_GammaRamps, vec2(dp_FragColor.g, 0)).g;\n"
333 " dp_FragColor.b = tex2D(Texture_GammaRamps, vec2(dp_FragColor.b, 0)).b;\n"
337 "#else // !MODE_GENERIC\n"
342 "#ifdef MODE_BLOOMBLUR\n"
343 "#ifdef VERTEX_SHADER\n"
346 "float4 gl_Vertex : POSITION,\n"
347 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
348 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
349 "out float4 gl_Position : POSITION,\n"
350 "out float2 TexCoord : TEXCOORD0\n"
353 " TexCoord = gl_MultiTexCoord0.xy;\n"
354 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
358 "#ifdef FRAGMENT_SHADER\n"
362 "float2 TexCoord : TEXCOORD0,\n"
363 "uniform sampler Texture_First : register(s0),\n"
364 "uniform float4 BloomBlur_Parameters : register(c1),\n"
365 "out float4 dp_FragColor : COLOR\n"
369 " float2 tc = TexCoord;\n"
370 " float3 color = tex2D(Texture_First, tc).rgb;\n"
371 " tc += BloomBlur_Parameters.xy;\n"
372 " for (i = 1;i < SAMPLES;i++)\n"
374 " color += tex2D(Texture_First, tc).rgb;\n"
375 " tc += BloomBlur_Parameters.xy;\n"
377 " dp_FragColor = float4(color * BloomBlur_Parameters.z + float3(BloomBlur_Parameters.w), 1);\n"
380 "#else // !MODE_BLOOMBLUR\n"
381 "#ifdef MODE_REFRACTION\n"
382 "#ifdef VERTEX_SHADER\n"
385 "float4 gl_Vertex : POSITION,\n"
386 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
387 "#ifdef USEALPHAGENVERTEX\n"
388 "float4 gl_Color : COLOR0,\n"
390 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
391 "uniform float4x4 TexMatrix : register(c0),\n"
392 "uniform float3 EyePosition : register(c24),\n"
393 "#ifdef USEALPHAGENVERTEX\n"
394 "out float4 gl_FrontColor : COLOR,\n"
396 "out float4 gl_Position : POSITION,\n"
397 "out float2 TexCoord : TEXCOORD0,\n"
398 "out float3 EyeVector : TEXCOORD1,\n"
399 "out float4 ModelViewProjectionPosition : TEXCOORD2\n"
402 "#ifdef USEALPHAGENVERTEX\n"
403 " gl_FrontColor = gl_Color;\n"
405 " TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n"
406 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
407 " ModelViewProjectionPosition = gl_Position;\n"
409 " gl_Position = TrippyVertex(gl_Position);\n"
414 "#ifdef FRAGMENT_SHADER\n"
417 "#ifdef USEALPHAGENVERTEX\n"
418 "float4 gl_FrontColor : COLOR,\n"
420 "float2 TexCoord : TEXCOORD0,\n"
421 "float3 EyeVector : TEXCOORD1,\n"
422 "float4 ModelViewProjectionPosition : TEXCOORD2,\n"
423 "uniform sampler Texture_Normal : register(s0),\n"
424 "uniform sampler Texture_Refraction : register(s3),\n"
425 "uniform sampler Texture_Reflection : register(s7),\n"
426 "uniform float4 DistortScaleRefractReflect : register(c14),\n"
427 "uniform float4 ScreenScaleRefractReflect : register(c32),\n"
428 "uniform float4 ScreenCenterRefractReflect : register(c31),\n"
429 "uniform float4 RefractColor : register(c29),\n"
430 "out float4 dp_FragColor : COLOR\n"
433 " float2 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect.xy * (1.0 / ModelViewProjectionPosition.w);\n"
434 " //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"
435 " float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n"
436 "#ifdef USEALPHAGENVERTEX\n"
437 " float2 distort = DistortScaleRefractReflect.xy * gl_FrontColor.a;\n"
438 " float4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), gl_FrontColor.a);\n"
440 " float2 distort = DistortScaleRefractReflect.xy;\n"
441 " float4 refractcolor = RefractColor;\n"
443 " float2 ScreenTexCoord = SafeScreenTexCoord + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy * distort;\n"
444 " // FIXME temporary hack to detect the case that the reflection\n"
445 " // gets blackened at edges due to leaving the area that contains actual\n"
447 " // Remove this 'ack once we have a better way to stop this thing from\n"
449 " float f = min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(0.01, 0.01)).rgb) / 0.05);\n"
450 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(0.01, -0.01)).rgb) / 0.05);\n"
451 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(-0.01, 0.01)).rgb) / 0.05);\n"
452 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(-0.01, -0.01)).rgb) / 0.05);\n"
453 " ScreenTexCoord = lerp(SafeScreenTexCoord, ScreenTexCoord, f);\n"
454 " dp_FragColor = float4(tex2D(Texture_Refraction, ScreenTexCoord).rgb, 1) * refractcolor;\n"
457 "#else // !MODE_REFRACTION\n"
462 "#ifdef MODE_WATER\n"
463 "#ifdef VERTEX_SHADER\n"
467 "float4 gl_Vertex : POSITION,\n"
468 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
469 "#ifdef USEALPHAGENVERTEX\n"
470 "float4 gl_Color : COLOR0,\n"
472 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
473 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n"
474 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n"
475 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n"
476 "uniform float4x4 TexMatrix : register(c0),\n"
477 "uniform float3 EyePosition : register(c24),\n"
478 "#ifdef USEALPHAGENVERTEX\n"
479 "out float4 gl_FrontColor : COLOR,\n"
481 "out float4 gl_Position : POSITION,\n"
482 "out float2 TexCoord : TEXCOORD0,\n"
483 "out float3 EyeVector : TEXCOORD1,\n"
484 "out float4 ModelViewProjectionPosition : TEXCOORD2\n"
487 "#ifdef USEALPHAGENVERTEX\n"
488 " gl_FrontColor = gl_Color;\n"
490 " TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n"
491 " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n"
492 " EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n"
493 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
494 " ModelViewProjectionPosition = gl_Position;\n"
496 " gl_Position = TrippyVertex(gl_Position);\n"
501 "#ifdef FRAGMENT_SHADER\n"
504 "#ifdef USEALPHAGENVERTEX\n"
505 "float4 gl_FrontColor : COLOR,\n"
507 "float2 TexCoord : TEXCOORD0,\n"
508 "float3 EyeVector : TEXCOORD1,\n"
509 "float4 ModelViewProjectionPosition : TEXCOORD2,\n"
510 "uniform sampler Texture_Normal : register(s0),\n"
511 "uniform sampler Texture_Refraction : register(s3),\n"
512 "uniform sampler Texture_Reflection : register(s7),\n"
513 "uniform float4 DistortScaleRefractReflect : register(c14),\n"
514 "uniform float4 ScreenScaleRefractReflect : register(c32),\n"
515 "uniform float4 ScreenCenterRefractReflect : register(c31),\n"
516 "uniform float4 RefractColor : register(c29),\n"
517 "uniform float4 ReflectColor : register(c26),\n"
518 "uniform float ReflectFactor : register(c27),\n"
519 "uniform float ReflectOffset : register(c28),\n"
520 "out float4 dp_FragColor : COLOR\n"
523 " float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n"
524 " //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n"
525 " float4 SafeScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n"
526 " //SafeScreenTexCoord = gl_FragCoord.xyxy * float4(1.0 / 1920.0, 1.0 / 1200.0, 1.0 / 1920.0, 1.0 / 1200.0);\n"
527 "#ifdef USEALPHAGENVERTEX\n"
528 " float4 distort = DistortScaleRefractReflect * gl_FrontColor.a;\n"
529 " float reflectoffset = ReflectOffset * gl_FrontColor.a;\n"
530 " float reflectfactor = ReflectFactor * gl_FrontColor.a;\n"
531 " float4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), gl_FrontColor.a);\n"
533 " float4 distort = DistortScaleRefractReflect;\n"
534 " float reflectoffset = ReflectOffset;\n"
535 " float reflectfactor = ReflectFactor;\n"
536 " float4 refractcolor = RefractColor;\n"
538 " float4 ScreenTexCoord = SafeScreenTexCoord + float2(normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy).xyxy * distort;\n"
539 " // FIXME temporary hack to detect the case that the reflection\n"
540 " // gets blackened at edges due to leaving the area that contains actual\n"
542 " // Remove this 'ack once we have a better way to stop this thing from\n"
544 " float f = min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(0.01, 0.01)).rgb) / 0.05);\n"
545 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(0.01, -0.01)).rgb) / 0.05);\n"
546 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(-0.01, 0.01)).rgb) / 0.05);\n"
547 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(-0.01, -0.01)).rgb) / 0.05);\n"
548 " ScreenTexCoord.xy = lerp(SafeScreenTexCoord.xy, ScreenTexCoord.xy, f);\n"
549 " f = min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(0.01, 0.01)).rgb) / 0.05);\n"
550 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(0.01, -0.01)).rgb) / 0.05);\n"
551 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(-0.01, 0.01)).rgb) / 0.05);\n"
552 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(-0.01, -0.01)).rgb) / 0.05);\n"
553 " ScreenTexCoord.zw = lerp(SafeScreenTexCoord.zw, ScreenTexCoord.zw, f);\n"
554 " float Fresnel = pow(min(1.0, 1.0 - float(normalize(EyeVector).z)), 2.0) * reflectfactor + reflectoffset;\n"
555 " dp_FragColor = lerp(float4(tex2D(Texture_Refraction, ScreenTexCoord.xy).rgb, 1) * refractcolor, float4(tex2D(Texture_Reflection, ScreenTexCoord.zw).rgb, 1) * ReflectColor, Fresnel);\n"
558 "#else // !MODE_WATER\n"
563 "// 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"
565 "// fragment shader specific:\n"
566 "#ifdef FRAGMENT_SHADER\n"
569 "float3 FogVertex(float4 surfacecolor, float3 FogColor, float3 EyeVectorModelSpace, float FogPlaneVertexDist, float FogRangeRecip, float FogPlaneViewDist, float FogHeightFade, sampler Texture_FogMask, sampler Texture_FogHeightTexture)\n"
572 " float3 fc = FogColor;\n"
573 "#ifdef USEFOGALPHAHACK\n"
574 " fc *= surfacecolor.a;\n"
576 "#ifdef USEFOGHEIGHTTEXTURE\n"
577 " float4 fogheightpixel = tex2D(Texture_FogHeightTexture, float2(1,1) + float2(FogPlaneVertexDist, FogPlaneViewDist) * (-2.0 * FogHeightFade));\n"
578 " fogfrac = fogheightpixel.a;\n"
579 " return lerp(fogheightpixel.rgb * fc, surfacecolor.rgb, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n"
581 "# ifdef USEFOGOUTSIDE\n"
582 " fogfrac = min(0.0, FogPlaneVertexDist) / (FogPlaneVertexDist - FogPlaneViewDist) * min(1.0, min(0.0, FogPlaneVertexDist) * FogHeightFade);\n"
584 " fogfrac = FogPlaneViewDist / (FogPlaneViewDist - max(0.0, FogPlaneVertexDist)) * min(1.0, (min(0.0, FogPlaneVertexDist) + FogPlaneViewDist) * FogHeightFade);\n"
586 " return lerp(fc, surfacecolor.rgb, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n"
591 "#ifdef USEOFFSETMAPPING\n"
592 "float2 OffsetMapping(float2 TexCoord, float4 OffsetMapping_ScaleSteps, float OffsetMapping_Bias, float OffsetMapping_LodDistance, float3 EyeVector, sampler Texture_Normal, float2 dPdx, float2 dPdy)\n"
595 " // distance-based LOD\n"
596 "#ifdef USEOFFSETMAPPING_LOD\n"
597 " float LODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n"
598 " mediump vec4 ScaleSteps = float4(OffsetMapping_ScaleSteps.x, OffsetMapping_ScaleSteps.y * LODFactor, OffsetMapping_ScaleSteps.z / LODFactor, OffsetMapping_ScaleSteps.w * LODFactor);\n"
600 " #define ScaleSteps OffsetMapping_ScaleSteps\n"
602 "#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n"
603 " // 14 sample relief mapping: linear search and then binary search\n"
604 " // this basically steps forward a small amount repeatedly until it finds\n"
605 " // itself inside solid, then jitters forward and back using decreasing\n"
606 " // amounts to find the impact\n"
607 " //float3 OffsetVector = float3(EyeVector.xy * ((1.0 / EyeVector.z) * ScaleSteps.x) * float2(-1, 1), -1);\n"
608 " //float3 OffsetVector = float3(normalize(EyeVector.xy) * ScaleSteps.x * float2(-1, 1), -1);\n"
609 " float3 OffsetVector = float3(normalize(EyeVector).xy * ScaleSteps.x * float2(-1, 1), -1);\n"
610 " float3 RT = float3(float2(TexCoord.xy - OffsetVector.xy*OffsetMapping_Bias), 1);\n"
611 " OffsetVector *= ScaleSteps.z;\n"
612 " for(i = 1.0; i < ScaleSteps.y; ++i)\n"
613 " RT += OffsetVector * step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z);\n"
614 " for(i = 0.0, f = 1.0; i < ScaleSteps.w; ++i, f *= 0.5)\n"
615 " RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * f - 0.5 * f);\n"
618 " // 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits)\n"
619 " //float2 OffsetVector = float2(EyeVector.xy * ((1.0 / EyeVector.z) * ScaleSteps.x) * float2(-1, 1));\n"
620 " //float2 OffsetVector = float2(normalize(EyeVector.xy) * ScaleSteps.x * float2(-1, 1));\n"
621 " float2 OffsetVector = float2(normalize(EyeVector).xy * ScaleSteps.x * float2(-1, 1));\n"
622 " OffsetVector *= ScaleSteps.z;\n"
623 " for(i = 0.0; i < ScaleSteps.y; ++i)\n"
624 " TexCoord += OffsetVector * ((1.0 - OffsetMapping_Bias) - tex2Dgrad(Texture_Normal, TexCoord, dPdx, dPdy).a);\n"
625 " return TexCoord;\n"
628 "#endif // USEOFFSETMAPPING\n"
630 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n"
631 "#if defined(USESHADOWMAP2D)\n"
632 "# ifdef USESHADOWMAPORTHO\n"
633 "# define GetShadowMapTC2D(dir, ShadowMap_Parameters) (min(dir, ShadowMap_Parameters.xyz))\n"
635 "# ifdef USESHADOWMAPVSDCT\n"
636 "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters, samplerCUBE Texture_CubeProjection)\n"
638 " float3 adir = abs(dir);\n"
639 " float2 mparams = ShadowMap_Parameters.xy / max(max(adir.x, adir.y), adir.z);\n"
640 " float4 proj = texCUBE(Texture_CubeProjection, dir);\n"
641 " return float3(lerp(dir.xy, dir.zz, proj.xy) * mparams.x + proj.zw * ShadowMap_Parameters.z, mparams.y + ShadowMap_Parameters.w);\n"
644 "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters)\n"
646 " float3 adir = abs(dir);\n"
647 " float m; float4 proj;\n"
648 " if (adir.x > adir.y) { m = adir.x; proj = float4(dir.zyx, 0.5); } else { m = adir.y; proj = float4(dir.xzy, 1.5); }\n"
649 " if (adir.z > m) { m = adir.z; proj = float4(dir, 2.5); }\n"
651 " return float3(proj.xy * ShadowMap_Parameters.x / m + float2(0.5,0.5) + float2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, m + 64 * ShadowMap_Parameters.w);\n"
653 " float2 mparams = ShadowMap_Parameters.xy / m;\n"
654 " return float3(proj.xy * mparams.x + float2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, mparams.y + ShadowMap_Parameters.w);\n"
659 "#endif // defined(USESHADOWMAP2D)\n"
661 "# ifdef USESHADOWMAP2D\n"
662 "#ifdef USESHADOWMAPVSDCT\n"
663 "float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale, samplerCUBE Texture_CubeProjection)\n"
665 "float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale)\n"
668 "#ifdef USESHADOWMAPVSDCT\n"
669 " float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters, Texture_CubeProjection);\n"
671 " float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters);\n"
675 "# ifdef USESHADOWSAMPLER\n"
676 "# ifdef USESHADOWMAPPCF\n"
677 "# define texval(x, y) tex2Dproj(Texture_ShadowMap2D, float4(center + float2(x, y)*ShadowMap_TextureScale, shadowmaptc.z, 1.0)).r \n"
678 " float2 center = shadowmaptc.xy*ShadowMap_TextureScale;\n"
679 " 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"
681 " f = tex2Dproj(Texture_ShadowMap2D, float4(shadowmaptc.xy*ShadowMap_TextureScale, shadowmaptc.z, 1.0)).r;\n"
684 "# ifdef USESHADOWMAPPCF\n"
685 "# if defined(GL_ARB_texture_gather) || defined(GL_AMD_texture_texture4)\n"
686 "# ifdef GL_ARB_texture_gather\n"
687 "# define texval(x, y) textureGatherOffset(Texture_ShadowMap2D, center, int2(x, y))\n"
689 "# define texval(x, y) texture4(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale)\n"
691 " float2 offset = frac(shadowmaptc.xy - 0.5), center = (shadowmaptc.xy - offset)*ShadowMap_TextureScale;\n"
692 "# if USESHADOWMAPPCF > 1\n"
693 " float4 group1 = step(shadowmaptc.z, texval(-2.0, -2.0));\n"
694 " float4 group2 = step(shadowmaptc.z, texval( 0.0, -2.0));\n"
695 " float4 group3 = step(shadowmaptc.z, texval( 2.0, -2.0));\n"
696 " float4 group4 = step(shadowmaptc.z, texval(-2.0, 0.0));\n"
697 " float4 group5 = step(shadowmaptc.z, texval( 0.0, 0.0));\n"
698 " float4 group6 = step(shadowmaptc.z, texval( 2.0, 0.0));\n"
699 " float4 group7 = step(shadowmaptc.z, texval(-2.0, 2.0));\n"
700 " float4 group8 = step(shadowmaptc.z, texval( 0.0, 2.0));\n"
701 " float4 group9 = step(shadowmaptc.z, texval( 2.0, 2.0));\n"
702 " float4 locols = float4(group1.ab, group3.ab);\n"
703 " float4 hicols = float4(group7.rg, group9.rg);\n"
704 " locols.yz += group2.ab;\n"
705 " hicols.yz += group8.rg;\n"
706 " float4 midcols = float4(group1.rg, group3.rg) + float4(group7.ab, group9.ab) +\n"
707 " float4(group4.rg, group6.rg) + float4(group4.ab, group6.ab) +\n"
708 " lerp(locols, hicols, offset.y);\n"
709 " float4 cols = group5 + float4(group2.rg, group8.ab);\n"
710 " cols.xyz += lerp(midcols.xyz, midcols.yzw, offset.x);\n"
711 " f = dot(cols, float4(1.0/25.0));\n"
713 " float4 group1 = step(shadowmaptc.z, texval(-1.0, -1.0));\n"
714 " float4 group2 = step(shadowmaptc.z, texval( 1.0, -1.0));\n"
715 " float4 group3 = step(shadowmaptc.z, texval(-1.0, 1.0));\n"
716 " float4 group4 = step(shadowmaptc.z, texval( 1.0, 1.0));\n"
717 " float4 cols = float4(group1.rg, group2.rg) + float4(group3.ab, group4.ab) +\n"
718 " lerp(float4(group1.ab, group2.ab), float4(group3.rg, group4.rg), offset.y);\n"
719 " f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n"
722 "# ifdef GL_EXT_gpu_shader4\n"
723 "# define texval(x, y) tex2DOffset(Texture_ShadowMap2D, center, int2(x, y)).r\n"
725 "# define texval(x, y) texDepth2D(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale).r \n"
727 "# if USESHADOWMAPPCF > 1\n"
728 " float2 center = shadowmaptc.xy - 0.5, offset = frac(center);\n"
729 " center *= ShadowMap_TextureScale;\n"
730 " 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"
731 " 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"
732 " 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"
733 " 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"
734 " float4 cols = row2 + row3 + lerp(row1, row4, offset.y);\n"
735 " f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n"
737 " float2 center = shadowmaptc.xy*ShadowMap_TextureScale, offset = frac(shadowmaptc.xy);\n"
738 " float3 row1 = step(shadowmaptc.z, float3(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0)));\n"
739 " float3 row2 = step(shadowmaptc.z, float3(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0)));\n"
740 " float3 row3 = step(shadowmaptc.z, float3(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0)));\n"
741 " float3 cols = row2 + lerp(row1, row3, offset.y);\n"
742 " f = dot(lerp(cols.xy, cols.yz, offset.x), float2(0.25,0.25));\n"
746 " f = step(shadowmaptc.z, tex2D(Texture_ShadowMap2D, shadowmaptc.xy*ShadowMap_TextureScale).r);\n"
749 "# ifdef USESHADOWMAPORTHO\n"
750 " return lerp(ShadowMap_Parameters.w, 1.0, f);\n"
756 "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n"
757 "#endif // FRAGMENT_SHADER\n"
762 "#ifdef MODE_DEFERREDGEOMETRY\n"
763 "#ifdef VERTEX_SHADER\n"
766 "float4 gl_Vertex : POSITION,\n"
767 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
768 "#ifdef USEVERTEXTEXTUREBLEND\n"
769 "float4 gl_Color : COLOR0,\n"
771 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
772 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n"
773 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n"
774 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n"
775 "uniform float4x4 TexMatrix : register(c0),\n"
776 "#ifdef USEVERTEXTEXTUREBLEND\n"
777 "uniform float4x4 BackgroundTexMatrix : register(c4),\n"
779 "uniform float4x4 ModelViewMatrix : register(c12),\n"
780 "#ifdef USEOFFSETMAPPING\n"
781 "uniform float3 EyePosition : register(c24),\n"
783 "out float4 gl_Position : POSITION,\n"
784 "#ifdef USEVERTEXTEXTUREBLEND\n"
785 "out float4 gl_FrontColor : COLOR,\n"
787 "out float4 TexCoordBoth : TEXCOORD0,\n"
788 "#ifdef USEOFFSETMAPPING\n"
789 "out float3 EyeVector : TEXCOORD2,\n"
791 "out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
792 "out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
793 "out float4 VectorR : TEXCOORD7 // direction of R texcoord (surface normal), Depth value\n"
796 " TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n"
797 "#ifdef USEVERTEXTEXTUREBLEND\n"
798 " gl_FrontColor = gl_Color;\n"
799 " TexCoordBoth.zw = float2(Backgroundmul(TexMatrix, gl_MultiTexCoord0));\n"
802 " // transform unnormalized eye direction into tangent space\n"
803 "#ifdef USEOFFSETMAPPING\n"
804 " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n"
805 " EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n"
808 " VectorS = mul(ModelViewMatrix, float4(gl_MultiTexCoord1.xyz, 0)).xyz;\n"
809 " VectorT = mul(ModelViewMatrix, float4(gl_MultiTexCoord2.xyz, 0)).xyz;\n"
810 " VectorR.xyz = mul(ModelViewMatrix, float4(gl_MultiTexCoord3.xyz, 0)).xyz;\n"
811 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
813 " gl_Position = TrippyVertex(gl_Position);\n"
815 " VectorR.w = mul(ModelViewMatrix, gl_Vertex).z;\n"
817 "#endif // VERTEX_SHADER\n"
819 "#ifdef FRAGMENT_SHADER\n"
822 "float4 TexCoordBoth : TEXCOORD0,\n"
823 "float3 EyeVector : TEXCOORD2,\n"
824 "float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
825 "float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
826 "float4 VectorR : TEXCOORD7, // direction of R texcoord (surface normal), Depth value\n"
827 "uniform sampler Texture_Normal : register(s0),\n"
828 "#ifdef USEALPHAKILL\n"
829 "uniform sampler Texture_Color : register(s1),\n"
831 "uniform sampler Texture_Gloss : register(s2),\n"
832 "#ifdef USEVERTEXTEXTUREBLEND\n"
833 "uniform sampler Texture_SecondaryNormal : register(s4),\n"
834 "uniform sampler Texture_SecondaryGloss : register(s6),\n"
836 "#ifdef USEOFFSETMAPPING\n"
837 "uniform float4 OffsetMapping_ScaleSteps : register(c24),\n"
838 "uniform float4 OffsetMapping_LodDistance : register(c53),\n"
839 "uniform float OffsetMapping_Bias : register(c54),\n"
841 "uniform half SpecularPower : register(c36),\n"
842 "out float4 dp_FragColor : COLOR\n"
845 " float2 TexCoord = TexCoordBoth.xy;\n"
846 "#ifdef USEOFFSETMAPPING\n"
847 " // apply offsetmapping\n"
848 " float2 dPdx = ddx(TexCoord);\n"
849 " float2 dPdy = ddy(TexCoord);\n"
850 " float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, OffsetMapping_Bias, OffsetMapping_LodDistance, EyeVector, Texture_Normal, dPdx, dPdy);\n"
851 "# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n"
853 "# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n"
856 "#ifdef USEALPHAKILL\n"
857 " if (offsetMappedTexture2D(Texture_Color).a < 0.5)\n"
861 "#ifdef USEVERTEXTEXTUREBLEND\n"
862 " float alpha = offsetMappedTexture2D(Texture_Color).a;\n"
863 " float terrainblend = clamp(float(gl_FrontColor.a) * alpha * 2.0 - 0.5, float(0.0), float(1.0));\n"
864 " //float terrainblend = min(float(gl_FrontColor.a) * alpha * 2.0, float(1.0));\n"
865 " //float terrainblend = float(gl_FrontColor.a) * alpha > 0.5;\n"
868 "#ifdef USEVERTEXTEXTUREBLEND\n"
869 " float3 surfacenormal = lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, offsetMappedTexture2D(Texture_Normal).rgb, terrainblend) - float3(0.5, 0.5, 0.5);\n"
870 " float a = lerp(tex2D(Texture_SecondaryGloss, TexCoord2).a, offsetMappedTexture2D(Texture_Gloss).a, terrainblend);\n"
872 " float3 surfacenormal = offsetMappedTexture2D(Texture_Normal).rgb - float3(0.5, 0.5, 0.5);\n"
873 " float a = offsetMappedTexture2D(Texture_Gloss).a;\n"
876 " float3 pixelnormal = normalize(surfacenormal.x * VectorS.xyz + surfacenormal.y * VectorT.xyz + surfacenormal.z * VectorR.xyz);\n"
877 " dp_FragColor = float4(pixelnormal.x, pixelnormal.y, VectorR.w, a);\n"
879 "#endif // FRAGMENT_SHADER\n"
880 "#else // !MODE_DEFERREDGEOMETRY\n"
885 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
886 "#ifdef VERTEX_SHADER\n"
889 "float4 gl_Vertex : POSITION,\n"
890 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
891 "uniform float4x4 ModelViewMatrix : register(c12),\n"
892 "out float4 gl_Position : POSITION,\n"
893 "out float4 ModelViewPosition : TEXCOORD0\n"
896 " ModelViewPosition = mul(ModelViewMatrix, gl_Vertex);\n"
897 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
899 "#endif // VERTEX_SHADER\n"
901 "#ifdef FRAGMENT_SHADER\n"
905 "float2 Pixel : VPOS,\n"
907 "float2 Pixel : WPOS,\n"
909 "float4 ModelViewPosition : TEXCOORD0,\n"
910 "uniform float4x4 ViewToLight : register(c44),\n"
911 "uniform float2 ScreenToDepth : register(c33), // ScreenToDepth = float2(Far / (Far - Near), Far * Near / (Near - Far));\n"
912 "uniform float3 LightPosition : register(c23),\n"
913 "uniform half2 PixelToScreenTexCoord : register(c42),\n"
914 "uniform half3 DeferredColor_Ambient : register(c9),\n"
915 "uniform half3 DeferredColor_Diffuse : register(c10),\n"
916 "#ifdef USESPECULAR\n"
917 "uniform half3 DeferredColor_Specular : register(c11),\n"
918 "uniform half SpecularPower : register(c36),\n"
920 "uniform sampler Texture_Attenuation : register(s9),\n"
921 "uniform sampler Texture_ScreenDepth : register(s13),\n"
922 "uniform sampler Texture_ScreenNormalMap : register(s14),\n"
924 "#ifdef USECUBEFILTER\n"
925 "uniform samplerCUBE Texture_Cube : register(s10),\n"
928 "#ifdef USESHADOWMAP2D\n"
929 "# ifdef USESHADOWSAMPLER\n"
930 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
932 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
936 "#ifdef USESHADOWMAPVSDCT\n"
937 "uniform samplerCUBE Texture_CubeProjection : register(s12),\n"
940 "#if defined(USESHADOWMAP2D)\n"
941 "uniform float2 ShadowMap_TextureScale : register(c35),\n"
942 "uniform float4 ShadowMap_Parameters : register(c34),\n"
945 "out float4 gl_FragData0 : COLOR0,\n"
946 "out float4 gl_FragData1 : COLOR1\n"
949 " // calculate viewspace pixel position\n"
950 " float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n"
951 " float3 position;\n"
952 " // get the geometry information (depth, normal, specular exponent)\n"
953 " half4 normalmap = half4(tex2D(Texture_ScreenNormalMap, ScreenTexCoord));\n"
954 " // decode viewspace pixel normal\n"
955 "// float3 surfacenormal = normalize(normalmap.rgb - cast_myhalf3(0.5,0.5,0.5));\n"
956 " float3 surfacenormal = half3(normalmap.rg, sqrt(1.0-dot(normalmap.rg, normalmap.rg)));\n"
957 " // decode viewspace pixel position\n"
958 "// position.z = decodedepthmacro(dp_texture2D(Texture_ScreenDepth, ScreenTexCoord));\n"
959 " position.z = normalmap.b;\n"
960 "// position.z = ScreenToDepth.y / (dp_texture2D(Texture_ScreenDepth, ScreenTexCoord).r + ScreenToDepth.x);\n"
961 " position.xy = ModelViewPosition.xy * (position.z / ModelViewPosition.z);\n"
963 " // now do the actual shading\n"
964 " // surfacenormal = pixel normal in viewspace\n"
965 " // LightVector = pixel to light in viewspace\n"
966 " // CubeVector = position in lightspace\n"
967 " // eyevector = pixel to view in viewspace\n"
968 " float3 CubeVector = mul(ViewToLight, float4(position,1)).xyz;\n"
969 " half fade = half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n"
970 "#ifdef USEDIFFUSE\n"
971 " // calculate diffuse shading\n"
972 " half3 lightnormal = half3(normalize(LightPosition - position));\n"
973 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n"
975 "#ifdef USESPECULAR\n"
976 " // calculate directional shading\n"
977 " float3 eyevector = position * -1.0;\n"
978 "# ifdef USEEXACTSPECULARMATH\n"
979 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(eyevector)))*-1.0, 0.0)), 1.0 + SpecularPower * normalmap.a));\n"
981 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(eyevector))));\n"
982 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * normalmap.a));\n"
986 "#if defined(USESHADOWMAP2D)\n"
987 " fade *= half(ShadowMapCompare(CubeVector, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n"
988 "#ifdef USESHADOWMAPVSDCT\n"
989 ", Texture_CubeProjection\n"
994 "#ifdef USEDIFFUSE\n"
995 " gl_FragData0 = float4((DeferredColor_Ambient + DeferredColor_Diffuse * diffuse) * fade, 1.0);\n"
997 " gl_FragData0 = float4(DeferredColor_Ambient * fade, 1.0);\n"
999 "#ifdef USESPECULAR\n"
1000 " gl_FragData1 = float4(DeferredColor_Specular * (specular * fade), 1.0);\n"
1002 " gl_FragData1 = float4(0.0, 0.0, 0.0, 1.0);\n"
1005 "# ifdef USECUBEFILTER\n"
1006 " float3 cubecolor = texCUBE(Texture_Cube, CubeVector).rgb;\n"
1007 " gl_FragData0.rgb *= cubecolor;\n"
1008 " gl_FragData1.rgb *= cubecolor;\n"
1011 "#endif // FRAGMENT_SHADER\n"
1012 "#else // !MODE_DEFERREDLIGHTSOURCE\n"
1017 "#ifdef VERTEX_SHADER\n"
1020 "float4 gl_Vertex : POSITION,\n"
1021 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
1022 "#if defined(USEVERTEXTEXTUREBLEND) || defined(MODE_VERTEXCOLOR) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n"
1023 "float4 gl_Color : COLOR0,\n"
1025 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
1026 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n"
1027 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n"
1028 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n"
1029 "float4 gl_MultiTexCoord4 : TEXCOORD4,\n"
1031 "uniform float3 EyePosition : register(c24),\n"
1032 "uniform float4x4 TexMatrix : register(c0),\n"
1033 "#ifdef USEVERTEXTEXTUREBLEND\n"
1034 "uniform float4x4 BackgroundTexMatrix : register(c4),\n"
1036 "#ifdef MODE_LIGHTSOURCE\n"
1037 "uniform float4x4 ModelToLight : register(c20),\n"
1039 "#ifdef MODE_LIGHTSOURCE\n"
1040 "uniform float3 LightPosition : register(c27),\n"
1042 "#ifdef MODE_LIGHTDIRECTION\n"
1043 "uniform float3 LightDir : register(c26),\n"
1045 "uniform float4 FogPlane : register(c25),\n"
1046 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
1047 "uniform float3 LightPosition : register(c27),\n"
1049 "#ifdef USESHADOWMAPORTHO\n"
1050 "uniform float4x4 ShadowMapMatrix : register(c16),\n"
1052 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR) || defined(USEALPHAGENVERTEX)\n"
1053 "out float4 gl_FrontColor : COLOR,\n"
1055 "out float4 TexCoordBoth : TEXCOORD0,\n"
1056 "#ifdef USELIGHTMAP\n"
1057 "out float2 TexCoordLightmap : TEXCOORD1,\n"
1059 "#ifdef USEEYEVECTOR\n"
1060 "out float3 EyeVector : TEXCOORD2,\n"
1062 "#ifdef USEREFLECTION\n"
1063 "out float4 ModelViewProjectionPosition : TEXCOORD3,\n"
1066 "out float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n"
1068 "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE) || defined(USEDIFFUSE)\n"
1069 "out float3 LightVector : TEXCOORD1,\n"
1071 "#ifdef MODE_LIGHTSOURCE\n"
1072 "out float3 CubeVector : TEXCOORD3,\n"
1074 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n"
1075 "out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
1076 "out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
1077 "out float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n"
1079 "#ifdef USESHADOWMAPORTHO\n"
1080 "out float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n"
1082 "out float4 gl_Position : POSITION\n"
1085 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR) || defined(USEALPHAGENVERTEX)\n"
1086 " gl_FrontColor = gl_Color;\n"
1088 " // copy the surface texcoord\n"
1089 " TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n"
1090 "#ifdef USEVERTEXTEXTUREBLEND\n"
1091 " TexCoordBoth.zw = mul(BackgroundTexMatrix, gl_MultiTexCoord0).xy;\n"
1093 "#ifdef USELIGHTMAP\n"
1094 " TexCoordLightmap = gl_MultiTexCoord4.xy;\n"
1097 "#ifdef MODE_LIGHTSOURCE\n"
1098 " // transform vertex position into light attenuation/cubemap space\n"
1099 " // (-1 to +1 across the light box)\n"
1100 " CubeVector = mul(ModelToLight, gl_Vertex).xyz;\n"
1102 "# ifdef USEDIFFUSE\n"
1103 " // transform unnormalized light direction into tangent space\n"
1104 " // (we use unnormalized to ensure that it interpolates correctly and then\n"
1105 " // normalize it per pixel)\n"
1106 " float3 lightminusvertex = LightPosition - gl_Vertex.xyz;\n"
1107 " LightVector = float3(dot(lightminusvertex, gl_MultiTexCoord1.xyz), dot(lightminusvertex, gl_MultiTexCoord2.xyz), dot(lightminusvertex, gl_MultiTexCoord3.xyz));\n"
1111 "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE)\n"
1112 " LightVector = float3(dot(LightDir, gl_MultiTexCoord1.xyz), dot(LightDir, gl_MultiTexCoord2.xyz), dot(LightDir, gl_MultiTexCoord3.xyz));\n"
1115 " // transform unnormalized eye direction into tangent space\n"
1116 "#ifdef USEEYEVECTOR\n"
1117 " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n"
1118 " EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n"
1122 " EyeVectorModelSpaceFogPlaneVertexDist.xyz = EyePosition - gl_Vertex.xyz;\n"
1123 " EyeVectorModelSpaceFogPlaneVertexDist.w = dot(FogPlane, gl_Vertex);\n"
1126 "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n"
1127 " VectorS = gl_MultiTexCoord1.xyz;\n"
1128 " VectorT = gl_MultiTexCoord2.xyz;\n"
1129 " VectorR = gl_MultiTexCoord3.xyz;\n"
1132 " // transform vertex to camera space, using ftransform to match non-VS rendering\n"
1133 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
1135 "#ifdef USESHADOWMAPORTHO\n"
1136 " ShadowMapTC = mul(ShadowMapMatrix, gl_Position).xyz;\n"
1139 "#ifdef USEREFLECTION\n"
1140 " ModelViewProjectionPosition = gl_Position;\n"
1142 "#ifdef USETRIPPY\n"
1143 " gl_Position = TrippyVertex(gl_Position);\n"
1146 "#endif // VERTEX_SHADER\n"
1151 "#ifdef FRAGMENT_SHADER\n"
1154 "#ifdef USEDEFERREDLIGHTMAP\n"
1156 "float2 Pixel : VPOS,\n"
1158 "float2 Pixel : WPOS,\n"
1161 "float4 gl_FrontColor : COLOR,\n"
1162 "float4 TexCoordBoth : TEXCOORD0,\n"
1163 "#ifdef USELIGHTMAP\n"
1164 "float2 TexCoordLightmap : TEXCOORD1,\n"
1166 "#ifdef USEEYEVECTOR\n"
1167 "float3 EyeVector : TEXCOORD2,\n"
1169 "#ifdef USEREFLECTION\n"
1170 "float4 ModelViewProjectionPosition : TEXCOORD3,\n"
1173 "float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n"
1175 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_LIGHTDIRECTION)\n"
1176 "float3 LightVector : TEXCOORD1,\n"
1178 "#ifdef MODE_LIGHTSOURCE\n"
1179 "float3 CubeVector : TEXCOORD3,\n"
1181 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
1182 "float4 ModelViewPosition : TEXCOORD0,\n"
1184 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n"
1185 "float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
1186 "float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
1187 "float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n"
1189 "#ifdef USESHADOWMAPORTHO\n"
1190 "float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n"
1193 "uniform sampler Texture_Normal : register(s0),\n"
1194 "uniform sampler Texture_Color : register(s1),\n"
1195 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n"
1196 "uniform sampler Texture_Gloss : register(s2),\n"
1199 "uniform sampler Texture_Glow : register(s3),\n"
1201 "#ifdef USEVERTEXTEXTUREBLEND\n"
1202 "uniform sampler Texture_SecondaryNormal : register(s4),\n"
1203 "uniform sampler Texture_SecondaryColor : register(s5),\n"
1204 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n"
1205 "uniform sampler Texture_SecondaryGloss : register(s6),\n"
1208 "uniform sampler Texture_SecondaryGlow : register(s7),\n"
1211 "#ifdef USECOLORMAPPING\n"
1212 "uniform sampler Texture_Pants : register(s4),\n"
1213 "uniform sampler Texture_Shirt : register(s7),\n"
1216 "uniform sampler Texture_FogHeightTexture : register(s14),\n"
1217 "uniform sampler Texture_FogMask : register(s8),\n"
1219 "#ifdef USELIGHTMAP\n"
1220 "uniform sampler Texture_Lightmap : register(s9),\n"
1222 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE)\n"
1223 "uniform sampler Texture_Deluxemap : register(s10),\n"
1225 "#ifdef USEREFLECTION\n"
1226 "uniform sampler Texture_Reflection : register(s7),\n"
1229 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
1230 "uniform sampler Texture_ScreenDepth : register(s13),\n"
1231 "uniform sampler Texture_ScreenNormalMap : register(s14),\n"
1233 "#ifdef USEDEFERREDLIGHTMAP\n"
1234 "uniform sampler Texture_ScreenDepth : register(s13),\n"
1235 "uniform sampler Texture_ScreenNormalMap : register(s14),\n"
1236 "uniform sampler Texture_ScreenDiffuse : register(s11),\n"
1237 "uniform sampler Texture_ScreenSpecular : register(s12),\n"
1240 "#ifdef USECOLORMAPPING\n"
1241 "uniform half3 Color_Pants : register(c7),\n"
1242 "uniform half3 Color_Shirt : register(c8),\n"
1245 "uniform float3 FogColor : register(c16),\n"
1246 "uniform float FogRangeRecip : register(c20),\n"
1247 "uniform float FogPlaneViewDist : register(c19),\n"
1248 "uniform float FogHeightFade : register(c17),\n"
1251 "#ifdef USEOFFSETMAPPING\n"
1252 "uniform float4 OffsetMapping_ScaleSteps : register(c24),\n"
1253 "uniform float OffsetMapping_Bias : register(c54),\n"
1256 "#ifdef USEDEFERREDLIGHTMAP\n"
1257 "uniform half2 PixelToScreenTexCoord : register(c42),\n"
1258 "uniform half3 DeferredMod_Diffuse : register(c12),\n"
1259 "uniform half3 DeferredMod_Specular : register(c13),\n"
1261 "uniform half3 Color_Ambient : register(c3),\n"
1262 "uniform half3 Color_Diffuse : register(c4),\n"
1263 "uniform half3 Color_Specular : register(c5),\n"
1264 "uniform half SpecularPower : register(c36),\n"
1266 "uniform half3 Color_Glow : register(c6),\n"
1268 "uniform half Alpha : register(c0),\n"
1269 "#ifdef USEREFLECTION\n"
1270 "uniform float4 DistortScaleRefractReflect : register(c14),\n"
1271 "uniform float4 ScreenScaleRefractReflect : register(c32),\n"
1272 "uniform float4 ScreenCenterRefractReflect : register(c31),\n"
1273 "uniform half4 ReflectColor : register(c26),\n"
1275 "#ifdef USEREFLECTCUBE\n"
1276 "uniform float4x4 ModelToReflectCube : register(c48),\n"
1277 "uniform sampler Texture_ReflectMask : register(s5),\n"
1278 "uniform samplerCUBE Texture_ReflectCube : register(s6),\n"
1280 "#ifdef MODE_LIGHTDIRECTION\n"
1281 "uniform half3 LightColor : register(c21),\n"
1283 "#ifdef MODE_LIGHTSOURCE\n"
1284 "uniform half3 LightColor : register(c21),\n"
1287 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE)\n"
1288 "uniform sampler Texture_Attenuation : register(s9),\n"
1289 "uniform samplerCUBE Texture_Cube : register(s10),\n"
1292 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n"
1294 "#ifdef USESHADOWMAP2D\n"
1295 "# ifdef USESHADOWSAMPLER\n"
1296 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
1298 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
1302 "#ifdef USESHADOWMAPVSDCT\n"
1303 "uniform samplerCUBE Texture_CubeProjection : register(s12),\n"
1306 "#if defined(USESHADOWMAP2D)\n"
1307 "uniform float2 ShadowMap_TextureScale : register(c35),\n"
1308 "uniform float4 ShadowMap_Parameters : register(c34),\n"
1310 "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n"
1312 "out float4 dp_FragColor : COLOR\n"
1315 " float2 TexCoord = TexCoordBoth.xy;\n"
1316 "#ifdef USEVERTEXTEXTUREBLEND\n"
1317 " float2 TexCoord2 = TexCoordBoth.zw;\n"
1319 "#ifdef USEOFFSETMAPPING\n"
1320 " // apply offsetmapping\n"
1321 " float2 dPdx = ddx(TexCoord);\n"
1322 " float2 dPdy = ddy(TexCoord);\n"
1323 " float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, OffsetMapping_Bias, OffsetMapping_LodDistance, EyeVector, Texture_Normal, dPdx, dPdy);\n"
1324 "# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n"
1326 "# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n"
1329 " // combine the diffuse textures (base, pants, shirt)\n"
1330 " half4 color = half4(offsetMappedTexture2D(Texture_Color));\n"
1331 "#ifdef USEALPHAKILL\n"
1332 " if (color.a < 0.5)\n"
1335 " color.a *= Alpha;\n"
1336 "#ifdef USECOLORMAPPING\n"
1337 " color.rgb += half3(offsetMappedTexture2D(Texture_Pants).rgb) * Color_Pants + half3(offsetMappedTexture2D(Texture_Shirt).rgb) * Color_Shirt;\n"
1339 "#ifdef USEVERTEXTEXTUREBLEND\n"
1340 "#ifdef USEBOTHALPHAS\n"
1341 " half4 color2 = half4(tex2D(Texture_SecondaryColor, TexCoord2));\n"
1342 " half terrainblend = clamp(half(gl_FrontColor.a) * color.a, half(1.0 - color2.a), half(1.0));\n"
1343 " color.rgb = lerp(color2.rgb, color.rgb, terrainblend);\n"
1345 " half terrainblend = clamp(half(gl_FrontColor.a) * color.a * 2.0 - 0.5, half(0.0), half(1.0));\n"
1346 " //half terrainblend = min(half(gl_FrontColor.a) * color.a * 2.0, half(1.0));\n"
1347 " //half terrainblend = half(gl_FrontColor.a) * color.a > 0.5;\n"
1348 " color.rgb = half3(lerp(tex2D(Texture_SecondaryColor, TexCoord2).rgb, float3(color.rgb), terrainblend));\n"
1350 " //color = half4(lerp(float4(1, 0, 0, 1), color, terrainblend));\n"
1353 "#ifdef USEALPHAGENVERTEX\n"
1354 " color.a *= gl_FrontColor.a;\n"
1357 " // get the surface normal\n"
1358 "#ifdef USEVERTEXTEXTUREBLEND\n"
1359 " half3 surfacenormal = normalize(half3(lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, offsetMappedTexture2D(Texture_Normal).rgb, terrainblend)) - half3(0.5, 0.5, 0.5));\n"
1361 " half3 surfacenormal = half3(normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5, 0.5, 0.5)));\n"
1364 " // get the material colors\n"
1365 " half3 diffusetex = color.rgb;\n"
1366 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n"
1367 "# ifdef USEVERTEXTEXTUREBLEND\n"
1368 " half4 glosstex = half4(lerp(tex2D(Texture_SecondaryGloss, TexCoord2), offsetMappedTexture2D(Texture_Gloss), terrainblend));\n"
1370 " half4 glosstex = half4(offsetMappedTexture2D(Texture_Gloss));\n"
1374 "#ifdef USEREFLECTCUBE\n"
1375 " float3 TangentReflectVector = reflect(-EyeVector, surfacenormal);\n"
1376 " float3 ModelReflectVector = TangentReflectVector.x * VectorS + TangentReflectVector.y * VectorT + TangentReflectVector.z * VectorR;\n"
1377 " float3 ReflectCubeTexCoord = mul(ModelToReflectCube, float4(ModelReflectVector, 0)).xyz;\n"
1378 " diffusetex += half3(offsetMappedTexture2D(Texture_ReflectMask).rgb) * half3(texCUBE(Texture_ReflectCube, ReflectCubeTexCoord).rgb);\n"
1384 "#ifdef MODE_LIGHTSOURCE\n"
1385 " // light source\n"
1386 "#ifdef USEDIFFUSE\n"
1387 " half3 lightnormal = half3(normalize(LightVector));\n"
1388 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n"
1389 " color.rgb = diffusetex * (Color_Ambient + diffuse * Color_Diffuse);\n"
1390 "#ifdef USESPECULAR\n"
1391 "#ifdef USEEXACTSPECULARMATH\n"
1392 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), 1.0 + SpecularPower * glosstex.a));\n"
1394 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n"
1395 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * glosstex.a));\n"
1397 " color.rgb += glosstex.rgb * (specular * Color_Specular);\n"
1400 " color.rgb = diffusetex * Color_Ambient;\n"
1402 " color.rgb *= LightColor;\n"
1403 " color.rgb *= half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n"
1404 "#if defined(USESHADOWMAP2D)\n"
1405 " color.rgb *= half(ShadowMapCompare(CubeVector, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n"
1406 "#ifdef USESHADOWMAPVSDCT\n"
1407 ", Texture_CubeProjection\n"
1412 "# ifdef USECUBEFILTER\n"
1413 " color.rgb *= half3(texCUBE(Texture_Cube, CubeVector).rgb);\n"
1416 "#ifdef USESHADOWMAP2D\n"
1417 "#ifdef USESHADOWMAPVSDCT\n"
1418 "// float3 shadowmaptc = GetShadowMapTC2D(CubeVector, ShadowMap_Parameters, Texture_CubeProjection);\n"
1420 "// float3 shadowmaptc = GetShadowMapTC2D(CubeVector, ShadowMap_Parameters);\n"
1422 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n"
1423 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale).rgb);\n"
1424 "// color.rgb = half3(shadowmaptc.xyz * float3(ShadowMap_TextureScale,1.0));\n"
1425 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n"
1426 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n"
1427 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale).rgb);\n"
1428 "// color.rgb = half3(shadowmaptc.xyz * float3(ShadowMap_TextureScale,1.0));\n"
1429 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n"
1430 "// color.r = half(shadowmaptc.z - texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n"
1431 "// color.r = half(shadowmaptc.z);\n"
1432 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n"
1433 "// color.r = half(shadowmaptc.z);\n"
1435 "// color.rgb = abs(CubeVector);\n"
1437 "// color.rgb = half3(1,1,1);\n"
1438 "#endif // MODE_LIGHTSOURCE\n"
1443 "#ifdef MODE_LIGHTDIRECTION\n"
1444 " #define SHADING\n"
1445 " #ifdef USEDIFFUSE\n"
1446 " half3 lightnormal = half3(normalize(LightVector));\n"
1448 " #define lightcolor LightColor\n"
1449 "#endif // MODE_LIGHTDIRECTION\n"
1450 "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n"
1451 " #define SHADING\n"
1452 " // deluxemap lightmapping using light vectors in modelspace (q3map2 -light -deluxe)\n"
1453 " half3 lightnormal_modelspace = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n"
1454 " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n"
1455 " // convert modelspace light vector to tangentspace\n"
1456 " half3 lightnormal = half3(dot(lightnormal_modelspace, half3(VectorS)), dot(lightnormal_modelspace, half3(VectorT)), dot(lightnormal_modelspace, half3(VectorR)));\n"
1457 " // calculate directional shading (and undoing the existing angle attenuation on the lightmap by the division)\n"
1458 " // note that q3map2 is too stupid to calculate proper surface normals when q3map_nonplanar\n"
1459 " // is used (the lightmap and deluxemap coords correspond to virtually random coordinates\n"
1460 " // on that luxel, and NOT to its center, because recursive triangle subdivision is used\n"
1461 " // to map the luxels to coordinates on the draw surfaces), which also causes\n"
1462 " // deluxemaps to be wrong because light contributions from the wrong side of the surface\n"
1463 " // are added up. To prevent divisions by zero or strong exaggerations, a max()\n"
1464 " // nudge is done here at expense of some additional fps. This is ONLY needed for\n"
1465 " // deluxemaps, tangentspace deluxemap avoid this problem by design.\n"
1466 " lightcolor *= 1.0 / max(0.25, lightnormal.z);\n"
1467 "#endif // MODE_LIGHTDIRECTIONMAP_MODELSPACE\n"
1468 "#ifdef MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n"
1469 " #define SHADING\n"
1470 " // deluxemap lightmapping using light vectors in tangentspace (hmap2 -light)\n"
1471 " half3 lightnormal = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n"
1472 " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n"
1474 "#if defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n"
1475 " #define SHADING\n"
1476 " // forced deluxemap on lightmapped/vertexlit surfaces\n"
1477 " half3 lightnormal = half3(0.0, 0.0, 1.0);\n"
1478 " #ifdef USELIGHTMAP\n"
1479 " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n"
1481 " half3 lightcolor = half3(gl_FrontColor.rgb);\n"
1484 "#ifdef MODE_FAKELIGHT\n"
1485 " #define SHADING\n"
1486 " half3 lightnormal = half3(normalize(EyeVector));\n"
1487 " half3 lightcolor = half3(1.0,1.0,1.0);\n"
1488 "#endif // MODE_FAKELIGHT\n"
1493 "#ifdef MODE_LIGHTMAP\n"
1494 " color.rgb = diffusetex * (Color_Ambient + half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb) * Color_Diffuse);\n"
1495 "#endif // MODE_LIGHTMAP\n"
1496 "#ifdef MODE_VERTEXCOLOR\n"
1497 " color.rgb = diffusetex * (Color_Ambient + half3(gl_FrontColor.rgb) * Color_Diffuse);\n"
1498 "#endif // MODE_VERTEXCOLOR\n"
1499 "#ifdef MODE_FLATCOLOR\n"
1500 " color.rgb = diffusetex * Color_Ambient;\n"
1501 "#endif // MODE_FLATCOLOR\n"
1507 "# ifdef USEDIFFUSE\n"
1508 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n"
1509 "# ifdef USESPECULAR\n"
1510 "# ifdef USEEXACTSPECULARMATH\n"
1511 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), 1.0 + SpecularPower * glosstex.a));\n"
1513 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n"
1514 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * glosstex.a));\n"
1516 " color.rgb = diffusetex * Color_Ambient + (diffusetex * Color_Diffuse * diffuse + glosstex.rgb * Color_Specular * specular) * lightcolor;\n"
1518 " color.rgb = diffusetex * (Color_Ambient + Color_Diffuse * diffuse * lightcolor);\n"
1521 " color.rgb = diffusetex * Color_Ambient;\n"
1525 "#ifdef USESHADOWMAPORTHO\n"
1526 " color.rgb *= half(ShadowMapCompare(ShadowMapTC, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale));\n"
1529 "#ifdef USEDEFERREDLIGHTMAP\n"
1530 " float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n"
1531 " color.rgb += diffusetex * half3(tex2D(Texture_ScreenDiffuse, ScreenTexCoord).rgb) * DeferredMod_Diffuse;\n"
1532 " color.rgb += glosstex.rgb * half3(tex2D(Texture_ScreenSpecular, ScreenTexCoord).rgb) * DeferredMod_Specular;\n"
1533 "// color.rgb = half3(tex2D(Texture_ScreenDepth, ScreenTexCoord).rgb);\n"
1534 "// color.r = half(texDepth2D(Texture_ScreenDepth, ScreenTexCoord)) * 1.0;\n"
1538 "#ifdef USEVERTEXTEXTUREBLEND\n"
1539 " color.rgb += half3(lerp(tex2D(Texture_SecondaryGlow, TexCoord2).rgb, offsetMappedTexture2D(Texture_Glow).rgb, terrainblend)) * Color_Glow;\n"
1541 " color.rgb += half3(offsetMappedTexture2D(Texture_Glow).rgb) * Color_Glow;\n"
1546 " color.rgb = half3(FogVertex(color, FogColor, EyeVectorModelSpaceFogPlaneVertexDist.xyz, EyeVectorModelSpaceFogPlaneVertexDist.w, FogRangeRecip, FogPlaneViewDist, FogHeightFade, Texture_FogMask, Texture_FogHeightTexture));\n"
1549 " // 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"
1550 "#ifdef USEREFLECTION\n"
1551 " float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n"
1552 " //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n"
1553 " float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW.zw + ScreenCenterRefractReflect.zw;\n"
1554 " float2 ScreenTexCoord = SafeScreenTexCoord + float3(normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5,0.5,0.5))).xy * DistortScaleRefractReflect.zw;\n"
1555 " // FIXME temporary hack to detect the case that the reflection\n"
1556 " // gets blackened at edges due to leaving the area that contains actual\n"
1558 " // Remove this 'ack once we have a better way to stop this thing from\n"
1560 " float f = min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(0.01, 0.01)).rgb) / 0.05);\n"
1561 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(0.01, -0.01)).rgb) / 0.05);\n"
1562 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, 0.01)).rgb) / 0.05);\n"
1563 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, -0.01)).rgb) / 0.05);\n"
1564 " ScreenTexCoord = lerp(SafeScreenTexCoord, ScreenTexCoord, f);\n"
1565 " color.rgb = lerp(color.rgb, half3(tex2D(Texture_Reflection, ScreenTexCoord).rgb) * ReflectColor.rgb, ReflectColor.a);\n"
1568 " dp_FragColor = float4(color);\n"
1570 "#endif // FRAGMENT_SHADER\n"
1572 "#endif // !MODE_DEFERREDLIGHTSOURCE\n"
1573 "#endif // !MODE_DEFERREDGEOMETRY\n"
1574 "#endif // !MODE_WATER\n"
1575 "#endif // !MODE_REFRACTION\n"
1576 "#endif // !MODE_BLOOMBLUR\n"
1577 "#endif // !MODE_GENERIC\n"
1578 "#endif // !MODE_POSTPROCESS\n"
1579 "#endif // !MODE_SHOWDEPTH\n"
1580 "#endif // !MODE_DEPTH_OR_SHADOW\n"