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\n",
40 " float worldTime = ClientTime;\n",
41 " // tweaked for Quake\n",
42 " worldTime *= 10.0;\n",
43 " position *= 0.125;\n",
44 " //~tweaked for Quake\n",
45 " float distanceSquared = (position.x * position.x + position.z * position.z);\n",
46 " position.y += 5.0*sin(distanceSquared*sin(worldTime/143.0)/1000.0);\n",
47 " float y = position.y;\n",
48 " float x = position.x;\n",
49 " float om = sin(distanceSquared*sin(worldTime/256.0)/5000.0) * sin(worldTime/200.0);\n",
50 " position.y = x*sin(om)+y*cos(om);\n",
51 " position.x = x*cos(om)-y*sin(om);\n",
52 " return position;\n",
57 "#ifdef MODE_DEPTH_OR_SHADOW\n",
58 "#ifdef VERTEX_SHADER\n",
61 "float4 gl_Vertex : POSITION,\n",
62 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
63 "uniform float ClientTime : register(c2),\n",
64 "out float4 gl_Position : POSITION,\n",
65 "out float Depth : TEXCOORD0\n",
68 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
70 " gl_Position = TrippyVertex(gl_Position, ClientTime);\n",
72 " Depth = gl_Position.z;\n",
76 "#ifdef FRAGMENT_SHADER\n",
79 "float Depth : TEXCOORD0,\n",
80 "out float4 dp_FragColor : COLOR\n",
83 "// float4 temp = float4(Depth,Depth*(65536.0/255.0),Depth*(16777216.0/255.0),0.0);\n",
84 " float4 temp = float4(Depth,Depth*256.0,Depth*65536.0,0.0);\n",
85 " temp.yz -= floor(temp.yz);\n",
86 " dp_FragColor = temp;\n",
87 "// dp_FragColor = float4(Depth,0,0,0);\n",
90 "#else // !MODE_DEPTH_OR_SHADOW\n",
95 "#ifdef MODE_POSTPROCESS\n",
97 "#ifdef VERTEX_SHADER\n",
100 "float4 gl_Vertex : POSITION,\n",
101 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
102 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
103 "float4 gl_MultiTexCoord4 : TEXCOORD4,\n",
104 "out float4 gl_Position : POSITION,\n",
105 "out float2 TexCoord1 : TEXCOORD0\n",
107 ", out float2 TexCoord2 : TEXCOORD1\n",
111 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
112 " TexCoord1 = gl_MultiTexCoord0.xy;\n",
114 " TexCoord2 = gl_MultiTexCoord4.xy;\n",
119 "#ifdef FRAGMENT_SHADER\n",
121 "// graphitemaster: based off the white paper by Timothy Lottes\n",
122 "// http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf\n",
125 " float4 inColor,\n",
127 " float2 TexCoord1,\n",
128 " uniform sampler Texture_First,\n",
129 " uniform float2 PixelSize\n",
132 " float4 ret = inColor; // preserve old\n",
133 " float mulreduct = 1.0/maxspan;\n",
134 " float minreduct = (1.0 / 128.0);\n",
136 " float3 NW = tex2D(Texture_First, TexCoord1 + (float2(-1.0, -1.0) * PixelSize)).xyz;\n",
137 " float3 NE = tex2D(Texture_First, TexCoord1 + (float2(+1.0, -1.0) * PixelSize)).xyz;\n",
138 " float3 SW = tex2D(Texture_First, TexCoord1 + (float2(-1.0, +1.0) * PixelSize)).xyz;\n",
139 " float3 SE = tex2D(Texture_First, TexCoord1 + (float2(+1.0, +1.0) * PixelSize)).xyz;\n",
140 " float3 M = tex2D(Texture_First, TexCoord1).xyz;\n",
142 " // luminance directions\n",
143 " float3 luma = float3(0.299, 0.587, 0.114);\n",
144 " float lNW = dot(NW, luma);\n",
145 " float lNE = dot(NE, luma);\n",
146 " float lSW = dot(SW, luma);\n",
147 " float lSE = dot(SE, luma);\n",
148 " float lM = dot(M, luma);\n",
149 " float lMin = min(lM, min(min(lNW, lNE), min(lSW, lSE)));\n",
150 " float lMax = max(lM, max(max(lNW, lNE), max(lSW, lSE)));\n",
152 " // direction and reciprocal\n",
153 " float2 dir = float2(-((lNW + lNE) - (lSW + lSE)), ((lNW + lSW) - (lNE + lSE)));\n",
154 " float rcp = 1.0/(min(abs(dir.x), abs(dir.y)) + max((lNW + lNE + lSW + lSE) * (0.25 * mulreduct), minreduct));\n",
157 " dir = min(float2(maxspan, maxspan), max(float2(-maxspan, -maxspan), dir * rcp)) * PixelSize;\n",
159 " float3 rA = (1.0/2.0) * (\n",
160 " tex2D(Texture_First, TexCoord1 + dir * (1.0/3.0 - 0.5)).xyz +\n",
161 " tex2D(Texture_First, TexCoord1 + dir * (2.0/3.0 - 0.5)).xyz);\n",
162 " float3 rB = rA * (1.0/2.0) + (1.0/4.0) * (\n",
163 " tex2D(Texture_First, TexCoord1 + dir * (0.0/3.0 - 0.5)).xyz +\n",
164 " tex2D(Texture_First, TexCoord1 + dir * (3.0/3.0 - 0.5)).xyz);\n",
165 " float lB = dot(rB, luma);\n",
167 " ret.xyz = ((lB < lMin) || (lB > lMax)) ? rA : rB;\n",
175 "float2 TexCoord1 : TEXCOORD0,\n",
177 "float2 TexCoord2 : TEXCOORD1,\n",
179 "uniform sampler Texture_First : register(s0),\n",
181 "uniform sampler Texture_Second : register(s1),\n",
183 "#ifdef USEGAMMARAMPS\n",
184 "uniform sampler Texture_GammaRamps : register(s2),\n",
186 "#ifdef USESATURATION\n",
187 "uniform float Saturation : register(c30),\n",
189 "#ifdef USEVIEWTINT\n",
190 "uniform float4 ViewTintColor : register(c41),\n",
192 "uniform float4 UserVec1 : register(c37),\n",
193 "uniform float4 UserVec2 : register(c38),\n",
194 "uniform float4 UserVec3 : register(c39),\n",
195 "uniform float4 UserVec4 : register(c40),\n",
196 "uniform float ClientTime : register(c2),\n",
197 "uniform float2 PixelSize : register(c25),\n",
198 "uniform float4 BloomColorSubtract : register(c43),\n",
199 "out float4 dp_FragColor : COLOR\n",
202 " dp_FragColor = tex2D(Texture_First, TexCoord1);\n",
205 " dp_FragColor = fxaa(dp_FragColor, 8.0, TexCoord1, Texture_First, PixelSize); // 8.0 can be changed for larger span\n",
208 "#ifdef USEPOSTPROCESSING\n",
209 "// do r_glsl_dumpshader, edit glsl/default.glsl, and replace this by your own postprocessing if you want\n",
210 "// 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",
211 "#if defined(USERVEC1) || defined(USERVEC2)\n",
212 " float sobel = 1.0;\n",
213 " // float2 ts = textureSize(Texture_First, 0);\n",
214 " // float2 px = float2(1/ts.x, 1/ts.y);\n",
215 " float2 px = PixelSize;\n",
216 " float3 x1 = tex2D(Texture_First, TexCoord1 + float2(-px.x, px.y)).rgb;\n",
217 " float3 x2 = tex2D(Texture_First, TexCoord1 + float2(-px.x, 0.0)).rgb;\n",
218 " float3 x3 = tex2D(Texture_First, TexCoord1 + float2(-px.x,-px.y)).rgb;\n",
219 " float3 x4 = tex2D(Texture_First, TexCoord1 + float2( px.x, px.y)).rgb;\n",
220 " float3 x5 = tex2D(Texture_First, TexCoord1 + float2( px.x, 0.0)).rgb;\n",
221 " float3 x6 = tex2D(Texture_First, TexCoord1 + float2( px.x,-px.y)).rgb;\n",
222 " float3 y1 = tex2D(Texture_First, TexCoord1 + float2( px.x,-px.y)).rgb;\n",
223 " float3 y2 = tex2D(Texture_First, TexCoord1 + float2( 0.0,-px.y)).rgb;\n",
224 " float3 y3 = tex2D(Texture_First, TexCoord1 + float2(-px.x,-px.y)).rgb;\n",
225 " float3 y4 = tex2D(Texture_First, TexCoord1 + float2( px.x, px.y)).rgb;\n",
226 " float3 y5 = tex2D(Texture_First, TexCoord1 + float2( 0.0, px.y)).rgb;\n",
227 " float3 y6 = tex2D(Texture_First, TexCoord1 + float2(-px.x, px.y)).rgb;\n",
228 " float px1 = -1.0 * dot(float3(0.3, 0.59, 0.11), x1);\n",
229 " float px2 = -2.0 * dot(float3(0.3, 0.59, 0.11), x2);\n",
230 " float px3 = -1.0 * dot(float3(0.3, 0.59, 0.11), x3);\n",
231 " float px4 = 1.0 * dot(float3(0.3, 0.59, 0.11), x4);\n",
232 " float px5 = 2.0 * dot(float3(0.3, 0.59, 0.11), x5);\n",
233 " float px6 = 1.0 * dot(float3(0.3, 0.59, 0.11), x6);\n",
234 " float py1 = -1.0 * dot(float3(0.3, 0.59, 0.11), y1);\n",
235 " float py2 = -2.0 * dot(float3(0.3, 0.59, 0.11), y2);\n",
236 " float py3 = -1.0 * dot(float3(0.3, 0.59, 0.11), y3);\n",
237 " float py4 = 1.0 * dot(float3(0.3, 0.59, 0.11), y4);\n",
238 " float py5 = 2.0 * dot(float3(0.3, 0.59, 0.11), y5);\n",
239 " float py6 = 1.0 * dot(float3(0.3, 0.59, 0.11), y6);\n",
240 " sobel = 0.25 * abs(px1 + px2 + px3 + px4 + px5 + px6) + 0.25 * abs(py1 + py2 + py3 + py4 + py5 + py6);\n",
241 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.987688, -0.156434)) * UserVec1.y;\n",
242 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.156434, -0.891007)) * UserVec1.y;\n",
243 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2( 0.891007, -0.453990)) * UserVec1.y;\n",
244 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2( 0.707107, 0.707107)) * UserVec1.y;\n",
245 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.453990, 0.891007)) * UserVec1.y;\n",
246 " dp_FragColor /= (1.0 + 5.0 * UserVec1.y);\n",
247 " dp_FragColor.rgb = dp_FragColor.rgb * (1.0 + UserVec2.x) + float3(1,1,1)*max(0.0, sobel - UserVec2.z)*UserVec2.y;\n",
252 " dp_FragColor += max(float4(0,0,0,0), tex2D(Texture_Second, TexCoord2) - BloomColorSubtract);\n",
255 "#ifdef USEVIEWTINT\n",
256 " dp_FragColor = lerp(dp_FragColor, ViewTintColor, ViewTintColor.a);\n",
259 "#ifdef USESATURATION\n",
260 " //apply saturation BEFORE gamma ramps, so v_glslgamma value does not matter\n",
261 " float y = dot(dp_FragColor.rgb, float3(0.299, 0.587, 0.114));\n",
262 " // 'vampire sight' effect, wheres red is compensated\n",
263 " #ifdef SATURATION_REDCOMPENSATE\n",
264 " float rboost = max(0.0, (dp_FragColor.r - max(dp_FragColor.g, dp_FragColor.b))*(1.0 - Saturation));\n",
265 " dp_FragColor.rgb = lerp(float3(y,y,y), dp_FragColor.rgb, Saturation);\n",
266 " dp_FragColor.r += r;\n",
268 " // normal desaturation\n",
269 " //dp_FragColor = float3(y,y,y) + (dp_FragColor.rgb - float3(y)) * Saturation;\n",
270 " dp_FragColor.rgb = lerp(float3(y,y,y), dp_FragColor.rgb, Saturation);\n",
274 "#ifdef USEGAMMARAMPS\n",
275 " dp_FragColor.r = tex2D(Texture_GammaRamps, float2(dp_FragColor.r, 0)).r;\n",
276 " dp_FragColor.g = tex2D(Texture_GammaRamps, float2(dp_FragColor.g, 0)).g;\n",
277 " dp_FragColor.b = tex2D(Texture_GammaRamps, float2(dp_FragColor.b, 0)).b;\n",
281 "#else // !MODE_POSTPROCESS\n",
286 "#ifdef MODE_GENERIC\n",
287 "#ifdef VERTEX_SHADER\n",
290 "float4 gl_Vertex : POSITION,\n",
291 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
292 "float4 gl_Color : COLOR0,\n",
293 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
294 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n",
295 "uniform float ClientTime : register(c2),\n",
296 "out float4 gl_Position : POSITION,\n",
297 "#ifdef USEDIFFUSE\n",
298 "out float2 TexCoord1 : TEXCOORD0,\n",
300 "#ifdef USESPECULAR\n",
301 "out float2 TexCoord2 : TEXCOORD1,\n",
303 "out float4 gl_FrontColor : COLOR\n",
306 " gl_FrontColor = gl_Color;\n",
307 "#ifdef USEDIFFUSE\n",
308 " TexCoord1 = gl_MultiTexCoord0.xy;\n",
310 "#ifdef USESPECULAR\n",
311 " TexCoord2 = gl_MultiTexCoord1.xy;\n",
313 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
314 "#ifdef USETRIPPY\n",
315 " gl_Position = TrippyVertex(gl_Position, ClientTime);\n",
320 "#ifdef FRAGMENT_SHADER\n",
324 "float4 gl_FrontColor : COLOR0,\n",
325 "float2 TexCoord1 : TEXCOORD0,\n",
326 "float2 TexCoord2 : TEXCOORD1,\n",
327 "#ifdef USEDIFFUSE\n",
328 "uniform sampler Texture_First : register(s0),\n",
330 "#ifdef USESPECULAR\n",
331 "uniform sampler Texture_Second : register(s1),\n",
333 "#ifdef USEGAMMARAMPS\n",
334 "uniform sampler Texture_GammaRamps : register(s2),\n",
336 "uniform half Alpha : register(c0),\n",
337 "out float4 dp_FragColor : COLOR\n",
340 "#ifdef USEVIEWTINT\n",
341 " dp_FragColor = gl_FrontColor;\n",
343 " dp_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n",
345 "#ifdef USEDIFFUSE\n",
346 "# ifdef USEREFLECTCUBE\n",
347 " // suppress texture alpha\n",
348 " dp_FragColor.rgb *= tex2D(Texture_First, TexCoord1).rgb;\n",
350 " dp_FragColor *= tex2D(Texture_First, TexCoord1);\n",
354 "#ifdef USESPECULAR\n",
355 " float4 tex2 = tex2D(Texture_Second, TexCoord2);\n",
356 "# ifdef USECOLORMAPPING\n",
357 " dp_FragColor *= tex2;\n",
360 " dp_FragColor += tex2;\n",
362 "# ifdef USEVERTEXTEXTUREBLEND\n",
363 " dp_FragColor = lerp(dp_FragColor, tex2, tex2.a);\n",
366 "#ifdef USEGAMMARAMPS\n",
367 " dp_FragColor.r = tex2D(Texture_GammaRamps, vec2(dp_FragColor.r, 0)).r;\n",
368 " dp_FragColor.g = tex2D(Texture_GammaRamps, vec2(dp_FragColor.g, 0)).g;\n",
369 " dp_FragColor.b = tex2D(Texture_GammaRamps, vec2(dp_FragColor.b, 0)).b;\n",
371 "#ifdef USEALPHAKILL\n",
372 " dp_FragColor.a *= Alpha;\n",
376 "#else // !MODE_GENERIC\n",
381 "#ifdef MODE_BLOOMBLUR\n",
382 "#ifdef VERTEX_SHADER\n",
385 "float4 gl_Vertex : POSITION,\n",
386 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
387 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
388 "out float4 gl_Position : POSITION,\n",
389 "out float2 TexCoord : TEXCOORD0\n",
392 " TexCoord = gl_MultiTexCoord0.xy;\n",
393 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
397 "#ifdef FRAGMENT_SHADER\n",
401 "float2 TexCoord : TEXCOORD0,\n",
402 "uniform sampler Texture_First : register(s0),\n",
403 "uniform float4 BloomBlur_Parameters : register(c1),\n",
404 "out float4 dp_FragColor : COLOR\n",
408 " float2 tc = TexCoord;\n",
409 " float3 color = tex2D(Texture_First, tc).rgb;\n",
410 " tc += BloomBlur_Parameters.xy;\n",
411 " for (i = 1;i < SAMPLES;i++)\n",
413 " color += tex2D(Texture_First, tc).rgb;\n",
414 " tc += BloomBlur_Parameters.xy;\n",
416 " dp_FragColor = float4(color * BloomBlur_Parameters.z + float3(BloomBlur_Parameters.w), 1);\n",
419 "#else // !MODE_BLOOMBLUR\n",
420 "#ifdef MODE_REFRACTION\n",
421 "#ifdef VERTEX_SHADER\n",
424 "float4 gl_Vertex : POSITION,\n",
425 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
426 "#ifdef USEALPHAGENVERTEX\n",
427 "float4 gl_Color : COLOR0,\n",
429 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
430 "uniform float4x4 TexMatrix : register(c0),\n",
431 "uniform float3 EyePosition : register(c24),\n",
432 "uniform float ClientTime : register(c2),\n",
433 "#ifdef USEALPHAGENVERTEX\n",
434 "out float4 gl_FrontColor : COLOR,\n",
436 "out float4 gl_Position : POSITION,\n",
437 "out float2 TexCoord : TEXCOORD0,\n",
438 "out float3 EyeVector : TEXCOORD1,\n",
439 "out float4 ModelViewProjectionPosition : TEXCOORD2\n",
442 "#ifdef USEALPHAGENVERTEX\n",
443 " gl_FrontColor = gl_Color;\n",
445 " TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n",
446 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
447 " ModelViewProjectionPosition = gl_Position;\n",
448 "#ifdef USETRIPPY\n",
449 " gl_Position = TrippyVertex(gl_Position, ClientTime);\n",
454 "#ifdef FRAGMENT_SHADER\n",
457 "#ifdef USEALPHAGENVERTEX\n",
458 "float4 gl_FrontColor : COLOR,\n",
460 "float2 TexCoord : TEXCOORD0,\n",
461 "float3 EyeVector : TEXCOORD1,\n",
462 "float4 ModelViewProjectionPosition : TEXCOORD2,\n",
463 "uniform sampler Texture_Normal : register(s0),\n",
464 "uniform sampler Texture_Refraction : register(s3),\n",
465 "uniform sampler Texture_Reflection : register(s7),\n",
466 "uniform float4 DistortScaleRefractReflect : register(c14),\n",
467 "uniform float4 ScreenScaleRefractReflect : register(c32),\n",
468 "uniform float4 ScreenCenterRefractReflect : register(c31),\n",
469 "uniform float4 RefractColor : register(c29),\n",
470 "out float4 dp_FragColor : COLOR\n",
473 " float2 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect.xy * (1.0 / ModelViewProjectionPosition.w);\n",
474 " //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",
475 " float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n",
476 "#ifdef USEALPHAGENVERTEX\n",
477 " float2 distort = DistortScaleRefractReflect.xy * gl_FrontColor.a;\n",
478 " float4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), gl_FrontColor.a);\n",
480 " float2 distort = DistortScaleRefractReflect.xy;\n",
481 " float4 refractcolor = RefractColor;\n",
483 " float2 ScreenTexCoord = SafeScreenTexCoord + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy * distort;\n",
484 " // FIXME temporary hack to detect the case that the reflection\n",
485 " // gets blackened at edges due to leaving the area that contains actual\n",
487 " // Remove this 'ack once we have a better way to stop this thing from\n",
489 " float f = min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(0.01, 0.01)).rgb) / 0.05);\n",
490 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(0.01, -0.01)).rgb) / 0.05);\n",
491 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(-0.01, 0.01)).rgb) / 0.05);\n",
492 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(-0.01, -0.01)).rgb) / 0.05);\n",
493 " ScreenTexCoord = lerp(SafeScreenTexCoord, ScreenTexCoord, f);\n",
494 " dp_FragColor = float4(tex2D(Texture_Refraction, ScreenTexCoord).rgb, 1) * refractcolor;\n",
497 "#else // !MODE_REFRACTION\n",
502 "#ifdef MODE_WATER\n",
503 "#ifdef VERTEX_SHADER\n",
507 "float4 gl_Vertex : POSITION,\n",
508 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
509 "#ifdef USEALPHAGENVERTEX\n",
510 "float4 gl_Color : COLOR0,\n",
512 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
513 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n",
514 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n",
515 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n",
516 "uniform float4x4 TexMatrix : register(c0),\n",
517 "uniform float3 EyePosition : register(c24),\n",
518 "uniform float ClientTime : register(c2),\n",
519 "#ifdef USEALPHAGENVERTEX\n",
520 "out float4 gl_FrontColor : COLOR,\n",
522 "out float4 gl_Position : POSITION,\n",
523 "out float2 TexCoord : TEXCOORD0,\n",
524 "out float3 EyeVector : TEXCOORD1,\n",
525 "out float4 ModelViewProjectionPosition : TEXCOORD2\n",
528 "#ifdef USEALPHAGENVERTEX\n",
529 " gl_FrontColor = gl_Color;\n",
531 " TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n",
532 " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n",
533 " EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n",
534 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
535 " ModelViewProjectionPosition = gl_Position;\n",
536 "#ifdef USETRIPPY\n",
537 " gl_Position = TrippyVertex(gl_Position, ClientTime);\n",
542 "#ifdef FRAGMENT_SHADER\n",
545 "#ifdef USEALPHAGENVERTEX\n",
546 "float4 gl_FrontColor : COLOR,\n",
548 "float2 TexCoord : TEXCOORD0,\n",
549 "float3 EyeVector : TEXCOORD1,\n",
550 "float4 ModelViewProjectionPosition : TEXCOORD2,\n",
551 "uniform sampler Texture_Normal : register(s0),\n",
552 "uniform sampler Texture_Refraction : register(s3),\n",
553 "uniform sampler Texture_Reflection : register(s7),\n",
554 "uniform float4 DistortScaleRefractReflect : register(c14),\n",
555 "uniform float4 ScreenScaleRefractReflect : register(c32),\n",
556 "uniform float4 ScreenCenterRefractReflect : register(c31),\n",
557 "uniform float4 RefractColor : register(c29),\n",
558 "uniform float4 ReflectColor : register(c26),\n",
559 "uniform float ReflectFactor : register(c27),\n",
560 "uniform float ReflectOffset : register(c28),\n",
561 "out float4 dp_FragColor : COLOR\n",
564 " float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n",
565 " //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
566 " float4 SafeScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
567 " //SafeScreenTexCoord = gl_FragCoord.xyxy * float4(1.0 / 1920.0, 1.0 / 1200.0, 1.0 / 1920.0, 1.0 / 1200.0);\n",
568 "#ifdef USEALPHAGENVERTEX\n",
569 " float4 distort = DistortScaleRefractReflect * gl_FrontColor.a;\n",
570 " float reflectoffset = ReflectOffset * gl_FrontColor.a;\n",
571 " float reflectfactor = ReflectFactor * gl_FrontColor.a;\n",
572 " float4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), gl_FrontColor.a);\n",
574 " float4 distort = DistortScaleRefractReflect;\n",
575 " float reflectoffset = ReflectOffset;\n",
576 " float reflectfactor = ReflectFactor;\n",
577 " float4 refractcolor = RefractColor;\n",
579 " float4 ScreenTexCoord = SafeScreenTexCoord + float2(normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy).xyxy * distort;\n",
580 " // FIXME temporary hack to detect the case that the reflection\n",
581 " // gets blackened at edges due to leaving the area that contains actual\n",
583 " // Remove this 'ack once we have a better way to stop this thing from\n",
585 " float f = min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(0.01, 0.01)).rgb) / 0.05);\n",
586 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(0.01, -0.01)).rgb) / 0.05);\n",
587 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(-0.01, 0.01)).rgb) / 0.05);\n",
588 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(-0.01, -0.01)).rgb) / 0.05);\n",
589 " ScreenTexCoord.xy = lerp(SafeScreenTexCoord.xy, ScreenTexCoord.xy, f);\n",
590 " f = min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(0.01, 0.01)).rgb) / 0.05);\n",
591 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(0.01, -0.01)).rgb) / 0.05);\n",
592 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(-0.01, 0.01)).rgb) / 0.05);\n",
593 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(-0.01, -0.01)).rgb) / 0.05);\n",
594 " ScreenTexCoord.zw = lerp(SafeScreenTexCoord.zw, ScreenTexCoord.zw, f);\n",
595 " float Fresnel = pow(min(1.0, 1.0 - float(normalize(EyeVector).z)), 2.0) * reflectfactor + reflectoffset;\n",
596 " dp_FragColor = lerp(float4(tex2D(Texture_Refraction, ScreenTexCoord.xy).rgb, 1) * refractcolor, float4(tex2D(Texture_Reflection, ScreenTexCoord.zw).rgb, 1) * ReflectColor, Fresnel);\n",
599 "#else // !MODE_WATER\n",
604 "// 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",
606 "// fragment shader specific:\n",
607 "#ifdef FRAGMENT_SHADER\n",
610 "float3 FogVertex(float4 surfacecolor, float3 FogColor, float3 EyeVectorModelSpace, float FogPlaneVertexDist, float FogRangeRecip, float FogPlaneViewDist, float FogHeightFade, sampler Texture_FogMask, sampler Texture_FogHeightTexture)\n",
613 " float3 fc = FogColor;\n",
614 "#ifdef USEFOGALPHAHACK\n",
615 " fc *= surfacecolor.a;\n",
617 "#ifdef USEFOGHEIGHTTEXTURE\n",
618 " float4 fogheightpixel = tex2D(Texture_FogHeightTexture, float2(1,1) + float2(FogPlaneVertexDist, FogPlaneViewDist) * (-2.0 * FogHeightFade));\n",
619 " fogfrac = fogheightpixel.a;\n",
620 " return lerp(fogheightpixel.rgb * fc, surfacecolor.rgb, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n",
622 "# ifdef USEFOGOUTSIDE\n",
623 " fogfrac = min(0.0, FogPlaneVertexDist) / (FogPlaneVertexDist - FogPlaneViewDist) * min(1.0, min(0.0, FogPlaneVertexDist) * FogHeightFade);\n",
625 " fogfrac = FogPlaneViewDist / (FogPlaneViewDist - max(0.0, FogPlaneVertexDist)) * min(1.0, (min(0.0, FogPlaneVertexDist) + FogPlaneViewDist) * FogHeightFade);\n",
627 " return lerp(fc, surfacecolor.rgb, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n",
632 "#ifdef USEOFFSETMAPPING\n",
633 "float2 OffsetMapping(float2 TexCoord, float4 OffsetMapping_ScaleSteps, float OffsetMapping_Bias, float OffsetMapping_LodDistance, float3 EyeVector, sampler Texture_Normal, float2 dPdx, float2 dPdy)\n",
636 " // distance-based LOD\n",
637 "#ifdef USEOFFSETMAPPING_LOD\n",
638 " //float LODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n",
639 " //float4 ScaleSteps = float4(OffsetMapping_ScaleSteps.x, OffsetMapping_ScaleSteps.y * LODFactor, OffsetMapping_ScaleSteps.z / LODFactor, OffsetMapping_ScaleSteps.w * LODFactor);\n",
640 " float GuessLODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n",
641 "#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n",
642 " // stupid workaround because 1-step and 2-step reliefmapping is void\n",
643 " float LODSteps = max(3.0, ceil(GuessLODFactor * OffsetMapping_ScaleSteps.y));\n",
645 " float LODSteps = ceil(GuessLODFactor * OffsetMapping_ScaleSteps.y);\n",
647 " float LODFactor = LODSteps / OffsetMapping_ScaleSteps.y;\n",
648 " float4 ScaleSteps = float4(OffsetMapping_ScaleSteps.x, LODSteps, 1.0 / LODSteps, OffsetMapping_ScaleSteps.w * LODFactor);\n",
650 " #define ScaleSteps OffsetMapping_ScaleSteps\n",
652 "#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n",
653 " // 14 sample relief mapping: linear search and then binary search\n",
654 " // this basically steps forward a small amount repeatedly until it finds\n",
655 " // itself inside solid, then jitters forward and back using decreasing\n",
656 " // amounts to find the impact\n",
657 " //float3 OffsetVector = float3(EyeVector.xy * ((1.0 / EyeVector.z) * ScaleSteps.x) * float2(-1, 1), -1);\n",
658 " //float3 OffsetVector = float3(normalize(EyeVector.xy) * ScaleSteps.x * float2(-1, 1), -1);\n",
659 " float3 OffsetVector = float3(normalize(EyeVector).xy * ScaleSteps.x * float2(-1, 1), -1);\n",
660 " float3 RT = float3(float2(TexCoord.xy - OffsetVector.xy*OffsetMapping_Bias), 1);\n",
661 " OffsetVector *= ScaleSteps.z;\n",
662 " for(i = 1.0; i < ScaleSteps.y; ++i)\n",
663 " RT += OffsetVector * step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z);\n",
664 " for(i = 0.0, f = 1.0; i < ScaleSteps.w; ++i, f *= 0.5)\n",
665 " RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * f - 0.5 * f);\n",
668 " // 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits)\n",
669 " //float2 OffsetVector = float2(EyeVector.xy * ((1.0 / EyeVector.z) * ScaleSteps.x) * float2(-1, 1));\n",
670 " //float2 OffsetVector = float2(normalize(EyeVector.xy) * ScaleSteps.x * float2(-1, 1));\n",
671 " float2 OffsetVector = float2(normalize(EyeVector).xy * ScaleSteps.x * float2(-1, 1));\n",
672 " OffsetVector *= ScaleSteps.z;\n",
673 " for(i = 0.0; i < ScaleSteps.y; ++i)\n",
674 " TexCoord += OffsetVector * ((1.0 - OffsetMapping_Bias) - tex2Dgrad(Texture_Normal, TexCoord, dPdx, dPdy).a);\n",
675 " return TexCoord;\n",
678 "#endif // USEOFFSETMAPPING\n",
680 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n",
681 "#if defined(USESHADOWMAP2D)\n",
682 "# ifdef USESHADOWMAPORTHO\n",
683 "# define GetShadowMapTC2D(dir, ShadowMap_Parameters) (max(float3(0.0, 0.0, 0.0), min(dir, ShadowMap_Parameters.xyz)))\n",
685 "# ifdef USESHADOWMAPVSDCT\n",
686 "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters, samplerCUBE Texture_CubeProjection)\n",
688 " float3 adir = abs(dir);\n",
689 " float2 mparams = ShadowMap_Parameters.xy / max(max(adir.x, adir.y), adir.z);\n",
690 " float4 proj = texCUBE(Texture_CubeProjection, dir);\n",
691 " return float3(lerp(dir.xy, dir.zz, proj.xy) * mparams.x + proj.zw * ShadowMap_Parameters.z, mparams.y + ShadowMap_Parameters.w);\n",
694 "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters)\n",
696 " float3 adir = abs(dir);\n",
697 " float m; float4 proj;\n",
698 " 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",
699 " if (adir.z > m) { m = adir.z; proj = float4(dir, 2.5); }\n",
701 " 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",
703 " float2 mparams = ShadowMap_Parameters.xy / m;\n",
704 " 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",
709 "#endif // defined(USESHADOWMAP2D)\n",
711 "# ifdef USESHADOWMAP2D\n",
712 "#ifdef USESHADOWMAPVSDCT\n",
713 "float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float4 ShadowMap_TextureScale, samplerCUBE Texture_CubeProjection)\n",
715 "float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float4 ShadowMap_TextureScale)\n",
718 "#ifdef USESHADOWMAPVSDCT\n",
719 " float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters, Texture_CubeProjection) + float3(ShadowMap_TextureScale.zw, 0.0f);\n",
721 " float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters) + float3(ShadowMap_TextureScale.zw, 0.0f);\n",
725 "# ifdef USESHADOWSAMPLER\n",
726 "# ifdef USESHADOWMAPPCF\n",
727 "# define texval(x, y) tex2Dproj(Texture_ShadowMap2D, float4(center + float2(x, y)*ShadowMap_TextureScale.xy, shadowmaptc.z, 1.0)).r \n",
728 " float2 center = shadowmaptc.xy*ShadowMap_TextureScale.xy;\n",
729 " 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",
731 " f = tex2Dproj(Texture_ShadowMap2D, float4(shadowmaptc.xy*ShadowMap_TextureScale.xy, shadowmaptc.z, 1.0)).r;\n",
734 "# ifdef USESHADOWMAPPCF\n",
735 "# if defined(GL_ARB_texture_gather) || defined(GL_AMD_texture_texture4)\n",
736 "# ifdef GL_ARB_texture_gather\n",
737 "# define texval(x, y) textureGatherOffset(Texture_ShadowMap2D, center, int2(x, y))\n",
739 "# define texval(x, y) texture4(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale.xy)\n",
741 " float2 offset = frac(shadowmaptc.xy - 0.5), center = (shadowmaptc.xy - offset)*ShadowMap_TextureScale.xy;\n",
742 "# if USESHADOWMAPPCF > 1\n",
743 " float4 group1 = step(shadowmaptc.z, texval(-2.0, -2.0));\n",
744 " float4 group2 = step(shadowmaptc.z, texval( 0.0, -2.0));\n",
745 " float4 group3 = step(shadowmaptc.z, texval( 2.0, -2.0));\n",
746 " float4 group4 = step(shadowmaptc.z, texval(-2.0, 0.0));\n",
747 " float4 group5 = step(shadowmaptc.z, texval( 0.0, 0.0));\n",
748 " float4 group6 = step(shadowmaptc.z, texval( 2.0, 0.0));\n",
749 " float4 group7 = step(shadowmaptc.z, texval(-2.0, 2.0));\n",
750 " float4 group8 = step(shadowmaptc.z, texval( 0.0, 2.0));\n",
751 " float4 group9 = step(shadowmaptc.z, texval( 2.0, 2.0));\n",
752 " float4 locols = float4(group1.ab, group3.ab);\n",
753 " float4 hicols = float4(group7.rg, group9.rg);\n",
754 " locols.yz += group2.ab;\n",
755 " hicols.yz += group8.rg;\n",
756 " float4 midcols = float4(group1.rg, group3.rg) + float4(group7.ab, group9.ab) +\n",
757 " float4(group4.rg, group6.rg) + float4(group4.ab, group6.ab) +\n",
758 " lerp(locols, hicols, offset.y);\n",
759 " float4 cols = group5 + float4(group2.rg, group8.ab);\n",
760 " cols.xyz += lerp(midcols.xyz, midcols.yzw, offset.x);\n",
761 " f = dot(cols, float4(1.0/25.0));\n",
763 " float4 group1 = step(shadowmaptc.z, texval(-1.0, -1.0));\n",
764 " float4 group2 = step(shadowmaptc.z, texval( 1.0, -1.0));\n",
765 " float4 group3 = step(shadowmaptc.z, texval(-1.0, 1.0));\n",
766 " float4 group4 = step(shadowmaptc.z, texval( 1.0, 1.0));\n",
767 " float4 cols = float4(group1.rg, group2.rg) + float4(group3.ab, group4.ab) +\n",
768 " lerp(float4(group1.ab, group2.ab), float4(group3.rg, group4.rg), offset.y);\n",
769 " f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n",
772 "# ifdef GL_EXT_gpu_shader4\n",
773 "# define texval(x, y) tex2DOffset(Texture_ShadowMap2D, center, int2(x, y)).r\n",
775 "# define texval(x, y) texDepth2D(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale.xy).r \n",
777 "# if USESHADOWMAPPCF > 1\n",
778 " float2 center = shadowmaptc.xy - 0.5, offset = frac(center);\n",
779 " center *= ShadowMap_TextureScale.xy;\n",
780 " 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",
781 " 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",
782 " 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",
783 " 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",
784 " float4 cols = row2 + row3 + lerp(row1, row4, offset.y);\n",
785 " f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n",
787 " float2 center = shadowmaptc.xy*ShadowMap_TextureScale.xy, offset = frac(shadowmaptc.xy);\n",
788 " float3 row1 = step(shadowmaptc.z, float3(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0)));\n",
789 " float3 row2 = step(shadowmaptc.z, float3(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0)));\n",
790 " float3 row3 = step(shadowmaptc.z, float3(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0)));\n",
791 " float3 cols = row2 + lerp(row1, row3, offset.y);\n",
792 " f = dot(lerp(cols.xy, cols.yz, offset.x), float2(0.25,0.25));\n",
796 " f = step(shadowmaptc.z, tex2D(Texture_ShadowMap2D, shadowmaptc.xy*ShadowMap_TextureScale.xy).r);\n",
799 "# ifdef USESHADOWMAPORTHO\n",
800 " return lerp(ShadowMap_Parameters.w, 1.0, f);\n",
806 "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n",
807 "#endif // FRAGMENT_SHADER\n",
812 "#ifdef MODE_DEFERREDGEOMETRY\n",
813 "#ifdef VERTEX_SHADER\n",
816 "float4 gl_Vertex : POSITION,\n",
817 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
818 "#ifdef USEVERTEXTEXTUREBLEND\n",
819 "float4 gl_Color : COLOR0,\n",
821 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
822 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n",
823 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n",
824 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n",
825 "uniform float4x4 TexMatrix : register(c0),\n",
826 "#ifdef USEVERTEXTEXTUREBLEND\n",
827 "uniform float4x4 BackgroundTexMatrix : register(c4),\n",
829 "uniform float4x4 ModelViewMatrix : register(c12),\n",
830 "#ifdef USEOFFSETMAPPING\n",
831 "uniform float3 EyePosition : register(c24),\n",
833 "uniform float ClientTime : register(c2),\n",
834 "out float4 gl_Position : POSITION,\n",
835 "#ifdef USEVERTEXTEXTUREBLEND\n",
836 "out float4 gl_FrontColor : COLOR,\n",
838 "out float4 TexCoordBoth : TEXCOORD0,\n",
839 "#ifdef USEOFFSETMAPPING\n",
840 "out float3 EyeVector : TEXCOORD2,\n",
842 "out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n",
843 "out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n",
844 "out float4 VectorR : TEXCOORD7 // direction of R texcoord (surface normal), Depth value\n",
847 " TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n",
848 "#ifdef USEVERTEXTEXTUREBLEND\n",
849 " gl_FrontColor = gl_Color;\n",
850 " TexCoordBoth.zw = float2(Backgroundmul(TexMatrix, gl_MultiTexCoord0));\n",
853 " // transform unnormalized eye direction into tangent space\n",
854 "#ifdef USEOFFSETMAPPING\n",
855 " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n",
856 " EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n",
859 " VectorS = mul(ModelViewMatrix, float4(gl_MultiTexCoord1.xyz, 0)).xyz;\n",
860 " VectorT = mul(ModelViewMatrix, float4(gl_MultiTexCoord2.xyz, 0)).xyz;\n",
861 " VectorR.xyz = mul(ModelViewMatrix, float4(gl_MultiTexCoord3.xyz, 0)).xyz;\n",
862 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
863 "#ifdef USETRIPPY\n",
864 " gl_Position = TrippyVertex(gl_Position, ClientTime);\n",
866 " VectorR.w = mul(ModelViewMatrix, gl_Vertex).z;\n",
868 "#endif // VERTEX_SHADER\n",
870 "#ifdef FRAGMENT_SHADER\n",
873 "float4 TexCoordBoth : TEXCOORD0,\n",
874 "float3 EyeVector : TEXCOORD2,\n",
875 "float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n",
876 "float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n",
877 "float4 VectorR : TEXCOORD7, // direction of R texcoord (surface normal), Depth value\n",
878 "uniform sampler Texture_Normal : register(s0),\n",
879 "#ifdef USEALPHAKILL\n",
880 "uniform sampler Texture_Color : register(s1),\n",
882 "uniform sampler Texture_Gloss : register(s2),\n",
883 "#ifdef USEVERTEXTEXTUREBLEND\n",
884 "uniform sampler Texture_SecondaryNormal : register(s4),\n",
885 "uniform sampler Texture_SecondaryGloss : register(s6),\n",
887 "#ifdef USEOFFSETMAPPING\n",
888 "uniform float4 OffsetMapping_ScaleSteps : register(c24),\n",
889 "uniform float4 OffsetMapping_LodDistance : register(c53),\n",
890 "uniform float OffsetMapping_Bias : register(c54),\n",
892 "uniform half SpecularPower : register(c36),\n",
893 "out float4 dp_FragColor : COLOR\n",
896 " float2 TexCoord = TexCoordBoth.xy;\n",
897 "#ifdef USEOFFSETMAPPING\n",
898 " // apply offsetmapping\n",
899 " float2 dPdx = ddx(TexCoord);\n",
900 " float2 dPdy = ddy(TexCoord);\n",
901 " float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, OffsetMapping_Bias, OffsetMapping_LodDistance, EyeVector, Texture_Normal, dPdx, dPdy);\n",
902 "# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n",
904 "# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n",
907 "#ifdef USEALPHAKILL\n",
908 " if (offsetMappedTexture2D(Texture_Color).a < 0.5)\n",
912 "#ifdef USEVERTEXTEXTUREBLEND\n",
913 " float alpha = offsetMappedTexture2D(Texture_Color).a;\n",
914 " float terrainblend = clamp(float(gl_FrontColor.a) * alpha * 2.0 - 0.5, float(0.0), float(1.0));\n",
915 " //float terrainblend = min(float(gl_FrontColor.a) * alpha * 2.0, float(1.0));\n",
916 " //float terrainblend = float(gl_FrontColor.a) * alpha > 0.5;\n",
919 "#ifdef USEVERTEXTEXTUREBLEND\n",
920 " float3 surfacenormal = lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, offsetMappedTexture2D(Texture_Normal).rgb, terrainblend) - float3(0.5, 0.5, 0.5);\n",
921 " float a = lerp(tex2D(Texture_SecondaryGloss, TexCoord2).a, offsetMappedTexture2D(Texture_Gloss).a, terrainblend);\n",
923 " float3 surfacenormal = offsetMappedTexture2D(Texture_Normal).rgb - float3(0.5, 0.5, 0.5);\n",
924 " float a = offsetMappedTexture2D(Texture_Gloss).a;\n",
927 " float3 pixelnormal = normalize(surfacenormal.x * VectorS.xyz + surfacenormal.y * VectorT.xyz + surfacenormal.z * VectorR.xyz);\n",
928 " dp_FragColor = float4(pixelnormal.x, pixelnormal.y, VectorR.w, a);\n",
930 "#endif // FRAGMENT_SHADER\n",
931 "#else // !MODE_DEFERREDGEOMETRY\n",
936 "#ifdef MODE_DEFERREDLIGHTSOURCE\n",
937 "#ifdef VERTEX_SHADER\n",
940 "float4 gl_Vertex : POSITION,\n",
941 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
942 "uniform float4x4 ModelViewMatrix : register(c12),\n",
943 "out float4 gl_Position : POSITION,\n",
944 "out float4 ModelViewPosition : TEXCOORD0\n",
947 " ModelViewPosition = mul(ModelViewMatrix, gl_Vertex);\n",
948 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
950 "#endif // VERTEX_SHADER\n",
952 "#ifdef FRAGMENT_SHADER\n",
956 "float2 Pixel : VPOS,\n",
958 "float2 Pixel : WPOS,\n",
960 "float4 ModelViewPosition : TEXCOORD0,\n",
961 "uniform float4x4 ViewToLight : register(c44),\n",
962 "uniform float2 ScreenToDepth : register(c33), // ScreenToDepth = float2(Far / (Far - Near), Far * Near / (Near - Far));\n",
963 "uniform float3 LightPosition : register(c23),\n",
964 "uniform half2 PixelToScreenTexCoord : register(c42),\n",
965 "uniform half3 DeferredColor_Ambient : register(c9),\n",
966 "uniform half3 DeferredColor_Diffuse : register(c10),\n",
967 "#ifdef USESPECULAR\n",
968 "uniform half3 DeferredColor_Specular : register(c11),\n",
969 "uniform half SpecularPower : register(c36),\n",
971 "uniform sampler Texture_Attenuation : register(s9),\n",
972 "uniform sampler Texture_ScreenDepth : register(s13),\n",
973 "uniform sampler Texture_ScreenNormalMap : register(s14),\n",
975 "#ifdef USECUBEFILTER\n",
976 "uniform samplerCUBE Texture_Cube : register(s10),\n",
979 "#ifdef USESHADOWMAP2D\n",
980 "# ifdef USESHADOWSAMPLER\n",
981 "uniform sampler Texture_ShadowMap2D : register(s15),\n",
983 "uniform sampler Texture_ShadowMap2D : register(s15),\n",
987 "#ifdef USESHADOWMAPVSDCT\n",
988 "uniform samplerCUBE Texture_CubeProjection : register(s12),\n",
991 "#if defined(USESHADOWMAP2D)\n",
992 "uniform float4 ShadowMap_TextureScale : register(c35),\n",
993 "uniform float4 ShadowMap_Parameters : register(c34),\n",
996 "out float4 gl_FragData0 : COLOR0,\n",
997 "out float4 gl_FragData1 : COLOR1\n",
1000 " // calculate viewspace pixel position\n",
1001 " float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n",
1002 " float3 position;\n",
1003 " // get the geometry information (depth, normal, specular exponent)\n",
1004 " half4 normalmap = half4(tex2D(Texture_ScreenNormalMap, ScreenTexCoord));\n",
1005 " // decode viewspace pixel normal\n",
1006 "// float3 surfacenormal = normalize(normalmap.rgb - cast_myhalf3(0.5,0.5,0.5));\n",
1007 " float3 surfacenormal = half3(normalmap.rg, sqrt(1.0-dot(normalmap.rg, normalmap.rg)));\n",
1008 " // decode viewspace pixel position\n",
1009 "// position.z = decodedepthmacro(dp_texture2D(Texture_ScreenDepth, ScreenTexCoord));\n",
1010 " position.z = normalmap.b;\n",
1011 "// position.z = ScreenToDepth.y / (dp_texture2D(Texture_ScreenDepth, ScreenTexCoord).r + ScreenToDepth.x);\n",
1012 " position.xy = ModelViewPosition.xy * (position.z / ModelViewPosition.z);\n",
1014 " // now do the actual shading\n",
1015 " // surfacenormal = pixel normal in viewspace\n",
1016 " // LightVector = pixel to light in viewspace\n",
1017 " // CubeVector = position in lightspace\n",
1018 " // eyevector = pixel to view in viewspace\n",
1019 " float3 CubeVector = mul(ViewToLight, float4(position,1)).xyz;\n",
1020 " half fade = half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n",
1021 "#ifdef USEDIFFUSE\n",
1022 " // calculate diffuse shading\n",
1023 " half3 lightnormal = half3(normalize(LightPosition - position));\n",
1024 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n",
1026 "#ifdef USESPECULAR\n",
1027 " // calculate directional shading\n",
1028 " float3 eyevector = position * -1.0;\n",
1029 "# ifdef USEEXACTSPECULARMATH\n",
1030 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(eyevector)))*-1.0, 0.0)), 1.0 + SpecularPower * normalmap.a));\n",
1032 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(eyevector))));\n",
1033 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * normalmap.a));\n",
1037 "#if defined(USESHADOWMAP2D)\n",
1038 " fade *= half(ShadowMapCompare(CubeVector, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n",
1039 "#ifdef USESHADOWMAPVSDCT\n",
1040 ", Texture_CubeProjection\n",
1045 "#ifdef USEDIFFUSE\n",
1046 " gl_FragData0 = float4((DeferredColor_Ambient + DeferredColor_Diffuse * diffuse) * fade, 1.0);\n",
1048 " gl_FragData0 = float4(DeferredColor_Ambient * fade, 1.0);\n",
1050 "#ifdef USESPECULAR\n",
1051 " gl_FragData1 = float4(DeferredColor_Specular * (specular * fade), 1.0);\n",
1053 " gl_FragData1 = float4(0.0, 0.0, 0.0, 1.0);\n",
1056 "# ifdef USECUBEFILTER\n",
1057 " float3 cubecolor = texCUBE(Texture_Cube, CubeVector).rgb;\n",
1058 " gl_FragData0.rgb *= cubecolor;\n",
1059 " gl_FragData1.rgb *= cubecolor;\n",
1062 "#endif // FRAGMENT_SHADER\n",
1063 "#else // !MODE_DEFERREDLIGHTSOURCE\n",
1068 "#ifdef VERTEX_SHADER\n",
1071 "float4 gl_Vertex : POSITION,\n",
1072 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
1073 "#if defined(USEVERTEXTEXTUREBLEND) || defined(MODE_VERTEXCOLOR) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n",
1074 "float4 gl_Color : COLOR0,\n",
1076 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
1077 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n",
1078 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n",
1079 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n",
1080 "float4 gl_MultiTexCoord4 : TEXCOORD4,\n",
1082 "uniform float3 EyePosition : register(c24),\n",
1083 "uniform float4x4 TexMatrix : register(c0),\n",
1084 "#ifdef USEVERTEXTEXTUREBLEND\n",
1085 "uniform float4x4 BackgroundTexMatrix : register(c4),\n",
1087 "#ifdef MODE_LIGHTSOURCE\n",
1088 "uniform float4x4 ModelToLight : register(c20),\n",
1090 "#ifdef MODE_LIGHTSOURCE\n",
1091 "uniform float3 LightPosition : register(c27),\n",
1093 "#ifdef MODE_LIGHTDIRECTION\n",
1094 "uniform float3 LightDir : register(c26),\n",
1096 "uniform float4 FogPlane : register(c25),\n",
1097 "#ifdef MODE_DEFERREDLIGHTSOURCE\n",
1098 "uniform float3 LightPosition : register(c27),\n",
1100 "#ifdef USESHADOWMAPORTHO\n",
1101 "uniform float4x4 ShadowMapMatrix : register(c16),\n",
1103 "uniform float ClientTime : register(c2),\n",
1104 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR) || defined(USEALPHAGENVERTEX)\n",
1105 "out float4 gl_FrontColor : COLOR,\n",
1107 "out float4 TexCoordBoth : TEXCOORD0,\n",
1108 "#ifdef USELIGHTMAP\n",
1109 "out float2 TexCoordLightmap : TEXCOORD1,\n",
1111 "#ifdef USEEYEVECTOR\n",
1112 "out float3 EyeVector : TEXCOORD2,\n",
1114 "#ifdef USEREFLECTION\n",
1115 "out float4 ModelViewProjectionPosition : TEXCOORD3,\n",
1118 "out float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n",
1120 "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE) || defined(USEDIFFUSE)\n",
1121 "out float3 LightVector : TEXCOORD1,\n",
1123 "#ifdef MODE_LIGHTSOURCE\n",
1124 "out float3 CubeVector : TEXCOORD3,\n",
1126 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n",
1127 "out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n",
1128 "out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n",
1129 "out float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n",
1131 "#ifdef USESHADOWMAPORTHO\n",
1132 "out float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n",
1134 "out float4 gl_Position : POSITION\n",
1137 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR) || defined(USEALPHAGENVERTEX)\n",
1138 " gl_FrontColor = gl_Color;\n",
1140 " // copy the surface texcoord\n",
1141 " TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n",
1142 "#ifdef USEVERTEXTEXTUREBLEND\n",
1143 " TexCoordBoth.zw = mul(BackgroundTexMatrix, gl_MultiTexCoord0).xy;\n",
1145 "#ifdef USELIGHTMAP\n",
1146 " TexCoordLightmap = gl_MultiTexCoord4.xy;\n",
1149 "#ifdef MODE_LIGHTSOURCE\n",
1150 " // transform vertex position into light attenuation/cubemap space\n",
1151 " // (-1 to +1 across the light box)\n",
1152 " CubeVector = mul(ModelToLight, gl_Vertex).xyz;\n",
1154 "# ifdef USEDIFFUSE\n",
1155 " // transform unnormalized light direction into tangent space\n",
1156 " // (we use unnormalized to ensure that it interpolates correctly and then\n",
1157 " // normalize it per pixel)\n",
1158 " float3 lightminusvertex = LightPosition - gl_Vertex.xyz;\n",
1159 " LightVector = float3(dot(lightminusvertex, gl_MultiTexCoord1.xyz), dot(lightminusvertex, gl_MultiTexCoord2.xyz), dot(lightminusvertex, gl_MultiTexCoord3.xyz));\n",
1163 "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE)\n",
1164 " LightVector = float3(dot(LightDir, gl_MultiTexCoord1.xyz), dot(LightDir, gl_MultiTexCoord2.xyz), dot(LightDir, gl_MultiTexCoord3.xyz));\n",
1167 " // transform unnormalized eye direction into tangent space\n",
1168 "#ifdef USEEYEVECTOR\n",
1169 " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n",
1170 " EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n",
1174 " EyeVectorModelSpaceFogPlaneVertexDist.xyz = EyePosition - gl_Vertex.xyz;\n",
1175 " EyeVectorModelSpaceFogPlaneVertexDist.w = dot(FogPlane, gl_Vertex);\n",
1178 "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n",
1179 " VectorS = gl_MultiTexCoord1.xyz;\n",
1180 " VectorT = gl_MultiTexCoord2.xyz;\n",
1181 " VectorR = gl_MultiTexCoord3.xyz;\n",
1184 " // transform vertex to camera space, using ftransform to match non-VS rendering\n",
1185 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
1187 "#ifdef USESHADOWMAPORTHO\n",
1188 " ShadowMapTC = mul(ShadowMapMatrix, gl_Position).xyz;\n",
1191 "#ifdef USEREFLECTION\n",
1192 " ModelViewProjectionPosition = gl_Position;\n",
1194 "#ifdef USETRIPPY\n",
1195 " gl_Position = TrippyVertex(gl_Position, ClientTime);\n",
1198 "#endif // VERTEX_SHADER\n",
1203 "#ifdef FRAGMENT_SHADER\n",
1206 "#ifdef USEDEFERREDLIGHTMAP\n",
1208 "float2 Pixel : VPOS,\n",
1210 "float2 Pixel : WPOS,\n",
1213 "float4 gl_FrontColor : COLOR,\n",
1214 "float4 TexCoordBoth : TEXCOORD0,\n",
1215 "#ifdef USELIGHTMAP\n",
1216 "float2 TexCoordLightmap : TEXCOORD1,\n",
1218 "#ifdef USEEYEVECTOR\n",
1219 "float3 EyeVector : TEXCOORD2,\n",
1221 "#ifdef USEREFLECTION\n",
1222 "float4 ModelViewProjectionPosition : TEXCOORD3,\n",
1225 "float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n",
1227 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_LIGHTDIRECTION)\n",
1228 "float3 LightVector : TEXCOORD1,\n",
1230 "#ifdef MODE_LIGHTSOURCE\n",
1231 "float3 CubeVector : TEXCOORD3,\n",
1233 "#ifdef MODE_DEFERREDLIGHTSOURCE\n",
1234 "float4 ModelViewPosition : TEXCOORD0,\n",
1236 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n",
1237 "float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n",
1238 "float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n",
1239 "float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n",
1241 "#ifdef USESHADOWMAPORTHO\n",
1242 "float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n",
1245 "uniform sampler Texture_Normal : register(s0),\n",
1246 "uniform sampler Texture_Color : register(s1),\n",
1247 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n",
1248 "uniform sampler Texture_Gloss : register(s2),\n",
1251 "uniform sampler Texture_Glow : register(s3),\n",
1253 "#ifdef USEVERTEXTEXTUREBLEND\n",
1254 "uniform sampler Texture_SecondaryNormal : register(s4),\n",
1255 "uniform sampler Texture_SecondaryColor : register(s5),\n",
1256 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n",
1257 "uniform sampler Texture_SecondaryGloss : register(s6),\n",
1260 "uniform sampler Texture_SecondaryGlow : register(s7),\n",
1263 "#ifdef USECOLORMAPPING\n",
1264 "uniform sampler Texture_Pants : register(s4),\n",
1265 "uniform sampler Texture_Shirt : register(s7),\n",
1268 "uniform sampler Texture_FogHeightTexture : register(s14),\n",
1269 "uniform sampler Texture_FogMask : register(s8),\n",
1271 "#ifdef USELIGHTMAP\n",
1272 "uniform sampler Texture_Lightmap : register(s9),\n",
1274 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE)\n",
1275 "uniform sampler Texture_Deluxemap : register(s10),\n",
1277 "#ifdef USEREFLECTION\n",
1278 "uniform sampler Texture_Reflection : register(s7),\n",
1281 "#ifdef MODE_DEFERREDLIGHTSOURCE\n",
1282 "uniform sampler Texture_ScreenDepth : register(s13),\n",
1283 "uniform sampler Texture_ScreenNormalMap : register(s14),\n",
1285 "#ifdef USEDEFERREDLIGHTMAP\n",
1286 "uniform sampler Texture_ScreenDepth : register(s13),\n",
1287 "uniform sampler Texture_ScreenNormalMap : register(s14),\n",
1288 "uniform sampler Texture_ScreenDiffuse : register(s11),\n",
1289 "uniform sampler Texture_ScreenSpecular : register(s12),\n",
1292 "#ifdef USECOLORMAPPING\n",
1293 "uniform half3 Color_Pants : register(c7),\n",
1294 "uniform half3 Color_Shirt : register(c8),\n",
1297 "uniform float3 FogColor : register(c16),\n",
1298 "uniform float FogRangeRecip : register(c20),\n",
1299 "uniform float FogPlaneViewDist : register(c19),\n",
1300 "uniform float FogHeightFade : register(c17),\n",
1303 "#ifdef USEOFFSETMAPPING\n",
1304 "uniform float4 OffsetMapping_ScaleSteps : register(c24),\n",
1305 "uniform float OffsetMapping_Bias : register(c54),\n",
1308 "#ifdef USEDEFERREDLIGHTMAP\n",
1309 "uniform half2 PixelToScreenTexCoord : register(c42),\n",
1310 "uniform half3 DeferredMod_Diffuse : register(c12),\n",
1311 "uniform half3 DeferredMod_Specular : register(c13),\n",
1313 "uniform half3 Color_Ambient : register(c3),\n",
1314 "uniform half3 Color_Diffuse : register(c4),\n",
1315 "uniform half3 Color_Specular : register(c5),\n",
1316 "uniform half SpecularPower : register(c36),\n",
1318 "uniform half3 Color_Glow : register(c6),\n",
1320 "uniform half Alpha : register(c0),\n",
1321 "#ifdef USEREFLECTION\n",
1322 "uniform float4 DistortScaleRefractReflect : register(c14),\n",
1323 "uniform float4 ScreenScaleRefractReflect : register(c32),\n",
1324 "uniform float4 ScreenCenterRefractReflect : register(c31),\n",
1325 "uniform half4 ReflectColor : register(c26),\n",
1327 "#ifdef USEREFLECTCUBE\n",
1328 "uniform float4x4 ModelToReflectCube : register(c48),\n",
1329 "uniform sampler Texture_ReflectMask : register(s5),\n",
1330 "uniform samplerCUBE Texture_ReflectCube : register(s6),\n",
1333 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE)\n",
1334 "uniform sampler Texture_Attenuation : register(s9),\n",
1335 "uniform samplerCUBE Texture_Cube : register(s10),\n",
1338 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n",
1340 "#ifdef USESHADOWMAP2D\n",
1341 "# ifdef USESHADOWSAMPLER\n",
1342 "uniform sampler Texture_ShadowMap2D : register(s15),\n",
1344 "uniform sampler Texture_ShadowMap2D : register(s15),\n",
1348 "#ifdef USESHADOWMAPVSDCT\n",
1349 "uniform samplerCUBE Texture_CubeProjection : register(s12),\n",
1352 "#if defined(USESHADOWMAP2D)\n",
1353 "uniform float4 ShadowMap_TextureScale : register(c35),\n",
1354 "uniform float4 ShadowMap_Parameters : register(c34),\n",
1356 "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n",
1358 "out float4 dp_FragColor : COLOR\n",
1361 " float2 TexCoord = TexCoordBoth.xy;\n",
1362 "#ifdef USEVERTEXTEXTUREBLEND\n",
1363 " float2 TexCoord2 = TexCoordBoth.zw;\n",
1365 "#ifdef USEOFFSETMAPPING\n",
1366 " // apply offsetmapping\n",
1367 " float2 dPdx = ddx(TexCoord);\n",
1368 " float2 dPdy = ddy(TexCoord);\n",
1369 " float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, OffsetMapping_Bias, OffsetMapping_LodDistance, EyeVector, Texture_Normal, dPdx, dPdy);\n",
1370 "# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n",
1372 "# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n",
1375 " // combine the diffuse textures (base, pants, shirt)\n",
1376 " half4 color = half4(offsetMappedTexture2D(Texture_Color));\n",
1377 "#ifdef USEALPHAKILL\n",
1378 " if (color.a < 0.5)\n",
1381 " color.a *= Alpha;\n",
1382 "#ifdef USECOLORMAPPING\n",
1383 " color.rgb += half3(offsetMappedTexture2D(Texture_Pants).rgb) * Color_Pants + half3(offsetMappedTexture2D(Texture_Shirt).rgb) * Color_Shirt;\n",
1385 "#ifdef USEVERTEXTEXTUREBLEND\n",
1386 "#ifdef USEBOTHALPHAS\n",
1387 " half4 color2 = half4(tex2D(Texture_SecondaryColor, TexCoord2));\n",
1388 " half terrainblend = clamp(half(gl_FrontColor.a) * color.a, half(1.0 - color2.a), half(1.0));\n",
1389 " color.rgb = lerp(color2.rgb, color.rgb, terrainblend);\n",
1391 " half terrainblend = clamp(half(gl_FrontColor.a) * color.a * 2.0 - 0.5, half(0.0), half(1.0));\n",
1392 " //half terrainblend = min(half(gl_FrontColor.a) * color.a * 2.0, half(1.0));\n",
1393 " //half terrainblend = half(gl_FrontColor.a) * color.a > 0.5;\n",
1394 " color.rgb = half3(lerp(tex2D(Texture_SecondaryColor, TexCoord2).rgb, float3(color.rgb), terrainblend));\n",
1395 " color.a = 1.0;\n",
1396 " //color = half4(lerp(float4(1, 0, 0, 1), color, terrainblend));\n",
1399 "#ifdef USEALPHAGENVERTEX\n",
1400 " color.a *= gl_FrontColor.a;\n",
1403 " // get the surface normal\n",
1404 "#ifdef USEVERTEXTEXTUREBLEND\n",
1405 " half3 surfacenormal = normalize(half3(lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, offsetMappedTexture2D(Texture_Normal).rgb, terrainblend)) - half3(0.5, 0.5, 0.5));\n",
1407 " half3 surfacenormal = half3(normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5, 0.5, 0.5)));\n",
1410 " // get the material colors\n",
1411 " half3 diffusetex = color.rgb;\n",
1412 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n",
1413 "# ifdef USEVERTEXTEXTUREBLEND\n",
1414 " half4 glosstex = half4(lerp(tex2D(Texture_SecondaryGloss, TexCoord2), offsetMappedTexture2D(Texture_Gloss), terrainblend));\n",
1416 " half4 glosstex = half4(offsetMappedTexture2D(Texture_Gloss));\n",
1420 "#ifdef USEREFLECTCUBE\n",
1421 " float3 TangentReflectVector = reflect(-EyeVector, surfacenormal);\n",
1422 " float3 ModelReflectVector = TangentReflectVector.x * VectorS + TangentReflectVector.y * VectorT + TangentReflectVector.z * VectorR;\n",
1423 " float3 ReflectCubeTexCoord = mul(ModelToReflectCube, float4(ModelReflectVector, 0)).xyz;\n",
1424 " diffusetex += half3(offsetMappedTexture2D(Texture_ReflectMask).rgb) * half3(texCUBE(Texture_ReflectCube, ReflectCubeTexCoord).rgb);\n",
1430 "#ifdef MODE_LIGHTSOURCE\n",
1431 " // light source\n",
1432 "#ifdef USEDIFFUSE\n",
1433 " half3 lightnormal = half3(normalize(LightVector));\n",
1434 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n",
1435 " color.rgb = diffusetex * (Color_Ambient + diffuse * Color_Diffuse);\n",
1436 "#ifdef USESPECULAR\n",
1437 "#ifdef USEEXACTSPECULARMATH\n",
1438 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), 1.0 + SpecularPower * glosstex.a));\n",
1440 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n",
1441 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * glosstex.a));\n",
1443 " color.rgb += glosstex.rgb * (specular * Color_Specular);\n",
1446 " color.rgb = diffusetex * Color_Ambient;\n",
1448 " color.rgb *= half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n",
1449 "#if defined(USESHADOWMAP2D)\n",
1450 " color.rgb *= half(ShadowMapCompare(CubeVector, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n",
1451 "#ifdef USESHADOWMAPVSDCT\n",
1452 ", Texture_CubeProjection\n",
1457 "# ifdef USECUBEFILTER\n",
1458 " color.rgb *= half3(texCUBE(Texture_Cube, CubeVector).rgb);\n",
1461 "#ifdef USESHADOWMAP2D\n",
1462 "#ifdef USESHADOWMAPVSDCT\n",
1463 "// float3 shadowmaptc = GetShadowMapTC2D(CubeVector, ShadowMap_Parameters, Texture_CubeProjection);\n",
1465 "// float3 shadowmaptc = GetShadowMapTC2D(CubeVector, ShadowMap_Parameters);\n",
1467 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n",
1468 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale.xy).rgb);\n",
1469 "// color.rgb = half3(shadowmaptc.xyz * float3(ShadowMap_TextureScale.xy,1.0));\n",
1470 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale.xy));\n",
1471 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n",
1472 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale.xy).rgb);\n",
1473 "// color.rgb = half3(shadowmaptc.xyz * float3(ShadowMap_TextureScale.xy,1.0));\n",
1474 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale.xy));\n",
1475 "// color.r = half(shadowmaptc.z - texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale.xy));\n",
1476 "// color.r = half(shadowmaptc.z);\n",
1477 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale.xy));\n",
1478 "// color.r = half(shadowmaptc.z);\n",
1479 "// color.r = 1;\n",
1480 "// color.rgb = abs(CubeVector);\n",
1482 "// color.rgb = half3(1,1,1);\n",
1483 "#endif // MODE_LIGHTSOURCE\n",
1488 "#ifdef MODE_LIGHTDIRECTION\n",
1489 " #define SHADING\n",
1490 " #ifdef USEDIFFUSE\n",
1491 " half3 lightnormal = half3(normalize(LightVector));\n",
1493 " #define lightcolor 1\n",
1494 "#endif // MODE_LIGHTDIRECTION\n",
1495 "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n",
1496 " #define SHADING\n",
1497 " // deluxemap lightmapping using light vectors in modelspace (q3map2 -light -deluxe)\n",
1498 " half3 lightnormal_modelspace = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n",
1499 " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n",
1500 " // convert modelspace light vector to tangentspace\n",
1501 " half3 lightnormal = half3(dot(lightnormal_modelspace, half3(VectorS)), dot(lightnormal_modelspace, half3(VectorT)), dot(lightnormal_modelspace, half3(VectorR)));\n",
1502 " // calculate directional shading (and undoing the existing angle attenuation on the lightmap by the division)\n",
1503 " // note that q3map2 is too stupid to calculate proper surface normals when q3map_nonplanar\n",
1504 " // is used (the lightmap and deluxemap coords correspond to virtually random coordinates\n",
1505 " // on that luxel, and NOT to its center, because recursive triangle subdivision is used\n",
1506 " // to map the luxels to coordinates on the draw surfaces), which also causes\n",
1507 " // deluxemaps to be wrong because light contributions from the wrong side of the surface\n",
1508 " // are added up. To prevent divisions by zero or strong exaggerations, a max()\n",
1509 " // nudge is done here at expense of some additional fps. This is ONLY needed for\n",
1510 " // deluxemaps, tangentspace deluxemap avoid this problem by design.\n",
1511 " lightcolor *= 1.0 / max(0.25, lightnormal.z);\n",
1512 "#endif // MODE_LIGHTDIRECTIONMAP_MODELSPACE\n",
1513 "#ifdef MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n",
1514 " #define SHADING\n",
1515 " // deluxemap lightmapping using light vectors in tangentspace (hmap2 -light)\n",
1516 " half3 lightnormal = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n",
1517 " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n",
1519 "#if defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n",
1520 " #define SHADING\n",
1521 " // forced deluxemap on lightmapped/vertexlit surfaces\n",
1522 " half3 lightnormal = half3(0.0, 0.0, 1.0);\n",
1523 " #ifdef USELIGHTMAP\n",
1524 " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n",
1526 " half3 lightcolor = half3(gl_FrontColor.rgb);\n",
1529 "#ifdef MODE_FAKELIGHT\n",
1530 " #define SHADING\n",
1531 " half3 lightnormal = half3(normalize(EyeVector));\n",
1532 " #define lightcolor 1\n",
1533 "#endif // MODE_FAKELIGHT\n",
1538 "#ifdef MODE_LIGHTMAP\n",
1539 " color.rgb = diffusetex * (Color_Ambient + half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb) * Color_Diffuse);\n",
1540 "#endif // MODE_LIGHTMAP\n",
1541 "#ifdef MODE_VERTEXCOLOR\n",
1542 " color.rgb = diffusetex * (Color_Ambient + half3(gl_FrontColor.rgb) * Color_Diffuse);\n",
1543 "#endif // MODE_VERTEXCOLOR\n",
1544 "#ifdef MODE_FLATCOLOR\n",
1545 " color.rgb = diffusetex * Color_Ambient;\n",
1546 "#endif // MODE_FLATCOLOR\n",
1552 "# ifdef USEDIFFUSE\n",
1553 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n",
1554 "# ifdef USESPECULAR\n",
1555 "# ifdef USEEXACTSPECULARMATH\n",
1556 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), 1.0 + SpecularPower * glosstex.a));\n",
1558 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n",
1559 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * glosstex.a));\n",
1561 " color.rgb = diffusetex * Color_Ambient + (diffusetex * Color_Diffuse * diffuse + glosstex.rgb * Color_Specular * specular) * lightcolor;\n",
1563 " color.rgb = diffusetex * (Color_Ambient + Color_Diffuse * diffuse * lightcolor);\n",
1566 " color.rgb = diffusetex * Color_Ambient;\n",
1570 "#ifdef USESHADOWMAPORTHO\n",
1571 " color.rgb *= half(ShadowMapCompare(ShadowMapTC, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale));\n",
1574 "#ifdef USEDEFERREDLIGHTMAP\n",
1575 " float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n",
1576 " color.rgb += diffusetex * half3(tex2D(Texture_ScreenDiffuse, ScreenTexCoord).rgb) * DeferredMod_Diffuse;\n",
1577 " color.rgb += glosstex.rgb * half3(tex2D(Texture_ScreenSpecular, ScreenTexCoord).rgb) * DeferredMod_Specular;\n",
1578 "// color.rgb = half3(tex2D(Texture_ScreenDepth, ScreenTexCoord).rgb);\n",
1579 "// color.r = half(texDepth2D(Texture_ScreenDepth, ScreenTexCoord)) * 1.0;\n",
1583 "#ifdef USEVERTEXTEXTUREBLEND\n",
1584 " color.rgb += half3(lerp(tex2D(Texture_SecondaryGlow, TexCoord2).rgb, offsetMappedTexture2D(Texture_Glow).rgb, terrainblend)) * Color_Glow;\n",
1586 " color.rgb += half3(offsetMappedTexture2D(Texture_Glow).rgb) * Color_Glow;\n",
1591 " color.rgb = half3(FogVertex(color, FogColor, EyeVectorModelSpaceFogPlaneVertexDist.xyz, EyeVectorModelSpaceFogPlaneVertexDist.w, FogRangeRecip, FogPlaneViewDist, FogHeightFade, Texture_FogMask, Texture_FogHeightTexture));\n",
1594 " // 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",
1595 "#ifdef USEREFLECTION\n",
1596 " float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n",
1597 " //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
1598 " float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW.zw + ScreenCenterRefractReflect.zw;\n",
1599 " float2 ScreenTexCoord = SafeScreenTexCoord + float3(normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5,0.5,0.5))).xy * DistortScaleRefractReflect.zw;\n",
1600 " // FIXME temporary hack to detect the case that the reflection\n",
1601 " // gets blackened at edges due to leaving the area that contains actual\n",
1603 " // Remove this 'ack once we have a better way to stop this thing from\n",
1605 " float f = min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(0.01, 0.01)).rgb) / 0.05);\n",
1606 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(0.01, -0.01)).rgb) / 0.05);\n",
1607 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, 0.01)).rgb) / 0.05);\n",
1608 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, -0.01)).rgb) / 0.05);\n",
1609 " ScreenTexCoord = lerp(SafeScreenTexCoord, ScreenTexCoord, f);\n",
1610 " color.rgb = lerp(color.rgb, half3(tex2D(Texture_Reflection, ScreenTexCoord).rgb) * ReflectColor.rgb, ReflectColor.a);\n",
1613 " dp_FragColor = float4(color);\n",
1615 "#endif // FRAGMENT_SHADER\n",
1617 "#endif // !MODE_DEFERREDLIGHTSOURCE\n",
1618 "#endif // !MODE_DEFERREDGEOMETRY\n",
1619 "#endif // !MODE_WATER\n",
1620 "#endif // !MODE_REFRACTION\n",
1621 "#endif // !MODE_BLOOMBLUR\n",
1622 "#endif // !MODE_GENERIC\n",
1623 "#endif // !MODE_POSTPROCESS\n",
1624 "#endif // !MODE_DEPTH_OR_SHADOW\n",