From 7baf344b8738c8a03986f8149f4c4f095a70e94e Mon Sep 17 00:00:00 2001 From: uis Date: Wed, 3 Jan 2024 21:39:27 +0300 Subject: [PATCH] Use wider vector for postproc with bloom instead of 2 smaller vectors --- shader_glsl.h | 63 +++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/shader_glsl.h b/shader_glsl.h index 8f205e0b..f9d17e5b 100644 --- a/shader_glsl.h +++ b/shader_glsl.h @@ -214,16 +214,19 @@ "\n", "\n", "#ifdef MODE_POSTPROCESS\n", +"#ifdef USEBLOOM\n", +"dp_varying mediump vec4 TexCoord1;\n", +"#else\n", "dp_varying mediump vec2 TexCoord1;\n", -"dp_varying mediump vec2 TexCoord2;\n", +"#endif\n", "\n", "#ifdef VERTEX_SHADER\n", "void main(void)\n", "{\n", " gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n", -" TexCoord1 = Attrib_TexCoord0.xy;\n", +" TexCoord1.xy = Attrib_TexCoord0.xy;\n", "#ifdef USEBLOOM\n", -" TexCoord2 = Attrib_TexCoord4.xy;\n", +" TexCoord1.zw = Attrib_TexCoord4.xy;\n", "#endif\n", "}\n", "#endif\n", @@ -261,11 +264,11 @@ " 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", +" vec3 NW = dp_texture2D(Texture_First, TexCoord1.xy + (vec2(-1.0, -1.0) * PixelSize)).xyz;\n", +" vec3 NE = dp_texture2D(Texture_First, TexCoord1.xy + (vec2(+1.0, -1.0) * PixelSize)).xyz;\n", +" vec3 SW = dp_texture2D(Texture_First, TexCoord1.xy + (vec2(-1.0, +1.0) * PixelSize)).xyz;\n", +" vec3 SE = dp_texture2D(Texture_First, TexCoord1.xy + (vec2(+1.0, +1.0) * PixelSize)).xyz;\n", +" vec3 M = dp_texture2D(Texture_First, TexCoord1.xy).xyz;\n", "\n", " // luminance directions\n", " vec3 luma = vec3(0.299, 0.587, 0.114);\n", @@ -285,11 +288,11 @@ " 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", +" dp_texture2D(Texture_First, TexCoord1.xy + dir * (1.0/3.0 - 0.5)).xyz +\n", +" dp_texture2D(Texture_First, TexCoord1.xy + 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", +" dp_texture2D(Texture_First, TexCoord1.xy + dir * (0.0/3.0 - 0.5)).xyz +\n", +" dp_texture2D(Texture_First, TexCoord1.xy + 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", @@ -314,18 +317,18 @@ " // vec2 ts = textureSize(Texture_First, 0);\n", " // vec2 px = vec2(1/ts.x, 1/ts.y);\n", " vec2 px = PixelSize;\n", -" vec3 x1 = dp_texture2D(Texture_First, TexCoord1 + vec2(-px.x, px.y)).rgb;\n", -" vec3 x2 = dp_texture2D(Texture_First, TexCoord1 + vec2(-px.x, 0.0)).rgb;\n", -" vec3 x3 = dp_texture2D(Texture_First, TexCoord1 + vec2(-px.x,-px.y)).rgb;\n", -" vec3 x4 = dp_texture2D(Texture_First, TexCoord1 + vec2( px.x, px.y)).rgb;\n", -" vec3 x5 = dp_texture2D(Texture_First, TexCoord1 + vec2( px.x, 0.0)).rgb;\n", -" vec3 x6 = dp_texture2D(Texture_First, TexCoord1 + vec2( px.x,-px.y)).rgb;\n", -" vec3 y1 = dp_texture2D(Texture_First, TexCoord1 + vec2( px.x,-px.y)).rgb;\n", -" vec3 y2 = dp_texture2D(Texture_First, TexCoord1 + vec2( 0.0,-px.y)).rgb;\n", -" vec3 y3 = dp_texture2D(Texture_First, TexCoord1 + vec2(-px.x,-px.y)).rgb;\n", -" vec3 y4 = dp_texture2D(Texture_First, TexCoord1 + vec2( px.x, px.y)).rgb;\n", -" vec3 y5 = dp_texture2D(Texture_First, TexCoord1 + vec2( 0.0, px.y)).rgb;\n", -" vec3 y6 = dp_texture2D(Texture_First, TexCoord1 + vec2(-px.x, px.y)).rgb;\n", +" vec3 x1 = dp_texture2D(Texture_First, TexCoord1.xy + vec2(-px.x, px.y)).rgb;\n", +" vec3 x2 = dp_texture2D(Texture_First, TexCoord1.xy + vec2(-px.x, 0.0)).rgb;\n", +" vec3 x3 = dp_texture2D(Texture_First, TexCoord1.xy + vec2(-px.x,-px.y)).rgb;\n", +" vec3 x4 = dp_texture2D(Texture_First, TexCoord1.xy + vec2( px.x, px.y)).rgb;\n", +" vec3 x5 = dp_texture2D(Texture_First, TexCoord1.xy + vec2( px.x, 0.0)).rgb;\n", +" vec3 x6 = dp_texture2D(Texture_First, TexCoord1.xy + vec2( px.x,-px.y)).rgb;\n", +" vec3 y1 = dp_texture2D(Texture_First, TexCoord1.xy + vec2( px.x,-px.y)).rgb;\n", +" vec3 y2 = dp_texture2D(Texture_First, TexCoord1.xy + vec2( 0.0,-px.y)).rgb;\n", +" vec3 y3 = dp_texture2D(Texture_First, TexCoord1.xy + vec2(-px.x,-px.y)).rgb;\n", +" vec3 y4 = dp_texture2D(Texture_First, TexCoord1.xy + vec2( px.x, px.y)).rgb;\n", +" vec3 y5 = dp_texture2D(Texture_First, TexCoord1.xy + vec2( 0.0, px.y)).rgb;\n", +" vec3 y6 = dp_texture2D(Texture_First, TexCoord1.xy + vec2(-px.x, px.y)).rgb;\n", " float px1 = -1.0 * dot(vec3(0.3, 0.59, 0.11), x1);\n", " float px2 = -2.0 * dot(vec3(0.3, 0.59, 0.11), x2);\n", " float px3 = -1.0 * dot(vec3(0.3, 0.59, 0.11), x3);\n", @@ -339,18 +342,18 @@ " float py5 = 2.0 * dot(vec3(0.3, 0.59, 0.11), y5);\n", " float py6 = 1.0 * dot(vec3(0.3, 0.59, 0.11), y6);\n", " sobel = 0.25 * abs(px1 + px2 + px3 + px4 + px5 + px6) + 0.25 * abs(py1 + py2 + py3 + py4 + py5 + py6);\n", -" dp_FragColor += dp_texture2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*vec2(-0.987688, -0.156434)) * UserVec1.y;\n", -" dp_FragColor += dp_texture2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*vec2(-0.156434, -0.891007)) * UserVec1.y;\n", -" dp_FragColor += dp_texture2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*vec2( 0.891007, -0.453990)) * UserVec1.y;\n", -" dp_FragColor += dp_texture2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*vec2( 0.707107, 0.707107)) * UserVec1.y;\n", -" dp_FragColor += dp_texture2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*vec2(-0.453990, 0.891007)) * UserVec1.y;\n", +" dp_FragColor += dp_texture2D(Texture_First, TexCoord1.xy + PixelSize*UserVec1.x*vec2(-0.987688, -0.156434)) * UserVec1.y;\n", +" dp_FragColor += dp_texture2D(Texture_First, TexCoord1.xy + PixelSize*UserVec1.x*vec2(-0.156434, -0.891007)) * UserVec1.y;\n", +" dp_FragColor += dp_texture2D(Texture_First, TexCoord1.xy + PixelSize*UserVec1.x*vec2( 0.891007, -0.453990)) * UserVec1.y;\n", +" dp_FragColor += dp_texture2D(Texture_First, TexCoord1.xy + PixelSize*UserVec1.x*vec2( 0.707107, 0.707107)) * UserVec1.y;\n", +" dp_FragColor += dp_texture2D(Texture_First, TexCoord1.xy + PixelSize*UserVec1.x*vec2(-0.453990, 0.891007)) * UserVec1.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", +" dp_FragColor += max(vec4(0,0,0,0), dp_texture2D(Texture_Second, TexCoord1.zw) - BloomColorSubtract);\n", "#endif\n", "\n", "#ifdef USEVIEWTINT\n", -- 2.39.2