DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
shader_glsl.h
Go to the documentation of this file.
1"// ambient+diffuse+specular+normalmap+attenuation+cubemap+fog shader\n",
2"// written by Ashley Rose Hale (LadyHavoc)\n",
3"// shadowmapping enhancements by Lee 'eihrul' Salzman\n",
4"\n",
5"#if defined(USESKELETAL) || defined(USEOCCLUDE)\n",
6"# ifdef GL_ARB_uniform_buffer_object\n",
7"# extension GL_ARB_uniform_buffer_object : enable\n",
8"# endif\n",
9"#endif\n",
10"\n",
11"#ifdef USESHADOWMAP2D\n",
12"# ifdef GL_EXT_gpu_shader4\n",
13"# extension GL_EXT_gpu_shader4 : enable\n",
14"# endif\n",
15"# ifdef GL_ARB_texture_gather\n",
16"# extension GL_ARB_texture_gather : enable\n",
17"# else\n",
18"# ifdef GL_AMD_texture_texture4\n",
19"# extension GL_AMD_texture_texture4 : enable\n",
20"# endif\n",
21"# endif\n",
22"#endif\n",
23"\n",
24"#define sat(x) clamp(x, 0, 1)\n",
25"#define possat(x) sat(x)\n",//As replacement of max(x, 0) when x<=1, better for gpus that can't do 0-cycle max(x, 0)
26"#define minonesat(x) sat(x)\n",//As replacement of min(x, 1) when x>=0, better for gpus that can't do 0-cycle min(x, 1)
27"#define possatdot(x, y) possat(dot(x, y))\n",
28"\n",
29"#ifdef USECELSHADING\n",
30"# define SHADEDIFFUSE myhalf diffuse = cast_myhalf(sat(float(dot(surfacenormal, lightnormal)) * 2.0));\n",
31"# ifdef USEEXACTSPECULARMATH\n",
32"# define SHADESPECULAR(specpow) myhalf specular = pow(cast_myhalf(float(possatdot(reflect(lightnormal, surfacenormal), -eyenormal))), 1.0 + specpow);specular = possat(specular * 10.0 - 9.0);\n",
33"# else\n",
34"# define SHADESPECULAR(specpow) myhalf3 specularnormal = normalize(lightnormal + eyenormal);myhalf specular = pow(cast_myhalf(float(possatdot(surfacenormal, specularnormal))), 1.0 + specpow);specular = possat(specular * 10.0 - 9.0);\n",
35"# endif\n",
36"#else\n",
37"# define SHADEDIFFUSE myhalf diffuse = cast_myhalf(float(possatdot(surfacenormal, lightnormal)));\n",
38"# ifdef USEEXACTSPECULARMATH\n",
39"# define SHADESPECULAR(specpow) myhalf specular = pow(cast_myhalf(float(possatdot(reflect(lightnormal, surfacenormal), -eyenormal))), 1.0 + specpow);\n",
40"# else\n",
41"# define SHADESPECULAR(specpow) myhalf3 specularnormal = normalize(lightnormal + eyenormal);myhalf specular = pow(cast_myhalf(float(possatdot(surfacenormal, specularnormal))), 1.0 + specpow);\n",
42"# endif\n",
43"#endif\n",
44"\n",
45"#if (defined(GLSL120) || defined(GLSL130) || defined(GLSL140) || defined(GLES)) && defined(VERTEX_SHADER)\n",
46"\n",
47"invariant gl_Position; // fix for lighting polygons not matching base surface\n",
48"# endif\n",
49#ifdef USE_GLES2
50"precision highp float;\n",
51#endif
52"#if defined(GLSL130) || defined(GLSL140)\n",
53"precision highp float;\n",
54"# ifdef VERTEX_SHADER\n",
55"# define dp_varying out\n",
56"# define dp_attribute in\n",
57"# endif\n",
58"# ifdef FRAGMENT_SHADER\n",
59"out vec4 dp_FragColor;\n",
60"# define dp_varying in\n",
61"# define dp_attribute in\n",
62"# endif\n",
63"# define dp_offsetmapping_dFdx dFdx\n",
64"# define dp_offsetmapping_dFdy dFdy\n",
65"# define dp_textureGrad textureGrad\n",
66"# define dp_textureOffset(a,b,c,d) textureOffset(a,b,ivec2(c,d))\n",
67"# define dp_texture2D texture\n",
68"# define dp_texture3D texture\n",
69"# define dp_textureCube texture\n",
70"# define dp_shadow2D(a,b) float(texture(a,b))\n",
71"#else\n",
72"# ifdef FRAGMENT_SHADER\n",
73"# define dp_FragColor gl_FragColor\n",
74"# endif\n",
75"# define dp_varying varying\n",
76"# define dp_attribute attribute\n",
77"# define dp_offsetmapping_dFdx(a) vec2(0.0, 0.0)\n",
78"# define dp_offsetmapping_dFdy(a) vec2(0.0, 0.0)\n",
79"# define dp_textureGrad(a,b,c,d) texture2D(a,b)\n",
80"# define dp_textureOffset(a,b,c,d) texture2DOffset(a,b,ivec2(c,d))\n",
81"# define dp_texture2D texture2D\n",
82"# define dp_texture3D texture3D\n",
83"# define dp_textureCube textureCube\n",
84"# define dp_shadow2D(a,b) float(shadow2D(a,b))\n",
85"#endif\n",
86"\n",
87"// GL ES and GLSL130 shaders use precision modifiers, standard GL does not\n",
88"// in GLSL130 we don't use them though because of syntax differences (can't use precision with inout)\n",
89"#ifndef GL_ES\n",
90"#define lowp\n",
91"#define mediump\n",
92"#define highp\n",
93"#endif\n",
94"\n",
95"#ifdef USEDEPTHRGB\n",
96" // for 565 RGB we'd need to use different multipliers\n",
97"#define decodedepthmacro(d) dot((d).rgb, vec3(1.0, 255.0 / 65536.0, 255.0 / 16777215.0))\n",
98"#define encodedepthmacro(d) fract(vec4(d, d*256.0, d*65536.0, 0.0))\n",
99"#endif\n",
100"\n",
101"#ifdef VERTEX_SHADER\n",
102"dp_attribute vec4 Attrib_Position; // vertex\n",
103"dp_attribute vec4 Attrib_Color; // color\n",
104"dp_attribute vec4 Attrib_TexCoord0; // material texcoords\n",
105"dp_attribute vec3 Attrib_TexCoord1; // svector\n",
106"dp_attribute vec3 Attrib_TexCoord2; // tvector\n",
107"dp_attribute vec3 Attrib_TexCoord3; // normal\n",
108"dp_attribute vec4 Attrib_TexCoord4; // lightmap texcoords\n",
109"#ifdef USESKELETAL\n",
110"//uniform mat4 Skeletal_Transform[128];\n",
111"// this is used with glBindBufferRange to bind a uniform block to the name\n",
112"// Skeletal_Transform12_UniformBlock, the Skeletal_Transform12 variable is\n",
113"// directly accessible without a namespace.\n",
114"// explanation: http://www.opengl.org/wiki/Interface_Block_%28GLSL%29#Syntax\n",
115"uniform Skeletal_Transform12_UniformBlock\n",
116"{\n",
117" vec4 Skeletal_Transform12[768];\n",
118"};\n",
119"dp_attribute vec4 Attrib_SkeletalIndex;\n",
120"dp_attribute vec4 Attrib_SkeletalWeight;\n",
121"#endif\n",
122"#endif\n",
123"dp_varying mediump vec4 VertexColor;\n",
124"\n",
125"#if defined(USEFOGINSIDE) || defined(USEFOGOUTSIDE) || defined(USEFOGHEIGHTTEXTURE)\n",
126"# define USEFOG\n",
127"#endif\n",
128"#if defined(MODE_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP)\n",
129"# define USELIGHTMAP\n",
130"#endif\n",
131"#if defined(USESPECULAR) || defined(USEOFFSETMAPPING) || defined(USEREFLECTCUBE) || defined(USEFOG)\n",
132"# define USEEYEVECTOR\n",
133"#endif\n",
134"\n",
135"//#ifdef __GLSL_CG_DATA_TYPES\n",
136"//# define myhalf half\n",
137"//# define myhalf2 half2\n",
138"//# define myhalf3 half3\n",
139"//# define myhalf4 half4\n",
140"//# define cast_myhalf half\n",
141"//# define cast_myhalf2 half2\n",
142"//# define cast_myhalf3 half3\n",
143"//# define cast_myhalf4 half4\n",
144"//#else\n",
145"# define myhalf mediump float\n",
146"# define myhalf2 mediump vec2\n",
147"# define myhalf3 mediump vec3\n",
148"# define myhalf4 mediump vec4\n",
149"# define cast_myhalf float\n",
150"# define cast_myhalf2 vec2\n",
151"# define cast_myhalf3 vec3\n",
152"# define cast_myhalf4 vec4\n",
153"//#endif\n",
154"\n",
155"#ifdef VERTEX_SHADER\n",
156"uniform highp mat4 ModelViewProjectionMatrix;\n",
157"#endif\n",
158"\n",
159"#ifdef VERTEX_SHADER\n",
160"#ifdef USETRIPPY\n",
161"// LadyHavoc: based on shader code linked at: http://www.youtube.com/watch?v=JpksyojwqzE\n",
162"// tweaked scale\n",
163"uniform highp float ClientTime;\n",
164"vec4 TrippyVertex(vec4 position)\n",
165"{\n",
166" float worldTime = ClientTime;\n",
167" // tweaked for Quake\n",
168" worldTime *= 10.0;\n",
169" position *= 0.125;\n",
170" //~tweaked for Quake\n",
171" float distanceSquared = (position.x * position.x + position.z * position.z);\n",
172" position.y += 5.0*sin(distanceSquared*sin(worldTime/143.0)/1000.0);\n",
173" float y = position.y;\n",
174" float x = position.x;\n",
175" float om = sin(distanceSquared*sin(worldTime/256.0)/5000.0) * sin(worldTime/200.0);\n",
176" position.y = x*sin(om)+y*cos(om);\n",
177" position.x = x*cos(om)-y*sin(om);\n",
178" return position;\n",
179"}\n",
180"#endif\n",
181"#endif\n",
182"\n",
183"#ifdef MODE_DEPTH_OR_SHADOW\n",
184"#ifdef VERTEX_SHADER\n",
185"void main(void)\n",
186"{\n",
187"#ifdef USESKELETAL\n",
188" ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n",
189" ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n",
190" ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n",
191" vec4 sw = Attrib_SkeletalWeight;\n",
192" vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n",
193" vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n",
194" vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n",
195" mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n",
196" vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n",
197"#define Attrib_Position SkeletalVertex\n",
198"#endif\n",
199" gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
200"#ifdef USETRIPPY\n",
201" gl_Position = TrippyVertex(gl_Position);\n",
202"#endif\n",
203"}\n",
204"#endif\n",
205"\n",
206"#ifdef FRAGMENT_SHADER\n",
207"void main(void)\n",
208"{\n",
209"#ifdef USEDEPTHRGB\n",
210" dp_FragColor = encodedepthmacro(gl_FragCoord.z);\n",
211"#else\n",
212" dp_FragColor = vec4(1.0,1.0,1.0,1.0);\n",
213"#endif\n",
214"}\n",
215"#endif\n",
216"#else // !MODE_DEPTH_ORSHADOW\n",
217"\n",
218"\n",
219"\n",
220"\n",
221"#ifdef MODE_POSTPROCESS\n",
222"#ifdef USEBLOOM\n",
223"dp_varying mediump vec4 TexCoord1;\n",
224"#else\n",
225"dp_varying mediump vec2 TexCoord1;\n",
226"#endif\n",
227"\n",
228"#ifdef VERTEX_SHADER\n",
229"void main(void)\n",
230"{\n",
231" gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
232" TexCoord1.xy = Attrib_TexCoord0.xy;\n",
233"#ifdef USEBLOOM\n",
234" TexCoord1.zw = Attrib_TexCoord4.xy;\n",
235"#endif\n",
236"}\n",
237"#endif\n",
238"\n",
239"#ifdef FRAGMENT_SHADER\n",
240"uniform sampler2D Texture_First;\n",
241"#ifdef USEBLOOM\n",
242"uniform sampler2D Texture_Second;\n",
243"uniform mediump vec4 BloomColorSubtract;\n",
244"#endif\n",
245"#ifdef USEGAMMARAMPS\n",
246"uniform sampler2D Texture_GammaRamps;\n",
247"#endif\n",
248"#ifdef USESATURATION\n",
249"uniform mediump float Saturation;\n",
250"#endif\n",
251"#ifdef USEVIEWTINT\n",
252"uniform mediump vec4 ViewTintColor;\n",
253"#endif\n",
254"//uncomment these if you want to use them:\n",
255"uniform mediump vec4 UserVec1;\n",
256"uniform mediump vec4 UserVec2;\n",
257"// uniform mediump vec4 UserVec3;\n",
258"// uniform mediump vec4 UserVec4;\n",
259"uniform mediump float ColorFringe;\n",
260"// uniform highp float ClientTime;\n",
261"uniform mediump vec2 PixelSize;\n",
262"\n",
263"#ifdef USEFXAA\n",
264"// graphitemaster: based off the white paper by Timothy Lottes\n",
265"// http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf\n",
266"vec4 fxaa(vec4 inColor, float maxspan)\n",
267"{\n",
268" vec4 ret = inColor; // preserve old\n",
269" float mulreduct = 1.0/maxspan;\n",
270" float minreduct = (1.0 / 128.0);\n",
271"\n",
272" // directions\n",
273" vec3 NW = dp_texture2D(Texture_First, TexCoord1.xy + (vec2(-1.0, -1.0) * PixelSize)).xyz;\n",
274" vec3 NE = dp_texture2D(Texture_First, TexCoord1.xy + (vec2(+1.0, -1.0) * PixelSize)).xyz;\n",
275" vec3 SW = dp_texture2D(Texture_First, TexCoord1.xy + (vec2(-1.0, +1.0) * PixelSize)).xyz;\n",
276" vec3 SE = dp_texture2D(Texture_First, TexCoord1.xy + (vec2(+1.0, +1.0) * PixelSize)).xyz;\n",
277" vec3 M = dp_texture2D(Texture_First, TexCoord1.xy).xyz;\n",
278"\n",
279" // luminance directions\n",
280" vec3 luma = vec3(0.299, 0.587, 0.114);\n",
281" float lNW = dot(NW, luma);\n",
282" float lNE = dot(NE, luma);\n",
283" float lSW = dot(SW, luma);\n",
284" float lSE = dot(SE, luma);\n",
285" float lM = dot(M, luma);\n",
286" float lMin = min(lM, min(min(lNW, lNE), min(lSW, lSE)));\n",
287" float lMax = max(lM, max(max(lNW, lNE), max(lSW, lSE)));\n",
288"\n",
289" // direction and reciprocal\n",
290" vec2 dir = vec2(-((lNW + lNE) - (lSW + lSE)), ((lNW + lSW) - (lNE + lSE)));\n",
291" float rcp = 1.0/(min(abs(dir.x), abs(dir.y)) + max((lNW + lNE + lSW + lSE) * (0.25 * mulreduct), minreduct));\n",
292"\n",
293" // span\n",
294" dir = min(vec2(maxspan, maxspan), max(vec2(-maxspan, -maxspan), dir * rcp)) * PixelSize;\n",
295"\n",
296" vec3 rA = (1.0/2.0) * (\n",
297" dp_texture2D(Texture_First, TexCoord1.xy + dir * (1.0/3.0 - 0.5)).xyz +\n",
298" dp_texture2D(Texture_First, TexCoord1.xy + dir * (2.0/3.0 - 0.5)).xyz);\n",
299" vec3 rB = rA * (1.0/2.0) + (1.0/4.0) * (\n",
300" dp_texture2D(Texture_First, TexCoord1.xy + dir * (0.0/3.0 - 0.5)).xyz +\n",
301" dp_texture2D(Texture_First, TexCoord1.xy + dir * (3.0/3.0 - 0.5)).xyz);\n",
302" float lB = dot(rB, luma);\n",
303"\n",
304" ret.xyz = ((lB < lMin) || (lB > lMax)) ? rA : rB;\n",
305" ret.a = 1.0;\n",
306" return ret;\n",
307"}\n",
308"#endif\n",
309"\n",
310"void main(void)\n",
311"{\n",
312"#ifdef USECOLORFRINGE\n",
313" float fringe = ColorFringe;//.0033f;\n",
314" float amount = distance(TexCoord1.xy, vec2(.5f,.5f));\n",
315" vec2 offset = vec2(amount*fringe,amount*fringe);\n",
316" dp_FragColor.xy = dp_texture2D(Texture_First, TexCoord1.xy-offset).xy;\n",
317" dp_FragColor.z = dp_texture2D(Texture_First, TexCoord1.xy+offset).z;\n",
318"#else\n",
319" dp_FragColor = dp_texture2D(Texture_First, TexCoord1.xy);\n",
320"#endif\n",
321"\n",
322"#ifdef USEFXAA\n",
323" dp_FragColor = fxaa(dp_FragColor, 8.0); // 8.0 can be changed for larger span\n",
324"#endif\n",
325"\n",
326"#ifdef USEPOSTPROCESSING\n",
327"// do r_glsl_dumpshader, edit glsl/default.glsl, and replace this by your own postprocessing if you want\n",
328"// 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",
329"#if defined(USERVEC1) || defined(USERVEC2)\n",
330" float sobel = 1.0;\n",
331" // vec2 ts = textureSize(Texture_First, 0);\n",
332" // vec2 px = vec2(1/ts.x, 1/ts.y);\n",
333" vec2 px = PixelSize;\n",
334" vec3 x1 = dp_texture2D(Texture_First, TexCoord1.xy + vec2(-px.x, px.y)).rgb;\n",
335" vec3 x2 = dp_texture2D(Texture_First, TexCoord1.xy + vec2(-px.x, 0.0)).rgb;\n",
336" vec3 x3 = dp_texture2D(Texture_First, TexCoord1.xy + vec2(-px.x,-px.y)).rgb;\n",
337" vec3 x4 = dp_texture2D(Texture_First, TexCoord1.xy + vec2( px.x, px.y)).rgb;\n",
338" vec3 x5 = dp_texture2D(Texture_First, TexCoord1.xy + vec2( px.x, 0.0)).rgb;\n",
339" vec3 x6 = dp_texture2D(Texture_First, TexCoord1.xy + vec2( px.x,-px.y)).rgb;\n",
340" vec3 y2 = dp_texture2D(Texture_First, TexCoord1.xy + vec2( 0.0,-px.y)).rgb;\n",
341" vec3 y5 = dp_texture2D(Texture_First, TexCoord1.xy + vec2( 0.0, px.y)).rgb;\n",
342" float px1 = -1.0 * dot(vec3(0.3, 0.59, 0.11), x1);\n",
343" float px2 = -2.0 * dot(vec3(0.3, 0.59, 0.11), x2);\n",
344" float px3 = -1.0 * dot(vec3(0.3, 0.59, 0.11), x3);\n",
345" float px4 = 1.0 * dot(vec3(0.3, 0.59, 0.11), x4);\n",
346" float px5 = 2.0 * dot(vec3(0.3, 0.59, 0.11), x5);\n",
347" float px6 = 1.0 * dot(vec3(0.3, 0.59, 0.11), x6);\n",
348" float py1 = -px6;\n",
349" float py2 = -2.0 * dot(vec3(0.3, 0.59, 0.11), y2);\n",
350" float py3 = px3;\n",
351" float py4 = px4;\n",
352" float py5 = 2.0 * dot(vec3(0.3, 0.59, 0.11), y5);\n",
353" float py6 = -px1;\n",
354" sobel = 0.25 * (abs(px1 + px2 + px3 + px4 + px5 + px6) + abs(py1 + py2 + py3 + py4 + py5 + py6));\n",
355" dp_FragColor += dp_texture2D(Texture_First, TexCoord1.xy + PixelSize*UserVec1.x*vec2(-0.987688, -0.156434)) * UserVec1.y;\n",
356" dp_FragColor += dp_texture2D(Texture_First, TexCoord1.xy + PixelSize*UserVec1.x*vec2(-0.156434, -0.891007)) * UserVec1.y;\n",
357" dp_FragColor += dp_texture2D(Texture_First, TexCoord1.xy + PixelSize*UserVec1.x*vec2( 0.891007, -0.453990)) * UserVec1.y;\n",
358" dp_FragColor += dp_texture2D(Texture_First, TexCoord1.xy + PixelSize*UserVec1.x*vec2( 0.707107, 0.707107)) * UserVec1.y;\n",
359" dp_FragColor += dp_texture2D(Texture_First, TexCoord1.xy + PixelSize*UserVec1.x*vec2(-0.453990, 0.891007)) * UserVec1.y;\n",
360" dp_FragColor /= (1.0 + 5.0 * UserVec1.y);\n",
361" dp_FragColor.rgb = dp_FragColor.rgb * (1.0 + UserVec2.x) + vec3(max(0.0, sobel - UserVec2.z))*UserVec2.y;\n",
362"#endif\n",
363"#endif\n",
364"\n",
365"#ifdef USEBLOOM\n",
366" //TODO: replacing here possat back to max may be needed for HDR\n",
367" dp_FragColor += possat(dp_texture2D(Texture_Second, TexCoord1.zw) - BloomColorSubtract);\n",
368"#endif\n",
369"\n",
370"#ifdef USEVIEWTINT\n",
371" dp_FragColor = mix(dp_FragColor, ViewTintColor, ViewTintColor.a);\n",
372"#endif\n",
373"\n",
374"#ifdef USESATURATION\n",
375" //apply saturation BEFORE gamma ramps, so v_glslgamma value does not matter\n",
376" float y = dot(dp_FragColor.rgb, vec3(0.299, 0.587, 0.114));\n",
377" // 'vampire sight' effect, wheres red is compensated\n",
378" #ifdef SATURATION_REDCOMPENSATE\n",
379" float rboost = max(0.0, (dp_FragColor.r - max(dp_FragColor.g, dp_FragColor.b))*(1.0 - Saturation));\n",
380" dp_FragColor.rgb = mix(vec3(y), dp_FragColor.rgb, Saturation);\n",
381" dp_FragColor.r += rboost;\n",
382" #else\n",
383" // normal desaturation\n",
384" //dp_FragColor = vec3(y) + (dp_FragColor.rgb - vec3(y)) * Saturation;\n",
385" dp_FragColor.rgb = mix(vec3(y), dp_FragColor.rgb, Saturation);\n",
386" #endif\n",
387"#endif\n",
388"\n",
389"#ifdef USEGAMMARAMPS\n",
390" dp_FragColor.r = dp_texture2D(Texture_GammaRamps, vec2(dp_FragColor.r, 0)).r;\n",
391" dp_FragColor.g = dp_texture2D(Texture_GammaRamps, vec2(dp_FragColor.g, 0)).g;\n",
392" dp_FragColor.b = dp_texture2D(Texture_GammaRamps, vec2(dp_FragColor.b, 0)).b;\n",
393"#endif\n",
394"}\n",
395"#endif\n",
396"#else // !MODE_POSTPROCESS\n",
397"\n",
398"\n",
399"\n",
400"\n",
401"#ifdef MODE_GENERIC\n",
402"#ifdef USEDIFFUSE\n",
403"dp_varying mediump vec2 TexCoord1;\n",
404"#endif\n",
405"#ifdef USESPECULAR\n",
406"dp_varying mediump vec2 TexCoord2;\n",
407"#endif\n",
408"uniform myhalf Alpha;\n",
409"#ifdef VERTEX_SHADER\n",
410"void main(void)\n",
411"{\n",
412"#ifdef USESKELETAL\n",
413" ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n",
414" ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n",
415" ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n",
416" vec4 sw = Attrib_SkeletalWeight;\n",
417" vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n",
418" vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n",
419" vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n",
420" mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n",
421" vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n",
422"#define Attrib_Position SkeletalVertex\n",
423"#endif\n",
424" VertexColor = Attrib_Color;\n",
425"#ifdef USEDIFFUSE\n",
426" TexCoord1 = Attrib_TexCoord0.xy;\n",
427"#endif\n",
428"#ifdef USESPECULAR\n",
429" TexCoord2 = Attrib_TexCoord1.xy;\n",
430"#endif\n",
431" gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
432"#ifdef USETRIPPY\n",
433" gl_Position = TrippyVertex(gl_Position);\n",
434"#endif\n",
435"}\n",
436"#endif\n",
437"\n",
438"#ifdef FRAGMENT_SHADER\n",
439"#ifdef USEDIFFUSE\n",
440"uniform sampler2D Texture_First;\n",
441"#endif\n",
442"#ifdef USESPECULAR\n",
443"uniform sampler2D Texture_Second;\n",
444"#endif\n",
445"#ifdef USEGAMMARAMPS\n",
446"uniform sampler2D Texture_GammaRamps;\n",
447"#endif\n",
448"\n",
449"void main(void)\n",
450"{\n",
451"#ifdef USEVIEWTINT\n",
452" dp_FragColor = VertexColor;\n",
453"#else\n",
454" dp_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n",
455"#endif\n",
456"#ifdef USEDIFFUSE\n",
457"# ifdef USEREFLECTCUBE\n",
458" // suppress texture alpha\n",
459" dp_FragColor.rgb *= dp_texture2D(Texture_First, TexCoord1).rgb;\n",
460"# else\n",
461" dp_FragColor *= dp_texture2D(Texture_First, TexCoord1);\n",
462"# endif\n",
463"#endif\n",
464"\n",
465"#ifdef USESPECULAR\n",
466" vec4 tex2 = dp_texture2D(Texture_Second, TexCoord2);\n",
467"# ifdef USECOLORMAPPING\n",
468" dp_FragColor *= tex2;\n",
469"# endif\n",
470"# ifdef USEGLOW\n",
471" dp_FragColor += tex2;\n",
472"# endif\n",
473"# ifdef USEVERTEXTEXTUREBLEND\n",
474" dp_FragColor = mix(dp_FragColor, tex2, tex2.a);\n",
475"# endif\n",
476"#endif\n",
477"#ifdef USEGAMMARAMPS\n",
478" dp_FragColor.r = dp_texture2D(Texture_GammaRamps, vec2(dp_FragColor.r, 0)).r;\n",
479" dp_FragColor.g = dp_texture2D(Texture_GammaRamps, vec2(dp_FragColor.g, 0)).g;\n",
480" dp_FragColor.b = dp_texture2D(Texture_GammaRamps, vec2(dp_FragColor.b, 0)).b;\n",
481"#endif\n",
482"#ifdef USEALPHAKILL\n",
483" dp_FragColor.a *= Alpha;\n",
484"#endif\n",
485"}\n",
486"#endif\n",
487"#else // !MODE_GENERIC\n",
488"\n",
489"\n",
490"\n",
491"\n",
492"#ifdef MODE_BLOOMBLUR\n",
493"dp_varying mediump vec2 TexCoord;\n",
494"#ifdef VERTEX_SHADER\n",
495"void main(void)\n",
496"{\n",
497" VertexColor = Attrib_Color;\n",
498" TexCoord = Attrib_TexCoord0.xy;\n",
499" gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
500"}\n",
501"#endif\n",
502"\n",
503"#ifdef FRAGMENT_SHADER\n",
504"uniform sampler2D Texture_First;\n",
505"uniform mediump vec4 BloomBlur_Parameters;\n",
506"\n",
507"void main(void)\n",
508"{\n",
509" int i;\n",
510" vec2 tc = TexCoord;\n",
511" vec3 color = dp_texture2D(Texture_First, tc).rgb;\n",
512" tc += BloomBlur_Parameters.xy;\n",
513" for (i = 1;i < SAMPLES;i++)\n",
514" {\n",
515" color += dp_texture2D(Texture_First, tc).rgb;\n",
516" tc += BloomBlur_Parameters.xy;\n",
517" }\n",
518" dp_FragColor = vec4(color * BloomBlur_Parameters.z + vec3(BloomBlur_Parameters.w), 1);\n",
519"}\n",
520"#endif\n",
521"#else // !MODE_BLOOMBLUR\n",
522"#ifdef MODE_REFRACTION\n",
523"dp_varying mediump vec2 TexCoord;\n",
524"dp_varying highp vec4 ModelViewProjectionPosition;\n",
525"uniform highp mat4 TexMatrix;\n",
526"#ifdef VERTEX_SHADER\n",
527"\n",
528"void main(void)\n",
529"{\n",
530"#ifdef USESKELETAL\n",
531" ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n",
532" ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n",
533" ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n",
534" vec4 sw = Attrib_SkeletalWeight;\n",
535" vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n",
536" vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n",
537" vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n",
538" mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n",
539" vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n",
540"#define Attrib_Position SkeletalVertex\n",
541"#endif\n",
542"#ifdef USEALPHAGENVERTEX\n",
543" VertexColor = Attrib_Color;\n",
544"#endif\n",
545" TexCoord = vec2(TexMatrix * Attrib_TexCoord0);\n",
546" gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
547" ModelViewProjectionPosition = gl_Position;\n",
548"#ifdef USETRIPPY\n",
549" gl_Position = TrippyVertex(gl_Position);\n",
550"#endif\n",
551"}\n",
552"#endif\n",
553"\n",
554"#ifdef FRAGMENT_SHADER\n",
555"uniform sampler2D Texture_Normal;\n",
556"uniform sampler2D Texture_Refraction;\n",
557"\n",
558"uniform mediump vec4 DistortScaleRefractReflect;\n",
559"uniform mediump vec4 ScreenScaleRefractReflect;\n",
560"uniform mediump vec4 ScreenCenterRefractReflect;\n",
561"uniform mediump vec4 RefractColor;\n",
562"uniform mediump vec4 ReflectColor;\n",
563"uniform highp float ClientTime;\n",
564"#ifdef USENORMALMAPSCROLLBLEND\n",
565"uniform highp vec2 NormalmapScrollBlend;\n",
566"#endif\n",
567"\n",
568"void main(void)\n",
569"{\n",
570" vec2 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect.xy * (1.0 / ModelViewProjectionPosition.w);\n",
571" //vec2 ScreenTexCoord = (ModelViewProjectionPosition.xy + normalize(vec3(dp_texture2D(Texture_Normal, TexCoord)) - vec3(0.5)).xy * DistortScaleRefractReflect.xy * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n",
572" vec2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n",
573"#ifdef USEALPHAGENVERTEX\n",
574" vec2 distort = DistortScaleRefractReflect.xy * VertexColor.a;\n",
575" vec4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), VertexColor.a);\n",
576"#else\n",
577" vec2 distort = DistortScaleRefractReflect.xy;\n",
578" vec4 refractcolor = RefractColor;\n",
579"#endif\n",
580" #ifdef USENORMALMAPSCROLLBLEND\n",
581" vec3 normal = dp_texture2D(Texture_Normal, (TexCoord + vec2(0.08, 0.08)*ClientTime*NormalmapScrollBlend.x*0.5)*NormalmapScrollBlend.y).rgb - vec3(1.0);\n",
582" normal += dp_texture2D(Texture_Normal, (TexCoord + vec2(-0.06, -0.09)*ClientTime*NormalmapScrollBlend.x)*NormalmapScrollBlend.y*0.75).rgb;\n",
583" vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(cast_myhalf3(normal))).xy * distort;\n",
584" #else\n",
585" vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(cast_myhalf3(dp_texture2D(Texture_Normal, TexCoord)) - cast_myhalf3(0.5))).xy * distort;\n",
586" #endif\n",
587" // FIXME temporary hack to detect the case that the reflection\n",
588" // gets blackened at edges due to leaving the area that contains actual\n",
589" // content.\n",
590" // Remove this 'ack once we have a better way to stop this thing from\n",
591" // 'appening.\n",
592" float f = minonesat(length(dp_texture2D(Texture_Refraction, ScreenTexCoord + vec2(0.01, 0.01)).rgb) / 0.05);\n",
593" f *= minonesat(length(dp_texture2D(Texture_Refraction, ScreenTexCoord + vec2(0.01, -0.01)).rgb) / 0.05);\n",
594" f *= minonesat(length(dp_texture2D(Texture_Refraction, ScreenTexCoord + vec2(-0.01, 0.01)).rgb) / 0.05);\n",
595" f *= minonesat(length(dp_texture2D(Texture_Refraction, ScreenTexCoord + vec2(-0.01, -0.01)).rgb) / 0.05);\n",
596" ScreenTexCoord = mix(SafeScreenTexCoord, ScreenTexCoord, f);\n",
597" dp_FragColor = vec4(dp_texture2D(Texture_Refraction, ScreenTexCoord).rgb, 1.0) * refractcolor;\n",
598"}\n",
599"#endif\n",
600"#else // !MODE_REFRACTION\n",
601"\n",
602"\n",
603"\n",
604"\n",
605"#ifdef MODE_WATER\n",
606"dp_varying mediump vec2 TexCoord;\n",
607"dp_varying highp vec3 EyeVector;\n",
608"dp_varying highp vec4 ModelViewProjectionPosition;\n",
609"#ifdef VERTEX_SHADER\n",
610"uniform highp vec3 EyePosition;\n",
611"uniform highp mat4 TexMatrix;\n",
612"\n",
613"void main(void)\n",
614"{\n",
615"#ifdef USESKELETAL\n",
616" ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n",
617" ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n",
618" ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n",
619" vec4 sw = Attrib_SkeletalWeight;\n",
620" vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n",
621" vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n",
622" vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n",
623" mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n",
624" mat3 SkeletalNormalMatrix = mat3(cross(SkeletalMatrix[1].xyz, SkeletalMatrix[2].xyz), cross(SkeletalMatrix[2].xyz, SkeletalMatrix[0].xyz), cross(SkeletalMatrix[0].xyz, SkeletalMatrix[1].xyz)); // is actually transpose(inverse(mat3(SkeletalMatrix))) * det(mat3(SkeletalMatrix))\n",
625" vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n",
626" vec3 SkeletalSVector = normalize(Attrib_TexCoord1.xyz * SkeletalNormalMatrix);\n",
627" vec3 SkeletalTVector = normalize(Attrib_TexCoord2.xyz * SkeletalNormalMatrix);\n",
628" vec3 SkeletalNormal = normalize(Attrib_TexCoord3.xyz * SkeletalNormalMatrix);\n",
629"#define Attrib_Position SkeletalVertex\n",
630"#define Attrib_TexCoord1 SkeletalSVector\n",
631"#define Attrib_TexCoord2 SkeletalTVector\n",
632"#define Attrib_TexCoord3 SkeletalNormal\n",
633"#endif\n",
634"#ifdef USEALPHAGENVERTEX\n",
635" VertexColor = Attrib_Color;\n",
636"#endif\n",
637" TexCoord = vec2(TexMatrix * Attrib_TexCoord0);\n",
638" vec3 EyeRelative = EyePosition - Attrib_Position.xyz;\n",
639" EyeVector.x = dot(EyeRelative, Attrib_TexCoord1.xyz);\n",
640" EyeVector.y = dot(EyeRelative, Attrib_TexCoord2.xyz);\n",
641" EyeVector.z = dot(EyeRelative, Attrib_TexCoord3.xyz);\n",
642" gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
643" ModelViewProjectionPosition = gl_Position;\n",
644"#ifdef USETRIPPY\n",
645" gl_Position = TrippyVertex(gl_Position);\n",
646"#endif\n",
647"}\n",
648"#endif\n",
649"\n",
650"#ifdef FRAGMENT_SHADER\n",
651"uniform sampler2D Texture_Normal;\n",
652"uniform sampler2D Texture_Refraction;\n",
653"uniform sampler2D Texture_Reflection;\n",
654"\n",
655"uniform mediump vec4 DistortScaleRefractReflect;\n",
656"uniform mediump vec4 ScreenScaleRefractReflect;\n",
657"uniform mediump vec4 ScreenCenterRefractReflect;\n",
658"uniform mediump vec4 RefractColor;\n",
659"uniform mediump vec4 ReflectColor;\n",
660"uniform mediump float ReflectFactor;\n",
661"uniform mediump float ReflectOffset;\n",
662"uniform highp float ClientTime;\n",
663"#ifdef USENORMALMAPSCROLLBLEND\n",
664"uniform highp vec2 NormalmapScrollBlend;\n",
665"#endif\n",
666"\n",
667"void main(void)\n",
668"{\n",
669" vec4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n",
670" //vec4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(vec3(dp_texture2D(Texture_Normal, TexCoord)) - vec3(0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
671" vec4 SafeScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
672" //SafeScreenTexCoord = gl_FragCoord.xyxy * vec4(1.0 / 1920.0, 1.0 / 1200.0, 1.0 / 1920.0, 1.0 / 1200.0);\n",
673" // slight water animation via 2 layer scrolling (todo: tweak)\n",
674"#ifdef USEALPHAGENVERTEX\n",
675" vec4 distort = DistortScaleRefractReflect * VertexColor.a;\n",
676" float reflectoffset = ReflectOffset * VertexColor.a;\n",
677" float reflectfactor = ReflectFactor * VertexColor.a;\n",
678" vec4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), VertexColor.a);\n",
679"#else\n",
680" vec4 distort = DistortScaleRefractReflect;\n",
681" float reflectoffset = ReflectOffset;\n",
682" float reflectfactor = ReflectFactor;\n",
683" vec4 refractcolor = RefractColor;\n",
684"#endif\n",
685" #ifdef USENORMALMAPSCROLLBLEND\n",
686" vec3 normal = dp_texture2D(Texture_Normal, (TexCoord + vec2(0.08, 0.08)*ClientTime*NormalmapScrollBlend.x*0.5)*NormalmapScrollBlend.y).rgb - vec3(1.0);\n",
687" normal += dp_texture2D(Texture_Normal, (TexCoord + vec2(-0.06, -0.09)*ClientTime*NormalmapScrollBlend.x)*NormalmapScrollBlend.y*0.75).rgb;\n",
688" vec4 ScreenTexCoord = SafeScreenTexCoord + (normalize(normal) + vec3(0.15)).xyxy * distort;\n",
689" #else\n",
690" vec4 ScreenTexCoord = SafeScreenTexCoord + vec2(normalize(vec3(dp_texture2D(Texture_Normal, TexCoord)) - vec3(0.5))).xyxy * distort;\n",
691" #endif\n",
692" // FIXME temporary hack to detect the case that the reflection\n",
693" // gets blackened at edges due to leaving the area that contains actual\n",
694" // content.\n",
695" // Remove this 'ack once we have a better way to stop this thing from\n",
696" // 'appening.\n",
697" float f = minonesat(length(dp_texture2D(Texture_Refraction, ScreenTexCoord.xy + vec2(0.005, 0.01)).rgb) / 0.002);\n",
698" f *= minonesat(length(dp_texture2D(Texture_Refraction, ScreenTexCoord.xy + vec2(0.005, -0.01)).rgb) / 0.002);\n",
699" f *= minonesat(length(dp_texture2D(Texture_Refraction, ScreenTexCoord.xy + vec2(-0.005, 0.01)).rgb) / 0.002);\n",
700" f *= minonesat(length(dp_texture2D(Texture_Refraction, ScreenTexCoord.xy + vec2(-0.005, -0.01)).rgb) / 0.002);\n",
701" ScreenTexCoord.xy = mix(SafeScreenTexCoord.xy, ScreenTexCoord.xy, f);\n",
702" f = minonesat(length(dp_texture2D(Texture_Reflection, ScreenTexCoord.zw + vec2(0.005, 0.005)).rgb) / 0.002);\n",
703" f *= minonesat(length(dp_texture2D(Texture_Reflection, ScreenTexCoord.zw + vec2(0.005, -0.005)).rgb) / 0.002);\n",
704" f *= minonesat(length(dp_texture2D(Texture_Reflection, ScreenTexCoord.zw + vec2(-0.005, 0.005)).rgb) / 0.002);\n",
705" f *= minonesat(length(dp_texture2D(Texture_Reflection, ScreenTexCoord.zw + vec2(-0.005, -0.005)).rgb) / 0.002);\n",
706" ScreenTexCoord.zw = mix(SafeScreenTexCoord.zw, ScreenTexCoord.zw, f);\n",
707" float Fresnel = pow(min(1.0, 1.0 - float(normalize(EyeVector).z)), 2.0) * reflectfactor + reflectoffset;\n",
708" dp_FragColor = mix(vec4(dp_texture2D(Texture_Refraction, ScreenTexCoord.xy).rgb, 1) * refractcolor, vec4(dp_texture2D(Texture_Reflection, ScreenTexCoord.zw).rgb, 1) * ReflectColor, Fresnel);\n",
709"}\n",
710"#endif\n",
711"#else // !MODE_WATER\n",
712"\n",
713"\n",
714"\n",
715"\n",
716"// common definitions between vertex shader and fragment shader:\n",
717"\n",
718"dp_varying mediump vec4 TexCoordSurfaceLightmap;\n",
719"#ifdef USEVERTEXTEXTUREBLEND\n",
720"dp_varying mediump vec2 TexCoord2;\n",
721"#endif\n",
722"\n",
723"#ifdef MODE_LIGHTSOURCE\n",
724"dp_varying mediump vec3 CubeVector;\n",
725"#endif\n",
726"\n",
727"#if (defined(MODE_LIGHTSOURCE) || defined(MODE_LIGHTDIRECTION)) && defined(USEDIFFUSE)\n",
728"dp_varying mediump vec3 LightVector;\n",
729"#endif\n",
730"\n",
731"#ifdef USEEYEVECTOR\n",
732"dp_varying highp vec4 EyeVectorFogDepth;\n",
733"#endif\n",
734"\n",
735"#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE) || defined(USEBOUNCEGRIDDIRECTIONAL) || defined(MODE_LIGHTGRID)\n",
736"dp_varying highp vec4 VectorS; // direction of S texcoord (sometimes crudely called tangent)\n",
737"dp_varying highp vec4 VectorT; // direction of T texcoord (sometimes crudely called binormal)\n",
738"dp_varying highp vec4 VectorR; // direction of R texcoord (surface normal)\n",
739"#else\n",
740"# ifdef USEFOG\n",
741"dp_varying highp vec3 EyeVectorModelSpace;\n",
742"# endif\n",
743"#endif\n",
744"\n",
745"#ifdef USEREFLECTION\n",
746"dp_varying highp vec4 ModelViewProjectionPosition;\n",
747"#endif\n",
748"#ifdef MODE_DEFERREDLIGHTSOURCE\n",
749"uniform highp vec3 LightPosition;\n",
750"dp_varying highp vec4 ModelViewPosition;\n",
751"#endif\n",
752"\n",
753"#ifdef MODE_LIGHTSOURCE\n",
754"uniform highp vec3 LightPosition;\n",
755"#endif\n",
756"uniform highp vec3 EyePosition;\n",
757"#ifdef MODE_LIGHTDIRECTION\n",
758"uniform highp vec3 LightDir;\n",
759"#endif\n",
760"uniform highp vec4 FogPlane;\n",
761"\n",
762"#ifdef USESHADOWMAPORTHO\n",
763"dp_varying highp vec3 ShadowMapTC;\n",
764"#endif\n",
765"\n",
766"#ifdef MODE_LIGHTGRID\n",
767"dp_varying highp vec3 LightGridTC;\n",
768"#endif\n",
769"#ifdef USEBOUNCEGRID\n",
770"dp_varying highp vec3 BounceGridTexCoord;\n",
771"#endif\n",
772"\n",
773"#ifdef MODE_DEFERREDGEOMETRY\n",
774"dp_varying highp float Depth;\n",
775"#endif\n",
776"\n",
777"\n",
778"\n",
779"\n",
780"\n",
781"\n",
782"// 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",
783"\n",
784"// fragment shader specific:\n",
785"#ifdef FRAGMENT_SHADER\n",
786"\n",
787"uniform sampler2D Texture_Normal;\n",
788"uniform sampler2D Texture_Color;\n",
789"uniform sampler2D Texture_Gloss;\n",
790"#ifdef USEGLOW\n",
791"uniform sampler2D Texture_Glow;\n",
792"#endif\n",
793"#ifdef USEVERTEXTEXTUREBLEND\n",
794"uniform sampler2D Texture_SecondaryNormal;\n",
795"uniform sampler2D Texture_SecondaryColor;\n",
796"uniform sampler2D Texture_SecondaryGloss;\n",
797"#ifdef USEGLOW\n",
798"uniform sampler2D Texture_SecondaryGlow;\n",
799"#endif\n",
800"#endif\n",
801"#ifdef USECOLORMAPPING\n",
802"uniform sampler2D Texture_Pants;\n",
803"uniform sampler2D Texture_Shirt;\n",
804"#endif\n",
805"#ifdef USEFOG\n",
806"#ifdef USEFOGHEIGHTTEXTURE\n",
807"uniform sampler2D Texture_FogHeightTexture;\n",
808"#endif\n",
809"uniform sampler2D Texture_FogMask;\n",
810"#endif\n",
811"#ifdef USELIGHTMAP\n",
812"uniform sampler2D Texture_Lightmap;\n",
813"#endif\n",
814"#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE)\n",
815"uniform sampler2D Texture_Deluxemap;\n",
816"#endif\n",
817"#ifdef USEREFLECTION\n",
818"uniform sampler2D Texture_Reflection;\n",
819"#endif\n",
820"\n",
821"#ifdef MODE_DEFERREDLIGHTSOURCE\n",
822"uniform sampler2D Texture_ScreenNormalMap;\n",
823"#endif\n",
824"#ifdef USEDEFERREDLIGHTMAP\n",
825"#ifdef USECELOUTLINES\n",
826"uniform sampler2D Texture_ScreenNormalMap;\n",
827"#endif\n",
828"uniform sampler2D Texture_ScreenDiffuse;\n",
829"uniform sampler2D Texture_ScreenSpecular;\n",
830"#endif\n",
831"\n",
832"uniform mediump vec3 Color_Pants;\n",
833"uniform mediump vec3 Color_Shirt;\n",
834"uniform mediump vec3 FogColor;\n",
835"\n",
836"#ifdef USEFOG\n",
837"uniform highp float FogRangeRecip;\n",
838"uniform highp float FogPlaneViewDist;\n",
839"uniform highp float FogHeightFade;\n",
840"vec3 FogVertex(vec4 surfacecolor)\n",
841"{\n",
842"#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE) || defined(USEBOUNCEGRIDDIRECTIONAL) || defined(MODE_LIGHTGRID)\n",
843" vec3 EyeVectorModelSpace = vec3(VectorS.w, VectorT.w, VectorR.w);\n",
844"#endif\n",
845" float FogPlaneVertexDist = EyeVectorFogDepth.w;\n",
846" float fogfrac;\n",
847" vec3 fc = FogColor;\n",
848"#ifdef USEFOGALPHAHACK\n",
849" fc *= surfacecolor.a;\n",
850"#endif\n",
851"#ifdef USEFOGHEIGHTTEXTURE\n",
852" vec4 fogheightpixel = dp_texture2D(Texture_FogHeightTexture, vec2(1,1) + vec2(FogPlaneVertexDist, FogPlaneViewDist) * (-2.0 * FogHeightFade));\n",
853" fogfrac = fogheightpixel.a;\n",
854" return mix(fogheightpixel.rgb * fc, surfacecolor.rgb, dp_texture2D(Texture_FogMask, cast_myhalf2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n",
855"#else\n",
856"# ifdef USEFOGOUTSIDE\n",
857" fogfrac = min(0.0, FogPlaneVertexDist) / (FogPlaneVertexDist - FogPlaneViewDist) * min(1.0, min(0.0, FogPlaneVertexDist) * FogHeightFade);\n",//TODO: can saturate?
858"# else\n",
859" fogfrac = FogPlaneViewDist / (FogPlaneViewDist - max(0.0, FogPlaneVertexDist)) * min(1.0, (min(0.0, FogPlaneVertexDist) + FogPlaneViewDist) * FogHeightFade);\n",
860"# endif\n",
861" return mix(fc, surfacecolor.rgb, dp_texture2D(Texture_FogMask, cast_myhalf2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n",
862"#endif\n",
863"}\n",
864"#endif\n",
865"\n",
866"#ifdef USEOFFSETMAPPING\n",
867"uniform mediump vec4 OffsetMapping_ScaleSteps;\n",
868"uniform mediump float OffsetMapping_Bias;\n",
869"#ifdef USEOFFSETMAPPING_LOD\n",
870"uniform mediump float OffsetMapping_LodDistance;\n",
871"#endif\n",
872"vec2 OffsetMapping(vec2 TexCoord, vec2 dPdx, vec2 dPdy)\n",
873"{\n",
874" float i;\n",
875" // distance-based LOD\n",
876"#ifdef USEOFFSETMAPPING_LOD\n",
877" //mediump float LODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n",
878" //mediump vec4 ScaleSteps = vec4(OffsetMapping_ScaleSteps.x, OffsetMapping_ScaleSteps.y * LODFactor, OffsetMapping_ScaleSteps.z / LODFactor, OffsetMapping_ScaleSteps.w * LODFactor);\n",
879" mediump float GuessLODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n",
880"#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n",
881" // stupid workaround because 1-step and 2-step reliefmapping is void\n",
882" mediump float LODSteps = max(3.0, ceil(GuessLODFactor * OffsetMapping_ScaleSteps.y));\n",
883"#else\n",
884" mediump float LODSteps = ceil(GuessLODFactor * OffsetMapping_ScaleSteps.y);\n",
885"#endif\n",
886" mediump vec4 ScaleSteps = vec4(OffsetMapping_ScaleSteps.x, LODSteps, vec2(1.0, OffsetMapping_ScaleSteps.w * LODSteps) / vec2(LODSteps, OffsetMapping_ScaleSteps.y));\n",
887"#else\n",
888" #define ScaleSteps OffsetMapping_ScaleSteps\n",
889"#endif\n",
890"#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n",
891" float f;\n",
892" // 14 sample relief mapping: linear search and then binary search\n",
893" // this basically steps forward a small amount repeatedly until it finds\n",
894" // itself inside solid, then jitters forward and back using decreasing\n",
895" // amounts to find the impact\n",
896" //vec3 OffsetVector = vec3(EyeVectorFogDepth.xy * ((1.0 / EyeVectorFogDepth.z) * ScaleSteps.x) * vec2(-1, 1), -1);\n",
897" //vec3 OffsetVector = vec3(normalize(EyeVectorFogDepth.xy) * ScaleSteps.x * vec2(-1, 1), -1);\n",
898" vec3 OffsetVector = vec3(normalize(EyeVectorFogDepth.xyz).xy * ScaleSteps.x * vec2(-1, 1), -1);\n",
899" vec3 RT = vec3(vec2(TexCoord.xy - OffsetVector.xy*OffsetMapping_Bias), 1);\n",
900" OffsetVector *= ScaleSteps.z;\n",
901" for(i = 1.0; i < ScaleSteps.y; ++i)\n",
902" RT += OffsetVector * step(dp_textureGrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z);\n",
903" for(i = 0.0, f = 1.0; i < ScaleSteps.w; ++i, f *= 0.5)\n",
904" RT += OffsetVector * (step(dp_textureGrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * f - 0.5 * f);\n",
905" return RT.xy;\n",
906"#else\n",
907" // 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits)\n",
908" //vec2 OffsetVector = vec2(EyeVectorFogDepth.xy * ((1.0 / EyeVectorFogDepth.z) * ScaleSteps.x) * vec2(-1, 1));\n",
909" //vec2 OffsetVector = vec2(normalize(EyeVectorFogDepth.xy) * ScaleSteps.x * vec2(-1, 1));\n",
910" vec2 OffsetVector = vec2(normalize(EyeVectorFogDepth.xyz).xy * ScaleSteps.x * vec2(-1, 1));\n",
911" OffsetVector *= ScaleSteps.z;\n",
912" vec2 OneMinusBias_OffsetVector = (1.0 - OffsetMapping_Bias) * OffsetVector;\n",
913" for(i = 0.0; i < ScaleSteps.y; ++i)\n",
914" TexCoord += -dp_textureGrad(Texture_Normal, TexCoord, dPdx, dPdy).a * OffsetVector + OneMinusBias_OffsetVector;\n",
915" return TexCoord;\n"
916"#endif\n",
917"}\n",
918"#endif // USEOFFSETMAPPING\n",
919"\n",
920"#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE)\n",
921"uniform sampler2D Texture_Attenuation;\n",
922"uniform samplerCube Texture_Cube;\n",
923"#endif\n",
924"\n",
925"#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n",
926"\n",
927"#ifdef USESHADOWMAP2D\n",
928"# ifdef USESHADOWSAMPLER\n",
929"uniform sampler2DShadow Texture_ShadowMap2D;\n",
930"# else\n",
931"uniform sampler2D Texture_ShadowMap2D;\n",
932"# endif\n",
933"#endif\n",
934"\n",
935"#ifdef USESHADOWMAPVSDCT\n",
936"uniform samplerCube Texture_CubeProjection;\n",
937"#endif\n",
938"\n",
939"#if defined(USESHADOWMAP2D)\n",
940"uniform mediump vec4 ShadowMap_TextureScale;\n",
941"uniform mediump vec4 ShadowMap_Parameters;\n",
942"#endif\n",
943"\n",
944"#if defined(USESHADOWMAP2D)\n",
945"# ifdef USESHADOWMAPORTHO\n",
946"# define GetShadowMapTC2D(dir) (max(vec3(0.0, 0.0, 0.0), min(dir, ShadowMap_Parameters.xyz)))\n",
947"# else\n",
948"# ifdef USESHADOWMAPVSDCT\n",
949"vec3 GetShadowMapTC2D(vec3 dir)\n",
950"{\n",
951" vec3 adir = abs(dir);\n",
952" float m = max(max(adir.x, adir.y), adir.z);\n",
953" vec4 proj = dp_textureCube(Texture_CubeProjection, dir);\n",
954"#ifdef USEDEPTHRGB\n",
955" return vec3(mix(dir.xy, dir.zz, proj.xy) * (ShadowMap_Parameters.x / m) + proj.zw * ShadowMap_Parameters.z, m + 64.0 * ShadowMap_Parameters.w);\n",
956"#else\n",
957" vec2 mparams = ShadowMap_Parameters.xy / m;\n",
958" return vec3(mix(dir.xy, dir.zz, proj.xy) * mparams.x + proj.zw * ShadowMap_Parameters.z, mparams.y + ShadowMap_Parameters.w);\n",
959"#endif\n",
960"}\n",
961"# else\n",
962"vec3 GetShadowMapTC2D(vec3 dir)\n",
963"{\n",
964" vec3 adir = abs(dir);\n",
965" float m; vec4 proj;\n",
966" if (adir.x > adir.y) { m = adir.x; proj = vec4(dir.zyx, 0.5); } else { m = adir.y; proj = vec4(dir.xzy, 1.5); }\n",
967" if (adir.z > m) { m = adir.z; proj = vec4(dir, 2.5); }\n",
968"#ifdef USEDEPTHRGB\n",
969" return vec3(proj.xy * (ShadowMap_Parameters.x / m) + vec2(0.5,0.5) + vec2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, m + 64.0 * ShadowMap_Parameters.w);\n",
970"#else\n",
971" vec2 mparams = ShadowMap_Parameters.xy / m;\n",
972" return vec3(proj.xy * mparams.x + vec2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, mparams.y + ShadowMap_Parameters.w);\n",
973"#endif\n",
974"}\n",
975"# endif\n",
976"# endif\n",
977"#endif // defined(USESHADOWMAP2D)\n",
978"\n",
979"# ifdef USESHADOWMAP2D\n",
980"float ShadowMapCompare(vec3 dir)\n",
981"{\n",
982" vec3 shadowmaptc = GetShadowMapTC2D(dir) + vec3(ShadowMap_TextureScale.zw, 0.0f);\n",
983" float f;\n",
984"\n",
985"# ifdef USEDEPTHRGB\n",
986"# ifdef USESHADOWMAPPCF\n",
987"# define texval(x, y) decodedepthmacro(dp_texture2D(Texture_ShadowMap2D, center + vec2(x, y)*ShadowMap_TextureScale.xy))\n",
988"# if USESHADOWMAPPCF > 1\n",
989" vec2 center = shadowmaptc.xy - 0.5, offset = fract(center);\n",
990" center *= ShadowMap_TextureScale.xy;\n",
991" vec4 row1 = step(shadowmaptc.z, vec4(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0), texval( 2.0, -1.0)));\n",
992" vec4 row2 = step(shadowmaptc.z, vec4(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0), texval( 2.0, 0.0)));\n",
993" vec4 row3 = step(shadowmaptc.z, vec4(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0), texval( 2.0, 1.0)));\n",
994" vec4 row4 = step(shadowmaptc.z, vec4(texval(-1.0, 2.0), texval( 0.0, 2.0), texval( 1.0, 2.0), texval( 2.0, 2.0)));\n",
995" vec4 cols = row2 + row3 + mix(row1, row4, offset.y);\n",
996" f = dot(mix(cols.xyz, cols.yzw, offset.x), vec3(1.0/9.0));\n",
997"# else\n",
998" vec2 center = shadowmaptc.xy*ShadowMap_TextureScale.xy, offset = fract(shadowmaptc.xy);\n",
999" vec3 row1 = step(shadowmaptc.z, vec3(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0)));\n",
1000" vec3 row2 = step(shadowmaptc.z, vec3(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0)));\n",
1001" vec3 row3 = step(shadowmaptc.z, vec3(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0)));\n",
1002" vec3 cols = row2 + mix(row1, row3, offset.y);\n",
1003" f = dot(mix(cols.xy, cols.yz, offset.x), vec2(0.25));\n",
1004"# endif\n",
1005"# else\n",
1006" f = step(shadowmaptc.z, decodedepthmacro(dp_texture2D(Texture_ShadowMap2D, shadowmaptc.xy*ShadowMap_TextureScale.xy)));\n",
1007"# endif\n",
1008"# else\n",
1009"# ifdef USESHADOWSAMPLER\n",
1010"# ifdef USESHADOWMAPPCF\n",
1011"# define texval(off) dp_shadow2D(Texture_ShadowMap2D, vec3(off, shadowmaptc.z)) \n",
1012" vec2 offset = fract(shadowmaptc.xy - 0.5);\n",
1013" vec4 size = vec4(offset + 1.0, 2.0 - offset);\n",
1014"# if USESHADOWMAPPCF > 1\n",
1015" vec2 center = (shadowmaptc.xy - offset + 0.5)*ShadowMap_TextureScale.xy;\n",
1016" vec4 weight = (vec4(-1.5, -1.5, 2.0, 2.0) + (shadowmaptc.xy - 0.5*offset).xyxy)*ShadowMap_TextureScale.xyxy;\n",
1017" f = (1.0/25.0)*dot(size.zxzx*size.wwyy, vec4(texval(weight.xy), texval(weight.zy), texval(weight.xw), texval(weight.zw))) +\n",
1018" (2.0/25.0)*dot(size, vec4(texval(vec2(weight.z, center.y)), texval(vec2(center.x, weight.w)), texval(vec2(weight.x, center.y)), texval(vec2(center.x, weight.y)))) +\n",
1019" (4.0/25.0)*texval(center);\n",
1020"# else\n",
1021" vec4 weight = (vec4(1.0, 1.0, -0.5, -0.5) + (shadowmaptc.xy - 0.5*offset).xyxy)*ShadowMap_TextureScale.xyxy;\n",
1022" f = (1.0/9.0)*dot(size.zxzx*size.wwyy, vec4(texval(weight.zw), texval(weight.xw), texval(weight.zy), texval(weight.xy)));\n",
1023"# endif \n",
1024"# else\n",
1025" f = dp_shadow2D(Texture_ShadowMap2D, vec3(shadowmaptc.xy*ShadowMap_TextureScale.xy, shadowmaptc.z));\n",
1026"# endif\n",
1027"# else\n",
1028"# ifdef USESHADOWMAPPCF\n",
1029"# if defined(GL_ARB_texture_gather) || defined(GL_AMD_texture_texture4)\n",
1030"# ifdef GL_ARB_texture_gather\n",
1031"# define texval(x, y) textureGatherOffset(Texture_ShadowMap2D, center, ivec2(x, y))\n",
1032"# else\n",
1033"# define texval(x, y) texture4(Texture_ShadowMap2D, center + vec2(x, y)*ShadowMap_TextureScale.xy)\n",
1034"# endif\n",
1035" vec2 offset = fract(shadowmaptc.xy - 0.5), center = (shadowmaptc.xy - offset)*ShadowMap_TextureScale.xy;\n",
1036"# if USESHADOWMAPPCF > 1\n",
1037" vec4 group1 = step(shadowmaptc.z, texval(-2.0, -2.0));\n",
1038" vec4 group2 = step(shadowmaptc.z, texval( 0.0, -2.0));\n",
1039" vec4 group3 = step(shadowmaptc.z, texval( 2.0, -2.0));\n",
1040" vec4 group4 = step(shadowmaptc.z, texval(-2.0, 0.0));\n",
1041" vec4 group5 = step(shadowmaptc.z, texval( 0.0, 0.0));\n",
1042" vec4 group6 = step(shadowmaptc.z, texval( 2.0, 0.0));\n",
1043" vec4 group7 = step(shadowmaptc.z, texval(-2.0, 2.0));\n",
1044" vec4 group8 = step(shadowmaptc.z, texval( 0.0, 2.0));\n",
1045" vec4 group9 = step(shadowmaptc.z, texval( 2.0, 2.0));\n",
1046" vec4 locols = vec4(group1.ab, group3.ab);\n",
1047" vec4 hicols = vec4(group7.rg, group9.rg);\n",
1048" locols.yz += group2.ab;\n",
1049" hicols.yz += group8.rg;\n",
1050" vec4 midcols = vec4(group1.rg, group3.rg) + vec4(group7.ab, group9.ab) +\n",
1051" vec4(group4.rg, group6.rg) + vec4(group4.ab, group6.ab) +\n",
1052" mix(locols, hicols, offset.y);\n",
1053" vec4 cols = group5 + vec4(group2.rg, group8.ab);\n",
1054" cols.xyz += mix(midcols.xyz, midcols.yzw, offset.x);\n",
1055" f = dot(cols, vec4(1.0/25.0));\n",
1056"# else\n",
1057" vec4 group1 = step(shadowmaptc.z, texval(-1.0, -1.0));\n",
1058" vec4 group2 = step(shadowmaptc.z, texval( 1.0, -1.0));\n",
1059" vec4 group3 = step(shadowmaptc.z, texval(-1.0, 1.0));\n",
1060" vec4 group4 = step(shadowmaptc.z, texval( 1.0, 1.0));\n",
1061" vec4 cols = vec4(group1.rg, group2.rg) + vec4(group3.ab, group4.ab) +\n",
1062" mix(vec4(group1.ab, group2.ab), vec4(group3.rg, group4.rg), offset.y);\n",
1063" f = dot(mix(cols.xyz, cols.yzw, offset.x), vec3(1.0/9.0));\n",
1064"# endif\n",
1065"# else\n",
1066"# ifdef GL_EXT_gpu_shader4\n",
1067"# define texval(x, y) dp_textureOffset(Texture_ShadowMap2D, center, x, y).r\n",
1068"# else\n",
1069"# define texval(x, y) dp_texture2D(Texture_ShadowMap2D, center + vec2(x, y)*ShadowMap_TextureScale.xy).r \n",
1070"# endif\n",
1071"# if USESHADOWMAPPCF > 1\n",
1072" vec2 center = shadowmaptc.xy - 0.5, offset = fract(center);\n",
1073" center *= ShadowMap_TextureScale.xy;\n",
1074" vec4 row1 = step(shadowmaptc.z, vec4(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0), texval( 2.0, -1.0)));\n",
1075" vec4 row2 = step(shadowmaptc.z, vec4(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0), texval( 2.0, 0.0)));\n",
1076" vec4 row3 = step(shadowmaptc.z, vec4(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0), texval( 2.0, 1.0)));\n",
1077" vec4 row4 = step(shadowmaptc.z, vec4(texval(-1.0, 2.0), texval( 0.0, 2.0), texval( 1.0, 2.0), texval( 2.0, 2.0)));\n",
1078" vec4 cols = row2 + row3 + mix(row1, row4, offset.y);\n",
1079" f = dot(mix(cols.xyz, cols.yzw, offset.x), vec3(1.0/9.0));\n",
1080"# else\n",
1081" vec2 center = shadowmaptc.xy*ShadowMap_TextureScale.xy, offset = fract(shadowmaptc.xy);\n",
1082" vec3 row1 = step(shadowmaptc.z, vec3(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0)));\n",
1083" vec3 row2 = step(shadowmaptc.z, vec3(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0)));\n",
1084" vec3 row3 = step(shadowmaptc.z, vec3(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0)));\n",
1085" vec3 cols = row2 + mix(row1, row3, offset.y);\n",
1086" f = dot(mix(cols.xy, cols.yz, offset.x), vec2(0.25));\n",
1087"# endif\n",
1088"# endif\n",
1089"# else\n",
1090" f = step(shadowmaptc.z, dp_texture2D(Texture_ShadowMap2D, shadowmaptc.xy*ShadowMap_TextureScale.xy).r);\n",
1091"# endif\n",
1092"# endif\n",
1093"# endif\n",
1094"# ifdef USESHADOWMAPORTHO\n",
1095" return mix(ShadowMap_Parameters.w, 1.0, f);\n",
1096"# else\n",
1097" return f;\n",
1098"# endif\n",
1099"}\n",
1100"# endif\n",
1101"#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n",
1102"#endif // FRAGMENT_SHADER\n",
1103"\n",
1104"\n",
1105"\n",
1106"\n",
1107"#ifdef MODE_DEFERREDGEOMETRY\n",
1108"#ifdef VERTEX_SHADER\n",
1109"uniform highp mat4 TexMatrix;\n",
1110"#ifdef USEVERTEXTEXTUREBLEND\n",
1111"uniform highp mat4 BackgroundTexMatrix;\n",
1112"#endif\n",
1113"uniform highp mat4 ModelViewMatrix;\n",
1114"void main(void)\n",
1115"{\n",
1116"#ifdef USESKELETAL\n",
1117" ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n",
1118" ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n",
1119" ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n",
1120" vec4 sw = Attrib_SkeletalWeight;\n",
1121" vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n",
1122" vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n",
1123" vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n",
1124" mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n",
1125" mat3 SkeletalNormalMatrix = mat3(cross(SkeletalMatrix[1].xyz, SkeletalMatrix[2].xyz), cross(SkeletalMatrix[2].xyz, SkeletalMatrix[0].xyz), cross(SkeletalMatrix[0].xyz, SkeletalMatrix[1].xyz)); // is actually transpose(inverse(mat3(SkeletalMatrix))) * det(mat3(SkeletalMatrix))\n",
1126" vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n",
1127" vec3 SkeletalSVector = normalize(Attrib_TexCoord1.xyz * SkeletalNormalMatrix);\n",
1128" vec3 SkeletalTVector = normalize(Attrib_TexCoord2.xyz * SkeletalNormalMatrix);\n",
1129" vec3 SkeletalNormal = normalize(Attrib_TexCoord3.xyz * SkeletalNormalMatrix);\n",
1130"#define Attrib_Position SkeletalVertex\n",
1131"#define Attrib_TexCoord1 SkeletalSVector\n",
1132"#define Attrib_TexCoord2 SkeletalTVector\n",
1133"#define Attrib_TexCoord3 SkeletalNormal\n",
1134"#endif\n",
1135" TexCoordSurfaceLightmap = vec4((TexMatrix * Attrib_TexCoord0).xy, 0.0, 0.0);\n",
1136"#ifdef USEVERTEXTEXTUREBLEND\n",
1137" VertexColor = Attrib_Color;\n",
1138" TexCoord2 = vec2(BackgroundTexMatrix * Attrib_TexCoord0);\n",
1139"#endif\n",
1140"\n",
1141" // transform unnormalized eye direction into tangent space\n",
1142"#ifdef USEOFFSETMAPPING\n",
1143" vec3 EyeRelative = EyePosition - Attrib_Position.xyz;\n",
1144" EyeVectorFogDepth.x = dot(EyeRelative, Attrib_TexCoord1.xyz);\n",
1145" EyeVectorFogDepth.y = dot(EyeRelative, Attrib_TexCoord2.xyz);\n",
1146" EyeVectorFogDepth.z = dot(EyeRelative, Attrib_TexCoord3.xyz);\n",
1147" EyeVectorFogDepth.w = 0.0;\n",
1148"#endif\n",
1149"\n",
1150" VectorS = (ModelViewMatrix * vec4(Attrib_TexCoord1.xyz, 0));\n",
1151" VectorT = (ModelViewMatrix * vec4(Attrib_TexCoord2.xyz, 0));\n",
1152" VectorR = (ModelViewMatrix * vec4(Attrib_TexCoord3.xyz, 0));\n",
1153" gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
1154"#ifdef USETRIPPY\n",
1155" gl_Position = TrippyVertex(gl_Position);\n",
1156"#endif\n",
1157" Depth = (ModelViewMatrix * Attrib_Position).z;\n",
1158"}\n",
1159"#endif // VERTEX_SHADER\n",
1160"\n",
1161"#ifdef FRAGMENT_SHADER\n",
1162"void main(void)\n",
1163"{\n",
1164"#ifdef USEOFFSETMAPPING\n",
1165" // apply offsetmapping\n",
1166" vec2 dPdx = dp_offsetmapping_dFdx(TexCoordSurfaceLightmap.xy);\n",
1167" vec2 dPdy = dp_offsetmapping_dFdy(TexCoordSurfaceLightmap.xy);\n",
1168" vec2 TexCoordOffset = OffsetMapping(TexCoordSurfaceLightmap.xy, dPdx, dPdy);\n",
1169"# define offsetMappedTexture2D(t) dp_textureGrad(t, TexCoordOffset, dPdx, dPdy)\n",
1170"#else\n",
1171"# define offsetMappedTexture2D(t) dp_texture2D(t, TexCoordSurfaceLightmap.xy)\n",
1172"#endif\n",
1173"\n",
1174"#ifdef USEALPHAKILL\n",
1175" if (offsetMappedTexture2D(Texture_Color).a < 0.5)\n",
1176" discard;\n",
1177"#endif\n",
1178"\n",
1179"#ifdef USEVERTEXTEXTUREBLEND\n",
1180" float alpha = offsetMappedTexture2D(Texture_Color).a;\n",
1181" float terrainblend = clamp(float(VertexColor.a) * alpha * 2.0 - 0.5, float(0.0), float(1.0));\n",
1182" //float terrainblend = min(float(VertexColor.a) * alpha * 2.0, float(1.0));\n",
1183" //float terrainblend = float(VertexColor.a) * alpha > 0.5;\n",
1184"#endif\n",
1185"\n",
1186"#ifdef USEVERTEXTEXTUREBLEND\n",
1187" vec3 surfacenormal = mix(vec3(dp_texture2D(Texture_SecondaryNormal, TexCoord2)), vec3(offsetMappedTexture2D(Texture_Normal)), terrainblend) - vec3(0.5, 0.5, 0.5);\n",
1188" float a = mix(dp_texture2D(Texture_SecondaryGloss, TexCoord2).a, offsetMappedTexture2D(Texture_Gloss).a, terrainblend);\n",
1189"#else\n",
1190" vec3 surfacenormal = vec3(offsetMappedTexture2D(Texture_Normal)) - vec3(0.5, 0.5, 0.5);\n",
1191" float a = offsetMappedTexture2D(Texture_Gloss).a;\n",
1192"#endif\n",
1193"\n",
1194" vec3 pixelnormal = normalize(surfacenormal.x * VectorS.xyz + surfacenormal.y * VectorT.xyz + surfacenormal.z * VectorR.xyz);\n",
1195" dp_FragColor = vec4(pixelnormal.x, pixelnormal.y, Depth, a);\n",
1196"}\n",
1197"#endif // FRAGMENT_SHADER\n",
1198"#else // !MODE_DEFERREDGEOMETRY\n",
1199"\n",
1200"\n",
1201"\n",
1202"\n",
1203"#ifdef MODE_DEFERREDLIGHTSOURCE\n",
1204"#ifdef VERTEX_SHADER\n",
1205"uniform highp mat4 ModelViewMatrix;\n",
1206"void main(void)\n",
1207"{\n",
1208" ModelViewPosition = ModelViewMatrix * Attrib_Position;\n",
1209" gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
1210"}\n",
1211"#endif // VERTEX_SHADER\n",
1212"\n",
1213"#ifdef FRAGMENT_SHADER\n",
1214"uniform highp mat4 ViewToLight;\n",
1215"// ScreenToDepth = vec2(Far / (Far - Near), Far * Near / (Near - Far));\n",
1216"uniform highp vec2 ScreenToDepth;\n",
1217"uniform myhalf3 DeferredColor_Ambient;\n",
1218"uniform myhalf3 DeferredColor_Diffuse;\n",
1219"#ifdef USESPECULAR\n",
1220"uniform myhalf3 DeferredColor_Specular;\n",
1221"uniform myhalf SpecularPower;\n",
1222"#endif\n",
1223"uniform myhalf2 PixelToScreenTexCoord;\n",
1224"void main(void)\n",
1225"{\n",
1226" // calculate viewspace pixel position\n",
1227" vec2 ScreenTexCoord = gl_FragCoord.xy * PixelToScreenTexCoord;\n",
1228" vec3 position;\n",
1229" // get the geometry information (depth, normal, specular exponent)\n",
1230" myhalf4 normalmap = dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord);\n",
1231" // decode viewspace pixel normal\n",
1232"// myhalf3 surfacenormal = normalize(normalmap.rgb - cast_myhalf3(0.5,0.5,0.5));\n",
1233" myhalf3 surfacenormal = myhalf3(normalmap.rg, sqrt(1.0-dot(normalmap.rg, normalmap.rg)));\n",
1234" // decode viewspace pixel position\n",
1235"// position.z = decodedepthmacro(dp_texture2D(Texture_ScreenDepth, ScreenTexCoord));\n",
1236" position.z = normalmap.b;\n",
1237"// position.z = ScreenToDepth.y / (dp_texture2D(Texture_ScreenDepth, ScreenTexCoord).r + ScreenToDepth.x);\n",
1238" position.xy = ModelViewPosition.xy * (position.z / ModelViewPosition.z);\n",
1239"\n",
1240" // now do the actual shading\n",
1241" // surfacenormal = pixel normal in viewspace\n",
1242" // LightVector = pixel to light in viewspace\n",
1243" // CubeVector = pixel in lightspace\n",
1244" // eyenormal = pixel to view direction in viewspace\n",
1245" vec3 CubeVector = vec3(ViewToLight * vec4(position,1));\n",
1246" myhalf fade = cast_myhalf(dp_texture2D(Texture_Attenuation, vec2(length(CubeVector), 0.0)));\n",
1247"#ifdef USEDIFFUSE\n",
1248" // calculate diffuse shading\n",
1249" myhalf3 lightnormal = cast_myhalf3(normalize(LightPosition - position));\n",
1250"SHADEDIFFUSE\n",
1251"#endif\n",
1252"#ifdef USESPECULAR\n",
1253" // calculate directional shading\n",
1254" myhalf3 eyenormal = -normalize(cast_myhalf3(position));\n",
1255"SHADESPECULAR(SpecularPower * normalmap.a)\n",
1256"#endif\n",
1257"\n",
1258"#if defined(USESHADOWMAP2D)\n",
1259" fade *= ShadowMapCompare(CubeVector);\n",
1260"#endif\n",
1261"\n",
1262"#ifdef USESPECULAR\n",
1263" gl_FragData[0] = vec4((DeferredColor_Ambient + DeferredColor_Diffuse * diffuse) * fade, 1.0);\n",
1264" gl_FragData[1] = vec4(DeferredColor_Specular * (specular * fade), 1.0);\n",
1265"# ifdef USECUBEFILTER\n",
1266" vec3 cubecolor = dp_textureCube(Texture_Cube, CubeVector).rgb;\n",
1267" gl_FragData[0].rgb *= cubecolor;\n",
1268" gl_FragData[1].rgb *= cubecolor;\n",
1269"# endif\n",
1270"#else\n",
1271"# ifdef USEDIFFUSE\n",
1272" gl_FragColor = vec4((DeferredColor_Ambient + DeferredColor_Diffuse * diffuse) * fade, 1.0);\n",
1273"# else\n",
1274" gl_FragColor = vec4(DeferredColor_Ambient * fade, 1.0);\n",
1275"# endif\n",
1276"# ifdef USECUBEFILTER\n",
1277" vec3 cubecolor = dp_textureCube(Texture_Cube, CubeVector).rgb;\n",
1278" gl_FragColor.rgb *= cubecolor;\n",
1279"# endif\n",
1280"#endif\n",
1281"}\n",
1282"#endif // FRAGMENT_SHADER\n",
1283"#else // !MODE_DEFERREDLIGHTSOURCE\n",
1284"\n",
1285"\n",
1286"\n",
1287"\n",
1288"#ifdef VERTEX_SHADER\n",
1289"uniform highp mat4 TexMatrix;\n",
1290"#ifdef USEVERTEXTEXTUREBLEND\n",
1291"uniform highp mat4 BackgroundTexMatrix;\n",
1292"#endif\n",
1293"#ifdef MODE_LIGHTSOURCE\n",
1294"uniform highp mat4 ModelToLight;\n",
1295"#endif\n",
1296"#ifdef USESHADOWMAPORTHO\n",
1297"uniform highp mat4 ShadowMapMatrix;\n",
1298"#endif\n",
1299"#ifdef MODE_LIGHTGRID\n",
1300"uniform highp mat4 LightGridMatrix;\n",
1301"#endif\n",
1302"#ifdef USEBOUNCEGRID\n",
1303"uniform highp mat4 BounceGridMatrix;\n",
1304"#endif\n",
1305"void main(void)\n",
1306"{\n",
1307"#ifdef USESKELETAL\n",
1308" ivec4 si0 = ivec4(Attrib_SkeletalIndex * 3.0);\n",
1309" ivec4 si1 = si0 + ivec4(1, 1, 1, 1);\n",
1310" ivec4 si2 = si0 + ivec4(2, 2, 2, 2);\n",
1311" vec4 sw = Attrib_SkeletalWeight;\n",
1312" vec4 SkeletalMatrix1 = Skeletal_Transform12[si0.x] * sw.x + Skeletal_Transform12[si0.y] * sw.y + Skeletal_Transform12[si0.z] * sw.z + Skeletal_Transform12[si0.w] * sw.w;\n",
1313" vec4 SkeletalMatrix2 = Skeletal_Transform12[si1.x] * sw.x + Skeletal_Transform12[si1.y] * sw.y + Skeletal_Transform12[si1.z] * sw.z + Skeletal_Transform12[si1.w] * sw.w;\n",
1314" vec4 SkeletalMatrix3 = Skeletal_Transform12[si2.x] * sw.x + Skeletal_Transform12[si2.y] * sw.y + Skeletal_Transform12[si2.z] * sw.z + Skeletal_Transform12[si2.w] * sw.w;\n",
1315" mat4 SkeletalMatrix = mat4(SkeletalMatrix1, SkeletalMatrix2, SkeletalMatrix3, vec4(0.0, 0.0, 0.0, 1.0));\n",
1316"// ivec4 si = ivec4(Attrib_SkeletalIndex);\n",
1317"// mat4 SkeletalMatrix = Skeletal_Transform[si.x] * Attrib_SkeletalWeight.x + Skeletal_Transform[si.y] * Attrib_SkeletalWeight.y + Skeletal_Transform[si.z] * Attrib_SkeletalWeight.z + Skeletal_Transform[si.w] * Attrib_SkeletalWeight.w;\n",
1318" mat3 SkeletalNormalMatrix = mat3(cross(SkeletalMatrix[1].xyz, SkeletalMatrix[2].xyz), cross(SkeletalMatrix[2].xyz, SkeletalMatrix[0].xyz), cross(SkeletalMatrix[0].xyz, SkeletalMatrix[1].xyz)); // is actually transpose(inverse(mat3(SkeletalMatrix))) * det(mat3(SkeletalMatrix))\n",
1319" vec4 SkeletalVertex = Attrib_Position * SkeletalMatrix;\n",
1320" SkeletalVertex.w = 1.0;\n",
1321" vec3 SkeletalSVector = normalize(Attrib_TexCoord1.xyz * SkeletalNormalMatrix);\n",
1322" vec3 SkeletalTVector = normalize(Attrib_TexCoord2.xyz * SkeletalNormalMatrix);\n",
1323" vec3 SkeletalNormal = normalize(Attrib_TexCoord3.xyz * SkeletalNormalMatrix);\n",
1324"#define Attrib_Position SkeletalVertex\n",
1325"#define Attrib_TexCoord1 SkeletalSVector\n",
1326"#define Attrib_TexCoord2 SkeletalTVector\n",
1327"#define Attrib_TexCoord3 SkeletalNormal\n",
1328"#endif\n",
1329"\n",
1330"#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR) || defined(USEALPHAGENVERTEX)\n",
1331" VertexColor = Attrib_Color;\n",
1332"#endif\n",
1333" // copy the surface texcoord\n",
1334"#ifdef USELIGHTMAP\n",
1335" TexCoordSurfaceLightmap = vec4((TexMatrix * Attrib_TexCoord0).xy, Attrib_TexCoord4.xy);\n",
1336"#else\n",
1337" TexCoordSurfaceLightmap = vec4((TexMatrix * Attrib_TexCoord0).xy, 0.0, 0.0);\n",
1338"#endif\n",
1339"#ifdef USEVERTEXTEXTUREBLEND\n",
1340" TexCoord2 = vec2(BackgroundTexMatrix * Attrib_TexCoord0);\n",
1341"#endif\n",
1342"\n",
1343"#ifdef MODE_LIGHTGRID\n",
1344" LightGridTC = vec3(LightGridMatrix * Attrib_Position);\n",
1345"#endif\n",
1346"#ifdef USEBOUNCEGRID\n",
1347" BounceGridTexCoord = vec3(BounceGridMatrix * Attrib_Position);\n",
1348"#ifdef USEBOUNCEGRIDDIRECTIONAL\n",
1349" BounceGridTexCoord.z *= 0.125;\n",
1350"#endif\n",
1351"#endif\n",
1352"\n",
1353"#ifdef MODE_LIGHTSOURCE\n",
1354" // transform vertex position into light attenuation/cubemap space\n",
1355" // (-1 to +1 across the light box)\n",
1356" CubeVector = vec3(ModelToLight * Attrib_Position);\n",
1357"\n",
1358"# ifdef USEDIFFUSE\n",
1359" // transform unnormalized light direction into tangent space\n",
1360" // (we use unnormalized to ensure that it interpolates correctly and then\n",
1361" // normalize it per pixel)\n",
1362" vec3 lightminusvertex = LightPosition - Attrib_Position.xyz;\n",
1363" LightVector.x = dot(lightminusvertex, Attrib_TexCoord1.xyz);\n",
1364" LightVector.y = dot(lightminusvertex, Attrib_TexCoord2.xyz);\n",
1365" LightVector.z = dot(lightminusvertex, Attrib_TexCoord3.xyz);\n",
1366"# endif\n",
1367"#endif\n",
1368"\n",
1369"#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE)\n",
1370" LightVector.x = dot(LightDir, Attrib_TexCoord1.xyz);\n",
1371" LightVector.y = dot(LightDir, Attrib_TexCoord2.xyz);\n",
1372" LightVector.z = dot(LightDir, Attrib_TexCoord3.xyz);\n",
1373"#endif\n",
1374"\n",
1375" // transform unnormalized eye direction into tangent space\n",
1376"#ifdef USEEYEVECTOR\n",
1377" vec3 EyeRelative = EyePosition - Attrib_Position.xyz;\n",
1378" EyeVectorFogDepth.x = dot(EyeRelative, Attrib_TexCoord1.xyz);\n",
1379" EyeVectorFogDepth.y = dot(EyeRelative, Attrib_TexCoord2.xyz);\n",
1380" EyeVectorFogDepth.z = dot(EyeRelative, Attrib_TexCoord3.xyz);\n",
1381"#ifdef USEFOG\n",
1382" EyeVectorFogDepth.w = dot(FogPlane, Attrib_Position);\n",
1383"#else\n",
1384" EyeVectorFogDepth.w = 0.0;\n",
1385"#endif\n",
1386"#endif\n",
1387"\n",
1388"\n",
1389"#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(USEREFLECTCUBE) || defined(USEBOUNCEGRIDDIRECTIONAL) || defined(MODE_LIGHTGRID)\n",
1390"# ifdef USEFOG\n",
1391" vec3 EyeDir = EyePosition - Attrib_Position.xyz;\n",
1392" VectorS = vec4(Attrib_TexCoord1.xyz, EyeDir.x);\n",
1393" VectorT = vec4(Attrib_TexCoord2.xyz, EyeDir.y);\n",
1394" VectorR = vec4(Attrib_TexCoord3.xyz, EyeDir.z);\n",
1395"# else\n",
1396" VectorS = vec4(Attrib_TexCoord1, 0);\n",
1397" VectorT = vec4(Attrib_TexCoord2, 0);\n",
1398" VectorR = vec4(Attrib_TexCoord3, 0);\n",
1399"# endif\n",
1400"#else\n",
1401"# ifdef USEFOG\n",
1402" EyeVectorModelSpace = EyePosition - Attrib_Position.xyz;\n",
1403"# endif\n",
1404"#endif\n",
1405"\n",
1406" // transform vertex to clipspace (post-projection, but before perspective divide by W occurs)\n",
1407" gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n",
1408"\n",
1409"#ifdef USESHADOWMAPORTHO\n",
1410" ShadowMapTC = vec3(ShadowMapMatrix * gl_Position);\n",
1411"#endif\n",
1412"\n",
1413"#ifdef USEREFLECTION\n",
1414" ModelViewProjectionPosition = gl_Position;\n",
1415"#endif\n",
1416"#ifdef USETRIPPY\n",
1417" gl_Position = TrippyVertex(gl_Position);\n",
1418"#endif\n",
1419"}\n",
1420"#endif // VERTEX_SHADER\n",
1421"\n",
1422"\n",
1423"\n",
1424"\n",
1425"#ifdef FRAGMENT_SHADER\n",
1426"#ifdef USEDEFERREDLIGHTMAP\n",
1427"uniform myhalf2 PixelToScreenTexCoord;\n",
1428"uniform myhalf3 DeferredMod_Diffuse;\n",
1429"uniform myhalf3 DeferredMod_Specular;\n",
1430"#endif\n",
1431"uniform myhalf3 Color_Ambient;\n",
1432"uniform myhalf3 Color_Diffuse;\n",
1433"uniform myhalf3 Color_Specular;\n",
1434"uniform myhalf SpecularPower;\n",
1435"#ifdef USEGLOW\n",
1436"uniform myhalf3 Color_Glow;\n",
1437"#endif\n",
1438"uniform myhalf Alpha;\n",
1439"#ifdef USEREFLECTION\n",
1440"uniform mediump vec4 DistortScaleRefractReflect;\n",
1441"uniform mediump vec4 ScreenScaleRefractReflect;\n",
1442"uniform mediump vec4 ScreenCenterRefractReflect;\n",
1443"uniform mediump vec4 ReflectColor;\n",
1444"#endif\n",
1445"#ifdef USEREFLECTCUBE\n",
1446"uniform highp mat4 ModelToReflectCube;\n",
1447"uniform sampler2D Texture_ReflectMask;\n",
1448"uniform samplerCube Texture_ReflectCube;\n",
1449"#endif\n",
1450"#ifdef MODE_LIGHTGRID\n",
1451"uniform sampler3D Texture_LightGrid;\n",
1452"uniform mat3 LightGridNormalMatrix;\n",
1453"#endif\n",
1454"#ifdef USEBOUNCEGRID\n",
1455"uniform sampler3D Texture_BounceGrid;\n",
1456"uniform float BounceGridIntensity;\n",
1457"uniform highp mat4 BounceGridMatrix;\n",
1458"#endif\n",
1459"uniform highp float ClientTime;\n",
1460"#ifdef USENORMALMAPSCROLLBLEND\n",
1461"uniform highp vec2 NormalmapScrollBlend;\n",
1462"#endif\n",
1463"#ifdef USEOCCLUDE\n",
1464"uniform occludeQuery {\n",
1465" uint visiblepixels;\n",
1466" uint allpixels;\n",
1467"};\n",
1468"#endif\n",
1469"void main(void)\n",
1470"{\n",
1471"#ifdef USEOFFSETMAPPING\n",
1472" // apply offsetmapping\n",
1473" vec2 dPdx = dp_offsetmapping_dFdx(TexCoordSurfaceLightmap.xy);\n",
1474" vec2 dPdy = dp_offsetmapping_dFdy(TexCoordSurfaceLightmap.xy);\n",
1475" vec2 TexCoordOffset = OffsetMapping(TexCoordSurfaceLightmap.xy, dPdx, dPdy);\n",
1476"# define offsetMappedTexture2D(t) dp_textureGrad(t, TexCoordOffset, dPdx, dPdy)\n",
1477"# define TexCoord TexCoordOffset\n",
1478"#else\n",
1479"# define offsetMappedTexture2D(t) dp_texture2D(t, TexCoordSurfaceLightmap.xy)\n",
1480"# define TexCoord TexCoordSurfaceLightmap.xy\n",
1481"#endif\n",
1482"\n",
1483" // combine the diffuse textures (base, pants, shirt)\n",
1484" myhalf4 color = cast_myhalf4(offsetMappedTexture2D(Texture_Color));\n",
1485"#ifdef USEALPHAKILL\n",
1486" if (color.a < 0.5)\n",
1487" discard;\n",
1488"#endif\n",
1489" color.a *= Alpha;\n",
1490"#ifdef USECOLORMAPPING\n",
1491" color.rgb += cast_myhalf3(offsetMappedTexture2D(Texture_Pants)) * Color_Pants + cast_myhalf3(offsetMappedTexture2D(Texture_Shirt)) * Color_Shirt;\n",
1492"#endif\n",
1493"#ifdef USEVERTEXTEXTUREBLEND\n",
1494"#ifdef USEBOTHALPHAS\n",
1495" myhalf4 color2 = cast_myhalf4(dp_texture2D(Texture_SecondaryColor, TexCoord2));\n",
1496" myhalf terrainblend = max(sat(cast_myhalf(VertexColor.a) * color.a), cast_myhalf(1.0 - color2.a));\n",//move sat outside?
1497" color.rgb = mix(color2.rgb, color.rgb, terrainblend);\n",
1498"#else\n",
1499" myhalf terrainblend = sat(cast_myhalf(VertexColor.a) * color.a * 2.0 - 0.5);\n",
1500" //myhalf terrainblend = min(cast_myhalf(VertexColor.a) * color.a * 2.0, cast_myhalf(1.0));\n",
1501" //myhalf terrainblend = cast_myhalf(VertexColor.a) * color.a > 0.5;\n",
1502" color.rgb = mix(cast_myhalf3(dp_texture2D(Texture_SecondaryColor, TexCoord2)), color.rgb, terrainblend);\n",
1503"#endif\n",
1504" color.a = 1.0;\n",
1505" //color = mix(cast_myhalf4(1, 0, 0, 1), color, terrainblend);\n",
1506"#endif\n",
1507"#ifdef USEALPHAGENVERTEX\n",
1508" color.a *= VertexColor.a;\n",
1509"#endif\n",
1510"\n",
1511" // get the surface normal\n",
1512"#ifdef USEVERTEXTEXTUREBLEND\n",
1513" myhalf3 surfacenormal = normalize(mix(cast_myhalf3(dp_texture2D(Texture_SecondaryNormal, TexCoord2)), cast_myhalf3(offsetMappedTexture2D(Texture_Normal)), terrainblend) - cast_myhalf3(0.5, 0.5, 0.5));\n",
1514"#else\n",
1515" myhalf3 surfacenormal = normalize(cast_myhalf3(offsetMappedTexture2D(Texture_Normal)) - cast_myhalf3(0.5, 0.5, 0.5));\n",
1516"#endif\n",
1517"\n",
1518" // get the material colors\n",
1519" myhalf3 diffusetex = color.rgb;\n",
1520"#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n",
1521"# ifdef USEVERTEXTEXTUREBLEND\n",
1522" myhalf4 glosstex = mix(cast_myhalf4(dp_texture2D(Texture_SecondaryGloss, TexCoord2)), cast_myhalf4(offsetMappedTexture2D(Texture_Gloss)), terrainblend);\n",
1523"# else\n",
1524" myhalf4 glosstex = cast_myhalf4(offsetMappedTexture2D(Texture_Gloss));\n",
1525"# endif\n",
1526"#endif\n",
1527"\n",
1528"#ifdef USEREFLECTCUBE\n",
1529" vec3 TangentReflectVector = reflect(-EyeVectorFogDepth.xyz, surfacenormal);\n",
1530" vec3 ModelReflectVector = TangentReflectVector.x * VectorS.xyz + TangentReflectVector.y * VectorT.xyz + TangentReflectVector.z * VectorR.xyz;\n",
1531" vec3 ReflectCubeTexCoord = vec3(ModelToReflectCube * vec4(ModelReflectVector, 0));\n",
1532" diffusetex += cast_myhalf3(offsetMappedTexture2D(Texture_ReflectMask)) * cast_myhalf3(dp_textureCube(Texture_ReflectCube, ReflectCubeTexCoord));\n",
1533"#endif\n",
1534"\n",
1535"#ifdef USESPECULAR\n",
1536" myhalf3 eyenormal = normalize(cast_myhalf3(EyeVectorFogDepth.xyz));\n",
1537"#endif\n",
1538"\n",
1539"\n",
1540"\n",
1541"\n",
1542"#ifdef MODE_LIGHTSOURCE\n",
1543" // light source\n",
1544"#ifdef USEDIFFUSE\n",
1545" myhalf3 lightnormal = cast_myhalf3(normalize(LightVector));\n",
1546"SHADEDIFFUSE\n",
1547" color.rgb = diffusetex * (Color_Ambient + diffuse * Color_Diffuse);\n",
1548"#ifdef USESPECULAR\n",
1549"SHADESPECULAR(SpecularPower * glosstex.a)\n",
1550" color.rgb += glosstex.rgb * (specular * Color_Specular);\n",
1551"#endif\n",
1552"#else\n",
1553" color.rgb = diffusetex * Color_Ambient;\n",
1554"#endif\n",
1555" color.rgb *= cast_myhalf(dp_texture2D(Texture_Attenuation, vec2(length(CubeVector), 0.0)));\n",
1556"#if defined(USESHADOWMAP2D)\n",
1557" color.rgb *= ShadowMapCompare(CubeVector);\n",
1558"#endif\n",
1559"# ifdef USECUBEFILTER\n",
1560" color.rgb *= cast_myhalf3(dp_textureCube(Texture_Cube, CubeVector));\n",
1561"# endif\n",
1562"#endif // MODE_LIGHTSOURCE\n",
1563"\n",
1564"\n",
1565"\n",
1566"\n",
1567"#ifdef MODE_LIGHTGRID\n",
1568" // clamp the LightGrid TC Z coordinate to the first of the 3 layers, to\n",
1569" // prevent repeat-artifacts for lightgrids smaller than the visible scene\n",
1570" // (which is often the case - the lightgrid bounds is defined by the level\n",
1571" // designer and usually matches the playable area, not the scenery around\n",
1572" // it), we can rely on GL_CLAMP_TO_EDGE for this in all other directions.\n",
1573" vec3 LGTC = vec3(LightGridTC.xy, min(LightGridTC.z, 0.333333));\n",
1574" myhalf3 ambientcolor = cast_myhalf3(dp_texture2D(Texture_LightGrid, LGTC));\n",
1575" myhalf3 lightcolor = cast_myhalf3(dp_texture2D(Texture_LightGrid, LGTC + vec3(0, 0, 0.333333)));\n",
1576" myhalf3 lightnormal_worldspace = cast_myhalf3(dp_texture2D(Texture_LightGrid, LGTC + vec3(0, 0, 0.6666667))) * 2.0 + cast_myhalf3(-1.0, -1.0, -1.0);\n",
1577" myhalf3 lightnormal_modelspace = cast_myhalf3(lightnormal_worldspace * LightGridNormalMatrix);\n",
1578" // convert modelspace light vector to tangentspace\n",
1579" myhalf3 lightnormal;\n",
1580" lightnormal.x = dot(lightnormal_modelspace, cast_myhalf3(VectorS));\n",
1581" lightnormal.y = dot(lightnormal_modelspace, cast_myhalf3(VectorT));\n",
1582" lightnormal.z = dot(lightnormal_modelspace, cast_myhalf3(VectorR));\n",
1583" lightnormal = normalize(lightnormal); // VectorS/T/R are not always perfectly normalized, and EXACTSPECULARMATH is very picky about this\n",
1584" // now we have the light parameters, so do the shading...\n",
1585"SHADEDIFFUSE\n",
1586" color.rgb = diffusetex * (Color_Ambient + Color_Diffuse * (ambientcolor + diffuse * lightcolor));\n",
1587"#ifdef USESPECULAR\n",
1588"SHADESPECULAR(SpecularPower * glosstex.a)\n",
1589" color.rgb += glosstex.rgb * (specular * Color_Specular * lightcolor);\n",
1590"#endif\n",
1591"#endif\n",
1592"\n",
1593"\n",
1594"\n",
1595"#ifdef MODE_LIGHTDIRECTION\n",
1596" #define SHADING\n",
1597" #ifdef USEDIFFUSE\n",
1598" myhalf3 lightnormal = cast_myhalf3(normalize(LightVector));\n",
1599" #endif\n",
1600" #define lightcolor 1\n",
1601"#endif // MODE_LIGHTDIRECTION\n",
1602"#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n",
1603" #define SHADING\n",
1604" // deluxemap lightmapping using light vectors in modelspace (q3map2 -light -deluxe)\n",
1605" myhalf3 lightnormal_modelspace = cast_myhalf3(dp_texture2D(Texture_Deluxemap, TexCoordSurfaceLightmap.zw)) * 2.0 + cast_myhalf3(-1.0, -1.0, -1.0);\n",
1606" myhalf3 lightcolor = cast_myhalf3(dp_texture2D(Texture_Lightmap, TexCoordSurfaceLightmap.zw));\n",
1607" // convert modelspace light vector to tangentspace\n",
1608" myhalf3 lightnormal;\n",
1609" lightnormal.x = dot(lightnormal_modelspace, cast_myhalf3(VectorS));\n",
1610" lightnormal.y = dot(lightnormal_modelspace, cast_myhalf3(VectorT));\n",
1611" lightnormal.z = dot(lightnormal_modelspace, cast_myhalf3(VectorR));\n",
1612" lightnormal = normalize(lightnormal); // VectorS/T/R are not always perfectly normalized, and EXACTSPECULARMATH is very picky about this\n",
1613" // calculate directional shading (and undoing the existing angle attenuation on the lightmap by the division)\n",
1614" // note that q3map2 is too stupid to calculate proper surface normals when q3map_nonplanar\n",
1615" // is used (the lightmap and deluxemap coords correspond to virtually random coordinates\n",
1616" // on that luxel, and NOT to its center, because recursive triangle subdivision is used\n",
1617" // to map the luxels to coordinates on the draw surfaces), which also causes\n",
1618" // deluxemaps to be wrong because light contributions from the wrong side of the surface\n",
1619" // are added up. To prevent divisions by zero or strong exaggerations, a max()\n",
1620" // nudge is done here at expense of some additional fps. This is ONLY needed for\n",
1621" // deluxemaps, tangentspace deluxemap avoid this problem by design.\n",
1622" lightcolor *= 1.0 / max(0.25, lightnormal.z);\n",
1623"#endif // MODE_LIGHTDIRECTIONMAP_MODELSPACE\n",
1624"#ifdef MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n",
1625" #define SHADING\n",
1626" // deluxemap lightmapping using light vectors in tangentspace (hmap2 -light)\n",
1627" myhalf3 lightnormal = cast_myhalf3(dp_texture2D(Texture_Deluxemap, TexCoordSurfaceLightmap.zw)) * 2.0 + cast_myhalf3(-1.0, -1.0, -1.0);\n",
1628" myhalf3 lightcolor = cast_myhalf3(dp_texture2D(Texture_Lightmap, TexCoordSurfaceLightmap.zw));\n",
1629"#endif\n",
1630"#if defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n",
1631" #define SHADING\n",
1632" // forced deluxemap on lightmapped/vertexlit surfaces\n",
1633" myhalf3 lightnormal = cast_myhalf3(0.0, 0.0, 1.0);\n",
1634" #ifdef USELIGHTMAP\n",
1635" myhalf3 lightcolor = cast_myhalf3(dp_texture2D(Texture_Lightmap, TexCoordSurfaceLightmap.zw));\n",
1636" #else\n",
1637" myhalf3 lightcolor = cast_myhalf3(VertexColor.rgb);\n",
1638" #endif\n",
1639"#endif\n",
1640"\n",
1641"\n",
1642"\n",
1643"\n",
1644"#ifdef MODE_LIGHTMAP\n",
1645" color.rgb = diffusetex * (Color_Ambient + cast_myhalf3(dp_texture2D(Texture_Lightmap, TexCoordSurfaceLightmap.zw)) * Color_Diffuse);\n",
1646"#endif // MODE_LIGHTMAP\n",
1647"#ifdef MODE_VERTEXCOLOR\n",
1648" color.rgb = diffusetex * (Color_Ambient + cast_myhalf3(VertexColor.rgb) * Color_Diffuse);\n",
1649"#endif // MODE_VERTEXCOLOR\n",
1650"#ifdef MODE_FLATCOLOR\n",
1651" color.rgb = diffusetex * Color_Ambient;\n",
1652"#endif // MODE_FLATCOLOR\n",
1653"\n",
1654"\n",
1655"\n",
1656"\n",
1657"#ifdef SHADING\n",
1658"# ifdef USEDIFFUSE\n",
1659"SHADEDIFFUSE\n",
1660"# ifdef USESPECULAR\n",
1661"SHADESPECULAR(SpecularPower * glosstex.a)\n",
1662" color.rgb = diffusetex * Color_Ambient + (diffusetex * Color_Diffuse * diffuse + glosstex.rgb * Color_Specular * specular) * lightcolor;\n",
1663"# else\n",
1664" color.rgb = diffusetex * (Color_Ambient + Color_Diffuse * diffuse * lightcolor);\n",
1665"# endif\n",
1666"# else\n",
1667" color.rgb = diffusetex * Color_Ambient;\n",
1668"# endif\n",
1669"#endif\n",
1670"\n",
1671"#ifdef USESHADOWMAPORTHO\n",
1672" color.rgb *= ShadowMapCompare(ShadowMapTC);\n",
1673"#endif\n",
1674"\n",
1675"#ifdef USEDEFERREDLIGHTMAP\n",
1676" vec2 ScreenTexCoord = gl_FragCoord.xy * PixelToScreenTexCoord;\n",
1677" color.rgb += diffusetex * cast_myhalf3(dp_texture2D(Texture_ScreenDiffuse, ScreenTexCoord)) * DeferredMod_Diffuse;\n",
1678" color.rgb += glosstex.rgb * cast_myhalf3(dp_texture2D(Texture_ScreenSpecular, ScreenTexCoord)) * DeferredMod_Specular;\n",
1679"// color.rgb = dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord).rgb * vec3(1.0, 1.0, 0.001);\n",
1680"#endif\n",
1681"\n",
1682"#ifdef USEBOUNCEGRID\n",
1683"#ifdef USEBOUNCEGRIDDIRECTIONAL\n",
1684"// myhalf4 bouncegrid_coeff1 = cast_myhalf4(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord ));\n",
1685"// myhalf4 bouncegrid_coeff2 = cast_myhalf4(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord + vec3(0.0, 0.0, 0.125))) * 2.0 + cast_myhalf4(-1.0, -1.0, -1.0, -1.0);\n",
1686" myhalf4 bouncegrid_coeff3 = cast_myhalf4(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord + vec3(0.0, 0.0, 0.250)));\n",
1687" myhalf4 bouncegrid_coeff4 = cast_myhalf4(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord + vec3(0.0, 0.0, 0.375)));\n",
1688" myhalf4 bouncegrid_coeff5 = cast_myhalf4(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord + vec3(0.0, 0.0, 0.500)));\n",
1689" myhalf4 bouncegrid_coeff6 = cast_myhalf4(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord + vec3(0.0, 0.0, 0.625)));\n",
1690" myhalf4 bouncegrid_coeff7 = cast_myhalf4(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord + vec3(0.0, 0.0, 0.750)));\n",
1691" myhalf4 bouncegrid_coeff8 = cast_myhalf4(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord + vec3(0.0, 0.0, 0.875)));\n",
1692" myhalf3 bouncegrid_dir = normalize(mat3(BounceGridMatrix) * (surfacenormal.x * VectorS.xyz + surfacenormal.y * VectorT.xyz + surfacenormal.z * VectorR.xyz));\n",
1693" myhalf3 bouncegrid_dirp = possat(bouncegrid_dir);\n",
1694" myhalf3 bouncegrid_dirn = possat(-bouncegrid_dir);\n",
1695"// bouncegrid_dirp = bouncegrid_dirn = cast_myhalf3(1.0,1.0,1.0);\n",
1696" myhalf3 bouncegrid_light = cast_myhalf3(\n",
1697" dot(bouncegrid_coeff3.xyz, bouncegrid_dirp) + dot(bouncegrid_coeff6.xyz, bouncegrid_dirn),\n",
1698" dot(bouncegrid_coeff4.xyz, bouncegrid_dirp) + dot(bouncegrid_coeff7.xyz, bouncegrid_dirn),\n",
1699" dot(bouncegrid_coeff5.xyz, bouncegrid_dirp) + dot(bouncegrid_coeff8.xyz, bouncegrid_dirn));\n",
1700" color.rgb += diffusetex * bouncegrid_light * BounceGridIntensity;\n",
1701"// color.rgb = bouncegrid_dir.rgb * 0.5 + vec3(0.5, 0.5, 0.5);\n",
1702"#else\n",
1703" color.rgb += diffusetex * cast_myhalf3(dp_texture3D(Texture_BounceGrid, BounceGridTexCoord)) * BounceGridIntensity;\n",
1704"#endif\n",
1705"#endif\n",
1706"\n",
1707"#ifdef USEGLOW\n",
1708"#ifdef USEVERTEXTEXTUREBLEND\n",
1709" color.rgb += mix(cast_myhalf3(dp_texture2D(Texture_SecondaryGlow, TexCoord2)), cast_myhalf3(offsetMappedTexture2D(Texture_Glow)), terrainblend) * Color_Glow;\n",
1710"#else\n",
1711" color.rgb += cast_myhalf3(offsetMappedTexture2D(Texture_Glow)) * Color_Glow;\n",
1712"#endif\n",
1713"#endif\n",
1714"\n",
1715"#ifdef USECELOUTLINES\n",
1716"# ifdef USEDEFERREDLIGHTMAP\n",
1717"// vec2 ScreenTexCoord = gl_FragCoord.xy * PixelToScreenTexCoord;\n",
1718" vec4 ScreenTexCoordStep = vec4(PixelToScreenTexCoord.x, 0.0, 0.0, PixelToScreenTexCoord.y);\n",
1719" vec4 DepthNeighbors;\n",
1720"\n",
1721" // enable to test ink on white geometry\n",
1722"// color.rgb = vec3(1.0, 1.0, 1.0);\n",
1723"\n",
1724" // note: this seems to be negative\n",
1725" float DepthCenter = dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord).b;\n",
1726"\n",
1727" // edge detect method\n",
1728"// DepthNeighbors.x = dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord - ScreenTexCoordStep.xy).b;\n",
1729"// DepthNeighbors.y = dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + ScreenTexCoordStep.xy).b;\n",
1730"// DepthNeighbors.z = dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + ScreenTexCoordStep.zw).b;\n",
1731"// DepthNeighbors.w = dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord - ScreenTexCoordStep.zw).b;\n",
1732"// float DepthAverage = dot(DepthNeighbors, vec4(0.25, 0.25, 0.25, 0.25));\n",
1733"// float DepthDelta = abs(dot(DepthNeighbors.xy, vec2(-1.0, 1.0))) + abs(dot(DepthNeighbors.zw, vec2(-1.0, 1.0)));\n",
1734"// color.rgb *= max(0.5, 1.0 - max(0.0, abs(DepthCenter - DepthAverage) - 0.2 * DepthDelta) / (0.01 + 0.2 * DepthDelta));\n",
1735"// color.rgb *= step(abs(DepthCenter - DepthAverage), 0.2 * DepthDelta); \n",
1736"\n",
1737" // shadow method\n",
1738" float DepthScale1 = 4.0 / DepthCenter; // inner ink (shadow on object)\n",
1739"// float DepthScale1 = -4.0 / DepthCenter; // outer ink (shadow around object)\n",
1740"// float DepthScale1 = 0.003;\n",
1741" float DepthScale2 = DepthScale1 * 0.5;\n",
1742"// float DepthScale3 = DepthScale1 / 4.0;\n",
1743" float DepthBias1 = -DepthCenter * DepthScale1;\n",
1744" float DepthBias2 = -DepthCenter * DepthScale2;\n",
1745"// float DepthBias3 = -DepthCenter * DepthScale3;\n",
1746" float DepthShadow = possat(dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2(-1.0, 0.0)).b * DepthScale1 + DepthBias1)\n",
1747" + possat(dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 1.0, 0.0)).b * DepthScale1 + DepthBias1)\n",
1748" + possat(dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 0.0, -1.0)).b * DepthScale1 + DepthBias1)\n",
1749" + possat(dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 0.0, 1.0)).b * DepthScale1 + DepthBias1)\n",
1750" + possat(dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2(-2.0, 0.0)).b * DepthScale2 + DepthBias2)\n",
1751" + possat(dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 2.0, 0.0)).b * DepthScale2 + DepthBias2)\n",
1752" + possat(dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 0.0, -2.0)).b * DepthScale2 + DepthBias2)\n",
1753" + possat(dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 0.0, 2.0)).b * DepthScale2 + DepthBias2)\n",
1754"// + possat(dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2(-3.0, 0.0)).b * DepthScale3 + DepthBias3)\n",
1755"// + possat(dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 3.0, 0.0)).b * DepthScale3 + DepthBias3)\n",
1756"// + possat(dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 0.0, -3.0)).b * DepthScale3 + DepthBias3)\n",
1757"// + possat(dp_texture2D(Texture_ScreenNormalMap, ScreenTexCoord + PixelToScreenTexCoord * vec2( 0.0, 3.0)).b * DepthScale3 + DepthBias3)\n",
1758" - 0.0;\n",
1759" color.rgb *= sat(1.0 - DepthShadow);\n",
1760"// color.r = DepthCenter / -1024.0;\n",
1761"# endif\n",
1762"#endif\n",
1763"\n",
1764"#ifdef USEFOG\n",
1765" color.rgb = FogVertex(color);\n",
1766"#endif\n",
1767"\n",
1768" // 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",
1769"#ifdef USEREFLECTION\n",
1770" vec4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n",
1771" //vec4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(cast_myhalf3(offsetMappedTexture2D(Texture_Normal)) - cast_myhalf3(0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
1772" vec2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW.zw + ScreenCenterRefractReflect.zw;\n",
1773" #ifdef USENORMALMAPSCROLLBLEND\n",
1774"# ifdef USEOFFSETMAPPING\n",
1775" vec3 normal = dp_textureGrad(Texture_Normal, (TexCoord + vec2(0.08, 0.08)*ClientTime*NormalmapScrollBlend.x*0.5)*NormalmapScrollBlend.y, dPdx*NormalmapScrollBlend.y, dPdy*NormalmapScrollBlend.y).rgb - vec3(1.0);\n",
1776"# else\n",
1777" vec3 normal = dp_texture2D(Texture_Normal, (TexCoord + vec2(0.08, 0.08)*ClientTime*NormalmapScrollBlend.x*0.5)*NormalmapScrollBlend.y).rgb - vec3(1.0);\n",
1778"# endif\n",
1779" normal += dp_texture2D(Texture_Normal, (TexCoord + vec2(-0.06, -0.09)*ClientTime*NormalmapScrollBlend.x)*NormalmapScrollBlend.y*0.75).rgb;\n",
1780" vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(cast_myhalf3(normal))).xy * DistortScaleRefractReflect.zw;\n",
1781" #else\n",
1782" vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(cast_myhalf3(offsetMappedTexture2D(Texture_Normal)) - cast_myhalf3(0.5))).xy * DistortScaleRefractReflect.zw;\n",
1783" #endif\n",
1784" // FIXME temporary hack to detect the case that the reflection\n",
1785" // gets blackened at edges due to leaving the area that contains actual\n",
1786" // content.\n",
1787" // Remove this 'ack once we have a better way to stop this thing from\n",
1788" // 'appening.\n",
1789" float f = minonesat(length(dp_texture2D(Texture_Reflection, ScreenTexCoord + vec2(0.01, 0.01)).rgb) / 0.05);\n",
1790" f *= minonesat(length(dp_texture2D(Texture_Reflection, ScreenTexCoord + vec2(0.01, -0.01)).rgb) / 0.05);\n",
1791" f *= minonesat(length(dp_texture2D(Texture_Reflection, ScreenTexCoord + vec2(-0.01, 0.01)).rgb) / 0.05);\n",
1792" f *= minonesat(length(dp_texture2D(Texture_Reflection, ScreenTexCoord + vec2(-0.01, -0.01)).rgb) / 0.05);\n",
1793" ScreenTexCoord = mix(SafeScreenTexCoord, ScreenTexCoord, f);\n",
1794" color.rgb = mix(color.rgb, cast_myhalf3(dp_texture2D(Texture_Reflection, ScreenTexCoord)) * ReflectColor.rgb, ReflectColor.a);\n",
1795"#endif\n",
1796"#ifdef USEOCCLUDE\n",
1797" color.rgb *= clamp(float(visiblepixels) / float(allpixels), 0.0, 1.0);\n",
1798"#endif\n",
1799"\n",
1800" dp_FragColor = vec4(color);\n",
1801"}\n",
1802"#endif // FRAGMENT_SHADER\n",
1803"\n",
1804"#endif // !MODE_DEFERREDLIGHTSOURCE\n",
1805"#endif // !MODE_DEFERREDGEOMETRY\n",
1806"#endif // !MODE_WATER\n",
1807"#endif // !MODE_REFRACTION\n",
1808"#endif // !MODE_BLOOMBLUR\n",
1809"#endif // !MODE_GENERIC\n",
1810"#endif // !MODE_POSTPROCESS\n",
1811"#endif // !MODE_DEPTH_OR_SHADOW\n",