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 " float sobel = 1.0;\n",
212 " // float2 ts = textureSize(Texture_First, 0);\n",
213 " // float2 px = float2(1/ts.x, 1/ts.y);\n",
214 " float2 px = PixelSize;\n",
215 " float3 x1 = tex2D(Texture_First, TexCoord1 + float2(-px.x, px.y)).rgb;\n",
216 " float3 x2 = tex2D(Texture_First, TexCoord1 + float2(-px.x, 0.0)).rgb;\n",
217 " float3 x3 = tex2D(Texture_First, TexCoord1 + float2(-px.x,-px.y)).rgb;\n",
218 " float3 x4 = tex2D(Texture_First, TexCoord1 + float2( px.x, px.y)).rgb;\n",
219 " float3 x5 = tex2D(Texture_First, TexCoord1 + float2( px.x, 0.0)).rgb;\n",
220 " float3 x6 = tex2D(Texture_First, TexCoord1 + float2( px.x,-px.y)).rgb;\n",
221 " float3 y1 = tex2D(Texture_First, TexCoord1 + float2( px.x,-px.y)).rgb;\n",
222 " float3 y2 = tex2D(Texture_First, TexCoord1 + float2( 0.0,-px.y)).rgb;\n",
223 " float3 y3 = tex2D(Texture_First, TexCoord1 + float2(-px.x,-px.y)).rgb;\n",
224 " float3 y4 = tex2D(Texture_First, TexCoord1 + float2( px.x, px.y)).rgb;\n",
225 " float3 y5 = tex2D(Texture_First, TexCoord1 + float2( 0.0, px.y)).rgb;\n",
226 " float3 y6 = tex2D(Texture_First, TexCoord1 + float2(-px.x, px.y)).rgb;\n",
227 " float px1 = -1.0 * dot(float3(0.3, 0.59, 0.11), x1);\n",
228 " float px2 = -2.0 * dot(float3(0.3, 0.59, 0.11), x2);\n",
229 " float px3 = -1.0 * dot(float3(0.3, 0.59, 0.11), x3);\n",
230 " float px4 = 1.0 * dot(float3(0.3, 0.59, 0.11), x4);\n",
231 " float px5 = 2.0 * dot(float3(0.3, 0.59, 0.11), x5);\n",
232 " float px6 = 1.0 * dot(float3(0.3, 0.59, 0.11), x6);\n",
233 " float py1 = -1.0 * dot(float3(0.3, 0.59, 0.11), y1);\n",
234 " float py2 = -2.0 * dot(float3(0.3, 0.59, 0.11), y2);\n",
235 " float py3 = -1.0 * dot(float3(0.3, 0.59, 0.11), y3);\n",
236 " float py4 = 1.0 * dot(float3(0.3, 0.59, 0.11), y4);\n",
237 " float py5 = 2.0 * dot(float3(0.3, 0.59, 0.11), y5);\n",
238 " float py6 = 1.0 * dot(float3(0.3, 0.59, 0.11), y6);\n",
239 " sobel = 0.25 * abs(px1 + px2 + px3 + px4 + px5 + px6) + 0.25 * abs(py1 + py2 + py3 + py4 + py5 + py6);\n",
240 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.987688, -0.156434)) * UserVec1.y;\n",
241 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.156434, -0.891007)) * UserVec1.y;\n",
242 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2( 0.891007, -0.453990)) * UserVec1.y;\n",
243 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2( 0.707107, 0.707107)) * UserVec1.y;\n",
244 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.453990, 0.891007)) * UserVec1.y;\n",
245 " dp_FragColor /= (1.0 + 5.0 * UserVec1.y);\n",
246 " dp_FragColor.rgb = dp_FragColor.rgb * (1.0 + UserVec2.x) + float3(1,1,1)*max(0.0, sobel - UserVec2.z)*UserVec2.y;\n",
250 " dp_FragColor += max(float4(0,0,0,0), tex2D(Texture_Second, TexCoord2) - BloomColorSubtract);\n",
253 "#ifdef USEVIEWTINT\n",
254 " dp_FragColor = lerp(dp_FragColor, ViewTintColor, ViewTintColor.a);\n",
257 "#ifdef USESATURATION\n",
258 " //apply saturation BEFORE gamma ramps, so v_glslgamma value does not matter\n",
259 " float y = dot(dp_FragColor.rgb, float3(0.299, 0.587, 0.114));\n",
260 " // 'vampire sight' effect, wheres red is compensated\n",
261 " #ifdef SATURATION_REDCOMPENSATE\n",
262 " float rboost = max(0.0, (dp_FragColor.r - max(dp_FragColor.g, dp_FragColor.b))*(1.0 - Saturation));\n",
263 " dp_FragColor.rgb = lerp(float3(y,y,y), dp_FragColor.rgb, Saturation);\n",
264 " dp_FragColor.r += r;\n",
266 " // normal desaturation\n",
267 " //dp_FragColor = float3(y,y,y) + (dp_FragColor.rgb - float3(y)) * Saturation;\n",
268 " dp_FragColor.rgb = lerp(float3(y,y,y), dp_FragColor.rgb, Saturation);\n",
272 "#ifdef USEGAMMARAMPS\n",
273 " dp_FragColor.r = tex2D(Texture_GammaRamps, float2(dp_FragColor.r, 0)).r;\n",
274 " dp_FragColor.g = tex2D(Texture_GammaRamps, float2(dp_FragColor.g, 0)).g;\n",
275 " dp_FragColor.b = tex2D(Texture_GammaRamps, float2(dp_FragColor.b, 0)).b;\n",
279 "#else // !MODE_POSTPROCESS\n",
284 "#ifdef MODE_GENERIC\n",
285 "#ifdef VERTEX_SHADER\n",
288 "float4 gl_Vertex : POSITION,\n",
289 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
290 "float4 gl_Color : COLOR0,\n",
291 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
292 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n",
293 "uniform float ClientTime : register(c2),\n",
294 "out float4 gl_Position : POSITION,\n",
295 "#ifdef USEDIFFUSE\n",
296 "out float2 TexCoord1 : TEXCOORD0,\n",
298 "#ifdef USESPECULAR\n",
299 "out float2 TexCoord2 : TEXCOORD1,\n",
301 "out float4 gl_FrontColor : COLOR\n",
304 " gl_FrontColor = gl_Color;\n",
305 "#ifdef USEDIFFUSE\n",
306 " TexCoord1 = gl_MultiTexCoord0.xy;\n",
308 "#ifdef USESPECULAR\n",
309 " TexCoord2 = gl_MultiTexCoord1.xy;\n",
311 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
312 "#ifdef USETRIPPY\n",
313 " gl_Position = TrippyVertex(gl_Position, ClientTime);\n",
318 "#ifdef FRAGMENT_SHADER\n",
322 "float4 gl_FrontColor : COLOR0,\n",
323 "float2 TexCoord1 : TEXCOORD0,\n",
324 "float2 TexCoord2 : TEXCOORD1,\n",
325 "#ifdef USEDIFFUSE\n",
326 "uniform sampler Texture_First : register(s0),\n",
328 "#ifdef USESPECULAR\n",
329 "uniform sampler Texture_Second : register(s1),\n",
331 "#ifdef USEGAMMARAMPS\n",
332 "uniform sampler Texture_GammaRamps : register(s2),\n",
334 "uniform half Alpha : register(c0),\n",
335 "out float4 dp_FragColor : COLOR\n",
338 "#ifdef USEVIEWTINT\n",
339 " dp_FragColor = gl_FrontColor;\n",
341 " dp_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n",
343 "#ifdef USEDIFFUSE\n",
344 "# ifdef USEREFLECTCUBE\n",
345 " // suppress texture alpha\n",
346 " dp_FragColor.rgb *= tex2D(Texture_First, TexCoord1).rgb;\n",
348 " dp_FragColor *= tex2D(Texture_First, TexCoord1);\n",
352 "#ifdef USESPECULAR\n",
353 " float4 tex2 = tex2D(Texture_Second, TexCoord2);\n",
354 "# ifdef USECOLORMAPPING\n",
355 " dp_FragColor *= tex2;\n",
358 " dp_FragColor += tex2;\n",
360 "# ifdef USEVERTEXTEXTUREBLEND\n",
361 " dp_FragColor = lerp(dp_FragColor, tex2, tex2.a);\n",
364 "#ifdef USEGAMMARAMPS\n",
365 " dp_FragColor.r = tex2D(Texture_GammaRamps, vec2(dp_FragColor.r, 0)).r;\n",
366 " dp_FragColor.g = tex2D(Texture_GammaRamps, vec2(dp_FragColor.g, 0)).g;\n",
367 " dp_FragColor.b = tex2D(Texture_GammaRamps, vec2(dp_FragColor.b, 0)).b;\n",
369 "#ifdef USEALPHAKILL\n",
370 " dp_FragColor.a *= Alpha;\n",
374 "#else // !MODE_GENERIC\n",
379 "#ifdef MODE_BLOOMBLUR\n",
380 "#ifdef VERTEX_SHADER\n",
383 "float4 gl_Vertex : POSITION,\n",
384 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
385 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
386 "out float4 gl_Position : POSITION,\n",
387 "out float2 TexCoord : TEXCOORD0\n",
390 " TexCoord = gl_MultiTexCoord0.xy;\n",
391 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
395 "#ifdef FRAGMENT_SHADER\n",
399 "float2 TexCoord : TEXCOORD0,\n",
400 "uniform sampler Texture_First : register(s0),\n",
401 "uniform float4 BloomBlur_Parameters : register(c1),\n",
402 "out float4 dp_FragColor : COLOR\n",
406 " float2 tc = TexCoord;\n",
407 " float3 color = tex2D(Texture_First, tc).rgb;\n",
408 " tc += BloomBlur_Parameters.xy;\n",
409 " for (i = 1;i < SAMPLES;i++)\n",
411 " color += tex2D(Texture_First, tc).rgb;\n",
412 " tc += BloomBlur_Parameters.xy;\n",
414 " dp_FragColor = float4(color * BloomBlur_Parameters.z + float3(BloomBlur_Parameters.w), 1);\n",
417 "#else // !MODE_BLOOMBLUR\n",
418 "#ifdef MODE_REFRACTION\n",
419 "#ifdef VERTEX_SHADER\n",
422 "float4 gl_Vertex : POSITION,\n",
423 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
424 "#ifdef USEALPHAGENVERTEX\n",
425 "float4 gl_Color : COLOR0,\n",
427 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
428 "uniform float4x4 TexMatrix : register(c0),\n",
429 "uniform float3 EyePosition : register(c24),\n",
430 "uniform float ClientTime : register(c2),\n",
431 "#ifdef USEALPHAGENVERTEX\n",
432 "out float4 gl_FrontColor : COLOR,\n",
434 "out float4 gl_Position : POSITION,\n",
435 "out float2 TexCoord : TEXCOORD0,\n",
436 "out float3 EyeVector : TEXCOORD1,\n",
437 "out float4 ModelViewProjectionPosition : TEXCOORD2\n",
440 "#ifdef USEALPHAGENVERTEX\n",
441 " gl_FrontColor = gl_Color;\n",
443 " TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n",
444 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
445 " ModelViewProjectionPosition = gl_Position;\n",
446 "#ifdef USETRIPPY\n",
447 " gl_Position = TrippyVertex(gl_Position, ClientTime);\n",
452 "#ifdef FRAGMENT_SHADER\n",
455 "#ifdef USEALPHAGENVERTEX\n",
456 "float4 gl_FrontColor : COLOR,\n",
458 "float2 TexCoord : TEXCOORD0,\n",
459 "float3 EyeVector : TEXCOORD1,\n",
460 "float4 ModelViewProjectionPosition : TEXCOORD2,\n",
461 "uniform sampler Texture_Normal : register(s0),\n",
462 "uniform sampler Texture_Refraction : register(s3),\n",
463 "uniform sampler Texture_Reflection : register(s7),\n",
464 "uniform float4 DistortScaleRefractReflect : register(c14),\n",
465 "uniform float4 ScreenScaleRefractReflect : register(c32),\n",
466 "uniform float4 ScreenCenterRefractReflect : register(c31),\n",
467 "uniform float4 RefractColor : register(c29),\n",
468 "out float4 dp_FragColor : COLOR\n",
471 " float2 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect.xy * (1.0 / ModelViewProjectionPosition.w);\n",
472 " //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",
473 " float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n",
474 "#ifdef USEALPHAGENVERTEX\n",
475 " float2 distort = DistortScaleRefractReflect.xy * gl_FrontColor.a;\n",
476 " float4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), gl_FrontColor.a);\n",
478 " float2 distort = DistortScaleRefractReflect.xy;\n",
479 " float4 refractcolor = RefractColor;\n",
481 " float2 ScreenTexCoord = SafeScreenTexCoord + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy * distort;\n",
482 " // FIXME temporary hack to detect the case that the reflection\n",
483 " // gets blackened at edges due to leaving the area that contains actual\n",
485 " // Remove this 'ack once we have a better way to stop this thing from\n",
487 " float f = min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(0.01, 0.01)).rgb) / 0.05);\n",
488 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(0.01, -0.01)).rgb) / 0.05);\n",
489 " 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 " ScreenTexCoord = lerp(SafeScreenTexCoord, ScreenTexCoord, f);\n",
492 " dp_FragColor = float4(tex2D(Texture_Refraction, ScreenTexCoord).rgb, 1) * refractcolor;\n",
495 "#else // !MODE_REFRACTION\n",
500 "#ifdef MODE_WATER\n",
501 "#ifdef VERTEX_SHADER\n",
505 "float4 gl_Vertex : POSITION,\n",
506 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
507 "#ifdef USEALPHAGENVERTEX\n",
508 "float4 gl_Color : COLOR0,\n",
510 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
511 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n",
512 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n",
513 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n",
514 "uniform float4x4 TexMatrix : register(c0),\n",
515 "uniform float3 EyePosition : register(c24),\n",
516 "uniform float ClientTime : register(c2),\n",
517 "#ifdef USEALPHAGENVERTEX\n",
518 "out float4 gl_FrontColor : COLOR,\n",
520 "out float4 gl_Position : POSITION,\n",
521 "out float2 TexCoord : TEXCOORD0,\n",
522 "out float3 EyeVector : TEXCOORD1,\n",
523 "out float4 ModelViewProjectionPosition : TEXCOORD2\n",
526 "#ifdef USEALPHAGENVERTEX\n",
527 " gl_FrontColor = gl_Color;\n",
529 " TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n",
530 " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n",
531 " EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n",
532 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
533 " ModelViewProjectionPosition = gl_Position;\n",
534 "#ifdef USETRIPPY\n",
535 " gl_Position = TrippyVertex(gl_Position, ClientTime);\n",
540 "#ifdef FRAGMENT_SHADER\n",
543 "#ifdef USEALPHAGENVERTEX\n",
544 "float4 gl_FrontColor : COLOR,\n",
546 "float2 TexCoord : TEXCOORD0,\n",
547 "float3 EyeVector : TEXCOORD1,\n",
548 "float4 ModelViewProjectionPosition : TEXCOORD2,\n",
549 "uniform sampler Texture_Normal : register(s0),\n",
550 "uniform sampler Texture_Refraction : register(s3),\n",
551 "uniform sampler Texture_Reflection : register(s7),\n",
552 "uniform float4 DistortScaleRefractReflect : register(c14),\n",
553 "uniform float4 ScreenScaleRefractReflect : register(c32),\n",
554 "uniform float4 ScreenCenterRefractReflect : register(c31),\n",
555 "uniform float4 RefractColor : register(c29),\n",
556 "uniform float4 ReflectColor : register(c26),\n",
557 "uniform float ReflectFactor : register(c27),\n",
558 "uniform float ReflectOffset : register(c28),\n",
559 "out float4 dp_FragColor : COLOR\n",
562 " float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n",
563 " //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
564 " float4 SafeScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
565 " //SafeScreenTexCoord = gl_FragCoord.xyxy * float4(1.0 / 1920.0, 1.0 / 1200.0, 1.0 / 1920.0, 1.0 / 1200.0);\n",
566 "#ifdef USEALPHAGENVERTEX\n",
567 " float4 distort = DistortScaleRefractReflect * gl_FrontColor.a;\n",
568 " float reflectoffset = ReflectOffset * gl_FrontColor.a;\n",
569 " float reflectfactor = ReflectFactor * gl_FrontColor.a;\n",
570 " float4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), gl_FrontColor.a);\n",
572 " float4 distort = DistortScaleRefractReflect;\n",
573 " float reflectoffset = ReflectOffset;\n",
574 " float reflectfactor = ReflectFactor;\n",
575 " float4 refractcolor = RefractColor;\n",
577 " float4 ScreenTexCoord = SafeScreenTexCoord + float2(normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy).xyxy * distort;\n",
578 " // FIXME temporary hack to detect the case that the reflection\n",
579 " // gets blackened at edges due to leaving the area that contains actual\n",
581 " // Remove this 'ack once we have a better way to stop this thing from\n",
583 " float f = min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(0.01, 0.01)).rgb) / 0.05);\n",
584 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(0.01, -0.01)).rgb) / 0.05);\n",
585 " 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 " ScreenTexCoord.xy = lerp(SafeScreenTexCoord.xy, ScreenTexCoord.xy, f);\n",
588 " f = min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(0.01, 0.01)).rgb) / 0.05);\n",
589 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(0.01, -0.01)).rgb) / 0.05);\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 " ScreenTexCoord.zw = lerp(SafeScreenTexCoord.zw, ScreenTexCoord.zw, f);\n",
593 " float Fresnel = pow(min(1.0, 1.0 - float(normalize(EyeVector).z)), 2.0) * reflectfactor + reflectoffset;\n",
594 " dp_FragColor = lerp(float4(tex2D(Texture_Refraction, ScreenTexCoord.xy).rgb, 1) * refractcolor, float4(tex2D(Texture_Reflection, ScreenTexCoord.zw).rgb, 1) * ReflectColor, Fresnel);\n",
597 "#else // !MODE_WATER\n",
602 "// 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",
604 "// fragment shader specific:\n",
605 "#ifdef FRAGMENT_SHADER\n",
608 "float3 FogVertex(float4 surfacecolor, float3 FogColor, float3 EyeVectorModelSpace, float FogPlaneVertexDist, float FogRangeRecip, float FogPlaneViewDist, float FogHeightFade, sampler Texture_FogMask, sampler Texture_FogHeightTexture)\n",
611 " float3 fc = FogColor;\n",
612 "#ifdef USEFOGALPHAHACK\n",
613 " fc *= surfacecolor.a;\n",
615 "#ifdef USEFOGHEIGHTTEXTURE\n",
616 " float4 fogheightpixel = tex2D(Texture_FogHeightTexture, float2(1,1) + float2(FogPlaneVertexDist, FogPlaneViewDist) * (-2.0 * FogHeightFade));\n",
617 " fogfrac = fogheightpixel.a;\n",
618 " return lerp(fogheightpixel.rgb * fc, surfacecolor.rgb, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n",
620 "# ifdef USEFOGOUTSIDE\n",
621 " fogfrac = min(0.0, FogPlaneVertexDist) / (FogPlaneVertexDist - FogPlaneViewDist) * min(1.0, min(0.0, FogPlaneVertexDist) * FogHeightFade);\n",
623 " fogfrac = FogPlaneViewDist / (FogPlaneViewDist - max(0.0, FogPlaneVertexDist)) * min(1.0, (min(0.0, FogPlaneVertexDist) + FogPlaneViewDist) * FogHeightFade);\n",
625 " return lerp(fc, surfacecolor.rgb, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n",
630 "#ifdef USEOFFSETMAPPING\n",
631 "float2 OffsetMapping(float2 TexCoord, float4 OffsetMapping_ScaleSteps, float OffsetMapping_Bias, float OffsetMapping_LodDistance, float3 EyeVector, sampler Texture_Normal, float2 dPdx, float2 dPdy)\n",
634 " // distance-based LOD\n",
635 "#ifdef USEOFFSETMAPPING_LOD\n",
636 " //float LODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n",
637 " //float4 ScaleSteps = float4(OffsetMapping_ScaleSteps.x, OffsetMapping_ScaleSteps.y * LODFactor, OffsetMapping_ScaleSteps.z / LODFactor, OffsetMapping_ScaleSteps.w * LODFactor);\n",
638 " float GuessLODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n",
639 "#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n",
640 " // stupid workaround because 1-step and 2-step reliefmapping is void\n",
641 " float LODSteps = max(3.0, ceil(GuessLODFactor * OffsetMapping_ScaleSteps.y));\n",
643 " float LODSteps = ceil(GuessLODFactor * OffsetMapping_ScaleSteps.y);\n",
645 " float LODFactor = LODSteps / OffsetMapping_ScaleSteps.y;\n",
646 " float4 ScaleSteps = float4(OffsetMapping_ScaleSteps.x, LODSteps, 1.0 / LODSteps, OffsetMapping_ScaleSteps.w * LODFactor);\n",
648 " #define ScaleSteps OffsetMapping_ScaleSteps\n",
650 "#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n",
651 " // 14 sample relief mapping: linear search and then binary search\n",
652 " // this basically steps forward a small amount repeatedly until it finds\n",
653 " // itself inside solid, then jitters forward and back using decreasing\n",
654 " // amounts to find the impact\n",
655 " //float3 OffsetVector = float3(EyeVector.xy * ((1.0 / EyeVector.z) * ScaleSteps.x) * float2(-1, 1), -1);\n",
656 " //float3 OffsetVector = float3(normalize(EyeVector.xy) * ScaleSteps.x * float2(-1, 1), -1);\n",
657 " float3 OffsetVector = float3(normalize(EyeVector).xy * ScaleSteps.x * float2(-1, 1), -1);\n",
658 " float3 RT = float3(float2(TexCoord.xy - OffsetVector.xy*OffsetMapping_Bias), 1);\n",
659 " OffsetVector *= ScaleSteps.z;\n",
660 " for(i = 1.0; i < ScaleSteps.y; ++i)\n",
661 " RT += OffsetVector * step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z);\n",
662 " for(i = 0.0, f = 1.0; i < ScaleSteps.w; ++i, f *= 0.5)\n",
663 " RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * f - 0.5 * f);\n",
666 " // 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits)\n",
667 " //float2 OffsetVector = float2(EyeVector.xy * ((1.0 / EyeVector.z) * ScaleSteps.x) * float2(-1, 1));\n",
668 " //float2 OffsetVector = float2(normalize(EyeVector.xy) * ScaleSteps.x * float2(-1, 1));\n",
669 " float2 OffsetVector = float2(normalize(EyeVector).xy * ScaleSteps.x * float2(-1, 1));\n",
670 " OffsetVector *= ScaleSteps.z;\n",
671 " for(i = 0.0; i < ScaleSteps.y; ++i)\n",
672 " TexCoord += OffsetVector * ((1.0 - OffsetMapping_Bias) - tex2Dgrad(Texture_Normal, TexCoord, dPdx, dPdy).a);\n",
673 " return TexCoord;\n",
676 "#endif // USEOFFSETMAPPING\n",
678 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n",
679 "#if defined(USESHADOWMAP2D)\n",
680 "# ifdef USESHADOWMAPORTHO\n",
681 "# define GetShadowMapTC2D(dir, ShadowMap_Parameters) (min(dir, ShadowMap_Parameters.xyz))\n",
683 "# ifdef USESHADOWMAPVSDCT\n",
684 "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters, samplerCUBE Texture_CubeProjection)\n",
686 " float3 adir = abs(dir);\n",
687 " float2 mparams = ShadowMap_Parameters.xy / max(max(adir.x, adir.y), adir.z);\n",
688 " float4 proj = texCUBE(Texture_CubeProjection, dir);\n",
689 " return float3(lerp(dir.xy, dir.zz, proj.xy) * mparams.x + proj.zw * ShadowMap_Parameters.z, mparams.y + ShadowMap_Parameters.w);\n",
692 "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters)\n",
694 " float3 adir = abs(dir);\n",
695 " float m; float4 proj;\n",
696 " 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",
697 " if (adir.z > m) { m = adir.z; proj = float4(dir, 2.5); }\n",
699 " 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",
701 " float2 mparams = ShadowMap_Parameters.xy / m;\n",
702 " 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",
707 "#endif // defined(USESHADOWMAP2D)\n",
709 "# ifdef USESHADOWMAP2D\n",
710 "#ifdef USESHADOWMAPVSDCT\n",
711 "float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale, samplerCUBE Texture_CubeProjection)\n",
713 "float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale)\n",
716 "#ifdef USESHADOWMAPVSDCT\n",
717 " float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters, Texture_CubeProjection);\n",
719 " float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters);\n",
723 "# ifdef USESHADOWSAMPLER\n",
724 "# ifdef USESHADOWMAPPCF\n",
725 "# define texval(x, y) tex2Dproj(Texture_ShadowMap2D, float4(center + float2(x, y)*ShadowMap_TextureScale, shadowmaptc.z, 1.0)).r \n",
726 " float2 center = shadowmaptc.xy*ShadowMap_TextureScale;\n",
727 " 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",
729 " f = tex2Dproj(Texture_ShadowMap2D, float4(shadowmaptc.xy*ShadowMap_TextureScale, shadowmaptc.z, 1.0)).r;\n",
732 "# ifdef USESHADOWMAPPCF\n",
733 "# if defined(GL_ARB_texture_gather) || defined(GL_AMD_texture_texture4)\n",
734 "# ifdef GL_ARB_texture_gather\n",
735 "# define texval(x, y) textureGatherOffset(Texture_ShadowMap2D, center, int2(x, y))\n",
737 "# define texval(x, y) texture4(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale)\n",
739 " float2 offset = frac(shadowmaptc.xy - 0.5), center = (shadowmaptc.xy - offset)*ShadowMap_TextureScale;\n",
740 "# if USESHADOWMAPPCF > 1\n",
741 " float4 group1 = step(shadowmaptc.z, texval(-2.0, -2.0));\n",
742 " float4 group2 = step(shadowmaptc.z, texval( 0.0, -2.0));\n",
743 " float4 group3 = step(shadowmaptc.z, texval( 2.0, -2.0));\n",
744 " float4 group4 = step(shadowmaptc.z, texval(-2.0, 0.0));\n",
745 " float4 group5 = step(shadowmaptc.z, texval( 0.0, 0.0));\n",
746 " float4 group6 = step(shadowmaptc.z, texval( 2.0, 0.0));\n",
747 " float4 group7 = step(shadowmaptc.z, texval(-2.0, 2.0));\n",
748 " float4 group8 = step(shadowmaptc.z, texval( 0.0, 2.0));\n",
749 " float4 group9 = step(shadowmaptc.z, texval( 2.0, 2.0));\n",
750 " float4 locols = float4(group1.ab, group3.ab);\n",
751 " float4 hicols = float4(group7.rg, group9.rg);\n",
752 " locols.yz += group2.ab;\n",
753 " hicols.yz += group8.rg;\n",
754 " float4 midcols = float4(group1.rg, group3.rg) + float4(group7.ab, group9.ab) +\n",
755 " float4(group4.rg, group6.rg) + float4(group4.ab, group6.ab) +\n",
756 " lerp(locols, hicols, offset.y);\n",
757 " float4 cols = group5 + float4(group2.rg, group8.ab);\n",
758 " cols.xyz += lerp(midcols.xyz, midcols.yzw, offset.x);\n",
759 " f = dot(cols, float4(1.0/25.0));\n",
761 " float4 group1 = step(shadowmaptc.z, texval(-1.0, -1.0));\n",
762 " float4 group2 = step(shadowmaptc.z, texval( 1.0, -1.0));\n",
763 " float4 group3 = step(shadowmaptc.z, texval(-1.0, 1.0));\n",
764 " float4 group4 = step(shadowmaptc.z, texval( 1.0, 1.0));\n",
765 " float4 cols = float4(group1.rg, group2.rg) + float4(group3.ab, group4.ab) +\n",
766 " lerp(float4(group1.ab, group2.ab), float4(group3.rg, group4.rg), offset.y);\n",
767 " f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n",
770 "# ifdef GL_EXT_gpu_shader4\n",
771 "# define texval(x, y) tex2DOffset(Texture_ShadowMap2D, center, int2(x, y)).r\n",
773 "# define texval(x, y) texDepth2D(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale).r \n",
775 "# if USESHADOWMAPPCF > 1\n",
776 " float2 center = shadowmaptc.xy - 0.5, offset = frac(center);\n",
777 " center *= ShadowMap_TextureScale;\n",
778 " 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",
779 " 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",
780 " 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",
781 " 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",
782 " float4 cols = row2 + row3 + lerp(row1, row4, offset.y);\n",
783 " f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n",
785 " float2 center = shadowmaptc.xy*ShadowMap_TextureScale, offset = frac(shadowmaptc.xy);\n",
786 " float3 row1 = step(shadowmaptc.z, float3(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0)));\n",
787 " float3 row2 = step(shadowmaptc.z, float3(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0)));\n",
788 " float3 row3 = step(shadowmaptc.z, float3(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0)));\n",
789 " float3 cols = row2 + lerp(row1, row3, offset.y);\n",
790 " f = dot(lerp(cols.xy, cols.yz, offset.x), float2(0.25,0.25));\n",
794 " f = step(shadowmaptc.z, tex2D(Texture_ShadowMap2D, shadowmaptc.xy*ShadowMap_TextureScale).r);\n",
797 "# ifdef USESHADOWMAPORTHO\n",
798 " return lerp(ShadowMap_Parameters.w, 1.0, f);\n",
804 "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n",
805 "#endif // FRAGMENT_SHADER\n",
810 "#ifdef MODE_DEFERREDGEOMETRY\n",
811 "#ifdef VERTEX_SHADER\n",
814 "float4 gl_Vertex : POSITION,\n",
815 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
816 "#ifdef USEVERTEXTEXTUREBLEND\n",
817 "float4 gl_Color : COLOR0,\n",
819 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
820 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n",
821 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n",
822 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n",
823 "uniform float4x4 TexMatrix : register(c0),\n",
824 "#ifdef USEVERTEXTEXTUREBLEND\n",
825 "uniform float4x4 BackgroundTexMatrix : register(c4),\n",
827 "uniform float4x4 ModelViewMatrix : register(c12),\n",
828 "#ifdef USEOFFSETMAPPING\n",
829 "uniform float3 EyePosition : register(c24),\n",
831 "uniform float ClientTime : register(c2),\n",
832 "out float4 gl_Position : POSITION,\n",
833 "#ifdef USEVERTEXTEXTUREBLEND\n",
834 "out float4 gl_FrontColor : COLOR,\n",
836 "out float4 TexCoordBoth : TEXCOORD0,\n",
837 "#ifdef USEOFFSETMAPPING\n",
838 "out float3 EyeVector : TEXCOORD2,\n",
840 "out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n",
841 "out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n",
842 "out float4 VectorR : TEXCOORD7 // direction of R texcoord (surface normal), Depth value\n",
845 " TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n",
846 "#ifdef USEVERTEXTEXTUREBLEND\n",
847 " gl_FrontColor = gl_Color;\n",
848 " TexCoordBoth.zw = float2(Backgroundmul(TexMatrix, gl_MultiTexCoord0));\n",
851 " // transform unnormalized eye direction into tangent space\n",
852 "#ifdef USEOFFSETMAPPING\n",
853 " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n",
854 " EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n",
857 " VectorS = mul(ModelViewMatrix, float4(gl_MultiTexCoord1.xyz, 0)).xyz;\n",
858 " VectorT = mul(ModelViewMatrix, float4(gl_MultiTexCoord2.xyz, 0)).xyz;\n",
859 " VectorR.xyz = mul(ModelViewMatrix, float4(gl_MultiTexCoord3.xyz, 0)).xyz;\n",
860 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
861 "#ifdef USETRIPPY\n",
862 " gl_Position = TrippyVertex(gl_Position, ClientTime);\n",
864 " VectorR.w = mul(ModelViewMatrix, gl_Vertex).z;\n",
866 "#endif // VERTEX_SHADER\n",
868 "#ifdef FRAGMENT_SHADER\n",
871 "float4 TexCoordBoth : TEXCOORD0,\n",
872 "float3 EyeVector : TEXCOORD2,\n",
873 "float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n",
874 "float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n",
875 "float4 VectorR : TEXCOORD7, // direction of R texcoord (surface normal), Depth value\n",
876 "uniform sampler Texture_Normal : register(s0),\n",
877 "#ifdef USEALPHAKILL\n",
878 "uniform sampler Texture_Color : register(s1),\n",
880 "uniform sampler Texture_Gloss : register(s2),\n",
881 "#ifdef USEVERTEXTEXTUREBLEND\n",
882 "uniform sampler Texture_SecondaryNormal : register(s4),\n",
883 "uniform sampler Texture_SecondaryGloss : register(s6),\n",
885 "#ifdef USEOFFSETMAPPING\n",
886 "uniform float4 OffsetMapping_ScaleSteps : register(c24),\n",
887 "uniform float4 OffsetMapping_LodDistance : register(c53),\n",
888 "uniform float OffsetMapping_Bias : register(c54),\n",
890 "uniform half SpecularPower : register(c36),\n",
891 "out float4 dp_FragColor : COLOR\n",
894 " float2 TexCoord = TexCoordBoth.xy;\n",
895 "#ifdef USEOFFSETMAPPING\n",
896 " // apply offsetmapping\n",
897 " float2 dPdx = ddx(TexCoord);\n",
898 " float2 dPdy = ddy(TexCoord);\n",
899 " float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, OffsetMapping_Bias, OffsetMapping_LodDistance, EyeVector, Texture_Normal, dPdx, dPdy);\n",
900 "# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n",
902 "# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n",
905 "#ifdef USEALPHAKILL\n",
906 " if (offsetMappedTexture2D(Texture_Color).a < 0.5)\n",
910 "#ifdef USEVERTEXTEXTUREBLEND\n",
911 " float alpha = offsetMappedTexture2D(Texture_Color).a;\n",
912 " float terrainblend = clamp(float(gl_FrontColor.a) * alpha * 2.0 - 0.5, float(0.0), float(1.0));\n",
913 " //float terrainblend = min(float(gl_FrontColor.a) * alpha * 2.0, float(1.0));\n",
914 " //float terrainblend = float(gl_FrontColor.a) * alpha > 0.5;\n",
917 "#ifdef USEVERTEXTEXTUREBLEND\n",
918 " float3 surfacenormal = lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, offsetMappedTexture2D(Texture_Normal).rgb, terrainblend) - float3(0.5, 0.5, 0.5);\n",
919 " float a = lerp(tex2D(Texture_SecondaryGloss, TexCoord2).a, offsetMappedTexture2D(Texture_Gloss).a, terrainblend);\n",
921 " float3 surfacenormal = offsetMappedTexture2D(Texture_Normal).rgb - float3(0.5, 0.5, 0.5);\n",
922 " float a = offsetMappedTexture2D(Texture_Gloss).a;\n",
925 " float3 pixelnormal = normalize(surfacenormal.x * VectorS.xyz + surfacenormal.y * VectorT.xyz + surfacenormal.z * VectorR.xyz);\n",
926 " dp_FragColor = float4(pixelnormal.x, pixelnormal.y, VectorR.w, a);\n",
928 "#endif // FRAGMENT_SHADER\n",
929 "#else // !MODE_DEFERREDGEOMETRY\n",
934 "#ifdef MODE_DEFERREDLIGHTSOURCE\n",
935 "#ifdef VERTEX_SHADER\n",
938 "float4 gl_Vertex : POSITION,\n",
939 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
940 "uniform float4x4 ModelViewMatrix : register(c12),\n",
941 "out float4 gl_Position : POSITION,\n",
942 "out float4 ModelViewPosition : TEXCOORD0\n",
945 " ModelViewPosition = mul(ModelViewMatrix, gl_Vertex);\n",
946 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
948 "#endif // VERTEX_SHADER\n",
950 "#ifdef FRAGMENT_SHADER\n",
954 "float2 Pixel : VPOS,\n",
956 "float2 Pixel : WPOS,\n",
958 "float4 ModelViewPosition : TEXCOORD0,\n",
959 "uniform float4x4 ViewToLight : register(c44),\n",
960 "uniform float2 ScreenToDepth : register(c33), // ScreenToDepth = float2(Far / (Far - Near), Far * Near / (Near - Far));\n",
961 "uniform float3 LightPosition : register(c23),\n",
962 "uniform half2 PixelToScreenTexCoord : register(c42),\n",
963 "uniform half3 DeferredColor_Ambient : register(c9),\n",
964 "uniform half3 DeferredColor_Diffuse : register(c10),\n",
965 "#ifdef USESPECULAR\n",
966 "uniform half3 DeferredColor_Specular : register(c11),\n",
967 "uniform half SpecularPower : register(c36),\n",
969 "uniform sampler Texture_Attenuation : register(s9),\n",
970 "uniform sampler Texture_ScreenDepth : register(s13),\n",
971 "uniform sampler Texture_ScreenNormalMap : register(s14),\n",
973 "#ifdef USECUBEFILTER\n",
974 "uniform samplerCUBE Texture_Cube : register(s10),\n",
977 "#ifdef USESHADOWMAP2D\n",
978 "# ifdef USESHADOWSAMPLER\n",
979 "uniform sampler Texture_ShadowMap2D : register(s15),\n",
981 "uniform sampler Texture_ShadowMap2D : register(s15),\n",
985 "#ifdef USESHADOWMAPVSDCT\n",
986 "uniform samplerCUBE Texture_CubeProjection : register(s12),\n",
989 "#if defined(USESHADOWMAP2D)\n",
990 "uniform float2 ShadowMap_TextureScale : register(c35),\n",
991 "uniform float4 ShadowMap_Parameters : register(c34),\n",
994 "out float4 gl_FragData0 : COLOR0,\n",
995 "out float4 gl_FragData1 : COLOR1\n",
998 " // calculate viewspace pixel position\n",
999 " float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n",
1000 " float3 position;\n",
1001 " // get the geometry information (depth, normal, specular exponent)\n",
1002 " half4 normalmap = half4(tex2D(Texture_ScreenNormalMap, ScreenTexCoord));\n",
1003 " // decode viewspace pixel normal\n",
1004 "// float3 surfacenormal = normalize(normalmap.rgb - cast_myhalf3(0.5,0.5,0.5));\n",
1005 " float3 surfacenormal = half3(normalmap.rg, sqrt(1.0-dot(normalmap.rg, normalmap.rg)));\n",
1006 " // decode viewspace pixel position\n",
1007 "// position.z = decodedepthmacro(dp_texture2D(Texture_ScreenDepth, ScreenTexCoord));\n",
1008 " position.z = normalmap.b;\n",
1009 "// position.z = ScreenToDepth.y / (dp_texture2D(Texture_ScreenDepth, ScreenTexCoord).r + ScreenToDepth.x);\n",
1010 " position.xy = ModelViewPosition.xy * (position.z / ModelViewPosition.z);\n",
1012 " // now do the actual shading\n",
1013 " // surfacenormal = pixel normal in viewspace\n",
1014 " // LightVector = pixel to light in viewspace\n",
1015 " // CubeVector = position in lightspace\n",
1016 " // eyevector = pixel to view in viewspace\n",
1017 " float3 CubeVector = mul(ViewToLight, float4(position,1)).xyz;\n",
1018 " half fade = half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n",
1019 "#ifdef USEDIFFUSE\n",
1020 " // calculate diffuse shading\n",
1021 " half3 lightnormal = half3(normalize(LightPosition - position));\n",
1022 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n",
1024 "#ifdef USESPECULAR\n",
1025 " // calculate directional shading\n",
1026 " float3 eyevector = position * -1.0;\n",
1027 "# ifdef USEEXACTSPECULARMATH\n",
1028 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(eyevector)))*-1.0, 0.0)), 1.0 + SpecularPower * normalmap.a));\n",
1030 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(eyevector))));\n",
1031 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * normalmap.a));\n",
1035 "#if defined(USESHADOWMAP2D)\n",
1036 " fade *= half(ShadowMapCompare(CubeVector, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n",
1037 "#ifdef USESHADOWMAPVSDCT\n",
1038 ", Texture_CubeProjection\n",
1043 "#ifdef USEDIFFUSE\n",
1044 " gl_FragData0 = float4((DeferredColor_Ambient + DeferredColor_Diffuse * diffuse) * fade, 1.0);\n",
1046 " gl_FragData0 = float4(DeferredColor_Ambient * fade, 1.0);\n",
1048 "#ifdef USESPECULAR\n",
1049 " gl_FragData1 = float4(DeferredColor_Specular * (specular * fade), 1.0);\n",
1051 " gl_FragData1 = float4(0.0, 0.0, 0.0, 1.0);\n",
1054 "# ifdef USECUBEFILTER\n",
1055 " float3 cubecolor = texCUBE(Texture_Cube, CubeVector).rgb;\n",
1056 " gl_FragData0.rgb *= cubecolor;\n",
1057 " gl_FragData1.rgb *= cubecolor;\n",
1060 "#endif // FRAGMENT_SHADER\n",
1061 "#else // !MODE_DEFERREDLIGHTSOURCE\n",
1066 "#ifdef VERTEX_SHADER\n",
1069 "float4 gl_Vertex : POSITION,\n",
1070 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
1071 "#if defined(USEVERTEXTEXTUREBLEND) || defined(MODE_VERTEXCOLOR) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n",
1072 "float4 gl_Color : COLOR0,\n",
1074 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
1075 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n",
1076 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n",
1077 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n",
1078 "float4 gl_MultiTexCoord4 : TEXCOORD4,\n",
1080 "uniform float3 EyePosition : register(c24),\n",
1081 "uniform float4x4 TexMatrix : register(c0),\n",
1082 "#ifdef USEVERTEXTEXTUREBLEND\n",
1083 "uniform float4x4 BackgroundTexMatrix : register(c4),\n",
1085 "#ifdef MODE_LIGHTSOURCE\n",
1086 "uniform float4x4 ModelToLight : register(c20),\n",
1088 "#ifdef MODE_LIGHTSOURCE\n",
1089 "uniform float3 LightPosition : register(c27),\n",
1091 "#ifdef MODE_LIGHTDIRECTION\n",
1092 "uniform float3 LightDir : register(c26),\n",
1094 "uniform float4 FogPlane : register(c25),\n",
1095 "#ifdef MODE_DEFERREDLIGHTSOURCE\n",
1096 "uniform float3 LightPosition : register(c27),\n",
1098 "#ifdef USESHADOWMAPORTHO\n",
1099 "uniform float4x4 ShadowMapMatrix : register(c16),\n",
1101 "uniform float ClientTime : register(c2),\n",
1102 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR) || defined(USEALPHAGENVERTEX)\n",
1103 "out float4 gl_FrontColor : COLOR,\n",
1105 "out float4 TexCoordBoth : TEXCOORD0,\n",
1106 "#ifdef USELIGHTMAP\n",
1107 "out float2 TexCoordLightmap : TEXCOORD1,\n",
1109 "#ifdef USEEYEVECTOR\n",
1110 "out float3 EyeVector : TEXCOORD2,\n",
1112 "#ifdef USEREFLECTION\n",
1113 "out float4 ModelViewProjectionPosition : TEXCOORD3,\n",
1116 "out float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n",
1118 "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE) || defined(USEDIFFUSE)\n",
1119 "out float3 LightVector : TEXCOORD1,\n",
1121 "#ifdef MODE_LIGHTSOURCE\n",
1122 "out float3 CubeVector : TEXCOORD3,\n",
1124 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n",
1125 "out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n",
1126 "out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n",
1127 "out float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n",
1129 "#ifdef USESHADOWMAPORTHO\n",
1130 "out float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n",
1132 "out float4 gl_Position : POSITION\n",
1135 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR) || defined(USEALPHAGENVERTEX)\n",
1136 " gl_FrontColor = gl_Color;\n",
1138 " // copy the surface texcoord\n",
1139 " TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n",
1140 "#ifdef USEVERTEXTEXTUREBLEND\n",
1141 " TexCoordBoth.zw = mul(BackgroundTexMatrix, gl_MultiTexCoord0).xy;\n",
1143 "#ifdef USELIGHTMAP\n",
1144 " TexCoordLightmap = gl_MultiTexCoord4.xy;\n",
1147 "#ifdef MODE_LIGHTSOURCE\n",
1148 " // transform vertex position into light attenuation/cubemap space\n",
1149 " // (-1 to +1 across the light box)\n",
1150 " CubeVector = mul(ModelToLight, gl_Vertex).xyz;\n",
1152 "# ifdef USEDIFFUSE\n",
1153 " // transform unnormalized light direction into tangent space\n",
1154 " // (we use unnormalized to ensure that it interpolates correctly and then\n",
1155 " // normalize it per pixel)\n",
1156 " float3 lightminusvertex = LightPosition - gl_Vertex.xyz;\n",
1157 " LightVector = float3(dot(lightminusvertex, gl_MultiTexCoord1.xyz), dot(lightminusvertex, gl_MultiTexCoord2.xyz), dot(lightminusvertex, gl_MultiTexCoord3.xyz));\n",
1161 "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE)\n",
1162 " LightVector = float3(dot(LightDir, gl_MultiTexCoord1.xyz), dot(LightDir, gl_MultiTexCoord2.xyz), dot(LightDir, gl_MultiTexCoord3.xyz));\n",
1165 " // transform unnormalized eye direction into tangent space\n",
1166 "#ifdef USEEYEVECTOR\n",
1167 " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n",
1168 " EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n",
1172 " EyeVectorModelSpaceFogPlaneVertexDist.xyz = EyePosition - gl_Vertex.xyz;\n",
1173 " EyeVectorModelSpaceFogPlaneVertexDist.w = dot(FogPlane, gl_Vertex);\n",
1176 "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n",
1177 " VectorS = gl_MultiTexCoord1.xyz;\n",
1178 " VectorT = gl_MultiTexCoord2.xyz;\n",
1179 " VectorR = gl_MultiTexCoord3.xyz;\n",
1182 " // transform vertex to camera space, using ftransform to match non-VS rendering\n",
1183 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
1185 "#ifdef USESHADOWMAPORTHO\n",
1186 " ShadowMapTC = mul(ShadowMapMatrix, gl_Position).xyz;\n",
1189 "#ifdef USEREFLECTION\n",
1190 " ModelViewProjectionPosition = gl_Position;\n",
1192 "#ifdef USETRIPPY\n",
1193 " gl_Position = TrippyVertex(gl_Position, ClientTime);\n",
1196 "#endif // VERTEX_SHADER\n",
1201 "#ifdef FRAGMENT_SHADER\n",
1204 "#ifdef USEDEFERREDLIGHTMAP\n",
1206 "float2 Pixel : VPOS,\n",
1208 "float2 Pixel : WPOS,\n",
1211 "float4 gl_FrontColor : COLOR,\n",
1212 "float4 TexCoordBoth : TEXCOORD0,\n",
1213 "#ifdef USELIGHTMAP\n",
1214 "float2 TexCoordLightmap : TEXCOORD1,\n",
1216 "#ifdef USEEYEVECTOR\n",
1217 "float3 EyeVector : TEXCOORD2,\n",
1219 "#ifdef USEREFLECTION\n",
1220 "float4 ModelViewProjectionPosition : TEXCOORD3,\n",
1223 "float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n",
1225 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_LIGHTDIRECTION)\n",
1226 "float3 LightVector : TEXCOORD1,\n",
1228 "#ifdef MODE_LIGHTSOURCE\n",
1229 "float3 CubeVector : TEXCOORD3,\n",
1231 "#ifdef MODE_DEFERREDLIGHTSOURCE\n",
1232 "float4 ModelViewPosition : TEXCOORD0,\n",
1234 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n",
1235 "float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n",
1236 "float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n",
1237 "float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n",
1239 "#ifdef USESHADOWMAPORTHO\n",
1240 "float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n",
1243 "uniform sampler Texture_Normal : register(s0),\n",
1244 "uniform sampler Texture_Color : register(s1),\n",
1245 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n",
1246 "uniform sampler Texture_Gloss : register(s2),\n",
1249 "uniform sampler Texture_Glow : register(s3),\n",
1251 "#ifdef USEVERTEXTEXTUREBLEND\n",
1252 "uniform sampler Texture_SecondaryNormal : register(s4),\n",
1253 "uniform sampler Texture_SecondaryColor : register(s5),\n",
1254 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n",
1255 "uniform sampler Texture_SecondaryGloss : register(s6),\n",
1258 "uniform sampler Texture_SecondaryGlow : register(s7),\n",
1261 "#ifdef USECOLORMAPPING\n",
1262 "uniform sampler Texture_Pants : register(s4),\n",
1263 "uniform sampler Texture_Shirt : register(s7),\n",
1266 "uniform sampler Texture_FogHeightTexture : register(s14),\n",
1267 "uniform sampler Texture_FogMask : register(s8),\n",
1269 "#ifdef USELIGHTMAP\n",
1270 "uniform sampler Texture_Lightmap : register(s9),\n",
1272 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE)\n",
1273 "uniform sampler Texture_Deluxemap : register(s10),\n",
1275 "#ifdef USEREFLECTION\n",
1276 "uniform sampler Texture_Reflection : register(s7),\n",
1279 "#ifdef MODE_DEFERREDLIGHTSOURCE\n",
1280 "uniform sampler Texture_ScreenDepth : register(s13),\n",
1281 "uniform sampler Texture_ScreenNormalMap : register(s14),\n",
1283 "#ifdef USEDEFERREDLIGHTMAP\n",
1284 "uniform sampler Texture_ScreenDepth : register(s13),\n",
1285 "uniform sampler Texture_ScreenNormalMap : register(s14),\n",
1286 "uniform sampler Texture_ScreenDiffuse : register(s11),\n",
1287 "uniform sampler Texture_ScreenSpecular : register(s12),\n",
1290 "#ifdef USECOLORMAPPING\n",
1291 "uniform half3 Color_Pants : register(c7),\n",
1292 "uniform half3 Color_Shirt : register(c8),\n",
1295 "uniform float3 FogColor : register(c16),\n",
1296 "uniform float FogRangeRecip : register(c20),\n",
1297 "uniform float FogPlaneViewDist : register(c19),\n",
1298 "uniform float FogHeightFade : register(c17),\n",
1301 "#ifdef USEOFFSETMAPPING\n",
1302 "uniform float4 OffsetMapping_ScaleSteps : register(c24),\n",
1303 "uniform float OffsetMapping_Bias : register(c54),\n",
1306 "#ifdef USEDEFERREDLIGHTMAP\n",
1307 "uniform half2 PixelToScreenTexCoord : register(c42),\n",
1308 "uniform half3 DeferredMod_Diffuse : register(c12),\n",
1309 "uniform half3 DeferredMod_Specular : register(c13),\n",
1311 "uniform half3 Color_Ambient : register(c3),\n",
1312 "uniform half3 Color_Diffuse : register(c4),\n",
1313 "uniform half3 Color_Specular : register(c5),\n",
1314 "uniform half SpecularPower : register(c36),\n",
1316 "uniform half3 Color_Glow : register(c6),\n",
1318 "uniform half Alpha : register(c0),\n",
1319 "#ifdef USEREFLECTION\n",
1320 "uniform float4 DistortScaleRefractReflect : register(c14),\n",
1321 "uniform float4 ScreenScaleRefractReflect : register(c32),\n",
1322 "uniform float4 ScreenCenterRefractReflect : register(c31),\n",
1323 "uniform half4 ReflectColor : register(c26),\n",
1325 "#ifdef USEREFLECTCUBE\n",
1326 "uniform float4x4 ModelToReflectCube : register(c48),\n",
1327 "uniform sampler Texture_ReflectMask : register(s5),\n",
1328 "uniform samplerCUBE Texture_ReflectCube : register(s6),\n",
1330 "#ifdef MODE_LIGHTDIRECTION\n",
1331 "uniform half3 LightColor : register(c21),\n",
1333 "#ifdef MODE_LIGHTSOURCE\n",
1334 "uniform half3 LightColor : register(c21),\n",
1337 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE)\n",
1338 "uniform sampler Texture_Attenuation : register(s9),\n",
1339 "uniform samplerCUBE Texture_Cube : register(s10),\n",
1342 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n",
1344 "#ifdef USESHADOWMAP2D\n",
1345 "# ifdef USESHADOWSAMPLER\n",
1346 "uniform sampler Texture_ShadowMap2D : register(s15),\n",
1348 "uniform sampler Texture_ShadowMap2D : register(s15),\n",
1352 "#ifdef USESHADOWMAPVSDCT\n",
1353 "uniform samplerCUBE Texture_CubeProjection : register(s12),\n",
1356 "#if defined(USESHADOWMAP2D)\n",
1357 "uniform float2 ShadowMap_TextureScale : register(c35),\n",
1358 "uniform float4 ShadowMap_Parameters : register(c34),\n",
1360 "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n",
1362 "out float4 dp_FragColor : COLOR\n",
1365 " float2 TexCoord = TexCoordBoth.xy;\n",
1366 "#ifdef USEVERTEXTEXTUREBLEND\n",
1367 " float2 TexCoord2 = TexCoordBoth.zw;\n",
1369 "#ifdef USEOFFSETMAPPING\n",
1370 " // apply offsetmapping\n",
1371 " float2 dPdx = ddx(TexCoord);\n",
1372 " float2 dPdy = ddy(TexCoord);\n",
1373 " float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, OffsetMapping_Bias, OffsetMapping_LodDistance, EyeVector, Texture_Normal, dPdx, dPdy);\n",
1374 "# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n",
1376 "# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n",
1379 " // combine the diffuse textures (base, pants, shirt)\n",
1380 " half4 color = half4(offsetMappedTexture2D(Texture_Color));\n",
1381 "#ifdef USEALPHAKILL\n",
1382 " if (color.a < 0.5)\n",
1385 " color.a *= Alpha;\n",
1386 "#ifdef USECOLORMAPPING\n",
1387 " color.rgb += half3(offsetMappedTexture2D(Texture_Pants).rgb) * Color_Pants + half3(offsetMappedTexture2D(Texture_Shirt).rgb) * Color_Shirt;\n",
1389 "#ifdef USEVERTEXTEXTUREBLEND\n",
1390 "#ifdef USEBOTHALPHAS\n",
1391 " half4 color2 = half4(tex2D(Texture_SecondaryColor, TexCoord2));\n",
1392 " half terrainblend = clamp(half(gl_FrontColor.a) * color.a, half(1.0 - color2.a), half(1.0));\n",
1393 " color.rgb = lerp(color2.rgb, color.rgb, terrainblend);\n",
1395 " half terrainblend = clamp(half(gl_FrontColor.a) * color.a * 2.0 - 0.5, half(0.0), half(1.0));\n",
1396 " //half terrainblend = min(half(gl_FrontColor.a) * color.a * 2.0, half(1.0));\n",
1397 " //half terrainblend = half(gl_FrontColor.a) * color.a > 0.5;\n",
1398 " color.rgb = half3(lerp(tex2D(Texture_SecondaryColor, TexCoord2).rgb, float3(color.rgb), terrainblend));\n",
1399 " color.a = 1.0;\n",
1400 " //color = half4(lerp(float4(1, 0, 0, 1), color, terrainblend));\n",
1403 "#ifdef USEALPHAGENVERTEX\n",
1404 " color.a *= gl_FrontColor.a;\n",
1407 " // get the surface normal\n",
1408 "#ifdef USEVERTEXTEXTUREBLEND\n",
1409 " half3 surfacenormal = normalize(half3(lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, offsetMappedTexture2D(Texture_Normal).rgb, terrainblend)) - half3(0.5, 0.5, 0.5));\n",
1411 " half3 surfacenormal = half3(normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5, 0.5, 0.5)));\n",
1414 " // get the material colors\n",
1415 " half3 diffusetex = color.rgb;\n",
1416 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n",
1417 "# ifdef USEVERTEXTEXTUREBLEND\n",
1418 " half4 glosstex = half4(lerp(tex2D(Texture_SecondaryGloss, TexCoord2), offsetMappedTexture2D(Texture_Gloss), terrainblend));\n",
1420 " half4 glosstex = half4(offsetMappedTexture2D(Texture_Gloss));\n",
1424 "#ifdef USEREFLECTCUBE\n",
1425 " float3 TangentReflectVector = reflect(-EyeVector, surfacenormal);\n",
1426 " float3 ModelReflectVector = TangentReflectVector.x * VectorS + TangentReflectVector.y * VectorT + TangentReflectVector.z * VectorR;\n",
1427 " float3 ReflectCubeTexCoord = mul(ModelToReflectCube, float4(ModelReflectVector, 0)).xyz;\n",
1428 " diffusetex += half3(offsetMappedTexture2D(Texture_ReflectMask).rgb) * half3(texCUBE(Texture_ReflectCube, ReflectCubeTexCoord).rgb);\n",
1434 "#ifdef MODE_LIGHTSOURCE\n",
1435 " // light source\n",
1436 "#ifdef USEDIFFUSE\n",
1437 " half3 lightnormal = half3(normalize(LightVector));\n",
1438 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n",
1439 " color.rgb = diffusetex * (Color_Ambient + diffuse * Color_Diffuse);\n",
1440 "#ifdef USESPECULAR\n",
1441 "#ifdef USEEXACTSPECULARMATH\n",
1442 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), 1.0 + SpecularPower * glosstex.a));\n",
1444 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n",
1445 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * glosstex.a));\n",
1447 " color.rgb += glosstex.rgb * (specular * Color_Specular);\n",
1450 " color.rgb = diffusetex * Color_Ambient;\n",
1452 " color.rgb *= LightColor;\n",
1453 " color.rgb *= half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n",
1454 "#if defined(USESHADOWMAP2D)\n",
1455 " color.rgb *= half(ShadowMapCompare(CubeVector, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n",
1456 "#ifdef USESHADOWMAPVSDCT\n",
1457 ", Texture_CubeProjection\n",
1462 "# ifdef USECUBEFILTER\n",
1463 " color.rgb *= half3(texCUBE(Texture_Cube, CubeVector).rgb);\n",
1466 "#ifdef USESHADOWMAP2D\n",
1467 "#ifdef USESHADOWMAPVSDCT\n",
1468 "// float3 shadowmaptc = GetShadowMapTC2D(CubeVector, ShadowMap_Parameters, Texture_CubeProjection);\n",
1470 "// float3 shadowmaptc = GetShadowMapTC2D(CubeVector, ShadowMap_Parameters);\n",
1472 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n",
1473 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale).rgb);\n",
1474 "// color.rgb = half3(shadowmaptc.xyz * float3(ShadowMap_TextureScale,1.0));\n",
1475 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n",
1476 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n",
1477 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale).rgb);\n",
1478 "// color.rgb = half3(shadowmaptc.xyz * float3(ShadowMap_TextureScale,1.0));\n",
1479 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n",
1480 "// color.r = half(shadowmaptc.z - texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n",
1481 "// color.r = half(shadowmaptc.z);\n",
1482 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n",
1483 "// color.r = half(shadowmaptc.z);\n",
1484 "// color.r = 1;\n",
1485 "// color.rgb = abs(CubeVector);\n",
1487 "// color.rgb = half3(1,1,1);\n",
1488 "#endif // MODE_LIGHTSOURCE\n",
1493 "#ifdef MODE_LIGHTDIRECTION\n",
1494 " #define SHADING\n",
1495 " #ifdef USEDIFFUSE\n",
1496 " half3 lightnormal = half3(normalize(LightVector));\n",
1498 " #define lightcolor LightColor\n",
1499 "#endif // MODE_LIGHTDIRECTION\n",
1500 "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n",
1501 " #define SHADING\n",
1502 " // deluxemap lightmapping using light vectors in modelspace (q3map2 -light -deluxe)\n",
1503 " half3 lightnormal_modelspace = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n",
1504 " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n",
1505 " // convert modelspace light vector to tangentspace\n",
1506 " half3 lightnormal = half3(dot(lightnormal_modelspace, half3(VectorS)), dot(lightnormal_modelspace, half3(VectorT)), dot(lightnormal_modelspace, half3(VectorR)));\n",
1507 " // calculate directional shading (and undoing the existing angle attenuation on the lightmap by the division)\n",
1508 " // note that q3map2 is too stupid to calculate proper surface normals when q3map_nonplanar\n",
1509 " // is used (the lightmap and deluxemap coords correspond to virtually random coordinates\n",
1510 " // on that luxel, and NOT to its center, because recursive triangle subdivision is used\n",
1511 " // to map the luxels to coordinates on the draw surfaces), which also causes\n",
1512 " // deluxemaps to be wrong because light contributions from the wrong side of the surface\n",
1513 " // are added up. To prevent divisions by zero or strong exaggerations, a max()\n",
1514 " // nudge is done here at expense of some additional fps. This is ONLY needed for\n",
1515 " // deluxemaps, tangentspace deluxemap avoid this problem by design.\n",
1516 " lightcolor *= 1.0 / max(0.25, lightnormal.z);\n",
1517 "#endif // MODE_LIGHTDIRECTIONMAP_MODELSPACE\n",
1518 "#ifdef MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n",
1519 " #define SHADING\n",
1520 " // deluxemap lightmapping using light vectors in tangentspace (hmap2 -light)\n",
1521 " half3 lightnormal = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n",
1522 " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n",
1524 "#if defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n",
1525 " #define SHADING\n",
1526 " // forced deluxemap on lightmapped/vertexlit surfaces\n",
1527 " half3 lightnormal = half3(0.0, 0.0, 1.0);\n",
1528 " #ifdef USELIGHTMAP\n",
1529 " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n",
1531 " half3 lightcolor = half3(gl_FrontColor.rgb);\n",
1534 "#ifdef MODE_FAKELIGHT\n",
1535 " #define SHADING\n",
1536 " half3 lightnormal = half3(normalize(EyeVector));\n",
1537 " half3 lightcolor = half3(1.0,1.0,1.0);\n",
1538 "#endif // MODE_FAKELIGHT\n",
1543 "#ifdef MODE_LIGHTMAP\n",
1544 " color.rgb = diffusetex * (Color_Ambient + half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb) * Color_Diffuse);\n",
1545 "#endif // MODE_LIGHTMAP\n",
1546 "#ifdef MODE_VERTEXCOLOR\n",
1547 " color.rgb = diffusetex * (Color_Ambient + half3(gl_FrontColor.rgb) * Color_Diffuse);\n",
1548 "#endif // MODE_VERTEXCOLOR\n",
1549 "#ifdef MODE_FLATCOLOR\n",
1550 " color.rgb = diffusetex * Color_Ambient;\n",
1551 "#endif // MODE_FLATCOLOR\n",
1557 "# ifdef USEDIFFUSE\n",
1558 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n",
1559 "# ifdef USESPECULAR\n",
1560 "# ifdef USEEXACTSPECULARMATH\n",
1561 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), 1.0 + SpecularPower * glosstex.a));\n",
1563 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n",
1564 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * glosstex.a));\n",
1566 " color.rgb = diffusetex * Color_Ambient + (diffusetex * Color_Diffuse * diffuse + glosstex.rgb * Color_Specular * specular) * lightcolor;\n",
1568 " color.rgb = diffusetex * (Color_Ambient + Color_Diffuse * diffuse * lightcolor);\n",
1571 " color.rgb = diffusetex * Color_Ambient;\n",
1575 "#ifdef USESHADOWMAPORTHO\n",
1576 " color.rgb *= half(ShadowMapCompare(ShadowMapTC, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale));\n",
1579 "#ifdef USEDEFERREDLIGHTMAP\n",
1580 " float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n",
1581 " color.rgb += diffusetex * half3(tex2D(Texture_ScreenDiffuse, ScreenTexCoord).rgb) * DeferredMod_Diffuse;\n",
1582 " color.rgb += glosstex.rgb * half3(tex2D(Texture_ScreenSpecular, ScreenTexCoord).rgb) * DeferredMod_Specular;\n",
1583 "// color.rgb = half3(tex2D(Texture_ScreenDepth, ScreenTexCoord).rgb);\n",
1584 "// color.r = half(texDepth2D(Texture_ScreenDepth, ScreenTexCoord)) * 1.0;\n",
1588 "#ifdef USEVERTEXTEXTUREBLEND\n",
1589 " color.rgb += half3(lerp(tex2D(Texture_SecondaryGlow, TexCoord2).rgb, offsetMappedTexture2D(Texture_Glow).rgb, terrainblend)) * Color_Glow;\n",
1591 " color.rgb += half3(offsetMappedTexture2D(Texture_Glow).rgb) * Color_Glow;\n",
1596 " color.rgb = half3(FogVertex(color, FogColor, EyeVectorModelSpaceFogPlaneVertexDist.xyz, EyeVectorModelSpaceFogPlaneVertexDist.w, FogRangeRecip, FogPlaneViewDist, FogHeightFade, Texture_FogMask, Texture_FogHeightTexture));\n",
1599 " // 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",
1600 "#ifdef USEREFLECTION\n",
1601 " float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n",
1602 " //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
1603 " float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW.zw + ScreenCenterRefractReflect.zw;\n",
1604 " float2 ScreenTexCoord = SafeScreenTexCoord + float3(normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5,0.5,0.5))).xy * DistortScaleRefractReflect.zw;\n",
1605 " // FIXME temporary hack to detect the case that the reflection\n",
1606 " // gets blackened at edges due to leaving the area that contains actual\n",
1608 " // Remove this 'ack once we have a better way to stop this thing from\n",
1610 " float f = min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(0.01, 0.01)).rgb) / 0.05);\n",
1611 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(0.01, -0.01)).rgb) / 0.05);\n",
1612 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, 0.01)).rgb) / 0.05);\n",
1613 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, -0.01)).rgb) / 0.05);\n",
1614 " ScreenTexCoord = lerp(SafeScreenTexCoord, ScreenTexCoord, f);\n",
1615 " color.rgb = lerp(color.rgb, half3(tex2D(Texture_Reflection, ScreenTexCoord).rgb) * ReflectColor.rgb, ReflectColor.a);\n",
1618 " dp_FragColor = float4(color);\n",
1620 "#endif // FRAGMENT_SHADER\n",
1622 "#endif // !MODE_DEFERREDLIGHTSOURCE\n",
1623 "#endif // !MODE_DEFERREDGEOMETRY\n",
1624 "#endif // !MODE_WATER\n",
1625 "#endif // !MODE_REFRACTION\n",
1626 "#endif // !MODE_BLOOMBLUR\n",
1627 "#endif // !MODE_GENERIC\n",
1628 "#endif // !MODE_POSTPROCESS\n",
1629 "#endif // !MODE_DEPTH_OR_SHADOW\n",