summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2021-04-04 03:27:46 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2021-04-04 03:41:40 +0100
commite65ff7e1e67e142c314b6e358ec15c2dfd76b175 (patch)
tree993432bd16b9b4cadcaa0c2df1638a829ab40cf5 /src
parent0c2cf7e1bf7ca547655d25aaea30d081101b42be (diff)
evas - gl - optimize dither shader - use integer vecs and go to 2x2
a 2x2 matrix visually here is about as good as 4x4. at least in what i see, but on low end gpu's it can halve the cost. in fact i was watching the gpu on my old i5-4200u drop down to 340-410mhz (no dithering is 320-360mhz). i got to 630-660mhz with the original 4x4 code. the 4x4 is still there ifdefed out. perhaps i can bring it back with a high-quality dither option, but 2x3 i think is good enough.
Diffstat (limited to 'src')
-rw-r--r--src/modules/evas/engines/gl_common/shader/evas_gl_shaders.x31
-rw-r--r--src/modules/evas/engines/gl_common/shader/fragment.glsl32
2 files changed, 41 insertions, 22 deletions
diff --git a/src/modules/evas/engines/gl_common/shader/evas_gl_shaders.x b/src/modules/evas/engines/gl_common/shader/evas_gl_shaders.x
index b534f66c41..411a680e78 100644
--- a/src/modules/evas/engines/gl_common/shader/evas_gl_shaders.x
+++ b/src/modules/evas/engines/gl_common/shader/evas_gl_shaders.x
@@ -99,26 +99,35 @@ static const char fragment_glsl[] =
99 "#endif\n" 99 "#endif\n"
100 "// ----------------------------------------------------------------------------\n" 100 "// ----------------------------------------------------------------------------\n"
101 "#ifdef SHD_DITHER\n" 101 "#ifdef SHD_DITHER\n"
102 "const mat4 dm = mat4(vec4( 0, 8, 2, 10),\n" 102 "#ifdef DM_HIQ\n"
103 " vec4(12, 4, 14, 6),\n" 103 "#define DMMOD 4.0\n"
104 " vec4( 3, 11, 1, 9),\n" 104 "#define DMDIV (16.0*256.0)\n"
105 " vec4(15, 7, 13, 5));\n" 105 "const mat4 dm = mat4(vec4( 0.0/DMDIV, 8.0/DMDIV, 2.0/DMDIV, 10.0/DMDIV),\n"
106 "float dither_closest(vec2 pos, float val)\n" 106 " vec4(12.0/DMDIV, 4.0/DMDIV, 14.0/DMDIV, 6.0/DMDIV),\n"
107 " vec4( 3.0/DMDIV, 11.0/DMDIV, 1.0/DMDIV, 9.0/DMDIV),\n"
108 " vec4(15.0/DMDIV, 7.0/DMDIV, 13.0/DMDIV, 5.0/DMDIV));\n"
109 "#else\n"
110 "#define DMMOD 2.0\n"
111 "#define DMDIV (4.0*256.0)\n"
112 "const mat2 dm = mat2(vec2( 0.0/DMDIV, 2.0/DMDIV),\n"
113 " vec2( 3.0/DMDIV, 1.0/DMDIV));\n"
114 "#endif\n"
115 "float dither_closest(ivec2 pos, float val)\n"
107 "{\n" 116 "{\n"
108 " float limit = dm[int(pos.x)][int(pos.y)] / 16.0;\n" 117 " float limit = dm[pos.x][pos.y];\n"
109 " if (val <= limit) return 0.0;\n" 118 " if (val <= limit) return 0.0;\n"
110 " return 1.0;\n" 119 " return (1.0 / 256.0);\n"
111 "}\n" 120 "}\n"
112 "float dither_8bit(vec2 modpos, float val)\n" 121 "float dither_8bit(ivec2 modpos, float val)\n"
113 "{\n" 122 "{\n"
114 " float val_quant = float(floor(val * 255.0)) / 255.0;\n" 123 " float val_quant = float(floor(val * 255.0)) / 255.0;\n"
115 " float val_delta = (val - val_quant) / (1.0 / 256.0);\n" 124 " float val_delta = val - val_quant;\n"
116 " float val_roundup = dither_closest(modpos, val_delta);\n" 125 " float val_roundup = dither_closest(modpos, val_delta);\n"
117 " return val_quant + (val_roundup * (1.0 / 256.0));\n" 126 " return val_quant + val_roundup;\n"
118 "}\n" 127 "}\n"
119 "vec4 dither(vec4 col, vec2 pos)\n" 128 "vec4 dither(vec4 col, vec2 pos)\n"
120 "{\n" 129 "{\n"
121 " vec2 modpos = vec2(mod(float(pos.x), 4.0), mod(float(pos.y), 4.0));\n" 130 " ivec2 modpos = ivec2(int(mod(pos.x, DMMOD)), int(mod(pos.y, DMMOD)));\n"
122 " return vec4(dither_8bit(modpos, col.r),\n" 131 " return vec4(dither_8bit(modpos, col.r),\n"
123 " dither_8bit(modpos, col.g),\n" 132 " dither_8bit(modpos, col.g),\n"
124 " dither_8bit(modpos, col.b),\n" 133 " dither_8bit(modpos, col.b),\n"
diff --git a/src/modules/evas/engines/gl_common/shader/fragment.glsl b/src/modules/evas/engines/gl_common/shader/fragment.glsl
index b715c8de99..5b1f8c24bc 100644
--- a/src/modules/evas/engines/gl_common/shader/fragment.glsl
+++ b/src/modules/evas/engines/gl_common/shader/fragment.glsl
@@ -98,29 +98,39 @@ uniform float blur_div;
98// ---------------------------------------------------------------------------- 98// ----------------------------------------------------------------------------
99 99
100#ifdef SHD_DITHER 100#ifdef SHD_DITHER
101const mat4 dm = mat4(vec4( 0, 8, 2, 10),
102 vec4(12, 4, 14, 6),
103 vec4( 3, 11, 1, 9),
104 vec4(15, 7, 13, 5));
105 101
106float dither_closest(vec2 pos, float val) 102#ifdef DM_HIQ
103#define DMMOD 4.0
104#define DMDIV (16.0*256.0)
105const mat4 dm = mat4(vec4( 0.0/DMDIV, 8.0/DMDIV, 2.0/DMDIV, 10.0/DMDIV),
106 vec4(12.0/DMDIV, 4.0/DMDIV, 14.0/DMDIV, 6.0/DMDIV),
107 vec4( 3.0/DMDIV, 11.0/DMDIV, 1.0/DMDIV, 9.0/DMDIV),
108 vec4(15.0/DMDIV, 7.0/DMDIV, 13.0/DMDIV, 5.0/DMDIV));
109#else
110#define DMMOD 2.0
111#define DMDIV (4.0*256.0)
112const mat2 dm = mat2(vec2( 0.0/DMDIV, 2.0/DMDIV),
113 vec2( 3.0/DMDIV, 1.0/DMDIV));
114#endif
115
116float dither_closest(ivec2 pos, float val)
107{ 117{
108 float limit = dm[int(pos.x)][int(pos.y)] / 16.0; 118 float limit = dm[pos.x][pos.y];
109 if (val <= limit) return 0.0; 119 if (val <= limit) return 0.0;
110 return 1.0; 120 return (1.0 / 256.0);
111} 121}
112 122
113float dither_8bit(vec2 modpos, float val) 123float dither_8bit(ivec2 modpos, float val)
114{ 124{
115 float val_quant = float(floor(val * 255.0)) / 255.0; 125 float val_quant = float(floor(val * 255.0)) / 255.0;
116 float val_delta = (val - val_quant) / (1.0 / 256.0); 126 float val_delta = val - val_quant;
117 float val_roundup = dither_closest(modpos, val_delta); 127 float val_roundup = dither_closest(modpos, val_delta);
118 return val_quant + (val_roundup * (1.0 / 256.0)); 128 return val_quant + val_roundup;
119} 129}
120 130
121vec4 dither(vec4 col, vec2 pos) 131vec4 dither(vec4 col, vec2 pos)
122{ 132{
123 vec2 modpos = vec2(mod(float(pos.x), 4.0), mod(float(pos.y), 4.0)); 133 ivec2 modpos = ivec2(int(mod(pos.x, DMMOD)), int(mod(pos.y, DMMOD)));
124 return vec4(dither_8bit(modpos, col.r), 134 return vec4(dither_8bit(modpos, col.r),
125 dither_8bit(modpos, col.g), 135 dither_8bit(modpos, col.g),
126 dither_8bit(modpos, col.b), 136 dither_8bit(modpos, col.b),