1 "// ambient+diffuse+specular+normalmap+attenuation+cubemap+fog shader\n"
2 "// written by Forest 'LordHavoc' Hale\n"
3 "// shadowmapping enhancements by Lee 'eihrul' Salzman\n"
5 "// FIXME: we need to get rid of ModelViewProjectionPosition to make room for the texcoord for this\n"
6 "#if defined(USEREFLECTION)\n"
7 "#undef USESHADOWMAPORTHO\n"
10 "#if defined(USEFOGINSIDE) || defined(USEFOGOUTSIDE) || defined(USEFOGHEIGHTTEXTURE)\n"
13 "#if defined(MODE_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE)\n"
14 "#define USELIGHTMAP\n"
16 "#if defined(USESPECULAR) || defined(USEOFFSETMAPPING) || defined(USEREFLECTCUBE) || defined(MODE_FAKELIGHT)\n"
17 "#define USEEYEVECTOR\n"
20 "#ifdef FRAGMENT_SHADER\n"
22 "//#undef USESHADOWMAPPCF\n"
23 "//#define texDepth2D(tex,texcoord) tex2D(tex,texcoord).r\n"
24 "#define texDepth2D(tex,texcoord) dot(tex2D(tex,texcoord).rgb, float3(1.0, 255.0/65536.0, 255.0/16777216.0))\n"
26 "#define texDepth2D(tex,texcoord) tex2D(tex,texcoord).r\n"
30 "#ifdef MODE_DEPTH_OR_SHADOW\n"
31 "#ifdef VERTEX_SHADER\n"
34 "float4 gl_Vertex : POSITION,\n"
35 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
36 "out float4 gl_Position : POSITION,\n"
37 "out float Depth : TEXCOORD0\n"
40 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
41 " Depth = gl_Position.z;\n"
45 "#ifdef FRAGMENT_SHADER\n"
48 "float Depth : TEXCOORD0,\n"
49 "out float4 gl_FragColor : COLOR\n"
52 "// float4 temp = float4(Depth,Depth*(65536.0/255.0),Depth*(16777216.0/255.0),0.0);\n"
53 " float4 temp = float4(Depth,Depth*256.0,Depth*65536.0,0.0);\n"
54 " temp.yz -= floor(temp.yz);\n"
55 " gl_FragColor = temp;\n"
56 "// gl_FragColor = float4(Depth,0,0,0);\n"
59 "#else // !MODE_DEPTH_ORSHADOW\n"
64 "#ifdef MODE_SHOWDEPTH\n"
65 "#ifdef VERTEX_SHADER\n"
68 "float4 gl_Vertex : POSITION,\n"
69 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
70 "out float4 gl_Position : POSITION,\n"
71 "out float4 gl_FrontColor : COLOR0\n"
74 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
75 " gl_FrontColor = float4(gl_Position.z, gl_Position.z, gl_Position.z, 1.0);\n"
79 "#ifdef FRAGMENT_SHADER\n"
82 "float4 gl_FrontColor : COLOR0,\n"
83 "out float4 gl_FragColor : COLOR\n"
86 " gl_FragColor = gl_FrontColor;\n"
89 "#else // !MODE_SHOWDEPTH\n"
94 "#ifdef MODE_POSTPROCESS\n"
96 "#ifdef VERTEX_SHADER\n"
99 "float4 gl_Vertex : POSITION,\n"
100 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
101 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
102 "float4 gl_MultiTexCoord4 : TEXCOORD4,\n"
103 "out float4 gl_Position : POSITION,\n"
104 "out float2 TexCoord1 : TEXCOORD0,\n"
105 "out float2 TexCoord2 : TEXCOORD1\n"
108 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
109 " TexCoord1 = gl_MultiTexCoord0.xy;\n"
111 " TexCoord2 = gl_MultiTexCoord4.xy;\n"
116 "#ifdef FRAGMENT_SHADER\n"
119 "float2 TexCoord1 : TEXCOORD0,\n"
120 "float2 TexCoord2 : TEXCOORD1,\n"
121 "uniform sampler Texture_First : register(s0),\n"
123 "uniform sampler Texture_Second : register(s1),\n"
125 "#ifdef USEGAMMARAMPS\n"
126 "uniform sampler Texture_GammaRamps : register(s2),\n"
128 "#ifdef USESATURATION\n"
129 "uniform float Saturation : register(c30),\n"
131 "#ifdef USEVIEWTINT\n"
132 "uniform float4 ViewTintColor : register(c41),\n"
134 "uniform float4 UserVec1 : register(c37),\n"
135 "uniform float4 UserVec2 : register(c38),\n"
136 "uniform float4 UserVec3 : register(c39),\n"
137 "uniform float4 UserVec4 : register(c40),\n"
138 "uniform float ClientTime : register(c2),\n"
139 "uniform float2 PixelSize : register(c25),\n"
140 "uniform float4 BloomColorSubtract : register(c43),\n"
141 "out float4 gl_FragColor : COLOR\n"
144 " gl_FragColor = tex2D(Texture_First, TexCoord1);\n"
146 " gl_FragColor += max(float4(0,0,0,0), tex2D(Texture_Second, TexCoord2) - BloomColorSubtract);\n"
148 "#ifdef USEVIEWTINT\n"
149 " gl_FragColor = lerp(gl_FragColor, ViewTintColor, ViewTintColor.a);\n"
152 "#ifdef USEPOSTPROCESSING\n"
153 "// do r_glsl_dumpshader, edit glsl/default.glsl, and replace this by your own postprocessing if you want\n"
154 "// this code does a blur with the radius specified in the first component of r_glsl_postprocess_uservec1 and blends it using the second component\n"
155 " float sobel = 1.0;\n"
156 " // float2 ts = textureSize(Texture_First, 0);\n"
157 " // float2 px = float2(1/ts.x, 1/ts.y);\n"
158 " float2 px = PixelSize;\n"
159 " float3 x1 = tex2D(Texture_First, TexCoord1 + float2(-px.x, px.y)).rgb;\n"
160 " float3 x2 = tex2D(Texture_First, TexCoord1 + float2(-px.x, 0.0)).rgb;\n"
161 " float3 x3 = tex2D(Texture_First, TexCoord1 + float2(-px.x,-px.y)).rgb;\n"
162 " float3 x4 = tex2D(Texture_First, TexCoord1 + float2( px.x, px.y)).rgb;\n"
163 " float3 x5 = tex2D(Texture_First, TexCoord1 + float2( px.x, 0.0)).rgb;\n"
164 " float3 x6 = tex2D(Texture_First, TexCoord1 + float2( px.x,-px.y)).rgb;\n"
165 " float3 y1 = tex2D(Texture_First, TexCoord1 + float2( px.x,-px.y)).rgb;\n"
166 " float3 y2 = tex2D(Texture_First, TexCoord1 + float2( 0.0,-px.y)).rgb;\n"
167 " float3 y3 = tex2D(Texture_First, TexCoord1 + float2(-px.x,-px.y)).rgb;\n"
168 " float3 y4 = tex2D(Texture_First, TexCoord1 + float2( px.x, px.y)).rgb;\n"
169 " float3 y5 = tex2D(Texture_First, TexCoord1 + float2( 0.0, px.y)).rgb;\n"
170 " float3 y6 = tex2D(Texture_First, TexCoord1 + float2(-px.x, px.y)).rgb;\n"
171 " float px1 = -1.0 * dot(float3(0.3, 0.59, 0.11), x1);\n"
172 " float px2 = -2.0 * dot(float3(0.3, 0.59, 0.11), x2);\n"
173 " float px3 = -1.0 * dot(float3(0.3, 0.59, 0.11), x3);\n"
174 " float px4 = 1.0 * dot(float3(0.3, 0.59, 0.11), x4);\n"
175 " float px5 = 2.0 * dot(float3(0.3, 0.59, 0.11), x5);\n"
176 " float px6 = 1.0 * dot(float3(0.3, 0.59, 0.11), x6);\n"
177 " float py1 = -1.0 * dot(float3(0.3, 0.59, 0.11), y1);\n"
178 " float py2 = -2.0 * dot(float3(0.3, 0.59, 0.11), y2);\n"
179 " float py3 = -1.0 * dot(float3(0.3, 0.59, 0.11), y3);\n"
180 " float py4 = 1.0 * dot(float3(0.3, 0.59, 0.11), y4);\n"
181 " float py5 = 2.0 * dot(float3(0.3, 0.59, 0.11), y5);\n"
182 " float py6 = 1.0 * dot(float3(0.3, 0.59, 0.11), y6);\n"
183 " sobel = 0.25 * abs(px1 + px2 + px3 + px4 + px5 + px6) + 0.25 * abs(py1 + py2 + py3 + py4 + py5 + py6);\n"
184 " gl_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.987688, -0.156434)) * UserVec1.y;\n"
185 " gl_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.156434, -0.891007)) * UserVec1.y;\n"
186 " gl_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2( 0.891007, -0.453990)) * UserVec1.y;\n"
187 " gl_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2( 0.707107, 0.707107)) * UserVec1.y;\n"
188 " gl_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.453990, 0.891007)) * UserVec1.y;\n"
189 " gl_FragColor /= (1.0 + 5.0 * UserVec1.y);\n"
190 " gl_FragColor.rgb = gl_FragColor.rgb * (1.0 + UserVec2.x) + float3(1,1,1)*max(0.0, sobel - UserVec2.z)*UserVec2.y;\n"
193 "#ifdef USESATURATION\n"
194 " //apply saturation BEFORE gamma ramps, so v_glslgamma value does not matter\n"
195 " float y = dot(gl_FragColor.rgb, float3(0.299, 0.587, 0.114));\n"
196 " // 'vampire sight' effect, wheres red is compensated\n"
197 " #ifdef SATURATION_REDCOMPENSATE\n"
198 " float rboost = max(0.0, (gl_FragColor.r - max(gl_FragColor.g, gl_FragColor.b))*(1.0 - Saturation));\n"
199 " gl_FragColor.rgb = lerp(float3(y,y,y), gl_FragColor.rgb, Saturation);\n"
200 " gl_FragColor.r += r;\n"
202 " // normal desaturation\n"
203 " //gl_FragColor = float3(y,y,y) + (gl_FragColor.rgb - float3(y)) * Saturation;\n"
204 " gl_FragColor.rgb = lerp(float3(y,y,y), gl_FragColor.rgb, Saturation);\n"
208 "#ifdef USEGAMMARAMPS\n"
209 " gl_FragColor.r = tex2D(Texture_GammaRamps, float2(gl_FragColor.r, 0)).r;\n"
210 " gl_FragColor.g = tex2D(Texture_GammaRamps, float2(gl_FragColor.g, 0)).g;\n"
211 " gl_FragColor.b = tex2D(Texture_GammaRamps, float2(gl_FragColor.b, 0)).b;\n"
215 "#else // !MODE_POSTPROCESS\n"
220 "#ifdef MODE_GENERIC\n"
221 "#ifdef VERTEX_SHADER\n"
224 "float4 gl_Vertex : POSITION,\n"
225 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
226 "float4 gl_Color : COLOR0,\n"
227 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
228 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n"
229 "out float4 gl_Position : POSITION,\n"
230 "#ifdef USEDIFFUSE\n"
231 "out float2 TexCoord1 : TEXCOORD0,\n"
233 "#ifdef USESPECULAR\n"
234 "out float2 TexCoord2 : TEXCOORD1,\n"
236 "out float4 gl_FrontColor : COLOR\n"
239 " gl_FrontColor = gl_Color;\n"
240 "#ifdef USEDIFFUSE\n"
241 " TexCoord1 = gl_MultiTexCoord0.xy;\n"
243 "#ifdef USESPECULAR\n"
244 " TexCoord2 = gl_MultiTexCoord1.xy;\n"
246 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
250 "#ifdef FRAGMENT_SHADER\n"
254 "float4 gl_FrontColor : COLOR0,\n"
255 "float2 TexCoord1 : TEXCOORD0,\n"
256 "float2 TexCoord2 : TEXCOORD1,\n"
257 "#ifdef USEDIFFUSE\n"
258 "uniform sampler Texture_First : register(s0),\n"
260 "#ifdef USESPECULAR\n"
261 "uniform sampler Texture_Second : register(s1),\n"
263 "out float4 gl_FragColor : COLOR\n"
266 "#ifdef USEVIEWTINT\n"
267 " gl_FragColor = gl_FrontColor;\n"
269 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
271 "#ifdef USEDIFFUSE\n"
272 " gl_FragColor *= tex2D(Texture_First, TexCoord1);\n"
275 "#ifdef USESPECULAR\n"
276 " float4 tex2 = tex2D(Texture_Second, TexCoord2);\n"
277 "# ifdef USECOLORMAPPING\n"
278 " gl_FragColor *= tex2;\n"
281 " gl_FragColor += tex2;\n"
283 "# ifdef USEVERTEXTEXTUREBLEND\n"
284 " gl_FragColor = lerp(gl_FragColor, tex2, tex2.a);\n"
289 "#else // !MODE_GENERIC\n"
294 "#ifdef MODE_BLOOMBLUR\n"
295 "#ifdef VERTEX_SHADER\n"
298 "float4 gl_Vertex : POSITION,\n"
299 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
300 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
301 "out float4 gl_Position : POSITION,\n"
302 "out float2 TexCoord : TEXCOORD0\n"
305 " TexCoord = gl_MultiTexCoord0.xy;\n"
306 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
310 "#ifdef FRAGMENT_SHADER\n"
314 "float2 TexCoord : TEXCOORD0,\n"
315 "uniform sampler Texture_First : register(s0),\n"
316 "uniform float4 BloomBlur_Parameters : register(c1),\n"
317 "out float4 gl_FragColor : COLOR\n"
321 " float2 tc = TexCoord;\n"
322 " float3 color = tex2D(Texture_First, tc).rgb;\n"
323 " tc += BloomBlur_Parameters.xy;\n"
324 " for (i = 1;i < SAMPLES;i++)\n"
326 " color += tex2D(Texture_First, tc).rgb;\n"
327 " tc += BloomBlur_Parameters.xy;\n"
329 " gl_FragColor = float4(color * BloomBlur_Parameters.z + float3(BloomBlur_Parameters.w), 1);\n"
332 "#else // !MODE_BLOOMBLUR\n"
333 "#ifdef MODE_REFRACTION\n"
334 "#ifdef VERTEX_SHADER\n"
337 "float4 gl_Vertex : POSITION,\n"
338 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
339 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
340 "uniform float4x4 TexMatrix : register(c0),\n"
341 "uniform float3 EyePosition : register(c24),\n"
342 "out float4 gl_Position : POSITION,\n"
343 "out float2 TexCoord : TEXCOORD0,\n"
344 "out float3 EyeVector : TEXCOORD1,\n"
345 "out float4 ModelViewProjectionPosition : TEXCOORD2\n"
348 " TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n"
349 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
350 " ModelViewProjectionPosition = gl_Position;\n"
354 "#ifdef FRAGMENT_SHADER\n"
357 "float2 TexCoord : TEXCOORD0,\n"
358 "float3 EyeVector : TEXCOORD1,\n"
359 "float4 ModelViewProjectionPosition : TEXCOORD2,\n"
360 "uniform sampler Texture_Normal : register(s0),\n"
361 "uniform sampler Texture_Refraction : register(s3),\n"
362 "uniform sampler Texture_Reflection : register(s7),\n"
363 "uniform float4 DistortScaleRefractReflect : register(c14),\n"
364 "uniform float4 ScreenScaleRefractReflect : register(c32),\n"
365 "uniform float4 ScreenCenterRefractReflect : register(c31),\n"
366 "uniform float4 RefractColor : register(c29),\n"
367 "out float4 gl_FragColor : COLOR\n"
370 " float2 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect.xy * (1.0 / ModelViewProjectionPosition.w);\n"
371 " //float2 ScreenTexCoord = (ModelViewProjectionPosition.xy + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy * DistortScaleRefractReflect.xy * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n"
372 " float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n"
373 " float2 ScreenTexCoord = SafeScreenTexCoord + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy * DistortScaleRefractReflect.xy;\n"
374 " // FIXME temporary hack to detect the case that the reflection\n"
375 " // gets blackened at edges due to leaving the area that contains actual\n"
377 " // Remove this 'ack once we have a better way to stop this thing from\n"
379 " float f = min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(0.01, 0.01)).rgb) / 0.05);\n"
380 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(0.01, -0.01)).rgb) / 0.05);\n"
381 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(-0.01, 0.01)).rgb) / 0.05);\n"
382 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(-0.01, -0.01)).rgb) / 0.05);\n"
383 " ScreenTexCoord = lerp(SafeScreenTexCoord, ScreenTexCoord, f);\n"
384 " gl_FragColor = float4(tex2D(Texture_Refraction, ScreenTexCoord).rgb, 1) * RefractColor;\n"
387 "#else // !MODE_REFRACTION\n"
392 "#ifdef MODE_WATER\n"
393 "#ifdef VERTEX_SHADER\n"
397 "float4 gl_Vertex : POSITION,\n"
398 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
399 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
400 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n"
401 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n"
402 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n"
403 "uniform float4x4 TexMatrix : register(c0),\n"
404 "uniform float3 EyePosition : register(c24),\n"
405 "out float4 gl_Position : POSITION,\n"
406 "out float2 TexCoord : TEXCOORD0,\n"
407 "out float3 EyeVector : TEXCOORD1,\n"
408 "out float4 ModelViewProjectionPosition : TEXCOORD2\n"
411 " TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n"
412 " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n"
413 " EyeVector.x = dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz);\n"
414 " EyeVector.y = dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz);\n"
415 " EyeVector.z = dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz);\n"
416 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
417 " ModelViewProjectionPosition = gl_Position;\n"
421 "#ifdef FRAGMENT_SHADER\n"
424 "float2 TexCoord : TEXCOORD0,\n"
425 "float3 EyeVector : TEXCOORD1,\n"
426 "float4 ModelViewProjectionPosition : TEXCOORD2,\n"
427 "uniform sampler Texture_Normal : register(s0),\n"
428 "uniform sampler Texture_Refraction : register(s3),\n"
429 "uniform sampler Texture_Reflection : register(s7),\n"
430 "uniform float4 DistortScaleRefractReflect : register(c14),\n"
431 "uniform float4 ScreenScaleRefractReflect : register(c32),\n"
432 "uniform float4 ScreenCenterRefractReflect : register(c31),\n"
433 "uniform float4 RefractColor : register(c29),\n"
434 "uniform float4 ReflectColor : register(c26),\n"
435 "uniform float ReflectFactor : register(c27),\n"
436 "uniform float ReflectOffset : register(c28),\n"
437 "out float4 gl_FragColor : COLOR\n"
440 " float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n"
441 " //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n"
442 " float4 SafeScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n"
443 " //SafeScreenTexCoord = gl_FragCoord.xyxy * float4(1.0 / 1920.0, 1.0 / 1200.0, 1.0 / 1920.0, 1.0 / 1200.0);\n"
444 " float4 ScreenTexCoord = SafeScreenTexCoord + float2(normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy).xyxy * DistortScaleRefractReflect;\n"
445 " // FIXME temporary hack to detect the case that the reflection\n"
446 " // gets blackened at edges due to leaving the area that contains actual\n"
448 " // Remove this 'ack once we have a better way to stop this thing from\n"
450 " float f = min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(0.01, 0.01)).rgb) / 0.05);\n"
451 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(0.01, -0.01)).rgb) / 0.05);\n"
452 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(-0.01, 0.01)).rgb) / 0.05);\n"
453 " f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(-0.01, -0.01)).rgb) / 0.05);\n"
454 " ScreenTexCoord.xy = lerp(SafeScreenTexCoord.xy, ScreenTexCoord.xy, f);\n"
455 " f = min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(0.01, 0.01)).rgb) / 0.05);\n"
456 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(0.01, -0.01)).rgb) / 0.05);\n"
457 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(-0.01, 0.01)).rgb) / 0.05);\n"
458 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(-0.01, -0.01)).rgb) / 0.05);\n"
459 " ScreenTexCoord.zw = lerp(SafeScreenTexCoord.zw, ScreenTexCoord.zw, f);\n"
460 " float Fresnel = pow(min(1.0, 1.0 - float(normalize(EyeVector).z)), 2.0) * ReflectFactor + ReflectOffset;\n"
461 " gl_FragColor = lerp(float4(tex2D(Texture_Refraction, ScreenTexCoord.xy).rgb, 1) * RefractColor, float4(tex2D(Texture_Reflection, ScreenTexCoord.zw).rgb, 1) * ReflectColor, Fresnel);\n"
464 "#else // !MODE_WATER\n"
469 "// TODO: get rid of tangentt (texcoord2) and use a crossproduct to regenerate it from tangents (texcoord1) and normal (texcoord3), this would require sending a 4 component texcoord1 with W as 1 or -1 according to which side the texcoord2 should be on\n"
471 "// fragment shader specific:\n"
472 "#ifdef FRAGMENT_SHADER\n"
475 "float3 FogVertex(float4 surfacecolor, float3 FogColor, float3 EyeVectorModelSpace, float FogPlaneVertexDist, float FogRangeRecip, float FogPlaneViewDist, float FogHeightFade, sampler Texture_FogMask, sampler Texture_FogHeightTexture)\n"
478 " float3 fc = FogColor;\n"
479 "#ifdef USEFOGALPHAHACK\n"
480 " fc *= surfacecolor.a;\n"
482 "#ifdef USEFOGHEIGHTTEXTURE\n"
483 " float4 fogheightpixel = tex2D(Texture_FogHeightTexture, float2(1,1) + float2(FogPlaneVertexDist, FogPlaneViewDist) * (-2.0 * FogHeightFade));\n"
484 " fogfrac = fogheightpixel.a;\n"
485 " return lerp(fogheightpixel.rgb * fc, surfacecolor.rgb, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n"
487 "# ifdef USEFOGOUTSIDE\n"
488 " fogfrac = min(0.0, FogPlaneVertexDist) / (FogPlaneVertexDist - FogPlaneViewDist) * min(1.0, min(0.0, FogPlaneVertexDist) * FogHeightFade);\n"
490 " fogfrac = FogPlaneViewDist / (FogPlaneViewDist - max(0.0, FogPlaneVertexDist)) * min(1.0, (min(0.0, FogPlaneVertexDist) + FogPlaneViewDist) * FogHeightFade);\n"
492 " return lerp(fc, surfacecolor.rgb, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n"
497 "#ifdef USEOFFSETMAPPING\n"
498 "float2 OffsetMapping(float2 TexCoord, float3 OffsetMapping_ScaleSteps, float3 EyeVector, sampler Texture_Normal, float2 dPdx, float2 dPdy)\n"
501 "#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n"
502 " // 14 sample relief mapping: linear search and then binary search\n"
503 " // this basically steps forward a small amount repeatedly until it finds\n"
504 " // itself inside solid, then jitters forward and back using decreasing\n"
505 " // amounts to find the impact\n"
506 " //float3 OffsetVector = float3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMapping_ScaleSteps.x) * float2(-1, 1), -1);\n"
507 " //float3 OffsetVector = float3(normalize(EyeVector.xy) * OffsetMapping_ScaleSteps.x * float2(-1, 1), -1);\n"
508 " float3 OffsetVector = float3(normalize(EyeVector).xy * OffsetMapping_ScaleSteps.x * float2(-1, 1), -1);\n"
509 " float3 RT = float3(TexCoord, 1);\n"
510 " OffsetVector *= OffsetMapping_ScaleSteps.z;\n"
511 " for(i = 1.0; i < OffsetMapping_ScaleSteps.y; ++i)\n"
512 " RT += OffsetVector * step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z);\n"
513 " RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) - 0.5);\n"
514 " RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * 0.5 - 0.25);\n"
515 " RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * 0.25 - 0.125);\n"
516 " RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * 0.125 - 0.0625);\n"
517 " RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * 0.0625 - 0.03125);\n"
520 " // 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits)\n"
521 " //float2 OffsetVector = float2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMapping_ScaleSteps.x) * float2(-1, 1));\n"
522 " //float2 OffsetVector = float2(normalize(EyeVector.xy) * OffsetMapping_ScaleSteps.x * float2(-1, 1));\n"
523 " float2 OffsetVector = float2(normalize(EyeVector).xy * OffsetMapping_ScaleSteps.x * float2(-1, 1));\n"
524 " OffsetVector *= OffsetMapping_ScaleSteps.z;\n"
525 " for(i = 0.0; i < OffsetMapping_ScaleSteps.y; ++i)\n"
526 " TexCoord += OffsetVector * (1.0 - tex2Dgrad(Texture_Normal, TexCoord, dPdx, dPdy).a);\n"
527 " return TexCoord;\n"
530 "#endif // USEOFFSETMAPPING\n"
532 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n"
533 "#if defined(USESHADOWMAP2D)\n"
534 "# ifdef USESHADOWMAPORTHO\n"
535 "# define GetShadowMapTC2D(dir, ShadowMap_Parameters) (min(dir, ShadowMap_Parameters.xyz))\n"
537 "# ifdef USESHADOWMAPVSDCT\n"
538 "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters, samplerCUBE Texture_CubeProjection)\n"
540 " float3 adir = abs(dir);\n"
541 " float2 aparams = ShadowMap_Parameters.xy / max(max(adir.x, adir.y), adir.z);\n"
542 " float4 proj = texCUBE(Texture_CubeProjection, dir);\n"
543 " return float3(lerp(dir.xy, dir.zz, proj.xy) * aparams.x + proj.zw * ShadowMap_Parameters.z, aparams.y + ShadowMap_Parameters.w);\n"
546 "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters)\n"
548 " float3 adir = abs(dir);\n"
549 " float ma = adir.z;\n"
550 " float4 proj = float4(dir, 2.5);\n"
551 " if (adir.x > ma) { ma = adir.x; proj = float4(dir.zyx, 0.5); }\n"
552 " if (adir.y > ma) { ma = adir.y; proj = float4(dir.xzy, 1.5); }\n"
554 " return float3(proj.xy * ShadowMap_Parameters.x / ma + float2(0.5,0.5) + float2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, ma + 64 * ShadowMap_Parameters.w);\n"
556 " float2 aparams = ShadowMap_Parameters.xy / ma;\n"
557 " return float3(proj.xy * aparams.x + float2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, aparams.y + ShadowMap_Parameters.w);\n"
562 "#endif // defined(USESHADOWMAP2D)\n"
564 "# ifdef USESHADOWMAP2D\n"
565 "#ifdef USESHADOWMAPVSDCT\n"
566 "float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale, samplerCUBE Texture_CubeProjection)\n"
568 "float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale)\n"
571 "#ifdef USESHADOWMAPVSDCT\n"
572 " float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters, Texture_CubeProjection);\n"
574 " float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters);\n"
578 "# ifdef USESHADOWSAMPLER\n"
579 "# ifdef USESHADOWMAPPCF\n"
580 "# define texval(x, y) tex2Dproj(Texture_ShadowMap2D, float4(center + float2(x, y)*ShadowMap_TextureScale, shadowmaptc.z, 1.0)).r \n"
581 " float2 center = shadowmaptc.xy*ShadowMap_TextureScale;\n"
582 " 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"
584 " f = tex2Dproj(Texture_ShadowMap2D, float4(shadowmaptc.xy*ShadowMap_TextureScale, shadowmaptc.z, 1.0)).r;\n"
587 "# ifdef USESHADOWMAPPCF\n"
588 "# if defined(GL_ARB_texture_gather) || defined(GL_AMD_texture_texture4)\n"
589 "# ifdef GL_ARB_texture_gather\n"
590 "# define texval(x, y) textureGatherOffset(Texture_ShadowMap2D, center, int2(x, y))\n"
592 "# define texval(x, y) texture4(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale)\n"
594 " float2 offset = frac(shadowmaptc.xy - 0.5), center = (shadowmaptc.xy - offset)*ShadowMap_TextureScale;\n"
595 "# if USESHADOWMAPPCF > 1\n"
596 " float4 group1 = step(shadowmaptc.z, texval(-2.0, -2.0));\n"
597 " float4 group2 = step(shadowmaptc.z, texval( 0.0, -2.0));\n"
598 " float4 group3 = step(shadowmaptc.z, texval( 2.0, -2.0));\n"
599 " float4 group4 = step(shadowmaptc.z, texval(-2.0, 0.0));\n"
600 " float4 group5 = step(shadowmaptc.z, texval( 0.0, 0.0));\n"
601 " float4 group6 = step(shadowmaptc.z, texval( 2.0, 0.0));\n"
602 " float4 group7 = step(shadowmaptc.z, texval(-2.0, 2.0));\n"
603 " float4 group8 = step(shadowmaptc.z, texval( 0.0, 2.0));\n"
604 " float4 group9 = step(shadowmaptc.z, texval( 2.0, 2.0));\n"
605 " float4 locols = float4(group1.ab, group3.ab);\n"
606 " float4 hicols = float4(group7.rg, group9.rg);\n"
607 " locols.yz += group2.ab;\n"
608 " hicols.yz += group8.rg;\n"
609 " float4 midcols = float4(group1.rg, group3.rg) + float4(group7.ab, group9.ab) +\n"
610 " float4(group4.rg, group6.rg) + float4(group4.ab, group6.ab) +\n"
611 " lerp(locols, hicols, offset.y);\n"
612 " float4 cols = group5 + float4(group2.rg, group8.ab);\n"
613 " cols.xyz += lerp(midcols.xyz, midcols.yzw, offset.x);\n"
614 " f = dot(cols, float4(1.0/25.0));\n"
616 " float4 group1 = step(shadowmaptc.z, texval(-1.0, -1.0));\n"
617 " float4 group2 = step(shadowmaptc.z, texval( 1.0, -1.0));\n"
618 " float4 group3 = step(shadowmaptc.z, texval(-1.0, 1.0));\n"
619 " float4 group4 = step(shadowmaptc.z, texval( 1.0, 1.0));\n"
620 " float4 cols = float4(group1.rg, group2.rg) + float4(group3.ab, group4.ab) +\n"
621 " lerp(float4(group1.ab, group2.ab), float4(group3.rg, group4.rg), offset.y);\n"
622 " f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n"
625 "# ifdef GL_EXT_gpu_shader4\n"
626 "# define texval(x, y) tex2DOffset(Texture_ShadowMap2D, center, int2(x, y)).r\n"
628 "# define texval(x, y) texDepth2D(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale).r \n"
630 "# if USESHADOWMAPPCF > 1\n"
631 " float2 center = shadowmaptc.xy - 0.5, offset = frac(center);\n"
632 " center *= ShadowMap_TextureScale;\n"
633 " 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"
634 " 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"
635 " 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"
636 " 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"
637 " float4 cols = row2 + row3 + lerp(row1, row4, offset.y);\n"
638 " f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n"
640 " float2 center = shadowmaptc.xy*ShadowMap_TextureScale, offset = frac(shadowmaptc.xy);\n"
641 " float3 row1 = step(shadowmaptc.z, float3(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0)));\n"
642 " float3 row2 = step(shadowmaptc.z, float3(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0)));\n"
643 " float3 row3 = step(shadowmaptc.z, float3(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0)));\n"
644 " float3 cols = row2 + lerp(row1, row3, offset.y);\n"
645 " f = dot(lerp(cols.xy, cols.yz, offset.x), float2(0.25,0.25));\n"
649 " f = step(shadowmaptc.z, tex2D(Texture_ShadowMap2D, shadowmaptc.xy*ShadowMap_TextureScale).r);\n"
652 "# ifdef USESHADOWMAPORTHO\n"
653 " return lerp(ShadowMap_Parameters.w, 1.0, f);\n"
659 "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n"
660 "#endif // FRAGMENT_SHADER\n"
665 "#ifdef MODE_DEFERREDGEOMETRY\n"
666 "#ifdef VERTEX_SHADER\n"
669 "float4 gl_Vertex : POSITION,\n"
670 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
671 "#ifdef USEVERTEXTEXTUREBLEND\n"
672 "float4 gl_Color : COLOR0,\n"
674 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
675 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n"
676 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n"
677 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n"
678 "uniform float4x4 TexMatrix : register(c0),\n"
679 "#ifdef USEVERTEXTEXTUREBLEND\n"
680 "uniform float4x4 BackgroundTexMatrix : register(c4),\n"
682 "uniform float4x4 ModelViewMatrix : register(c12),\n"
683 "#ifdef USEOFFSETMAPPING\n"
684 "uniform float3 EyePosition : register(c24),\n"
686 "out float4 gl_Position : POSITION,\n"
687 "#ifdef USEVERTEXTEXTUREBLEND\n"
688 "out float4 gl_FrontColor : COLOR,\n"
690 "out float4 TexCoordBoth : TEXCOORD0,\n"
691 "#ifdef USEOFFSETMAPPING\n"
692 "out float3 EyeVector : TEXCOORD2,\n"
694 "out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
695 "out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
696 "out float4 VectorR : TEXCOORD7 // direction of R texcoord (surface normal), Depth value\n"
699 " TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n"
700 "#ifdef USEVERTEXTEXTUREBLEND\n"
701 " gl_FrontColor = gl_Color;\n"
702 " TexCoordBoth.zw = float2(Backgroundmul(TexMatrix, gl_MultiTexCoord0));\n"
705 " // transform unnormalized eye direction into tangent space\n"
706 "#ifdef USEOFFSETMAPPING\n"
707 " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n"
708 " EyeVector.x = dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz);\n"
709 " EyeVector.y = dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz);\n"
710 " EyeVector.z = dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz);\n"
713 " VectorS = mul(ModelViewMatrix, float4(gl_MultiTexCoord1.xyz, 0)).xyz;\n"
714 " VectorT = mul(ModelViewMatrix, float4(gl_MultiTexCoord2.xyz, 0)).xyz;\n"
715 " VectorR.xyz = mul(ModelViewMatrix, float4(gl_MultiTexCoord3.xyz, 0)).xyz;\n"
716 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
717 " VectorR.w = gl_Position.z;\n"
719 "#endif // VERTEX_SHADER\n"
721 "#ifdef FRAGMENT_SHADER\n"
724 "float4 TexCoordBoth : TEXCOORD0,\n"
725 "float3 EyeVector : TEXCOORD2,\n"
726 "float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
727 "float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
728 "float4 VectorR : TEXCOORD7, // direction of R texcoord (surface normal), Depth value\n"
729 "uniform sampler Texture_Normal : register(s0),\n"
730 "#ifdef USEALPHAKILL\n"
731 "uniform sampler Texture_Color : register(s1),\n"
733 "uniform sampler Texture_Gloss : register(s2),\n"
734 "#ifdef USEVERTEXTEXTUREBLEND\n"
735 "uniform sampler Texture_SecondaryNormal : register(s4),\n"
736 "uniform sampler Texture_SecondaryGloss : register(s6),\n"
738 "#ifdef USEOFFSETMAPPING\n"
739 "uniform float3 OffsetMapping_ScaleSteps : register(c24),\n"
741 "uniform half SpecularPower : register(c36),\n"
743 "out float4 gl_FragData0 : COLOR0,\n"
744 "out float4 gl_FragData1 : COLOR1\n"
746 "out float4 gl_FragColor : COLOR\n"
750 " float2 TexCoord = TexCoordBoth.xy;\n"
751 "#ifdef USEOFFSETMAPPING\n"
752 " // apply offsetmapping\n"
753 " float2 dPdx = ddx(TexCoord);\n"
754 " float2 dPdy = ddy(TexCoord);\n"
755 " float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, EyeVector, Texture_Normal, dPdx, dPdy);\n"
756 "# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n"
758 "# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n"
761 "#ifdef USEALPHAKILL\n"
762 " if (offsetMappedTexture2D(Texture_Color).a < 0.5)\n"
766 "#ifdef USEVERTEXTEXTUREBLEND\n"
767 " float alpha = offsetMappedTexture2D(Texture_Color).a;\n"
768 " float terrainblend = clamp(float(gl_FrontColor.a) * alpha * 2.0 - 0.5, float(0.0), float(1.0));\n"
769 " //float terrainblend = min(float(gl_FrontColor.a) * alpha * 2.0, float(1.0));\n"
770 " //float terrainblend = float(gl_FrontColor.a) * alpha > 0.5;\n"
773 "#ifdef USEVERTEXTEXTUREBLEND\n"
774 " float3 surfacenormal = lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, offsetMappedTexture2D(Texture_Normal).rgb, terrainblend) - float3(0.5, 0.5, 0.5);\n"
775 " float a = lerp(tex2D(Texture_SecondaryGloss, TexCoord2).a, offsetMappedTexture2D(Texture_Gloss).a, terrainblend);\n"
777 " float3 surfacenormal = offsetMappedTexture2D(Texture_Normal).rgb - float3(0.5, 0.5, 0.5);\n"
778 " float a = offsetMappedTexture2D(Texture_Gloss).a;\n"
782 " gl_FragData0 = float4(normalize(surfacenormal.x * VectorS + surfacenormal.y * VectorT + surfacenormal.z * VectorR.xyz) * 0.5 + float3(0.5, 0.5, 0.5), a);\n"
783 " float Depth = VectorR.w / 256.0;\n"
784 " float4 depthcolor = float4(Depth,Depth*65536.0/255.0,Depth*16777216.0/255.0,0.0);\n"
785 "// float4 depthcolor = float4(Depth,Depth*256.0,Depth*65536.0,0.0);\n"
786 " depthcolor.yz -= floor(depthcolor.yz);\n"
787 " gl_FragData1 = depthcolor;\n"
789 " gl_FragColor = float4(normalize(surfacenormal.x * VectorS + surfacenormal.y * VectorT + surfacenormal.z * VectorR) * 0.5 + float3(0.5, 0.5, 0.5), a);\n"
792 "#endif // FRAGMENT_SHADER\n"
793 "#else // !MODE_DEFERREDGEOMETRY\n"
798 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
799 "#ifdef VERTEX_SHADER\n"
802 "float4 gl_Vertex : POSITION,\n"
803 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
804 "uniform float4x4 ModelViewMatrix : register(c12),\n"
805 "out float4 gl_Position : POSITION,\n"
806 "out float4 ModelViewPosition : TEXCOORD0\n"
809 " ModelViewPosition = mul(ModelViewMatrix, gl_Vertex);\n"
810 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
812 "#endif // VERTEX_SHADER\n"
814 "#ifdef FRAGMENT_SHADER\n"
818 "float2 Pixel : VPOS,\n"
820 "float2 Pixel : WPOS,\n"
822 "float4 ModelViewPosition : TEXCOORD0,\n"
823 "uniform float4x4 ViewToLight : register(c44),\n"
824 "uniform float2 ScreenToDepth : register(c33), // ScreenToDepth = float2(Far / (Far - Near), Far * Near / (Near - Far));\n"
825 "uniform float3 LightPosition : register(c23),\n"
826 "uniform half2 PixelToScreenTexCoord : register(c42),\n"
827 "uniform half3 DeferredColor_Ambient : register(c9),\n"
828 "uniform half3 DeferredColor_Diffuse : register(c10),\n"
829 "#ifdef USESPECULAR\n"
830 "uniform half3 DeferredColor_Specular : register(c11),\n"
831 "uniform half SpecularPower : register(c36),\n"
833 "uniform sampler Texture_Attenuation : register(s9),\n"
834 "uniform sampler Texture_ScreenDepth : register(s13),\n"
835 "uniform sampler Texture_ScreenNormalMap : register(s14),\n"
837 "#ifdef USECUBEFILTER\n"
838 "uniform samplerCUBE Texture_Cube : register(s10),\n"
841 "#ifdef USESHADOWMAP2D\n"
842 "# ifdef USESHADOWSAMPLER\n"
843 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
845 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
849 "#ifdef USESHADOWMAPVSDCT\n"
850 "uniform samplerCUBE Texture_CubeProjection : register(s12),\n"
853 "#if defined(USESHADOWMAP2D)\n"
854 "uniform float2 ShadowMap_TextureScale : register(c35),\n"
855 "uniform float4 ShadowMap_Parameters : register(c34),\n"
858 "out float4 gl_FragData0 : COLOR0,\n"
859 "out float4 gl_FragData1 : COLOR1\n"
862 " // calculate viewspace pixel position\n"
863 " float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n"
864 " //ScreenTexCoord.y = ScreenTexCoord.y * -1 + 1; // Cg is opposite?\n"
865 " float3 position;\n"
867 " position.z = texDepth2D(Texture_ScreenDepth, ScreenTexCoord) * 256.0;\n"
869 " position.z = ScreenToDepth.y / (texDepth2D(Texture_ScreenDepth, ScreenTexCoord) + ScreenToDepth.x);\n"
871 " position.xy = ModelViewPosition.xy * (position.z / ModelViewPosition.z);\n"
872 " // decode viewspace pixel normal\n"
873 " half4 normalmap = half4(tex2D(Texture_ScreenNormalMap, ScreenTexCoord));\n"
874 " half3 surfacenormal = half3(normalize(normalmap.rgb - half3(0.5,0.5,0.5)));\n"
875 " // surfacenormal = pixel normal in viewspace\n"
876 " // LightVector = pixel to light in viewspace\n"
877 " // CubeVector = position in lightspace\n"
878 " // eyevector = pixel to view in viewspace\n"
879 " float3 CubeVector = mul(ViewToLight, float4(position,1)).xyz;\n"
880 " half fade = half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n"
881 "#ifdef USEDIFFUSE\n"
882 " // calculate diffuse shading\n"
883 " half3 lightnormal = half3(normalize(LightPosition - position));\n"
884 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n"
886 "#ifdef USESPECULAR\n"
887 " // calculate directional shading\n"
888 " float3 eyevector = position * -1.0;\n"
889 "# ifdef USEEXACTSPECULARMATH\n"
890 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(eyevector)))*-1.0, 0.0)), SpecularPower * normalmap.a));\n"
892 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(eyevector))));\n"
893 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * normalmap.a));\n"
897 "#if defined(USESHADOWMAP2D)\n"
898 " fade *= half(ShadowMapCompare(CubeVector, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n"
899 "#ifdef USESHADOWMAPVSDCT\n"
900 ", Texture_CubeProjection\n"
905 "#ifdef USEDIFFUSE\n"
906 " gl_FragData0 = float4((DeferredColor_Ambient + DeferredColor_Diffuse * diffuse) * fade, 1.0);\n"
908 " gl_FragData0 = float4(DeferredColor_Ambient * fade, 1.0);\n"
910 "#ifdef USESPECULAR\n"
911 " gl_FragData1 = float4(DeferredColor_Specular * (specular * fade), 1.0);\n"
913 " gl_FragData1 = float4(0.0, 0.0, 0.0, 1.0);\n"
916 "# ifdef USECUBEFILTER\n"
917 " float3 cubecolor = texCUBE(Texture_Cube, CubeVector).rgb;\n"
918 " gl_FragData0.rgb *= cubecolor;\n"
919 " gl_FragData1.rgb *= cubecolor;\n"
922 "#endif // FRAGMENT_SHADER\n"
923 "#else // !MODE_DEFERREDLIGHTSOURCE\n"
928 "#ifdef VERTEX_SHADER\n"
931 "float4 gl_Vertex : POSITION,\n"
932 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
933 "#if defined(USEVERTEXTEXTUREBLEND) || defined(MODE_VERTEXCOLOR)\n"
934 "float4 gl_Color : COLOR0,\n"
936 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
937 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n"
938 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n"
939 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n"
940 "float4 gl_MultiTexCoord4 : TEXCOORD4,\n"
942 "uniform float3 EyePosition : register(c24),\n"
943 "uniform float4x4 TexMatrix : register(c0),\n"
944 "#ifdef USEVERTEXTEXTUREBLEND\n"
945 "uniform float4x4 BackgroundTexMatrix : register(c4),\n"
947 "#ifdef MODE_LIGHTSOURCE\n"
948 "uniform float4x4 ModelToLight : register(c20),\n"
950 "#ifdef MODE_LIGHTSOURCE\n"
951 "uniform float3 LightPosition : register(c27),\n"
953 "#ifdef MODE_LIGHTDIRECTION\n"
954 "uniform float3 LightDir : register(c26),\n"
956 "uniform float4 FogPlane : register(c25),\n"
957 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
958 "uniform float3 LightPosition : register(c27),\n"
960 "#ifdef USESHADOWMAPORTHO\n"
961 "uniform float4x4 ShadowMapMatrix : register(c16),\n"
963 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND)\n"
964 "out float4 gl_FrontColor : COLOR,\n"
966 "out float4 TexCoordBoth : TEXCOORD0,\n"
967 "#ifdef USELIGHTMAP\n"
968 "out float2 TexCoordLightmap : TEXCOORD1,\n"
970 "#ifdef USEEYEVECTOR\n"
971 "out float3 EyeVector : TEXCOORD2,\n"
973 "#ifdef USEREFLECTION\n"
974 "out float4 ModelViewProjectionPosition : TEXCOORD3,\n"
977 "out float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n"
979 "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE) || defined(USEDIFFUSE)\n"
980 "out float3 LightVector : TEXCOORD1,\n"
982 "#ifdef MODE_LIGHTSOURCE\n"
983 "out float3 CubeVector : TEXCOORD3,\n"
985 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n"
986 "out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
987 "out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
988 "out float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n"
990 "#ifdef USESHADOWMAPORTHO\n"
991 "out float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n"
993 "out float4 gl_Position : POSITION\n"
996 "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND)\n"
997 " gl_FrontColor = gl_Color;\n"
999 " // copy the surface texcoord\n"
1000 " TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n"
1001 "#ifdef USEVERTEXTEXTUREBLEND\n"
1002 " TexCoordBoth.zw = mul(BackgroundTexMatrix, gl_MultiTexCoord0).xy;\n"
1004 "#ifdef USELIGHTMAP\n"
1005 " TexCoordLightmap = gl_MultiTexCoord4.xy;\n"
1008 "#ifdef MODE_LIGHTSOURCE\n"
1009 " // transform vertex position into light attenuation/cubemap space\n"
1010 " // (-1 to +1 across the light box)\n"
1011 " CubeVector = mul(ModelToLight, gl_Vertex).xyz;\n"
1013 "# ifdef USEDIFFUSE\n"
1014 " // transform unnormalized light direction into tangent space\n"
1015 " // (we use unnormalized to ensure that it interpolates correctly and then\n"
1016 " // normalize it per pixel)\n"
1017 " float3 lightminusvertex = LightPosition - gl_Vertex.xyz;\n"
1018 " LightVector.x = dot(lightminusvertex, gl_MultiTexCoord1.xyz);\n"
1019 " LightVector.y = dot(lightminusvertex, gl_MultiTexCoord2.xyz);\n"
1020 " LightVector.z = dot(lightminusvertex, gl_MultiTexCoord3.xyz);\n"
1024 "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE)\n"
1025 " LightVector.x = dot(LightDir, gl_MultiTexCoord1.xyz);\n"
1026 " LightVector.y = dot(LightDir, gl_MultiTexCoord2.xyz);\n"
1027 " LightVector.z = dot(LightDir, gl_MultiTexCoord3.xyz);\n"
1030 " // transform unnormalized eye direction into tangent space\n"
1031 "#ifdef USEEYEVECTOR\n"
1032 " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n"
1033 " EyeVector.x = dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz);\n"
1034 " EyeVector.y = dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz);\n"
1035 " EyeVector.z = dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz);\n"
1039 " EyeVectorModelSpaceFogPlaneVertexDist.xyz = EyePosition - gl_Vertex.xyz;\n"
1040 " EyeVectorModelSpaceFogPlaneVertexDist.w = dot(FogPlane, gl_Vertex);\n"
1043 "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n"
1044 " VectorS = gl_MultiTexCoord1.xyz;\n"
1045 " VectorT = gl_MultiTexCoord2.xyz;\n"
1046 " VectorR = gl_MultiTexCoord3.xyz;\n"
1049 " // transform vertex to camera space, using ftransform to match non-VS rendering\n"
1050 " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
1052 "#ifdef USESHADOWMAPORTHO\n"
1053 " ShadowMapTC = mul(ShadowMapMatrix, gl_Position).xyz;\n"
1056 "#ifdef USEREFLECTION\n"
1057 " ModelViewProjectionPosition = gl_Position;\n"
1060 "#endif // VERTEX_SHADER\n"
1065 "#ifdef FRAGMENT_SHADER\n"
1068 "#ifdef USEDEFERREDLIGHTMAP\n"
1070 "float2 Pixel : VPOS,\n"
1072 "float2 Pixel : WPOS,\n"
1075 "float4 gl_FrontColor : COLOR,\n"
1076 "float4 TexCoordBoth : TEXCOORD0,\n"
1077 "#ifdef USELIGHTMAP\n"
1078 "float2 TexCoordLightmap : TEXCOORD1,\n"
1080 "#ifdef USEEYEVECTOR\n"
1081 "float3 EyeVector : TEXCOORD2,\n"
1083 "#ifdef USEREFLECTION\n"
1084 "float4 ModelViewProjectionPosition : TEXCOORD3,\n"
1087 "float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n"
1089 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_LIGHTDIRECTION)\n"
1090 "float3 LightVector : TEXCOORD1,\n"
1092 "#ifdef MODE_LIGHTSOURCE\n"
1093 "float3 CubeVector : TEXCOORD3,\n"
1095 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
1096 "float4 ModelViewPosition : TEXCOORD0,\n"
1098 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n"
1099 "float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n"
1100 "float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n"
1101 "float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n"
1103 "#ifdef USESHADOWMAPORTHO\n"
1104 "float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n"
1107 "uniform sampler Texture_Normal : register(s0),\n"
1108 "uniform sampler Texture_Color : register(s1),\n"
1109 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n"
1110 "uniform sampler Texture_Gloss : register(s2),\n"
1113 "uniform sampler Texture_Glow : register(s3),\n"
1115 "#ifdef USEVERTEXTEXTUREBLEND\n"
1116 "uniform sampler Texture_SecondaryNormal : register(s4),\n"
1117 "uniform sampler Texture_SecondaryColor : register(s5),\n"
1118 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n"
1119 "uniform sampler Texture_SecondaryGloss : register(s6),\n"
1122 "uniform sampler Texture_SecondaryGlow : register(s7),\n"
1125 "#ifdef USECOLORMAPPING\n"
1126 "uniform sampler Texture_Pants : register(s4),\n"
1127 "uniform sampler Texture_Shirt : register(s7),\n"
1130 "uniform sampler Texture_FogHeightTexture : register(s14),\n"
1131 "uniform sampler Texture_FogMask : register(s8),\n"
1133 "#ifdef USELIGHTMAP\n"
1134 "uniform sampler Texture_Lightmap : register(s9),\n"
1136 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE)\n"
1137 "uniform sampler Texture_Deluxemap : register(s10),\n"
1139 "#ifdef USEREFLECTION\n"
1140 "uniform sampler Texture_Reflection : register(s7),\n"
1143 "#ifdef MODE_DEFERREDLIGHTSOURCE\n"
1144 "uniform sampler Texture_ScreenDepth : register(s13),\n"
1145 "uniform sampler Texture_ScreenNormalMap : register(s14),\n"
1147 "#ifdef USEDEFERREDLIGHTMAP\n"
1148 "uniform sampler Texture_ScreenDepth : register(s13),\n"
1149 "uniform sampler Texture_ScreenNormalMap : register(s14),\n"
1150 "uniform sampler Texture_ScreenDiffuse : register(s11),\n"
1151 "uniform sampler Texture_ScreenSpecular : register(s12),\n"
1154 "#ifdef USECOLORMAPPING\n"
1155 "uniform half3 Color_Pants : register(c7),\n"
1156 "uniform half3 Color_Shirt : register(c8),\n"
1159 "uniform float3 FogColor : register(c16),\n"
1160 "uniform float FogRangeRecip : register(c20),\n"
1161 "uniform float FogPlaneViewDist : register(c19),\n"
1162 "uniform float FogHeightFade : register(c17),\n"
1165 "#ifdef USEOFFSETMAPPING\n"
1166 "uniform float3 OffsetMapping_ScaleSteps : register(c24),\n"
1169 "#ifdef USEDEFERREDLIGHTMAP\n"
1170 "uniform half2 PixelToScreenTexCoord : register(c42),\n"
1171 "uniform half3 DeferredMod_Diffuse : register(c12),\n"
1172 "uniform half3 DeferredMod_Specular : register(c13),\n"
1174 "uniform half3 Color_Ambient : register(c3),\n"
1175 "uniform half3 Color_Diffuse : register(c4),\n"
1176 "uniform half3 Color_Specular : register(c5),\n"
1177 "uniform half SpecularPower : register(c36),\n"
1179 "uniform half3 Color_Glow : register(c6),\n"
1181 "uniform half Alpha : register(c0),\n"
1182 "#ifdef USEREFLECTION\n"
1183 "uniform float4 DistortScaleRefractReflect : register(c14),\n"
1184 "uniform float4 ScreenScaleRefractReflect : register(c32),\n"
1185 "uniform float4 ScreenCenterRefractReflect : register(c31),\n"
1186 "uniform half4 ReflectColor : register(c26),\n"
1188 "#ifdef USEREFLECTCUBE\n"
1189 "uniform float4x4 ModelToReflectCube : register(c48),\n"
1190 "uniform sampler Texture_ReflectMask : register(s5),\n"
1191 "uniform samplerCUBE Texture_ReflectCube : register(s6),\n"
1193 "#ifdef MODE_LIGHTDIRECTION\n"
1194 "uniform half3 LightColor : register(c21),\n"
1196 "#ifdef MODE_LIGHTSOURCE\n"
1197 "uniform half3 LightColor : register(c21),\n"
1200 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE)\n"
1201 "uniform sampler Texture_Attenuation : register(s9),\n"
1202 "uniform samplerCUBE Texture_Cube : register(s10),\n"
1205 "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n"
1207 "#ifdef USESHADOWMAP2D\n"
1208 "# ifdef USESHADOWSAMPLER\n"
1209 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
1211 "uniform sampler Texture_ShadowMap2D : register(s15),\n"
1215 "#ifdef USESHADOWMAPVSDCT\n"
1216 "uniform samplerCUBE Texture_CubeProjection : register(s12),\n"
1219 "#if defined(USESHADOWMAP2D)\n"
1220 "uniform float2 ShadowMap_TextureScale : register(c35),\n"
1221 "uniform float4 ShadowMap_Parameters : register(c34),\n"
1223 "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n"
1225 "out float4 gl_FragColor : COLOR\n"
1228 " float2 TexCoord = TexCoordBoth.xy;\n"
1229 "#ifdef USEVERTEXTEXTUREBLEND\n"
1230 " float2 TexCoord2 = TexCoordBoth.zw;\n"
1232 "#ifdef USEOFFSETMAPPING\n"
1233 " // apply offsetmapping\n"
1234 " float2 dPdx = ddx(TexCoord);\n"
1235 " float2 dPdy = ddy(TexCoord);\n"
1236 " float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, EyeVector, Texture_Normal, dPdx, dPdy);\n"
1237 "# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n"
1239 "# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n"
1242 " // combine the diffuse textures (base, pants, shirt)\n"
1243 " half4 color = half4(offsetMappedTexture2D(Texture_Color));\n"
1244 "#ifdef USEALPHAKILL\n"
1245 " if (color.a < 0.5)\n"
1248 " color.a *= Alpha;\n"
1249 "#ifdef USECOLORMAPPING\n"
1250 " color.rgb += half3(offsetMappedTexture2D(Texture_Pants).rgb) * Color_Pants + half3(offsetMappedTexture2D(Texture_Shirt).rgb) * Color_Shirt;\n"
1252 "#ifdef USEVERTEXTEXTUREBLEND\n"
1253 "#ifdef USEBOTHALPHAS\n"
1254 " half4 color2 = half4(tex2D(Texture_SecondaryColor, TexCoord2));\n"
1255 " half terrainblend = clamp(half(gl_FrontColor.a) * color.a, half(1.0 - color2.a), half(1.0));\n"
1256 " color.rgb = lerp(color2.rgb, color.rgb, terrainblend);\n"
1258 " half terrainblend = clamp(half(gl_FrontColor.a) * color.a * 2.0 - 0.5, half(0.0), half(1.0));\n"
1259 " //half terrainblend = min(half(gl_FrontColor.a) * color.a * 2.0, half(1.0));\n"
1260 " //half terrainblend = half(gl_FrontColor.a) * color.a > 0.5;\n"
1261 " color.rgb = half3(lerp(tex2D(Texture_SecondaryColor, TexCoord2).rgb, float3(color.rgb), terrainblend));\n"
1263 " //color = half4(lerp(float4(1, 0, 0, 1), color, terrainblend));\n"
1267 " // get the surface normal\n"
1268 "#ifdef USEVERTEXTEXTUREBLEND\n"
1269 " half3 surfacenormal = normalize(half3(lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, offsetMappedTexture2D(Texture_Normal).rgb, terrainblend)) - half3(0.5, 0.5, 0.5));\n"
1271 " half3 surfacenormal = half3(normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5, 0.5, 0.5)));\n"
1274 " // get the material colors\n"
1275 " half3 diffusetex = color.rgb;\n"
1276 "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n"
1277 "# ifdef USEVERTEXTEXTUREBLEND\n"
1278 " half4 glosstex = half4(lerp(tex2D(Texture_SecondaryGloss, TexCoord2), offsetMappedTexture2D(Texture_Gloss), terrainblend));\n"
1280 " half4 glosstex = half4(offsetMappedTexture2D(Texture_Gloss));\n"
1284 "#ifdef USEREFLECTCUBE\n"
1285 " float3 TangentReflectVector = reflect(-EyeVector, surfacenormal);\n"
1286 " float3 ModelReflectVector = TangentReflectVector.x * VectorS + TangentReflectVector.y * VectorT + TangentReflectVector.z * VectorR;\n"
1287 " float3 ReflectCubeTexCoord = mul(ModelToReflectCube, float4(ModelReflectVector, 0)).xyz;\n"
1288 " diffusetex += half3(offsetMappedTexture2D(Texture_ReflectMask).rgb) * half3(texCUBE(Texture_ReflectCube, ReflectCubeTexCoord).rgb);\n"
1294 "#ifdef MODE_LIGHTSOURCE\n"
1295 " // light source\n"
1296 "#ifdef USEDIFFUSE\n"
1297 " half3 lightnormal = half3(normalize(LightVector));\n"
1298 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n"
1299 " color.rgb = diffusetex * (Color_Ambient + diffuse * Color_Diffuse);\n"
1300 "#ifdef USESPECULAR\n"
1301 "#ifdef USEEXACTSPECULARMATH\n"
1302 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower * glosstex.a));\n"
1304 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n"
1305 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * glosstex.a));\n"
1307 " color.rgb += glosstex.rgb * (specular * Color_Specular);\n"
1310 " color.rgb = diffusetex * Color_Ambient;\n"
1312 " color.rgb *= LightColor;\n"
1313 " color.rgb *= half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n"
1314 "#if defined(USESHADOWMAP2D)\n"
1315 " color.rgb *= half(ShadowMapCompare(CubeVector, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n"
1316 "#ifdef USESHADOWMAPVSDCT\n"
1317 ", Texture_CubeProjection\n"
1322 "# ifdef USECUBEFILTER\n"
1323 " color.rgb *= half3(texCUBE(Texture_Cube, CubeVector).rgb);\n"
1326 "#ifdef USESHADOWMAP2D\n"
1327 "#ifdef USESHADOWMAPVSDCT\n"
1328 "// float3 shadowmaptc = GetShadowMapTC2D(CubeVector, ShadowMap_Parameters, Texture_CubeProjection);\n"
1330 "// float3 shadowmaptc = GetShadowMapTC2D(CubeVector, ShadowMap_Parameters);\n"
1332 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n"
1333 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale).rgb);\n"
1334 "// color.rgb = half3(shadowmaptc.xyz * float3(ShadowMap_TextureScale,1.0));\n"
1335 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n"
1336 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n"
1337 "// color.rgb = half3(tex2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale).rgb);\n"
1338 "// color.rgb = half3(shadowmaptc.xyz * float3(ShadowMap_TextureScale,1.0));\n"
1339 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n"
1340 "// color.r = half(shadowmaptc.z - texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n"
1341 "// color.r = half(shadowmaptc.z);\n"
1342 "// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n"
1343 "// color.r = half(shadowmaptc.z);\n"
1345 "// color.rgb = abs(CubeVector);\n"
1347 "// color.rgb = half3(1,1,1);\n"
1348 "#endif // MODE_LIGHTSOURCE\n"
1353 "#ifdef MODE_LIGHTDIRECTION\n"
1355 "#ifdef USEDIFFUSE\n"
1356 " half3 lightnormal = half3(normalize(LightVector));\n"
1358 "#define lightcolor LightColor\n"
1359 "#endif // MODE_LIGHTDIRECTION\n"
1360 "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n"
1362 " // deluxemap lightmapping using light vectors in modelspace (q3map2 -light -deluxe)\n"
1363 " half3 lightnormal_modelspace = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n"
1364 " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n"
1365 " // convert modelspace light vector to tangentspace\n"
1366 " half3 lightnormal;\n"
1367 " lightnormal.x = dot(lightnormal_modelspace, half3(VectorS));\n"
1368 " lightnormal.y = dot(lightnormal_modelspace, half3(VectorT));\n"
1369 " lightnormal.z = dot(lightnormal_modelspace, half3(VectorR));\n"
1370 " // calculate directional shading (and undoing the existing angle attenuation on the lightmap by the division)\n"
1371 " // note that q3map2 is too stupid to calculate proper surface normals when q3map_nonplanar\n"
1372 " // is used (the lightmap and deluxemap coords correspond to virtually random coordinates\n"
1373 " // on that luxel, and NOT to its center, because recursive triangle subdivision is used\n"
1374 " // to map the luxels to coordinates on the draw surfaces), which also causes\n"
1375 " // deluxemaps to be wrong because light contributions from the wrong side of the surface\n"
1376 " // are added up. To prevent divisions by zero or strong exaggerations, a max()\n"
1377 " // nudge is done here at expense of some additional fps. This is ONLY needed for\n"
1378 " // deluxemaps, tangentspace deluxemap avoid this problem by design.\n"
1379 " lightcolor *= 1.0 / max(0.25, lightnormal.z);\n"
1380 "#endif // MODE_LIGHTDIRECTIONMAP_MODELSPACE\n"
1381 "#ifdef MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n"
1383 " // deluxemap lightmapping using light vectors in tangentspace (hmap2 -light)\n"
1384 " half3 lightnormal = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n"
1385 " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n"
1391 "#ifdef MODE_FAKELIGHT\n"
1393 "half3 lightnormal = half3(normalize(EyeVector));\n"
1394 "half3 lightcolor = half3(1.0,1.0,1.0);\n"
1395 "#endif // MODE_FAKELIGHT\n"
1400 "#ifdef MODE_LIGHTMAP\n"
1401 " color.rgb = diffusetex * (Color_Ambient + half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb) * Color_Diffuse);\n"
1402 "#endif // MODE_LIGHTMAP\n"
1403 "#ifdef MODE_VERTEXCOLOR\n"
1404 " color.rgb = diffusetex * (Color_Ambient + half3(gl_FrontColor.rgb) * Color_Diffuse);\n"
1405 "#endif // MODE_VERTEXCOLOR\n"
1406 "#ifdef MODE_FLATCOLOR\n"
1407 " color.rgb = diffusetex * Color_Ambient;\n"
1408 "#endif // MODE_FLATCOLOR\n"
1414 "# ifdef USEDIFFUSE\n"
1415 " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n"
1416 "# ifdef USESPECULAR\n"
1417 "# ifdef USEEXACTSPECULARMATH\n"
1418 " half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower * glosstex.a));\n"
1420 " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n"
1421 " half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * glosstex.a));\n"
1423 " color.rgb = diffusetex * Color_Ambient + (diffusetex * Color_Diffuse * diffuse + glosstex.rgb * Color_Specular * specular) * lightcolor;\n"
1425 " color.rgb = diffusetex * (Color_Ambient + Color_Diffuse * diffuse * lightcolor);\n"
1428 " color.rgb = diffusetex * Color_Ambient;\n"
1432 "#ifdef USESHADOWMAPORTHO\n"
1433 " color.rgb *= half(ShadowMapCompare(ShadowMapTC, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale));\n"
1436 "#ifdef USEDEFERREDLIGHTMAP\n"
1437 " float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n"
1438 " color.rgb += diffusetex * half3(tex2D(Texture_ScreenDiffuse, ScreenTexCoord).rgb) * DeferredMod_Diffuse;\n"
1439 " color.rgb += glosstex.rgb * half3(tex2D(Texture_ScreenSpecular, ScreenTexCoord).rgb) * DeferredMod_Specular;\n"
1440 "// color.rgb = half3(tex2D(Texture_ScreenDepth, ScreenTexCoord).rgb);\n"
1441 "// color.r = half(texDepth2D(Texture_ScreenDepth, ScreenTexCoord)) * 1.0;\n"
1445 "#ifdef USEVERTEXTEXTUREBLEND\n"
1446 " color.rgb += half3(lerp(tex2D(Texture_SecondaryGlow, TexCoord2).rgb, offsetMappedTexture2D(Texture_Glow).rgb, terrainblend)) * Color_Glow;\n"
1448 " color.rgb += half3(offsetMappedTexture2D(Texture_Glow).rgb) * Color_Glow;\n"
1453 " color.rgb = half3(FogVertex(color, FogColor, EyeVectorModelSpaceFogPlaneVertexDist.xyz, EyeVectorModelSpaceFogPlaneVertexDist.w, FogRangeRecip, FogPlaneViewDist, FogHeightFade, Texture_FogMask, Texture_FogHeightTexture));\n"
1456 " // 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"
1457 "#ifdef USEREFLECTION\n"
1458 " float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n"
1459 " //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n"
1460 " float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW.zw + ScreenCenterRefractReflect.zw;\n"
1461 " float2 ScreenTexCoord = SafeScreenTexCoord + float3(normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5,0.5,0.5))).xy * DistortScaleRefractReflect.zw;\n"
1462 " // FIXME temporary hack to detect the case that the reflection\n"
1463 " // gets blackened at edges due to leaving the area that contains actual\n"
1465 " // Remove this 'ack once we have a better way to stop this thing from\n"
1467 " float f = min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(0.01, 0.01)).rgb) / 0.05);\n"
1468 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(0.01, -0.01)).rgb) / 0.05);\n"
1469 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, 0.01)).rgb) / 0.05);\n"
1470 " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, -0.01)).rgb) / 0.05);\n"
1471 " ScreenTexCoord = lerp(SafeScreenTexCoord, ScreenTexCoord, f);\n"
1472 " color.rgb = lerp(color.rgb, half3(tex2D(Texture_Reflection, ScreenTexCoord).rgb) * ReflectColor.rgb, ReflectColor.a);\n"
1475 " gl_FragColor = float4(color);\n"
1477 "#endif // FRAGMENT_SHADER\n"
1479 "#endif // !MODE_DEFERREDLIGHTSOURCE\n"
1480 "#endif // !MODE_DEFERREDGEOMETRY\n"
1481 "#endif // !MODE_WATER\n"
1482 "#endif // !MODE_REFRACTION\n"
1483 "#endif // !MODE_BLOOMBLUR\n"
1484 "#endif // !MODE_GENERIC\n"
1485 "#endif // !MODE_POSTPROCESS\n"
1486 "#endif // !MODE_SHOWDEPTH\n"
1487 "#endif // !MODE_DEPTH_OR_SHADOW\n"