1 "// ambient+diffuse+specular+normalmap+attenuation+cubemap+fog shader\n",
2 "// written by Forest 'LordHavoc' Hale\n",
3 "// shadowmapping enhancements by Lee 'eihrul' Salzman\n",
5 "// FIXME: we need to get rid of ModelViewProjectionPosition to make room for the texcoord for this\n",
6 "#if defined(USEREFLECTION)\n",
7 "#undef USESHADOWMAPORTHO\n",
10 "#if defined(USEFOGINSIDE) || defined(USEFOGOUTSIDE) || defined(USEFOGHEIGHTTEXTURE)\n",
13 "#if defined(MODE_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP)\n",
14 "#define USELIGHTMAP\n",
16 "#if defined(USESPECULAR) || defined(USEOFFSETMAPPING) || defined(USEREFLECTCUBE) || defined(MODE_FAKELIGHT)\n",
17 "#define USEEYEVECTOR\n",
20 "#ifdef FRAGMENT_SHADER\n",
22 "//#undef USESHADOWMAPPCF\n",
23 "//#define texDepth2D(tex,texcoord) tex2D(tex,texcoord).r\n",
24 "#define texDepth2D(tex,texcoord) dot(tex2D(tex,texcoord).rgb, float3(1.0, 255.0/65536.0, 255.0/16777216.0))\n",
26 "#define texDepth2D(tex,texcoord) tex2D(tex,texcoord).r\n",
30 "#ifdef VERTEX_SHADER\n",
32 "// LordHavoc: based on shader code linked at: http://www.youtube.com/watch?v=JpksyojwqzE\n",
34 "float4 TrippyVertex(float4 position)\n",
36 "uniform float ClientTime : register(c2)\n",
39 " float worldTime = ClientTime;\n",
40 " // tweaked for Quake\n",
41 " worldTime *= 10.0;\n",
42 " position *= 0.125;\n",
43 " //~tweaked for Quake\n",
44 " float distanceSquared = (position.x * position.x + position.z * position.z);\n",
45 " position.y += 5.0*sin(distanceSquared*sin(worldTime/143.0)/1000.0);\n",
46 " float y = position.y;\n",
47 " float x = position.x;\n",
48 " float om = sin(distanceSquared*sin(worldTime/256.0)/5000.0) * sin(worldTime/200.0);\n",
49 " position.y = x*sin(om)+y*cos(om);\n",
50 " position.x = x*cos(om)-y*sin(om);\n",
51 " return position;\n",
56 "#ifdef MODE_DEPTH_OR_SHADOW\n",
57 "#ifdef VERTEX_SHADER\n",
60 "float4 gl_Vertex : POSITION,\n",
61 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
62 "out float4 gl_Position : POSITION,\n",
63 "out float Depth : TEXCOORD0\n",
66 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
68 " gl_Position = TrippyVertex(gl_Position);\n",
70 " Depth = gl_Position.z;\n",
74 "#ifdef FRAGMENT_SHADER\n",
77 "float Depth : TEXCOORD0,\n",
78 "out float4 dp_FragColor : COLOR\n",
81 "// float4 temp = float4(Depth,Depth*(65536.0/255.0),Depth*(16777216.0/255.0),0.0);\n",
82 " float4 temp = float4(Depth,Depth*256.0,Depth*65536.0,0.0);\n",
83 " temp.yz -= floor(temp.yz);\n",
84 " dp_FragColor = temp;\n",
85 "// dp_FragColor = float4(Depth,0,0,0);\n",
88 "#else // !MODE_DEPTH_OR_SHADOW\n",
93 "#ifdef MODE_POSTPROCESS\n",
95 "#ifdef VERTEX_SHADER\n",
98 "float4 gl_Vertex : POSITION,\n",
99 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
100 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
101 "float4 gl_MultiTexCoord4 : TEXCOORD4,\n",
102 "out float4 gl_Position : POSITION,\n",
103 "out float2 TexCoord1 : TEXCOORD0,\n",
104 "out float2 TexCoord2 : TEXCOORD1\n",
107 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
108 " TexCoord1 = gl_MultiTexCoord0.xy;\n",
110 " TexCoord2 = gl_MultiTexCoord4.xy;\n",
115 "#ifdef FRAGMENT_SHADER\n",
118 "float2 TexCoord1 : TEXCOORD0,\n",
119 "float2 TexCoord2 : TEXCOORD1,\n",
120 "uniform sampler Texture_First : register(s0),\n",
122 "uniform sampler Texture_Second : register(s1),\n",
124 "#ifdef USEGAMMARAMPS\n",
125 "uniform sampler Texture_GammaRamps : register(s2),\n",
127 "#ifdef USESATURATION\n",
128 "uniform float Saturation : register(c30),\n",
130 "#ifdef USEVIEWTINT\n",
131 "uniform float4 ViewTintColor : register(c41),\n",
133 "uniform float4 UserVec1 : register(c37),\n",
134 "uniform float4 UserVec2 : register(c38),\n",
135 "uniform float4 UserVec3 : register(c39),\n",
136 "uniform float4 UserVec4 : register(c40),\n",
137 "uniform float ClientTime : register(c2),\n",
138 "uniform float2 PixelSize : register(c25),\n",
139 "uniform float4 BloomColorSubtract : register(c43),\n",
140 "out float4 dp_FragColor : COLOR\n",
143 " dp_FragColor = tex2D(Texture_First, TexCoord1);\n",
145 "#ifdef USEPOSTPROCESSING\n",
146 "// do r_glsl_dumpshader, edit glsl/default.glsl, and replace this by your own postprocessing if you want\n",
147 "// 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",
148 " float sobel = 1.0;\n",
149 " // float2 ts = textureSize(Texture_First, 0);\n",
150 " // float2 px = float2(1/ts.x, 1/ts.y);\n",
151 " float2 px = PixelSize;\n",
152 " float3 x1 = tex2D(Texture_First, TexCoord1 + float2(-px.x, px.y)).rgb;\n",
153 " float3 x2 = tex2D(Texture_First, TexCoord1 + float2(-px.x, 0.0)).rgb;\n",
154 " float3 x3 = tex2D(Texture_First, TexCoord1 + float2(-px.x,-px.y)).rgb;\n",
155 " float3 x4 = tex2D(Texture_First, TexCoord1 + float2( px.x, px.y)).rgb;\n",
156 " float3 x5 = tex2D(Texture_First, TexCoord1 + float2( px.x, 0.0)).rgb;\n",
157 " float3 x6 = tex2D(Texture_First, TexCoord1 + float2( px.x,-px.y)).rgb;\n",
158 " float3 y1 = tex2D(Texture_First, TexCoord1 + float2( px.x,-px.y)).rgb;\n",
159 " float3 y2 = tex2D(Texture_First, TexCoord1 + float2( 0.0,-px.y)).rgb;\n",
160 " float3 y3 = tex2D(Texture_First, TexCoord1 + float2(-px.x,-px.y)).rgb;\n",
161 " float3 y4 = tex2D(Texture_First, TexCoord1 + float2( px.x, px.y)).rgb;\n",
162 " float3 y5 = tex2D(Texture_First, TexCoord1 + float2( 0.0, px.y)).rgb;\n",
163 " float3 y6 = tex2D(Texture_First, TexCoord1 + float2(-px.x, px.y)).rgb;\n",
164 " float px1 = -1.0 * dot(float3(0.3, 0.59, 0.11), x1);\n",
165 " float px2 = -2.0 * dot(float3(0.3, 0.59, 0.11), x2);\n",
166 " float px3 = -1.0 * dot(float3(0.3, 0.59, 0.11), x3);\n",
167 " float px4 = 1.0 * dot(float3(0.3, 0.59, 0.11), x4);\n",
168 " float px5 = 2.0 * dot(float3(0.3, 0.59, 0.11), x5);\n",
169 " float px6 = 1.0 * dot(float3(0.3, 0.59, 0.11), x6);\n",
170 " float py1 = -1.0 * dot(float3(0.3, 0.59, 0.11), y1);\n",
171 " float py2 = -2.0 * dot(float3(0.3, 0.59, 0.11), y2);\n",
172 " float py3 = -1.0 * dot(float3(0.3, 0.59, 0.11), y3);\n",
173 " float py4 = 1.0 * dot(float3(0.3, 0.59, 0.11), y4);\n",
174 " float py5 = 2.0 * dot(float3(0.3, 0.59, 0.11), y5);\n",
175 " float py6 = 1.0 * dot(float3(0.3, 0.59, 0.11), y6);\n",
176 " sobel = 0.25 * abs(px1 + px2 + px3 + px4 + px5 + px6) + 0.25 * abs(py1 + py2 + py3 + py4 + py5 + py6);\n",
177 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.987688, -0.156434)) * UserVec1.y;\n",
178 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.156434, -0.891007)) * UserVec1.y;\n",
179 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2( 0.891007, -0.453990)) * UserVec1.y;\n",
180 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2( 0.707107, 0.707107)) * UserVec1.y;\n",
181 " dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.453990, 0.891007)) * UserVec1.y;\n",
182 " dp_FragColor /= (1.0 + 5.0 * UserVec1.y);\n",
183 " dp_FragColor.rgb = dp_FragColor.rgb * (1.0 + UserVec2.x) + float3(1,1,1)*max(0.0, sobel - UserVec2.z)*UserVec2.y;\n",
187 " dp_FragColor += max(float4(0,0,0,0), tex2D(Texture_Second, TexCoord2) - BloomColorSubtract);\n",
190 "#ifdef USEVIEWTINT\n",
191 " dp_FragColor = lerp(dp_FragColor, ViewTintColor, ViewTintColor.a);\n",
194 "#ifdef USESATURATION\n",
195 " //apply saturation BEFORE gamma ramps, so v_glslgamma value does not matter\n",
196 " float y = dot(dp_FragColor.rgb, float3(0.299, 0.587, 0.114));\n",
197 " // 'vampire sight' effect, wheres red is compensated\n",
198 " #ifdef SATURATION_REDCOMPENSATE\n",
199 " float rboost = max(0.0, (dp_FragColor.r - max(dp_FragColor.g, dp_FragColor.b))*(1.0 - Saturation));\n",
200 " dp_FragColor.rgb = lerp(float3(y,y,y), dp_FragColor.rgb, Saturation);\n",
201 " dp_FragColor.r += r;\n",
203 " // normal desaturation\n",
204 " //dp_FragColor = float3(y,y,y) + (dp_FragColor.rgb - float3(y)) * Saturation;\n",
205 " dp_FragColor.rgb = lerp(float3(y,y,y), dp_FragColor.rgb, Saturation);\n",
209 "#ifdef USEGAMMARAMPS\n",
210 " dp_FragColor.r = tex2D(Texture_GammaRamps, float2(dp_FragColor.r, 0)).r;\n",
211 " dp_FragColor.g = tex2D(Texture_GammaRamps, float2(dp_FragColor.g, 0)).g;\n",
212 " dp_FragColor.b = tex2D(Texture_GammaRamps, float2(dp_FragColor.b, 0)).b;\n",
216 "#else // !MODE_POSTPROCESS\n",
221 "#ifdef MODE_GENERIC\n",
222 "#ifdef VERTEX_SHADER\n",
225 "float4 gl_Vertex : POSITION,\n",
226 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
227 "float4 gl_Color : COLOR0,\n",
228 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
229 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n",
230 "out float4 gl_Position : POSITION,\n",
231 "#ifdef USEDIFFUSE\n",
232 "out float2 TexCoord1 : TEXCOORD0,\n",
234 "#ifdef USESPECULAR\n",
235 "out float2 TexCoord2 : TEXCOORD1,\n",
237 "out float4 gl_FrontColor : COLOR\n",
240 " gl_FrontColor = gl_Color;\n",
241 "#ifdef USEDIFFUSE\n",
242 " TexCoord1 = gl_MultiTexCoord0.xy;\n",
244 "#ifdef USESPECULAR\n",
245 " TexCoord2 = gl_MultiTexCoord1.xy;\n",
247 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
248 "#ifdef USETRIPPY\n",
249 " gl_Position = TrippyVertex(gl_Position);\n",
254 "#ifdef FRAGMENT_SHADER\n",
258 "float4 gl_FrontColor : COLOR0,\n",
259 "float2 TexCoord1 : TEXCOORD0,\n",
260 "float2 TexCoord2 : TEXCOORD1,\n",
261 "#ifdef USEDIFFUSE\n",
262 "uniform sampler Texture_First : register(s0),\n",
264 "#ifdef USESPECULAR\n",
265 "uniform sampler Texture_Second : register(s1),\n",
267 "#ifdef USEGAMMARAMPS\n",
268 "uniform sampler Texture_GammaRamps : register(s2),\n",
270 "uniform half Alpha : register(c0),\n",
271 "out float4 dp_FragColor : COLOR\n",
274 "#ifdef USEVIEWTINT\n",
275 " dp_FragColor = gl_FrontColor;\n",
277 " dp_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n",
279 "#ifdef USEDIFFUSE\n",
280 "# ifdef USEREFLECTCUBE\n",
281 " // suppress texture alpha\n",
282 " dp_FragColor.rgb *= tex2D(Texture_First, TexCoord1).rgb;\n",
284 " dp_FragColor *= tex2D(Texture_First, TexCoord1);\n",
288 "#ifdef USESPECULAR\n",
289 " float4 tex2 = tex2D(Texture_Second, TexCoord2);\n",
290 "# ifdef USECOLORMAPPING\n",
291 " dp_FragColor *= tex2;\n",
294 " dp_FragColor += tex2;\n",
296 "# ifdef USEVERTEXTEXTUREBLEND\n",
297 " dp_FragColor = lerp(dp_FragColor, tex2, tex2.a);\n",
300 "#ifdef USEGAMMARAMPS\n",
301 " dp_FragColor.r = tex2D(Texture_GammaRamps, vec2(dp_FragColor.r, 0)).r;\n",
302 " dp_FragColor.g = tex2D(Texture_GammaRamps, vec2(dp_FragColor.g, 0)).g;\n",
303 " dp_FragColor.b = tex2D(Texture_GammaRamps, vec2(dp_FragColor.b, 0)).b;\n",
305 "#ifdef USEALPHAKILL\n",
306 " dp_FragColor.a *= Alpha;\n",
310 "#else // !MODE_GENERIC\n",
315 "#ifdef MODE_BLOOMBLUR\n",
316 "#ifdef VERTEX_SHADER\n",
319 "float4 gl_Vertex : POSITION,\n",
320 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
321 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
322 "out float4 gl_Position : POSITION,\n",
323 "out float2 TexCoord : TEXCOORD0\n",
326 " TexCoord = gl_MultiTexCoord0.xy;\n",
327 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
331 "#ifdef FRAGMENT_SHADER\n",
335 "float2 TexCoord : TEXCOORD0,\n",
336 "uniform sampler Texture_First : register(s0),\n",
337 "uniform float4 BloomBlur_Parameters : register(c1),\n",
338 "out float4 dp_FragColor : COLOR\n",
342 " float2 tc = TexCoord;\n",
343 " float3 color = tex2D(Texture_First, tc).rgb;\n",
344 " tc += BloomBlur_Parameters.xy;\n",
345 " for (i = 1;i < SAMPLES;i++)\n",
347 " color += tex2D(Texture_First, tc).rgb;\n",
348 " tc += BloomBlur_Parameters.xy;\n",
350 " dp_FragColor = float4(color * BloomBlur_Parameters.z + float3(BloomBlur_Parameters.w), 1);\n",
353 "#else // !MODE_BLOOMBLUR\n",
354 "#ifdef MODE_REFRACTION\n",
355 "#ifdef VERTEX_SHADER\n",
358 "float4 gl_Vertex : POSITION,\n",
359 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
360 "#ifdef USEALPHAGENVERTEX\n",
361 "float4 gl_Color : COLOR0,\n",
363 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
364 "uniform float4x4 TexMatrix : register(c0),\n",
365 "uniform float3 EyePosition : register(c24),\n",
366 "#ifdef USEALPHAGENVERTEX\n",
367 "out float4 gl_FrontColor : COLOR,\n",
369 "out float4 gl_Position : POSITION,\n",
370 "out float2 TexCoord : TEXCOORD0,\n",
371 "out float3 EyeVector : TEXCOORD1,\n",
372 "out float4 ModelViewProjectionPosition : TEXCOORD2\n",
375 "#ifdef USEALPHAGENVERTEX\n",
376 " gl_FrontColor = gl_Color;\n",
378 " TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n",
379 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
380 " ModelViewProjectionPosition = gl_Position;\n",
381 "#ifdef USETRIPPY\n",
382 " gl_Position = TrippyVertex(gl_Position);\n",
387 "#ifdef FRAGMENT_SHADER\n",
390 "#ifdef USEALPHAGENVERTEX\n",
391 "float4 gl_FrontColor : COLOR,\n",
393 "float2 TexCoord : TEXCOORD0,\n",
394 "float3 EyeVector : TEXCOORD1,\n",
395 "float4 ModelViewProjectionPosition : TEXCOORD2,\n",
396 "uniform sampler Texture_Normal : register(s0),\n",
397 "uniform sampler Texture_Refraction : register(s3),\n",
398 "uniform sampler Texture_Reflection : register(s7),\n",
399 "uniform float4 DistortScaleRefractReflect : register(c14),\n",
400 "uniform float4 ScreenScaleRefractReflect : register(c32),\n",
401 "uniform float4 ScreenCenterRefractReflect : register(c31),\n",
402 "uniform float4 RefractColor : register(c29),\n",
403 "out float4 dp_FragColor : COLOR\n",
406 " float2 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect.xy * (1.0 / ModelViewProjectionPosition.w);\n",
407 " //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",
408 " float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n",
409 "#ifdef USEALPHAGENVERTEX\n",
410 " float2 distort = DistortScaleRefractReflect.xy * gl_FrontColor.a;\n",
411 " float4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), gl_FrontColor.a);\n",
413 " float2 distort = DistortScaleRefractReflect.xy;\n",
414 " float4 refractcolor = RefractColor;\n",
416 " float2 ScreenTexCoord = SafeScreenTexCoord + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy * distort;\n",
417 " // FIXME temporary hack to detect the case that the reflection\n",
418 " // gets blackened at edges due to leaving the area that contains actual\n",
420 " // Remove this 'ack once we have a better way to stop this thing from\n",
422 " float f = min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(0.01, 0.01)).rgb) / 0.05);\n",
423 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(0.01, -0.01)).rgb) / 0.05);\n",
424 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(-0.01, 0.01)).rgb) / 0.05);\n",
425 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(-0.01, -0.01)).rgb) / 0.05);\n",
426 " ScreenTexCoord = lerp(SafeScreenTexCoord, ScreenTexCoord, f);\n",
427 " dp_FragColor = float4(tex2D(Texture_Refraction, ScreenTexCoord).rgb, 1) * refractcolor;\n",
430 "#else // !MODE_REFRACTION\n",
435 "#ifdef MODE_WATER\n",
436 "#ifdef VERTEX_SHADER\n",
440 "float4 gl_Vertex : POSITION,\n",
441 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
442 "#ifdef USEALPHAGENVERTEX\n",
443 "float4 gl_Color : COLOR0,\n",
445 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
446 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n",
447 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n",
448 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n",
449 "uniform float4x4 TexMatrix : register(c0),\n",
450 "uniform float3 EyePosition : register(c24),\n",
451 "#ifdef USEALPHAGENVERTEX\n",
452 "out float4 gl_FrontColor : COLOR,\n",
454 "out float4 gl_Position : POSITION,\n",
455 "out float2 TexCoord : TEXCOORD0,\n",
456 "out float3 EyeVector : TEXCOORD1,\n",
457 "out float4 ModelViewProjectionPosition : TEXCOORD2\n",
460 "#ifdef USEALPHAGENVERTEX\n",
461 " gl_FrontColor = gl_Color;\n",
463 " TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n",
464 " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n",
465 " EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n",
466 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
467 " ModelViewProjectionPosition = gl_Position;\n",
468 "#ifdef USETRIPPY\n",
469 " gl_Position = TrippyVertex(gl_Position);\n",
474 "#ifdef FRAGMENT_SHADER\n",
477 "#ifdef USEALPHAGENVERTEX\n",
478 "float4 gl_FrontColor : COLOR,\n",
480 "float2 TexCoord : TEXCOORD0,\n",
481 "float3 EyeVector : TEXCOORD1,\n",
482 "float4 ModelViewProjectionPosition : TEXCOORD2,\n",
483 "uniform sampler Texture_Normal : register(s0),\n",
484 "uniform sampler Texture_Refraction : register(s3),\n",
485 "uniform sampler Texture_Reflection : register(s7),\n",
486 "uniform float4 DistortScaleRefractReflect : register(c14),\n",
487 "uniform float4 ScreenScaleRefractReflect : register(c32),\n",
488 "uniform float4 ScreenCenterRefractReflect : register(c31),\n",
489 "uniform float4 RefractColor : register(c29),\n",
490 "uniform float4 ReflectColor : register(c26),\n",
491 "uniform float ReflectFactor : register(c27),\n",
492 "uniform float ReflectOffset : register(c28),\n",
493 "out float4 dp_FragColor : COLOR\n",
496 " float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n",
497 " //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
498 " float4 SafeScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
499 " //SafeScreenTexCoord = gl_FragCoord.xyxy * float4(1.0 / 1920.0, 1.0 / 1200.0, 1.0 / 1920.0, 1.0 / 1200.0);\n",
500 "#ifdef USEALPHAGENVERTEX\n",
501 " float4 distort = DistortScaleRefractReflect * gl_FrontColor.a;\n",
502 " float reflectoffset = ReflectOffset * gl_FrontColor.a;\n",
503 " float reflectfactor = ReflectFactor * gl_FrontColor.a;\n",
504 " float4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), gl_FrontColor.a);\n",
506 " float4 distort = DistortScaleRefractReflect;\n",
507 " float reflectoffset = ReflectOffset;\n",
508 " float reflectfactor = ReflectFactor;\n",
509 " float4 refractcolor = RefractColor;\n",
511 " float4 ScreenTexCoord = SafeScreenTexCoord + float2(normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy).xyxy * distort;\n",
512 " // FIXME temporary hack to detect the case that the reflection\n",
513 " // gets blackened at edges due to leaving the area that contains actual\n",
515 " // Remove this 'ack once we have a better way to stop this thing from\n",
517 " float f = min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(0.01, 0.01)).rgb) / 0.05);\n",
518 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(0.01, -0.01)).rgb) / 0.05);\n",
519 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(-0.01, 0.01)).rgb) / 0.05);\n",
520 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(-0.01, -0.01)).rgb) / 0.05);\n",
521 " ScreenTexCoord.xy = lerp(SafeScreenTexCoord.xy, ScreenTexCoord.xy, f);\n",
522 " f = min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(0.01, 0.01)).rgb) / 0.05);\n",
523 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(0.01, -0.01)).rgb) / 0.05);\n",
524 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(-0.01, 0.01)).rgb) / 0.05);\n",
525 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(-0.01, -0.01)).rgb) / 0.05);\n",
526 " ScreenTexCoord.zw = lerp(SafeScreenTexCoord.zw, ScreenTexCoord.zw, f);\n",
527 " float Fresnel = pow(min(1.0, 1.0 - float(normalize(EyeVector).z)), 2.0) * reflectfactor + reflectoffset;\n",
528 " dp_FragColor = lerp(float4(tex2D(Texture_Refraction, ScreenTexCoord.xy).rgb, 1) * refractcolor, float4(tex2D(Texture_Reflection, ScreenTexCoord.zw).rgb, 1) * ReflectColor, Fresnel);\n",
531 "#else // !MODE_WATER\n",
536 "// 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",
538 "// fragment shader specific:\n",
539 "#ifdef FRAGMENT_SHADER\n",
542 "float3 FogVertex(float4 surfacecolor, float3 FogColor, float3 EyeVectorModelSpace, float FogPlaneVertexDist, float FogRangeRecip, float FogPlaneViewDist, float FogHeightFade, sampler Texture_FogMask, sampler Texture_FogHeightTexture)\n",
545 " float3 fc = FogColor;\n",
546 "#ifdef USEFOGALPHAHACK\n",
547 " fc *= surfacecolor.a;\n",
549 "#ifdef USEFOGHEIGHTTEXTURE\n",
550 " float4 fogheightpixel = tex2D(Texture_FogHeightTexture, float2(1,1) + float2(FogPlaneVertexDist, FogPlaneViewDist) * (-2.0 * FogHeightFade));\n",
551 " fogfrac = fogheightpixel.a;\n",
552 " return lerp(fogheightpixel.rgb * fc, surfacecolor.rgb, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n",
554 "# ifdef USEFOGOUTSIDE\n",
555 " fogfrac = min(0.0, FogPlaneVertexDist) / (FogPlaneVertexDist - FogPlaneViewDist) * min(1.0, min(0.0, FogPlaneVertexDist) * FogHeightFade);\n",
557 " fogfrac = FogPlaneViewDist / (FogPlaneViewDist - max(0.0, FogPlaneVertexDist)) * min(1.0, (min(0.0, FogPlaneVertexDist) + FogPlaneViewDist) * FogHeightFade);\n",
559 " return lerp(fc, surfacecolor.rgb, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n",
564 "#ifdef USEOFFSETMAPPING\n",
565 "float2 OffsetMapping(float2 TexCoord, float4 OffsetMapping_ScaleSteps, float OffsetMapping_Bias, float OffsetMapping_LodDistance, float3 EyeVector, sampler Texture_Normal, float2 dPdx, float2 dPdy)\n",
568 " // distance-based LOD\n",
569 "#ifdef USEOFFSETMAPPING_LOD\n",
570 " //float LODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n",
571 " //float4 ScaleSteps = float4(OffsetMapping_ScaleSteps.x, OffsetMapping_ScaleSteps.y * LODFactor, OffsetMapping_ScaleSteps.z / LODFactor, OffsetMapping_ScaleSteps.w * LODFactor);\n",
572 " float GuessLODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n",
573 "#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n",
574 " // stupid workaround because 1-step and 2-step reliefmapping is void\n",
575 " float LODSteps = max(3.0, ceil(GuessLODFactor * OffsetMapping_ScaleSteps.y));\n",
577 " float LODSteps = ceil(GuessLODFactor * OffsetMapping_ScaleSteps.y);\n",
579 " float LODFactor = LODSteps / OffsetMapping_ScaleSteps.y;\n",
580 " float4 ScaleSteps = float4(OffsetMapping_ScaleSteps.x, LODSteps, 1.0 / LODSteps, OffsetMapping_ScaleSteps.w * LODFactor);\n",
582 " #define ScaleSteps OffsetMapping_ScaleSteps\n",
584 "#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n",
585 " // 14 sample relief mapping: linear search and then binary search\n",
586 " // this basically steps forward a small amount repeatedly until it finds\n",
587 " // itself inside solid, then jitters forward and back using decreasing\n",
588 " // amounts to find the impact\n",
589 " //float3 OffsetVector = float3(EyeVector.xy * ((1.0 / EyeVector.z) * ScaleSteps.x) * float2(-1, 1), -1);\n",
590 " //float3 OffsetVector = float3(normalize(EyeVector.xy) * ScaleSteps.x * float2(-1, 1), -1);\n",
591 " float3 OffsetVector = float3(normalize(EyeVector).xy * ScaleSteps.x * float2(-1, 1), -1);\n",
592 " float3 RT = float3(float2(TexCoord.xy - OffsetVector.xy*OffsetMapping_Bias), 1);\n",
593 " OffsetVector *= ScaleSteps.z;\n",
594 " for(i = 1.0; i < ScaleSteps.y; ++i)\n",
595 " RT += OffsetVector * step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z);\n",
596 " for(i = 0.0, f = 1.0; i < ScaleSteps.w; ++i, f *= 0.5)\n",
597 " RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * f - 0.5 * f);\n",
600 " // 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits)\n",
601 " //float2 OffsetVector = float2(EyeVector.xy * ((1.0 / EyeVector.z) * ScaleSteps.x) * float2(-1, 1));\n",
602 " //float2 OffsetVector = float2(normalize(EyeVector.xy) * ScaleSteps.x * float2(-1, 1));\n",
603 " float2 OffsetVector = float2(normalize(EyeVector).xy * ScaleSteps.x * float2(-1, 1));\n",
604 " OffsetVector *= ScaleSteps.z;\n",
605 " for(i = 0.0; i < ScaleSteps.y; ++i)\n",
606 " TexCoord += OffsetVector * ((1.0 - OffsetMapping_Bias) - tex2Dgrad(Texture_Normal, TexCoord, dPdx, dPdy).a);\n",
607 " return TexCoord;\n",
610 "#endif // USEOFFSETMAPPING\n",
612 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n",
613 "#if defined(USESHADOWMAP2D)\n",
614 "# ifdef USESHADOWMAPORTHO\n",
615 "# define GetShadowMapTC2D(dir, ShadowMap_Parameters) (min(dir, ShadowMap_Parameters.xyz))\n",
617 "# ifdef USESHADOWMAPVSDCT\n",
618 "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters, samplerCUBE Texture_CubeProjection)\n",
620 " float3 adir = abs(dir);\n",
621 " float2 mparams = ShadowMap_Parameters.xy / max(max(adir.x, adir.y), adir.z);\n",
622 " float4 proj = texCUBE(Texture_CubeProjection, dir);\n",
623 " return float3(lerp(dir.xy, dir.zz, proj.xy) * mparams.x + proj.zw * ShadowMap_Parameters.z, mparams.y + ShadowMap_Parameters.w);\n",
626 "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters)\n",
628 " float3 adir = abs(dir);\n",
629 " float m; float4 proj;\n",
630 " 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",
631 " if (adir.z > m) { m = adir.z; proj = float4(dir, 2.5); }\n",
633 " 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",
635 " float2 mparams = ShadowMap_Parameters.xy / m;\n",
636 " 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",
641 "#endif // defined(USESHADOWMAP2D)\n",
643 "# ifdef USESHADOWMAP2D\n",
644 "#ifdef USESHADOWMAPVSDCT\n",
645 "float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale, samplerCUBE Texture_CubeProjection)\n",
647 "float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale)\n",
650 "#ifdef USESHADOWMAPVSDCT\n",
651 " float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters, Texture_CubeProjection);\n",
653 " float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters);\n",
657 "# ifdef USESHADOWSAMPLER\n",
658 "# ifdef USESHADOWMAPPCF\n",
659 "# define texval(x, y) tex2Dproj(Texture_ShadowMap2D, float4(center + float2(x, y)*ShadowMap_TextureScale, shadowmaptc.z, 1.0)).r \n",
660 " float2 center = shadowmaptc.xy*ShadowMap_TextureScale;\n",
661 " 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",
663 " f = tex2Dproj(Texture_ShadowMap2D, float4(shadowmaptc.xy*ShadowMap_TextureScale, shadowmaptc.z, 1.0)).r;\n",
666 "# ifdef USESHADOWMAPPCF\n",
667 "# if defined(GL_ARB_texture_gather) || defined(GL_AMD_texture_texture4)\n",
668 "# ifdef GL_ARB_texture_gather\n",
669 "# define texval(x, y) textureGatherOffset(Texture_ShadowMap2D, center, int2(x, y))\n",
671 "# define texval(x, y) texture4(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale)\n",
673 " float2 offset = frac(shadowmaptc.xy - 0.5), center = (shadowmaptc.xy - offset)*ShadowMap_TextureScale;\n",
674 "# if USESHADOWMAPPCF > 1\n",
675 " float4 group1 = step(shadowmaptc.z, texval(-2.0, -2.0));\n",
676 " float4 group2 = step(shadowmaptc.z, texval( 0.0, -2.0));\n",
677 " float4 group3 = step(shadowmaptc.z, texval( 2.0, -2.0));\n",
678 " float4 group4 = step(shadowmaptc.z, texval(-2.0, 0.0));\n",
679 " float4 group5 = step(shadowmaptc.z, texval( 0.0, 0.0));\n",
680 " float4 group6 = step(shadowmaptc.z, texval( 2.0, 0.0));\n",
681 " float4 group7 = step(shadowmaptc.z, texval(-2.0, 2.0));\n",
682 " float4 group8 = step(shadowmaptc.z, texval( 0.0, 2.0));\n",
683 " float4 group9 = step(shadowmaptc.z, texval( 2.0, 2.0));\n",
684 " float4 locols = float4(group1.ab, group3.ab);\n",
685 " float4 hicols = float4(group7.rg, group9.rg);\n",
686 " locols.yz += group2.ab;\n",
687 " hicols.yz += group8.rg;\n",
688 " float4 midcols = float4(group1.rg, group3.rg) + float4(group7.ab, group9.ab) +\n",
689 " float4(group4.rg, group6.rg) + float4(group4.ab, group6.ab) +\n",
690 " lerp(locols, hicols, offset.y);\n",
691 " float4 cols = group5 + float4(group2.rg, group8.ab);\n",
692 " cols.xyz += lerp(midcols.xyz, midcols.yzw, offset.x);\n",
693 " f = dot(cols, float4(1.0/25.0));\n",
695 " float4 group1 = step(shadowmaptc.z, texval(-1.0, -1.0));\n",
696 " float4 group2 = step(shadowmaptc.z, texval( 1.0, -1.0));\n",
697 " float4 group3 = step(shadowmaptc.z, texval(-1.0, 1.0));\n",
698 " float4 group4 = step(shadowmaptc.z, texval( 1.0, 1.0));\n",
699 " float4 cols = float4(group1.rg, group2.rg) + float4(group3.ab, group4.ab) +\n",
700 " lerp(float4(group1.ab, group2.ab), float4(group3.rg, group4.rg), offset.y);\n",
701 " f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n",
704 "# ifdef GL_EXT_gpu_shader4\n",
705 "# define texval(x, y) tex2DOffset(Texture_ShadowMap2D, center, int2(x, y)).r\n",
707 "# define texval(x, y) texDepth2D(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale).r \n",
709 "# if USESHADOWMAPPCF > 1\n",
710 " float2 center = shadowmaptc.xy - 0.5, offset = frac(center);\n",
711 " center *= ShadowMap_TextureScale;\n",
712 " 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",
713 " 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",
714 " 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",
715 " 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",
716 " float4 cols = row2 + row3 + lerp(row1, row4, offset.y);\n",
717 " f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n",
719 " float2 center = shadowmaptc.xy*ShadowMap_TextureScale, offset = frac(shadowmaptc.xy);\n",
720 " float3 row1 = step(shadowmaptc.z, float3(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0)));\n",
721 " float3 row2 = step(shadowmaptc.z, float3(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0)));\n",
722 " float3 row3 = step(shadowmaptc.z, float3(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0)));\n",
723 " float3 cols = row2 + lerp(row1, row3, offset.y);\n",
724 " f = dot(lerp(cols.xy, cols.yz, offset.x), float2(0.25,0.25));\n",
728 " f = step(shadowmaptc.z, tex2D(Texture_ShadowMap2D, shadowmaptc.xy*ShadowMap_TextureScale).r);\n",
731 "# ifdef USESHADOWMAPORTHO\n",
732 " return lerp(ShadowMap_Parameters.w, 1.0, f);\n",
738 "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n",
739 "#endif // FRAGMENT_SHADER\n",
744 "#ifdef MODE_DEFERREDGEOMETRY\n",
745 "#ifdef VERTEX_SHADER\n",
748 "float4 gl_Vertex : POSITION,\n",
749 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
750 "#ifdef USEVERTEXTEXTUREBLEND\n",
751 "float4 gl_Color : COLOR0,\n",
753 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
754 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n",
755 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n",
756 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n",
757 "uniform float4x4 TexMatrix : register(c0),\n",
758 "#ifdef USEVERTEXTEXTUREBLEND\n",
759 "uniform float4x4 BackgroundTexMatrix : register(c4),\n",
761 "uniform float4x4 ModelViewMatrix : register(c12),\n",
762 "#ifdef USEOFFSETMAPPING\n",
763 "uniform float3 EyePosition : register(c24),\n",
765 "out float4 gl_Position : POSITION,\n",
766 "#ifdef USEVERTEXTEXTUREBLEND\n",
767 "out float4 gl_FrontColor : COLOR,\n",
769 "out float4 TexCoordBoth : TEXCOORD0,\n",
770 "#ifdef USEOFFSETMAPPING\n",
771 "out float3 EyeVector : TEXCOORD2,\n",
773 "out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n",
774 "out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n",
775 "out float4 VectorR : TEXCOORD7 // direction of R texcoord (surface normal), Depth value\n",
778 " TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n",
779 "#ifdef USEVERTEXTEXTUREBLEND\n",
780 " gl_FrontColor = gl_Color;\n",
781 " TexCoordBoth.zw = float2(Backgroundmul(TexMatrix, gl_MultiTexCoord0));\n",
784 " // transform unnormalized eye direction into tangent space\n",
785 "#ifdef USEOFFSETMAPPING\n",
786 " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n",
787 " EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n",
790 " VectorS = mul(ModelViewMatrix, float4(gl_MultiTexCoord1.xyz, 0)).xyz;\n",
791 " VectorT = mul(ModelViewMatrix, float4(gl_MultiTexCoord2.xyz, 0)).xyz;\n",
792 " VectorR.xyz = mul(ModelViewMatrix, float4(gl_MultiTexCoord3.xyz, 0)).xyz;\n",
793 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
794 "#ifdef USETRIPPY\n",
795 " gl_Position = TrippyVertex(gl_Position);\n",
797 " VectorR.w = mul(ModelViewMatrix, gl_Vertex).z;\n",
799 "#endif // VERTEX_SHADER\n",
801 "#ifdef FRAGMENT_SHADER\n",
804 "float4 TexCoordBoth : TEXCOORD0,\n",
805 "float3 EyeVector : TEXCOORD2,\n",
806 "float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n",
807 "float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n",
808 "float4 VectorR : TEXCOORD7, // direction of R texcoord (surface normal), Depth value\n",
809 "uniform sampler Texture_Normal : register(s0),\n",
810 "#ifdef USEALPHAKILL\n",
811 "uniform sampler Texture_Color : register(s1),\n",
813 "uniform sampler Texture_Gloss : register(s2),\n",
814 "#ifdef USEVERTEXTEXTUREBLEND\n",
815 "uniform sampler Texture_SecondaryNormal : register(s4),\n",
816 "uniform sampler Texture_SecondaryGloss : register(s6),\n",
818 "#ifdef USEOFFSETMAPPING\n",
819 "uniform float4 OffsetMapping_ScaleSteps : register(c24),\n",
820 "uniform float4 OffsetMapping_LodDistance : register(c53),\n",
821 "uniform float OffsetMapping_Bias : register(c54),\n",
823 "uniform half SpecularPower : register(c36),\n",
824 "out float4 dp_FragColor : COLOR\n",
827 " float2 TexCoord = TexCoordBoth.xy;\n",
828 "#ifdef USEOFFSETMAPPING\n",
829 " // apply offsetmapping\n",
830 " float2 dPdx = ddx(TexCoord);\n",
831 " float2 dPdy = ddy(TexCoord);\n",
832 " float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, OffsetMapping_Bias, OffsetMapping_LodDistance, EyeVector, Texture_Normal, dPdx, dPdy);\n",
833 "# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n",
835 "# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n",
838 "#ifdef USEALPHAKILL\n",
839 " if (offsetMappedTexture2D(Texture_Color).a < 0.5)\n",
843 "#ifdef USEVERTEXTEXTUREBLEND\n",
844 " float alpha = offsetMappedTexture2D(Texture_Color).a;\n",
845 " float terrainblend = clamp(float(gl_FrontColor.a) * alpha * 2.0 - 0.5, float(0.0), float(1.0));\n",
846 " //float terrainblend = min(float(gl_FrontColor.a) * alpha * 2.0, float(1.0));\n",
847 " //float terrainblend = float(gl_FrontColor.a) * alpha > 0.5;\n",
850 "#ifdef USEVERTEXTEXTUREBLEND\n",
851 " float3 surfacenormal = lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, offsetMappedTexture2D(Texture_Normal).rgb, terrainblend) - float3(0.5, 0.5, 0.5);\n",
852 " float a = lerp(tex2D(Texture_SecondaryGloss, TexCoord2).a, offsetMappedTexture2D(Texture_Gloss).a, terrainblend);\n",
854 " float3 surfacenormal = offsetMappedTexture2D(Texture_Normal).rgb - float3(0.5, 0.5, 0.5);\n",
855 " float a = offsetMappedTexture2D(Texture_Gloss).a;\n",
858 " float3 pixelnormal = normalize(surfacenormal.x * VectorS.xyz + surfacenormal.y * VectorT.xyz + surfacenormal.z * VectorR.xyz);\n",
859 " dp_FragColor = float4(pixelnormal.x, pixelnormal.y, VectorR.w, a);\n",
861 "#endif // FRAGMENT_SHADER\n",
862 "#else // !MODE_DEFERREDGEOMETRY\n",
867 "#ifdef MODE_DEFERREDLIGHTSOURCE\n",
868 "#ifdef VERTEX_SHADER\n",
871 "float4 gl_Vertex : POSITION,\n",
872 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
873 "uniform float4x4 ModelViewMatrix : register(c12),\n",
874 "out float4 gl_Position : POSITION,\n",
875 "out float4 ModelViewPosition : TEXCOORD0\n",
878 " ModelViewPosition = mul(ModelViewMatrix, gl_Vertex);\n",
879 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
881 "#endif // VERTEX_SHADER\n",
883 "#ifdef FRAGMENT_SHADER\n",
887 "float2 Pixel : VPOS,\n",
889 "float2 Pixel : WPOS,\n",
891 "float4 ModelViewPosition : TEXCOORD0,\n",
892 "uniform float4x4 ViewToLight : register(c44),\n",
893 "uniform float2 ScreenToDepth : register(c33), // ScreenToDepth = float2(Far / (Far - Near), Far * Near / (Near - Far));\n",
894 "uniform float3 LightPosition : register(c23),\n",
895 "uniform half2 PixelToScreenTexCoord : register(c42),\n",
896 "uniform half3 DeferredColor_Ambient : register(c9),\n",
897 "uniform half3 DeferredColor_Diffuse : register(c10),\n",
898 "#ifdef USESPECULAR\n",
899 "uniform half3 DeferredColor_Specular : register(c11),\n",
900 "uniform half SpecularPower : register(c36),\n",
902 "uniform sampler Texture_Attenuation : register(s9),\n",
903 "uniform sampler Texture_ScreenDepth : register(s13),\n",
904 "uniform sampler Texture_ScreenNormalMap : register(s14),\n",
906 "#ifdef USECUBEFILTER\n",
907 "uniform samplerCUBE Texture_Cube : register(s10),\n",
910 "#ifdef USESHADOWMAP2D\n",
911 "# ifdef USESHADOWSAMPLER\n",
912 "uniform sampler Texture_ShadowMap2D : register(s15),\n",
914 "uniform sampler Texture_ShadowMap2D : register(s15),\n",
918 "#ifdef USESHADOWMAPVSDCT\n",
919 "uniform samplerCUBE Texture_CubeProjection : register(s12),\n",
922 "#if defined(USESHADOWMAP2D)\n",
923 "uniform float2 ShadowMap_TextureScale : register(c35),\n",
924 "uniform float4 ShadowMap_Parameters : register(c34),\n",
927 "out float4 gl_FragData0 : COLOR0,\n",
928 "out float4 gl_FragData1 : COLOR1\n",
931 " // calculate viewspace pixel position\n",
932 " float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n",
933 " float3 position;\n",
934 " // get the geometry information (depth, normal, specular exponent)\n",
935 " half4 normalmap = half4(tex2D(Texture_ScreenNormalMap, ScreenTexCoord));\n",
936 " // decode viewspace pixel normal\n",
937 "// float3 surfacenormal = normalize(normalmap.rgb - cast_myhalf3(0.5,0.5,0.5));\n",
938 " float3 surfacenormal = half3(normalmap.rg, sqrt(1.0-dot(normalmap.rg, normalmap.rg)));\n",
939 " // decode viewspace pixel position\n",
940 "// position.z = decodedepthmacro(dp_texture2D(Texture_ScreenDepth, ScreenTexCoord));\n",
941 " position.z = normalmap.b;\n",
942 "// position.z = ScreenToDepth.y / (dp_texture2D(Texture_ScreenDepth, ScreenTexCoord).r + ScreenToDepth.x);\n",
943 " position.xy = ModelViewPosition.xy * (position.z / ModelViewPosition.z);\n",
945 " // now do the actual shading\n",
946 " // surfacenormal = pixel normal in viewspace\n",
947 " // LightVector = pixel to light in viewspace\n",
948 " // CubeVector = position in lightspace\n",
949 " // eyevector = pixel to view in viewspace\n",
950 " float3 CubeVector = mul(ViewToLight, float4(position,1)).xyz;\n",
951 " half fade = half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n",
952 "#ifdef USEDIFFUSE\n",
953 " // calculate diffuse shading\n",
954 " half3 lightnormal = half3(normalize(LightPosition - position));\n",
955 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n",
957 "#ifdef USESPECULAR\n",
958 " // calculate directional shading\n",
959 " float3 eyevector = position * -1.0;\n",
960 "# ifdef USEEXACTSPECULARMATH\n",
961 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(eyevector)))*-1.0, 0.0)), 1.0 + SpecularPower * normalmap.a));\n",
963 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(eyevector))));\n",
964 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * normalmap.a));\n",
968 "#if defined(USESHADOWMAP2D)\n",
969 " fade *= half(ShadowMapCompare(CubeVector, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n",
970 "#ifdef USESHADOWMAPVSDCT\n",
971 ", Texture_CubeProjection\n",
976 "#ifdef USEDIFFUSE\n",
977 " gl_FragData0 = float4((DeferredColor_Ambient + DeferredColor_Diffuse * diffuse) * fade, 1.0);\n",
979 " gl_FragData0 = float4(DeferredColor_Ambient * fade, 1.0);\n",
981 "#ifdef USESPECULAR\n",
982 " gl_FragData1 = float4(DeferredColor_Specular * (specular * fade), 1.0);\n",
984 " gl_FragData1 = float4(0.0, 0.0, 0.0, 1.0);\n",
987 "# ifdef USECUBEFILTER\n",
988 " float3 cubecolor = texCUBE(Texture_Cube, CubeVector).rgb;\n",
989 " gl_FragData0.rgb *= cubecolor;\n",
990 " gl_FragData1.rgb *= cubecolor;\n",
993 "#endif // FRAGMENT_SHADER\n",
994 "#else // !MODE_DEFERREDLIGHTSOURCE\n",
999 "#ifdef VERTEX_SHADER\n",
1002 "float4 gl_Vertex : POSITION,\n",
1003 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
1004 "#if defined(USEVERTEXTEXTUREBLEND) || defined(MODE_VERTEXCOLOR) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n",
1005 "float4 gl_Color : COLOR0,\n",
1007 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
1008 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n",
1009 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n",
1010 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n",
1011 "float4 gl_MultiTexCoord4 : TEXCOORD4,\n",
1013 "uniform float3 EyePosition : register(c24),\n",
1014 "uniform float4x4 TexMatrix : register(c0),\n",
1015 "#ifdef USEVERTEXTEXTUREBLEND\n",
1016 "uniform float4x4 BackgroundTexMatrix : register(c4),\n",
1018 "#ifdef MODE_LIGHTSOURCE\n",
1019 "uniform float4x4 ModelToLight : register(c20),\n",
1021 "#ifdef MODE_LIGHTSOURCE\n",
1022 "uniform float3 LightPosition : register(c27),\n",
1024 "#ifdef MODE_LIGHTDIRECTION\n",
1025 "uniform float3 LightDir : register(c26),\n",
1027 "uniform float4 FogPlane : register(c25),\n",
1028 "#ifdef MODE_DEFERREDLIGHTSOURCE\n",
1029 "uniform float3 LightPosition : register(c27),\n",
1031 "#ifdef USESHADOWMAPORTHO\n",
1032 "uniform float4x4 ShadowMapMatrix : register(c16),\n",
1034 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR) || defined(USEALPHAGENVERTEX)\n",
1035 "out float4 gl_FrontColor : COLOR,\n",
1037 "out float4 TexCoordBoth : TEXCOORD0,\n",
1038 "#ifdef USELIGHTMAP\n",
1039 "out float2 TexCoordLightmap : TEXCOORD1,\n",
1041 "#ifdef USEEYEVECTOR\n",
1042 "out float3 EyeVector : TEXCOORD2,\n",
1044 "#ifdef USEREFLECTION\n",
1045 "out float4 ModelViewProjectionPosition : TEXCOORD3,\n",
1048 "out float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n",
1050 "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE) || defined(USEDIFFUSE)\n",
1051 "out float3 LightVector : TEXCOORD1,\n",
1053 "#ifdef MODE_LIGHTSOURCE\n",
1054 "out float3 CubeVector : TEXCOORD3,\n",
1056 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n",
1057 "out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n",
1058 "out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n",
1059 "out float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n",
1061 "#ifdef USESHADOWMAPORTHO\n",
1062 "out float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n",
1064 "out float4 gl_Position : POSITION\n",
1067 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR) || defined(USEALPHAGENVERTEX)\n",
1068 " gl_FrontColor = gl_Color;\n",
1070 " // copy the surface texcoord\n",
1071 " TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n",
1072 "#ifdef USEVERTEXTEXTUREBLEND\n",
1073 " TexCoordBoth.zw = mul(BackgroundTexMatrix, gl_MultiTexCoord0).xy;\n",
1075 "#ifdef USELIGHTMAP\n",
1076 " TexCoordLightmap = gl_MultiTexCoord4.xy;\n",
1079 "#ifdef MODE_LIGHTSOURCE\n",
1080 " // transform vertex position into light attenuation/cubemap space\n",
1081 " // (-1 to +1 across the light box)\n",
1082 " CubeVector = mul(ModelToLight, gl_Vertex).xyz;\n",
1084 "# ifdef USEDIFFUSE\n",
1085 " // transform unnormalized light direction into tangent space\n",
1086 " // (we use unnormalized to ensure that it interpolates correctly and then\n",
1087 " // normalize it per pixel)\n",
1088 " float3 lightminusvertex = LightPosition - gl_Vertex.xyz;\n",
1089 " LightVector = float3(dot(lightminusvertex, gl_MultiTexCoord1.xyz), dot(lightminusvertex, gl_MultiTexCoord2.xyz), dot(lightminusvertex, gl_MultiTexCoord3.xyz));\n",
1093 "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE)\n",
1094 " LightVector = float3(dot(LightDir, gl_MultiTexCoord1.xyz), dot(LightDir, gl_MultiTexCoord2.xyz), dot(LightDir, gl_MultiTexCoord3.xyz));\n",
1097 " // transform unnormalized eye direction into tangent space\n",
1098 "#ifdef USEEYEVECTOR\n",
1099 " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n",
1100 " EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n",
1104 " EyeVectorModelSpaceFogPlaneVertexDist.xyz = EyePosition - gl_Vertex.xyz;\n",
1105 " EyeVectorModelSpaceFogPlaneVertexDist.w = dot(FogPlane, gl_Vertex);\n",
1108 "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n",
1109 " VectorS = gl_MultiTexCoord1.xyz;\n",
1110 " VectorT = gl_MultiTexCoord2.xyz;\n",
1111 " VectorR = gl_MultiTexCoord3.xyz;\n",
1114 " // transform vertex to camera space, using ftransform to match non-VS rendering\n",
1115 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
1117 "#ifdef USESHADOWMAPORTHO\n",
1118 " ShadowMapTC = mul(ShadowMapMatrix, gl_Position).xyz;\n",
1121 "#ifdef USEREFLECTION\n",
1122 " ModelViewProjectionPosition = gl_Position;\n",
1124 "#ifdef USETRIPPY\n",
1125 " gl_Position = TrippyVertex(gl_Position);\n",
1128 "#endif // VERTEX_SHADER\n",
1133 "#ifdef FRAGMENT_SHADER\n",
1136 "#ifdef USEDEFERREDLIGHTMAP\n",
1138 "float2 Pixel : VPOS,\n",
1140 "float2 Pixel : WPOS,\n",
1143 "float4 gl_FrontColor : COLOR,\n",
1144 "float4 TexCoordBoth : TEXCOORD0,\n",
1145 "#ifdef USELIGHTMAP\n",
1146 "float2 TexCoordLightmap : TEXCOORD1,\n",
1148 "#ifdef USEEYEVECTOR\n",
1149 "float3 EyeVector : TEXCOORD2,\n",
1151 "#ifdef USEREFLECTION\n",
1152 "float4 ModelViewProjectionPosition : TEXCOORD3,\n",
1155 "float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n",
1157 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_LIGHTDIRECTION)\n",
1158 "float3 LightVector : TEXCOORD1,\n",
1160 "#ifdef MODE_LIGHTSOURCE\n",
1161 "float3 CubeVector : TEXCOORD3,\n",
1163 "#ifdef MODE_DEFERREDLIGHTSOURCE\n",
1164 "float4 ModelViewPosition : TEXCOORD0,\n",
1166 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n",
1167 "float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n",
1168 "float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n",
1169 "float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n",
1171 "#ifdef USESHADOWMAPORTHO\n",
1172 "float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n",
1175 "uniform sampler Texture_Normal : register(s0),\n",
1176 "uniform sampler Texture_Color : register(s1),\n",
1177 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n",
1178 "uniform sampler Texture_Gloss : register(s2),\n",
1181 "uniform sampler Texture_Glow : register(s3),\n",
1183 "#ifdef USEVERTEXTEXTUREBLEND\n",
1184 "uniform sampler Texture_SecondaryNormal : register(s4),\n",
1185 "uniform sampler Texture_SecondaryColor : register(s5),\n",
1186 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n",
1187 "uniform sampler Texture_SecondaryGloss : register(s6),\n",
1190 "uniform sampler Texture_SecondaryGlow : register(s7),\n",
1193 "#ifdef USECOLORMAPPING\n",
1194 "uniform sampler Texture_Pants : register(s4),\n",
1195 "uniform sampler Texture_Shirt : register(s7),\n",
1198 "uniform sampler Texture_FogHeightTexture : register(s14),\n",
1199 "uniform sampler Texture_FogMask : register(s8),\n",
1201 "#ifdef USELIGHTMAP\n",
1202 "uniform sampler Texture_Lightmap : register(s9),\n",
1204 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE)\n",
1205 "uniform sampler Texture_Deluxemap : register(s10),\n",
1207 "#ifdef USEREFLECTION\n",
1208 "uniform sampler Texture_Reflection : register(s7),\n",
1211 "#ifdef MODE_DEFERREDLIGHTSOURCE\n",
1212 "uniform sampler Texture_ScreenDepth : register(s13),\n",
1213 "uniform sampler Texture_ScreenNormalMap : register(s14),\n",
1215 "#ifdef USEDEFERREDLIGHTMAP\n",
1216 "uniform sampler Texture_ScreenDepth : register(s13),\n",
1217 "uniform sampler Texture_ScreenNormalMap : register(s14),\n",
1218 "uniform sampler Texture_ScreenDiffuse : register(s11),\n",
1219 "uniform sampler Texture_ScreenSpecular : register(s12),\n",
1222 "#ifdef USECOLORMAPPING\n",
1223 "uniform half3 Color_Pants : register(c7),\n",
1224 "uniform half3 Color_Shirt : register(c8),\n",
1227 "uniform float3 FogColor : register(c16),\n",
1228 "uniform float FogRangeRecip : register(c20),\n",
1229 "uniform float FogPlaneViewDist : register(c19),\n",
1230 "uniform float FogHeightFade : register(c17),\n",
1233 "#ifdef USEOFFSETMAPPING\n",
1234 "uniform float4 OffsetMapping_ScaleSteps : register(c24),\n",
1235 "uniform float OffsetMapping_Bias : register(c54),\n",
1238 "#ifdef USEDEFERREDLIGHTMAP\n",
1239 "uniform half2 PixelToScreenTexCoord : register(c42),\n",
1240 "uniform half3 DeferredMod_Diffuse : register(c12),\n",
1241 "uniform half3 DeferredMod_Specular : register(c13),\n",
1243 "uniform half3 Color_Ambient : register(c3),\n",
1244 "uniform half3 Color_Diffuse : register(c4),\n",
1245 "uniform half3 Color_Specular : register(c5),\n",
1246 "uniform half SpecularPower : register(c36),\n",
1248 "uniform half3 Color_Glow : register(c6),\n",
1250 "uniform half Alpha : register(c0),\n",
1251 "#ifdef USEREFLECTION\n",
1252 "uniform float4 DistortScaleRefractReflect : register(c14),\n",
1253 "uniform float4 ScreenScaleRefractReflect : register(c32),\n",
1254 "uniform float4 ScreenCenterRefractReflect : register(c31),\n",
1255 "uniform half4 ReflectColor : register(c26),\n",
1257 "#ifdef USEREFLECTCUBE\n",
1258 "uniform float4x4 ModelToReflectCube : register(c48),\n",
1259 "uniform sampler Texture_ReflectMask : register(s5),\n",
1260 "uniform samplerCUBE Texture_ReflectCube : register(s6),\n",
1262 "#ifdef MODE_LIGHTDIRECTION\n",
1263 "uniform half3 LightColor : register(c21),\n",
1265 "#ifdef MODE_LIGHTSOURCE\n",
1266 "uniform half3 LightColor : register(c21),\n",
1269 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE)\n",
1270 "uniform sampler Texture_Attenuation : register(s9),\n",
1271 "uniform samplerCUBE Texture_Cube : register(s10),\n",
1274 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n",
1276 "#ifdef USESHADOWMAP2D\n",
1277 "# ifdef USESHADOWSAMPLER\n",
1278 "uniform sampler Texture_ShadowMap2D : register(s15),\n",
1280 "uniform sampler Texture_ShadowMap2D : register(s15),\n",
1284 "#ifdef USESHADOWMAPVSDCT\n",
1285 "uniform samplerCUBE Texture_CubeProjection : register(s12),\n",
1288 "#if defined(USESHADOWMAP2D)\n",
1289 "uniform float2 ShadowMap_TextureScale : register(c35),\n",
1290 "uniform float4 ShadowMap_Parameters : register(c34),\n",
1292 "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n",
1294 "out float4 dp_FragColor : COLOR\n",
1297 " float2 TexCoord = TexCoordBoth.xy;\n",
1298 "#ifdef USEVERTEXTEXTUREBLEND\n",
1299 " float2 TexCoord2 = TexCoordBoth.zw;\n",
1301 "#ifdef USEOFFSETMAPPING\n",
1302 " // apply offsetmapping\n",
1303 " float2 dPdx = ddx(TexCoord);\n",
1304 " float2 dPdy = ddy(TexCoord);\n",
1305 " float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, OffsetMapping_Bias, OffsetMapping_LodDistance, EyeVector, Texture_Normal, dPdx, dPdy);\n",
1306 "# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n",
1308 "# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n",
1311 " // combine the diffuse textures (base, pants, shirt)\n",
1312 " half4 color = half4(offsetMappedTexture2D(Texture_Color));\n",
1313 "#ifdef USEALPHAKILL\n",
1314 " if (color.a < 0.5)\n",
1317 " color.a *= Alpha;\n",
1318 "#ifdef USECOLORMAPPING\n",
1319 " color.rgb += half3(offsetMappedTexture2D(Texture_Pants).rgb) * Color_Pants + half3(offsetMappedTexture2D(Texture_Shirt).rgb) * Color_Shirt;\n",
1321 "#ifdef USEVERTEXTEXTUREBLEND\n",
1322 "#ifdef USEBOTHALPHAS\n",
1323 " half4 color2 = half4(tex2D(Texture_SecondaryColor, TexCoord2));\n",
1324 " half terrainblend = clamp(half(gl_FrontColor.a) * color.a, half(1.0 - color2.a), half(1.0));\n",
1325 " color.rgb = lerp(color2.rgb, color.rgb, terrainblend);\n",
1327 " half terrainblend = clamp(half(gl_FrontColor.a) * color.a * 2.0 - 0.5, half(0.0), half(1.0));\n",
1328 " //half terrainblend = min(half(gl_FrontColor.a) * color.a * 2.0, half(1.0));\n",
1329 " //half terrainblend = half(gl_FrontColor.a) * color.a > 0.5;\n",
1330 " color.rgb = half3(lerp(tex2D(Texture_SecondaryColor, TexCoord2).rgb, float3(color.rgb), terrainblend));\n",
1331 " color.a = 1.0;\n",
1332 " //color = half4(lerp(float4(1, 0, 0, 1), color, terrainblend));\n",
1335 "#ifdef USEALPHAGENVERTEX\n",
1336 " color.a *= gl_FrontColor.a;\n",
1339 " // get the surface normal\n",
1340 "#ifdef USEVERTEXTEXTUREBLEND\n",
1341 " half3 surfacenormal = normalize(half3(lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, offsetMappedTexture2D(Texture_Normal).rgb, terrainblend)) - half3(0.5, 0.5, 0.5));\n",
1343 " half3 surfacenormal = half3(normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5, 0.5, 0.5)));\n",
1346 " // get the material colors\n",
1347 " half3 diffusetex = color.rgb;\n",
1348 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n",
1349 "# ifdef USEVERTEXTEXTUREBLEND\n",
1350 " half4 glosstex = half4(lerp(tex2D(Texture_SecondaryGloss, TexCoord2), offsetMappedTexture2D(Texture_Gloss), terrainblend));\n",
1352 " half4 glosstex = half4(offsetMappedTexture2D(Texture_Gloss));\n",
1356 "#ifdef USEREFLECTCUBE\n",
1357 " float3 TangentReflectVector = reflect(-EyeVector, surfacenormal);\n",
1358 " float3 ModelReflectVector = TangentReflectVector.x * VectorS + TangentReflectVector.y * VectorT + TangentReflectVector.z * VectorR;\n",
1359 " float3 ReflectCubeTexCoord = mul(ModelToReflectCube, float4(ModelReflectVector, 0)).xyz;\n",
1360 " diffusetex += half3(offsetMappedTexture2D(Texture_ReflectMask).rgb) * half3(texCUBE(Texture_ReflectCube, ReflectCubeTexCoord).rgb);\n",
1366 "#ifdef MODE_LIGHTSOURCE\n",
1367 " // light source\n",
1368 "#ifdef USEDIFFUSE\n",
1369 " half3 lightnormal = half3(normalize(LightVector));\n",
1370 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n",
1371 " color.rgb = diffusetex * (Color_Ambient + diffuse * Color_Diffuse);\n",
1372 "#ifdef USESPECULAR\n",
1373 "#ifdef USEEXACTSPECULARMATH\n",
1374 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), 1.0 + SpecularPower * glosstex.a));\n",
1376 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n",
1377 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * glosstex.a));\n",
1379 " color.rgb += glosstex.rgb * (specular * Color_Specular);\n",
1382 " color.rgb = diffusetex * Color_Ambient;\n",
1384 " color.rgb *= LightColor;\n",
1385 " color.rgb *= half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n",
1386 "#if defined(USESHADOWMAP2D)\n",
1387 " color.rgb *= half(ShadowMapCompare(CubeVector, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n",
1388 "#ifdef USESHADOWMAPVSDCT\n",
1389 ", Texture_CubeProjection\n",
1394 "# ifdef USECUBEFILTER\n",
1395 " color.rgb *= half3(texCUBE(Texture_Cube, CubeVector).rgb);\n",
1398 "#ifdef USESHADOWMAP2D\n",
1399 "#ifdef USESHADOWMAPVSDCT\n",
1400 "// float3 shadowmaptc = GetShadowMapTC2D(CubeVector, ShadowMap_Parameters, Texture_CubeProjection);\n",
1402 "// float3 shadowmaptc = GetShadowMapTC2D(CubeVector, ShadowMap_Parameters);\n",
1404 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n",
1405 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale).rgb);\n",
1406 "// color.rgb = half3(shadowmaptc.xyz * float3(ShadowMap_TextureScale,1.0));\n",
1407 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n",
1408 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n",
1409 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale).rgb);\n",
1410 "// color.rgb = half3(shadowmaptc.xyz * float3(ShadowMap_TextureScale,1.0));\n",
1411 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n",
1412 "// color.r = half(shadowmaptc.z - texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n",
1413 "// color.r = half(shadowmaptc.z);\n",
1414 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n",
1415 "// color.r = half(shadowmaptc.z);\n",
1416 "// color.r = 1;\n",
1417 "// color.rgb = abs(CubeVector);\n",
1419 "// color.rgb = half3(1,1,1);\n",
1420 "#endif // MODE_LIGHTSOURCE\n",
1425 "#ifdef MODE_LIGHTDIRECTION\n",
1426 " #define SHADING\n",
1427 " #ifdef USEDIFFUSE\n",
1428 " half3 lightnormal = half3(normalize(LightVector));\n",
1430 " #define lightcolor LightColor\n",
1431 "#endif // MODE_LIGHTDIRECTION\n",
1432 "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n",
1433 " #define SHADING\n",
1434 " // deluxemap lightmapping using light vectors in modelspace (q3map2 -light -deluxe)\n",
1435 " half3 lightnormal_modelspace = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n",
1436 " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n",
1437 " // convert modelspace light vector to tangentspace\n",
1438 " half3 lightnormal = half3(dot(lightnormal_modelspace, half3(VectorS)), dot(lightnormal_modelspace, half3(VectorT)), dot(lightnormal_modelspace, half3(VectorR)));\n",
1439 " // calculate directional shading (and undoing the existing angle attenuation on the lightmap by the division)\n",
1440 " // note that q3map2 is too stupid to calculate proper surface normals when q3map_nonplanar\n",
1441 " // is used (the lightmap and deluxemap coords correspond to virtually random coordinates\n",
1442 " // on that luxel, and NOT to its center, because recursive triangle subdivision is used\n",
1443 " // to map the luxels to coordinates on the draw surfaces), which also causes\n",
1444 " // deluxemaps to be wrong because light contributions from the wrong side of the surface\n",
1445 " // are added up. To prevent divisions by zero or strong exaggerations, a max()\n",
1446 " // nudge is done here at expense of some additional fps. This is ONLY needed for\n",
1447 " // deluxemaps, tangentspace deluxemap avoid this problem by design.\n",
1448 " lightcolor *= 1.0 / max(0.25, lightnormal.z);\n",
1449 "#endif // MODE_LIGHTDIRECTIONMAP_MODELSPACE\n",
1450 "#ifdef MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n",
1451 " #define SHADING\n",
1452 " // deluxemap lightmapping using light vectors in tangentspace (hmap2 -light)\n",
1453 " half3 lightnormal = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n",
1454 " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n",
1456 "#if defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n",
1457 " #define SHADING\n",
1458 " // forced deluxemap on lightmapped/vertexlit surfaces\n",
1459 " half3 lightnormal = half3(0.0, 0.0, 1.0);\n",
1460 " #ifdef USELIGHTMAP\n",
1461 " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n",
1463 " half3 lightcolor = half3(gl_FrontColor.rgb);\n",
1466 "#ifdef MODE_FAKELIGHT\n",
1467 " #define SHADING\n",
1468 " half3 lightnormal = half3(normalize(EyeVector));\n",
1469 " half3 lightcolor = half3(1.0,1.0,1.0);\n",
1470 "#endif // MODE_FAKELIGHT\n",
1475 "#ifdef MODE_LIGHTMAP\n",
1476 " color.rgb = diffusetex * (Color_Ambient + half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb) * Color_Diffuse);\n",
1477 "#endif // MODE_LIGHTMAP\n",
1478 "#ifdef MODE_VERTEXCOLOR\n",
1479 " color.rgb = diffusetex * (Color_Ambient + half3(gl_FrontColor.rgb) * Color_Diffuse);\n",
1480 "#endif // MODE_VERTEXCOLOR\n",
1481 "#ifdef MODE_FLATCOLOR\n",
1482 " color.rgb = diffusetex * Color_Ambient;\n",
1483 "#endif // MODE_FLATCOLOR\n",
1489 "# ifdef USEDIFFUSE\n",
1490 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n",
1491 "# ifdef USESPECULAR\n",
1492 "# ifdef USEEXACTSPECULARMATH\n",
1493 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), 1.0 + SpecularPower * glosstex.a));\n",
1495 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n",
1496 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * glosstex.a));\n",
1498 " color.rgb = diffusetex * Color_Ambient + (diffusetex * Color_Diffuse * diffuse + glosstex.rgb * Color_Specular * specular) * lightcolor;\n",
1500 " color.rgb = diffusetex * (Color_Ambient + Color_Diffuse * diffuse * lightcolor);\n",
1503 " color.rgb = diffusetex * Color_Ambient;\n",
1507 "#ifdef USESHADOWMAPORTHO\n",
1508 " color.rgb *= half(ShadowMapCompare(ShadowMapTC, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale));\n",
1511 "#ifdef USEDEFERREDLIGHTMAP\n",
1512 " float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n",
1513 " color.rgb += diffusetex * half3(tex2D(Texture_ScreenDiffuse, ScreenTexCoord).rgb) * DeferredMod_Diffuse;\n",
1514 " color.rgb += glosstex.rgb * half3(tex2D(Texture_ScreenSpecular, ScreenTexCoord).rgb) * DeferredMod_Specular;\n",
1515 "// color.rgb = half3(tex2D(Texture_ScreenDepth, ScreenTexCoord).rgb);\n",
1516 "// color.r = half(texDepth2D(Texture_ScreenDepth, ScreenTexCoord)) * 1.0;\n",
1520 "#ifdef USEVERTEXTEXTUREBLEND\n",
1521 " color.rgb += half3(lerp(tex2D(Texture_SecondaryGlow, TexCoord2).rgb, offsetMappedTexture2D(Texture_Glow).rgb, terrainblend)) * Color_Glow;\n",
1523 " color.rgb += half3(offsetMappedTexture2D(Texture_Glow).rgb) * Color_Glow;\n",
1528 " color.rgb = half3(FogVertex(color, FogColor, EyeVectorModelSpaceFogPlaneVertexDist.xyz, EyeVectorModelSpaceFogPlaneVertexDist.w, FogRangeRecip, FogPlaneViewDist, FogHeightFade, Texture_FogMask, Texture_FogHeightTexture));\n",
1531 " // 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",
1532 "#ifdef USEREFLECTION\n",
1533 " float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n",
1534 " //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
1535 " float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW.zw + ScreenCenterRefractReflect.zw;\n",
1536 " float2 ScreenTexCoord = SafeScreenTexCoord + float3(normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5,0.5,0.5))).xy * DistortScaleRefractReflect.zw;\n",
1537 " // FIXME temporary hack to detect the case that the reflection\n",
1538 " // gets blackened at edges due to leaving the area that contains actual\n",
1540 " // Remove this 'ack once we have a better way to stop this thing from\n",
1542 " float f = min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(0.01, 0.01)).rgb) / 0.05);\n",
1543 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(0.01, -0.01)).rgb) / 0.05);\n",
1544 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, 0.01)).rgb) / 0.05);\n",
1545 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, -0.01)).rgb) / 0.05);\n",
1546 " ScreenTexCoord = lerp(SafeScreenTexCoord, ScreenTexCoord, f);\n",
1547 " color.rgb = lerp(color.rgb, half3(tex2D(Texture_Reflection, ScreenTexCoord).rgb) * ReflectColor.rgb, ReflectColor.a);\n",
1550 " dp_FragColor = float4(color);\n",
1552 "#endif // FRAGMENT_SHADER\n",
1554 "#endif // !MODE_DEFERREDLIGHTSOURCE\n",
1555 "#endif // !MODE_DEFERREDGEOMETRY\n",
1556 "#endif // !MODE_WATER\n",
1557 "#endif // !MODE_REFRACTION\n",
1558 "#endif // !MODE_BLOOMBLUR\n",
1559 "#endif // !MODE_GENERIC\n",
1560 "#endif // !MODE_POSTPROCESS\n",
1561 "#endif // !MODE_DEPTH_OR_SHADOW\n",