"// written by Forest 'LordHavoc' Hale\n",
"// shadowmapping enhancements by Lee 'eihrul' Salzman\n",
"\n",
+"#if defined(USESKELETAL) || defined(USEOCCLUDE)\n",
+"# ifdef GL_ARB_uniform_buffer_object\n",
+"# extension GL_ARB_uniform_buffer_object : enable\n",
+"# endif\n",
+"#endif\n",
+"\n",
+"#ifdef USESHADOWMAP2D\n",
+"# ifdef GL_EXT_gpu_shader4\n",
+"# extension GL_EXT_gpu_shader4 : enable\n",
+"# endif\n",
+"# ifdef GL_ARB_texture_gather\n",
+"# extension GL_ARB_texture_gather : enable\n",
+"# else\n",
+"# ifdef GL_AMD_texture_texture4\n",
+"# extension GL_AMD_texture_texture4 : enable\n",
+"# endif\n",
+"# endif\n",
+"#endif\n",
+"\n",
"#ifdef USECELSHADING\n",
"# define SHADEDIFFUSE myhalf diffuse = cast_myhalf(min(max(float(dot(surfacenormal, lightnormal)) * 2.0, 0.0), 1.0));\n",
"# ifdef USEEXACTSPECULARMATH\n",
"# endif\n",
"#endif\n",
"\n",
-"#ifdef GLSL130\n",
+"#if defined(GLSL130) || defined(GLSL140)\n",
"precision highp float;\n",
"# ifdef VERTEX_SHADER\n",
"# define dp_varying out\n",
"dp_attribute vec4 Attrib_TexCoord4; // lightmap texcoords\n",
"#ifdef USESKELETAL\n",
"//uniform mat4 Skeletal_Transform[128];\n",
-"uniform vec4 Skeletal_Transform12[768];\n",
+"// this is used with glBindBufferRange to bind a uniform block to the name\n",
+"// Skeletal_Transform12_UniformBlock, the Skeletal_Transform12 variable is\n",
+"// directly accessible without a namespace.\n",
+"// explanation: http://www.opengl.org/wiki/Interface_Block_%28GLSL%29#Syntax\n",
+"uniform Skeletal_Transform12_UniformBlock\n",
+"{\n",
+" vec4 Skeletal_Transform12[768];\n",
+"};\n",
"dp_attribute vec4 Attrib_SkeletalIndex;\n",
"dp_attribute vec4 Attrib_SkeletalWeight;\n",
"#endif\n",
"# define USEEYEVECTOR\n",
"#endif\n",
"\n",
-"#ifdef USESHADOWMAP2D\n",
-"# ifdef GL_EXT_gpu_shader4\n",
-"# extension GL_EXT_gpu_shader4 : enable\n",
-"# endif\n",
-"# ifdef GL_ARB_texture_gather\n",
-"# extension GL_ARB_texture_gather : enable\n",
-"# else\n",
-"# ifdef GL_AMD_texture_texture4\n",
-"# extension GL_AMD_texture_texture4 : enable\n",
-"# endif\n",
-"# endif\n",
-"#endif\n",
-"\n",
-"//#ifdef USESHADOWSAMPLER\n",
-"//# extension GL_ARB_shadow : enable\n",
-"//#endif\n",
-"\n",
"//#ifdef __GLSL_CG_DATA_TYPES\n",
"//# define myhalf half\n",
"//# define myhalf2 half2\n",
"// uniform mediump vec4 UserVec4;\n",
"// uniform highp float ClientTime;\n",
"uniform mediump vec2 PixelSize;\n",
+"\n",
+"#ifdef USEFXAA\n",
+"// graphitemaster: based off the white paper by Timothy Lottes\n",
+"// http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf\n",
+"vec4 fxaa(vec4 inColor, float maxspan)\n",
+"{\n",
+" vec4 ret = inColor; // preserve old\n",
+" float mulreduct = 1.0/maxspan;\n",
+" float minreduct = (1.0 / 128.0);\n",
+"\n",
+" // directions\n",
+" vec3 NW = dp_texture2D(Texture_First, TexCoord1 + (vec2(-1.0, -1.0) * PixelSize)).xyz;\n",
+" vec3 NE = dp_texture2D(Texture_First, TexCoord1 + (vec2(+1.0, -1.0) * PixelSize)).xyz;\n",
+" vec3 SW = dp_texture2D(Texture_First, TexCoord1 + (vec2(-1.0, +1.0) * PixelSize)).xyz;\n",
+" vec3 SE = dp_texture2D(Texture_First, TexCoord1 + (vec2(+1.0, +1.0) * PixelSize)).xyz;\n",
+" vec3 M = dp_texture2D(Texture_First, TexCoord1).xyz;\n",
+"\n",
+" // luminance directions\n",
+" vec3 luma = vec3(0.299, 0.587, 0.114);\n",
+" float lNW = dot(NW, luma);\n",
+" float lNE = dot(NE, luma);\n",
+" float lSW = dot(SW, luma);\n",
+" float lSE = dot(SE, luma);\n",
+" float lM = dot(M, luma);\n",
+" float lMin = min(lM, min(min(lNW, lNE), min(lSW, lSE)));\n",
+" float lMax = max(lM, max(max(lNW, lNE), max(lSW, lSE)));\n",
+"\n",
+" // direction and reciprocal\n",
+" vec2 dir = vec2(-((lNW + lNE) - (lSW + lSE)), ((lNW + lSW) - (lNE + lSE)));\n",
+" float rcp = 1.0/(min(abs(dir.x), abs(dir.y)) + max((lNW + lNE + lSW + lSE) * (0.25 * mulreduct), minreduct));\n",
+"\n",
+" // span\n",
+" dir = min(vec2(maxspan, maxspan), max(vec2(-maxspan, -maxspan), dir * rcp)) * PixelSize;\n",
+"\n",
+" vec3 rA = (1.0/2.0) * (\n",
+" dp_texture2D(Texture_First, TexCoord1 + dir * (1.0/3.0 - 0.5)).xyz +\n",
+" dp_texture2D(Texture_First, TexCoord1 + dir * (2.0/3.0 - 0.5)).xyz);\n",
+" vec3 rB = rA * (1.0/2.0) + (1.0/4.0) * (\n",
+" dp_texture2D(Texture_First, TexCoord1 + dir * (0.0/3.0 - 0.5)).xyz +\n",
+" dp_texture2D(Texture_First, TexCoord1 + dir * (3.0/3.0 - 0.5)).xyz);\n",
+" float lB = dot(rB, luma);\n",
+"\n",
+" ret.xyz = ((lB < lMin) || (lB > lMax)) ? rA : rB;\n",
+" ret.a = 1.0;\n",
+" return ret;\n",
+"}\n",
+"#endif\n",
+"\n",
"void main(void)\n",
"{\n",
" dp_FragColor = dp_texture2D(Texture_First, TexCoord1);\n",
-"#ifdef USEBLOOM\n",
-" dp_FragColor += max(vec4(0,0,0,0), dp_texture2D(Texture_Second, TexCoord2) - BloomColorSubtract);\n",
-"#endif\n",
-"#ifdef USEVIEWTINT\n",
-" dp_FragColor = mix(dp_FragColor, ViewTintColor, ViewTintColor.a);\n",
+"\n",
+"#ifdef USEFXAA\n",
+" dp_FragColor = fxaa(dp_FragColor, 8.0); // 8.0 can be changed for larger span\n",
"#endif\n",
"\n",
"#ifdef USEPOSTPROCESSING\n",
"// do r_glsl_dumpshader, edit glsl/default.glsl, and replace this by your own postprocessing if you want\n",
"// 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",
+"#if defined(USERVEC1) || defined(USERVEC2)\n",
" float sobel = 1.0;\n",
" // vec2 ts = textureSize(Texture_First, 0);\n",
" // vec2 px = vec2(1/ts.x, 1/ts.y);\n",
" dp_FragColor /= (1.0 + 5.0 * UserVec1.y);\n",
" dp_FragColor.rgb = dp_FragColor.rgb * (1.0 + UserVec2.x) + vec3(max(0.0, sobel - UserVec2.z))*UserVec2.y;\n",
"#endif\n",
+"#endif\n",
+"\n",
+"#ifdef USEBLOOM\n",
+" dp_FragColor += max(vec4(0,0,0,0), dp_texture2D(Texture_Second, TexCoord2) - BloomColorSubtract);\n",
+"#endif\n",
+"\n",
+"#ifdef USEVIEWTINT\n",
+" dp_FragColor = mix(dp_FragColor, ViewTintColor, ViewTintColor.a);\n",
+"#endif\n",
"\n",
"#ifdef USESATURATION\n",
" //apply saturation BEFORE gamma ramps, so v_glslgamma value does not matter\n",
"#ifdef USENORMALMAPSCROLLBLEND\n",
"uniform highp vec2 NormalmapScrollBlend;\n",
"#endif\n",
+"#ifdef USEOCCLUDE\n",
+"uniform occludeQuery {\n",
+" uint visiblepixels;\n",
+" uint allpixels;\n",
+"};\n",
+"#endif\n",
"void main(void)\n",
"{\n",
"#ifdef USEOFFSETMAPPING\n",
" ScreenTexCoord = mix(SafeScreenTexCoord, ScreenTexCoord, f);\n",
" color.rgb = mix(color.rgb, cast_myhalf3(dp_texture2D(Texture_Reflection, ScreenTexCoord)) * ReflectColor.rgb, ReflectColor.a);\n",
"#endif\n",
+"#ifdef USEOCCLUDE\n",
+" color.rgb *= clamp(float(visiblepixels) / float(allpixels), 0.0, 1.0);\n",
+"#endif\n",
"\n",
" dp_FragColor = vec4(color);\n",
"}\n",