From: Mario Date: Tue, 9 Jun 2020 17:48:05 +0000 (+1000) Subject: Add GLSL implementation of texture lookup tables (LUT), ported from Wrath X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=ac6cc772c0e06bdd434fab030c96c700f44f6070;p=xonotic%2Fdarkplaces.git Add GLSL implementation of texture lookup tables (LUT), ported from Wrath --- diff --git a/shader_glsl.h b/shader_glsl.h index fff9af5f..ed74055a 100644 --- a/shader_glsl.h +++ b/shader_glsl.h @@ -249,7 +249,7 @@ "// uniform mediump vec4 UserVec4;\n", "uniform mediump float ColorFringe;\n", "// uniform highp float ClientTime;\n", -"// uniform sampler2D Texture_LUT;\n", +"uniform sampler2D Texture_LUT;\n", "uniform mediump vec2 PixelSize;\n", "\n", "#ifdef USEFXAA\n", @@ -299,6 +299,35 @@ "}\n", "#endif\n", "\n", +"#ifdef USEPOSTPROCESSING\n", +"// https://github.com/mattdesl/glsl-lut\n", +"vec4 sampleLUT(sampler2D lookupTable, vec3 textureColor) {\n", +" mediump float blueColor = textureColor.b * 63.0;\n", +"\n", +" mediump vec2 quad1;\n", +" quad1.y = floor(floor(blueColor) / 8.0);\n", +" quad1.x = floor(blueColor) - (quad1.y * 8.0);\n", +"\n", +" mediump vec2 quad2;\n", +" quad2.y = floor(ceil(blueColor) / 8.0);\n", +" quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n", +"\n", +" highp vec2 texPos1;\n", +" texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n", +" texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g);\n", +"\n", +" highp vec2 texPos2;\n", +" texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n", +" texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g);\n", +"\n", +" lowp vec4 newColor1 = texture2D(lookupTable, texPos1);\n", +" lowp vec4 newColor2 = texture2D(lookupTable, texPos2);\n", +"\n", +" lowp vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n", +" return newColor;\n", +"}\n", +"#endif\n", +"\n", "void main(void)\n", "{\n", " float fringe = ColorFringe;//.0033f;\n", @@ -312,6 +341,13 @@ "#endif\n", "\n", "#ifdef USEPOSTPROCESSING\n", +" // color grading using LUTs\n", +" vec4 oldColor = dp_texture2D(Texture_First, TexCoord1);\n", +" dp_FragColor.rgb = sampleLUT(Texture_LUT, oldColor.rgb).rgb;\n", +" dp_FragColor.a = oldColor.a;\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",