]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - shader_glsl.h
Stop using bytes >= 128 in format strings. They break on Android.
[xonotic/darkplaces.git] / shader_glsl.h
index 1c6cb906768149fce8126ff71705baf75a5ec494..1f5803c07045bad0eff82940f5c90e9618add50e 100644 (file)
@@ -2,7 +2,7 @@
 "// written by Forest 'LordHavoc' Hale\n",
 "// shadowmapping enhancements by Lee 'eihrul' Salzman\n",
 "\n",
-"#ifdef USESKELETAL\n",
+"#if defined(USESKELETAL) || defined(USEOCCLUDE)\n",
 "#  ifdef GL_ARB_uniform_buffer_object\n",
 "#    extension GL_ARB_uniform_buffer_object : enable\n",
 "#  endif\n",
 "      float minreduct = (1.0 / 128.0);\n",
 "\n",
 "      // directions\n",
-"      vec3 NW = texture2D(Texture_First, TexCoord1 + (vec2(-1.0, -1.0) * PixelSize)).xyz;\n",
-"      vec3 NE = texture2D(Texture_First, TexCoord1 + (vec2(+1.0, -1.0) * PixelSize)).xyz;\n",
-"      vec3 SW = texture2D(Texture_First, TexCoord1 + (vec2(-1.0, +1.0) * PixelSize)).xyz;\n",
-"      vec3 SE = texture2D(Texture_First, TexCoord1 + (vec2(+1.0, +1.0) * PixelSize)).xyz;\n",
-"      vec3 M = texture2D(Texture_First, TexCoord1).xyz;\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",
 "      dir = min(vec2(maxspan, maxspan), max(vec2(-maxspan, -maxspan), dir * rcp)) * PixelSize;\n",
 "\n",
 "      vec3 rA = (1.0/2.0) * (\n",
-"              texture2D(Texture_First, TexCoord1 + dir * (1.0/3.0 - 0.5)).xyz +\n",
-"              texture2D(Texture_First, TexCoord1 + dir * (2.0/3.0 - 0.5)).xyz);\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",
-"              texture2D(Texture_First, TexCoord1 + dir * (0.0/3.0 - 0.5)).xyz +\n",
-"              texture2D(Texture_First, TexCoord1 + dir * (3.0/3.0 - 0.5)).xyz);\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",
 "#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",
 "#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",