From 99c82aaad14685e2341698797e7686a1fae5322c Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Thu, 6 Jul 2023 19:45:15 +0200 Subject: [PATCH] update opengl shaders --- inc/openglshader.h | 87 +++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 56 deletions(-) diff --git a/inc/openglshader.h b/inc/openglshader.h index f23bfdd..1b23724 100644 --- a/inc/openglshader.h +++ b/inc/openglshader.h @@ -128,12 +128,11 @@ const char PASSTHROUGH_FRAG_SHADER_CORE[] = "}\n"; /* -// Bicubic Catmull-Rom 9 taps (Fast) - ported by Hyllian - 2020 // The following code is licensed under the MIT license: https://gist.github.com/TheRealMJP/bc503b0b87b643d3505d41eab8b332ae // Ported from code: https://gist.github.com/TheRealMJP/c83b8c0f46b63f3a88a5986f4fa982b1 // Samples a texture with Catmull-Rom filtering, using 9 texture fetches instead of 16. // See http://vec3.ca/bicubic-filtering-in-fewer-taps/ for more details -// ATENTION: This code only work using LINEAR filter sampling set on Retroarch! +// Modified to use 5 texture fetches */ const char CATMULL_ROM_FRAG_SHADER[] = @@ -153,8 +152,6 @@ const char CATMULL_ROM_FRAG_SHADER[] = "#define SourceSize vec4(TextureSize, 1.0 / TextureSize)\n" "#define outsize vec4(OutputSize, 1.0 / OutputSize)\n" "\n" - "#define mul(c,d) (d*c)\n" - "\n" "void main()\n" "{\n" " vec2 samplePos = vTexCoord * SourceSize.xy;\n" @@ -166,7 +163,6 @@ const char CATMULL_ROM_FRAG_SHADER[] = " vec2 w1 = 1.0 + f * f * (-2.5 + 1.5 * f);\n" " vec2 w2 = f * (0.5 + f * (2.0 - 1.5 * f));\n" " vec2 w3 = f * f * (-0.5 + 0.5 * f);\n" - " //vec2 w3 = 1.0 - w0 - w1 - w2;\n" "\n" " vec2 w12 = w1 + w2;\n" " vec2 offset12 = w2 / (w1 + w2);\n" @@ -175,34 +171,25 @@ const char CATMULL_ROM_FRAG_SHADER[] = " vec2 texPos3 = texPos1 + 2.;\n" " vec2 texPos12 = texPos1 + offset12;\n" "\n" - " texPos0 *= SourceSize.zw;\n" - " texPos3 *= SourceSize.zw;\n" - " texPos12 *= SourceSize.zw;\n" + " texPos0 /= SourceSize.xy;\n" + " texPos3 /= SourceSize.xy;\n" + " texPos12 /= SourceSize.xy;\n" "\n" - " vec4 c00 = texture(Source, vec2(texPos0.x, texPos0.y));\n" - " vec4 c10 = texture(Source, vec2(texPos12.x, texPos0.y));\n" - " vec4 c20 = texture(Source, vec2(texPos3.x, texPos0.y));\n" + " float wtm = w12.x * w0.y;\n" + " float wml = w0.x * w12.y;\n" + " float wmm = w12.x * w12.y;\n" + " float wmr = w3.x * w12.y;\n" + " float wbm = w12.x * w3.y;\n" "\n" - " vec4 c01 = texture(Source, vec2(texPos0.x, texPos12.y));\n" - " vec4 c11 = texture(Source, vec2(texPos12.x, texPos12.y));\n" - " vec4 c21 = texture(Source, vec2(texPos3.x, texPos12.y));\n" + " vec3 result = vec3(0.0f);\n" "\n" - " vec4 c02 = texture(Source, vec2(texPos0.x, texPos3.y));\n" - " vec4 c12 = texture(Source, vec2(texPos12.x, texPos3.y));\n" - " vec4 c22 = texture(Source, vec2(texPos3.x, texPos3.y));\n" + " result += texture(Source, vec2(texPos12.x, texPos0.y)).rgb * wtm;\n" + " result += texture(Source, vec2(texPos0.x, texPos12.y)).rgb * wml;\n" + " result += texture(Source, vec2(texPos12.x, texPos12.y)).rgb * wmm;\n" + " result += texture(Source, vec2(texPos3.x, texPos12.y)).rgb * wmr;\n" + " result += texture(Source, vec2(texPos12.x, texPos3.y)).rgb * wbm;\n" "\n" - " vec4 c1, c2, c3, wx, wy = vec4(0.,0.,0.,0.);\n" - "\n" - " vec4 dummy = vec4(0.,0.,0.,1.);\n" - "\n" - " wx = vec4(w0.x, w12.x, w3.x, 1.0);\n" - " wy = vec4(w0.y, w12.y, w3.y, 1.0);\n" - "\n" - " c1 = vec4(mul(wx, mat4(c00, c10, c20, dummy)));\n" - " c2 = vec4(mul(wx, mat4(c01, c11, c21, dummy)));\n" - " c3 = vec4(mul(wx, mat4(c02, c12, c22, dummy)));\n" - "\n" - " FragColor = mul(wy, mat4(c1, c2, c3, dummy));\n" + " FragColor = vec4(result * (1. / (wtm + wml + wmm + wmr + wbm)), 1.0);\n" "}\n"; @@ -223,8 +210,6 @@ const char CATMULL_ROM_FRAG_SHADER_CORE[] = "#define SourceSize vec4(TextureSize, 1.0 / TextureSize)\n" "#define outsize vec4(OutputSize, 1.0 / OutputSize)\n" "\n" - "#define mul(c,d) (d*c)\n" - "\n" "void main()\n" "{\n" " vec2 samplePos = vTexCoord * SourceSize.xy;\n" @@ -236,7 +221,6 @@ const char CATMULL_ROM_FRAG_SHADER_CORE[] = " vec2 w1 = 1.0 + f * f * (-2.5 + 1.5 * f);\n" " vec2 w2 = f * (0.5 + f * (2.0 - 1.5 * f));\n" " vec2 w3 = f * f * (-0.5 + 0.5 * f);\n" - " //vec2 w3 = 1.0 - w0 - w1 - w2;\n" "\n" " vec2 w12 = w1 + w2;\n" " vec2 offset12 = w2 / (w1 + w2);\n" @@ -245,34 +229,25 @@ const char CATMULL_ROM_FRAG_SHADER_CORE[] = " vec2 texPos3 = texPos1 + 2.;\n" " vec2 texPos12 = texPos1 + offset12;\n" "\n" - " texPos0 *= SourceSize.zw;\n" - " texPos3 *= SourceSize.zw;\n" - " texPos12 *= SourceSize.zw;\n" + " texPos0 /= SourceSize.xy;\n" + " texPos3 /= SourceSize.xy;\n" + " texPos12 /= SourceSize.xy;\n" "\n" - " vec4 c00 = texture(Source, vec2(texPos0.x, texPos0.y));\n" - " vec4 c10 = texture(Source, vec2(texPos12.x, texPos0.y));\n" - " vec4 c20 = texture(Source, vec2(texPos3.x, texPos0.y));\n" + " float wtm = w12.x * w0.y;\n" + " float wml = w0.x * w12.y;\n" + " float wmm = w12.x * w12.y;\n" + " float wmr = w3.x * w12.y;\n" + " float wbm = w12.x * w3.y;\n" "\n" - " vec4 c01 = texture(Source, vec2(texPos0.x, texPos12.y));\n" - " vec4 c11 = texture(Source, vec2(texPos12.x, texPos12.y));\n" - " vec4 c21 = texture(Source, vec2(texPos3.x, texPos12.y));\n" + " vec3 result = vec3(0.0f);\n" "\n" - " vec4 c02 = texture(Source, vec2(texPos0.x, texPos3.y));\n" - " vec4 c12 = texture(Source, vec2(texPos12.x, texPos3.y));\n" - " vec4 c22 = texture(Source, vec2(texPos3.x, texPos3.y));\n" + " result += texture(Source, vec2(texPos12.x, texPos0.y)).rgb * wtm;\n" + " result += texture(Source, vec2(texPos0.x, texPos12.y)).rgb * wml;\n" + " result += texture(Source, vec2(texPos12.x, texPos12.y)).rgb * wmm;\n" + " result += texture(Source, vec2(texPos3.x, texPos12.y)).rgb * wmr;\n" + " result += texture(Source, vec2(texPos12.x, texPos3.y)).rgb * wbm;\n" "\n" - " vec4 c1, c2, c3, wx, wy = vec4(0.,0.,0.,0.);\n" - "\n" - " vec4 dummy = vec4(0.,0.,0.,1.);\n" - "\n" - " wx = vec4(w0.x, w12.x, w3.x, 1.0);\n" - " wy = vec4(w0.y, w12.y, w3.y, 1.0);\n" - "\n" - " c1 = vec4(mul(wx, mat4(c00, c10, c20, dummy)));\n" - " c2 = vec4(mul(wx, mat4(c01, c11, c21, dummy)));\n" - " c3 = vec4(mul(wx, mat4(c02, c12, c22, dummy)));\n" - "\n" - " FragColor = mul(wy, mat4(c1, c2, c3, dummy));\n" + " FragColor = vec4(result * (1. / (wtm + wml + wmm + wmr + wbm)), 1.0);\n" "}\n";