summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorHermet Park <chuneon.park@samsung.com>2020-11-30 11:51:14 +0900
committerHermet Park <chuneon.park@samsung.com>2020-11-30 11:51:14 +0900
commitadcce602e4b9371f82754f7a2e785f3938f2a545 (patch)
treee801ef2d97ed4889c643585669185610474cf36f /src/modules
parentf9e7eff759aab07f661c95017a018849e2010979 (diff)
parentb59b60502122b505d20e91ed4dbddcee3abc9ce5 (diff)
downloadefl-adcce602e4b9371f82754f7a2e785f3938f2a545.tar.gz
Merge branch 'master' into devs/hermet/lottie
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_shader.c8
-rw-r--r--src/modules/evas/engines/gl_common/shader/evas_gl_shaders.x55
-rw-r--r--src/modules/evas/engines/gl_common/shader/fragment.glsl57
-rwxr-xr-xsrc/modules/evas/engines/gl_common/shader/gen_shaders.sh2
4 files changed, 113 insertions, 9 deletions
diff --git a/src/modules/evas/engines/gl_common/evas_gl_shader.c b/src/modules/evas/engines/gl_common/evas_gl_shader.c
index 99b104f651..2f1388056d 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_shader.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_shader.c
@@ -13,9 +13,9 @@
#define I(p) ((int)(intptr_t)p)
#ifdef WORDS_BIGENDIAN
-# define BASEFLAG SHADER_FLAG_BIGENDIAN
+# define BASEFLAG SHADER_FLAG_DITHER | SHADER_FLAG_BIGENDIAN
#else
-# define BASEFLAG 0
+# define BASEFLAG SHADER_FLAG_DITHER
#endif
typedef enum {
@@ -47,8 +47,9 @@ typedef enum {
SHADER_FLAG_FILTER_ALPHA_ONLY = (1 << 25),
SHADER_FLAG_FILTER_GRAYSCALE = (1 << 26),
SHADER_FLAG_FILTER_INVERSE_COLOR = (1 << 27),
+ SHADER_FLAG_DITHER = (1 << 28),
} Shader_Flag;
-#define SHADER_FLAG_COUNT 28
+#define SHADER_FLAG_COUNT 29
static const char *_shader_flags[SHADER_FLAG_COUNT] = {
"TEX",
@@ -79,6 +80,7 @@ static const char *_shader_flags[SHADER_FLAG_COUNT] = {
"ALPHA_ONLY",
"FILTER_GRAYSCALE",
"FILTER_INVERSE_COLOR",
+ "DITHER",
};
static Eina_Bool compiler_released = EINA_FALSE;
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 d244b37f08..b534f66c41 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
@@ -98,6 +98,33 @@ static const char fragment_glsl[] =
"uniform float blur_div;\n"
"#endif\n"
"// ----------------------------------------------------------------------------\n"
+ "#ifdef SHD_DITHER\n"
+ "const mat4 dm = mat4(vec4( 0, 8, 2, 10),\n"
+ " vec4(12, 4, 14, 6),\n"
+ " vec4( 3, 11, 1, 9),\n"
+ " vec4(15, 7, 13, 5));\n"
+ "float dither_closest(vec2 pos, float val)\n"
+ "{\n"
+ " float limit = dm[int(pos.x)][int(pos.y)] / 16.0;\n"
+ " if (val <= limit) return 0.0;\n"
+ " return 1.0;\n"
+ "}\n"
+ "float dither_8bit(vec2 modpos, float val)\n"
+ "{\n"
+ " float val_quant = float(floor(val * 255.0)) / 255.0;\n"
+ " float val_delta = (val - val_quant) / (1.0 / 256.0);\n"
+ " float val_roundup = dither_closest(modpos, val_delta);\n"
+ " return val_quant + (val_roundup * (1.0 / 256.0));\n"
+ "}\n"
+ "vec4 dither(vec4 col, vec2 pos)\n"
+ "{\n"
+ " vec2 modpos = vec2(mod(float(pos.x), 4.0), mod(float(pos.y), 4.0));\n"
+ " return vec4(dither_8bit(modpos, col.r),\n"
+ " dither_8bit(modpos, col.g),\n"
+ " dither_8bit(modpos, col.b),\n"
+ " dither_8bit(modpos, col.a));\n"
+ "}\n"
+ "#endif\n"
"#ifndef SHD_FILTER_BLUR\n"
"void main()\n"
"{\n"
@@ -220,10 +247,13 @@ static const char fragment_glsl[] =
" c.b = c.r;\n"
"#endif\n"
"#ifdef SHD_FILTER_INVERSE_COLOR\n"
- " c.rgb = c.a - c.rgb;\n"
+ " c.rgb = c.a - c.rgba;\n"
"#endif\n"
"#ifndef SHD_FILTER_BLUR\n"
" gl_FragColor =\n"
+ "#ifdef SHD_DITHER\n"
+ " dither(\n"
+ "#endif\n"
" c\n"
"#ifndef SHD_NOMUL\n"
" * col\n"
@@ -234,6 +264,9 @@ static const char fragment_glsl[] =
"#ifdef SHD_FILTER_DISPLACE\n"
" * fa\n"
"#endif\n"
+ "#ifdef SHD_DITHER\n"
+ " , gl_FragCoord.xy)\n"
+ "#endif\n"
" ;\n"
"}\n"
"#else // SHD_FILTER_BLUR\n"
@@ -278,9 +311,25 @@ static const char fragment_glsl[] =
" acc += (px1 + px2) * weight;\n"
" }\n"
"#ifndef SHD_NOMUL\n"
- " gl_FragColor = (acc / blur_div) * col;\n"
+ " gl_FragColor =\n"
+ "#ifdef SHD_DITHER\n"
+ " dither(\n"
+ "#endif\n"
+ " (acc / blur_div) * col, gl_FragCoord.xy\n"
+ "#ifdef SHD_DITHER\n"
+ " )\n"
+ "#endif\n"
+ " ;\n"
"#else\n"
- " gl_FragColor = (acc / blur_div);\n"
+ " gl_FragColor =\n"
+ "#ifdef SHD_DITHER\n"
+ " dither(\n"
+ "#endif\n"
+ " (acc / blur_div), gl_FragCoord.xy\n"
+ "#ifdef SHD_DITHER\n"
+ " )\n"
+ "#endif\n"
+ " ;\n"
"#endif\n"
"}\n"
"#endif // SHD_FILTER_BLUR\n";
diff --git a/src/modules/evas/engines/gl_common/shader/fragment.glsl b/src/modules/evas/engines/gl_common/shader/fragment.glsl
index 09947968e9..b715c8de99 100644
--- a/src/modules/evas/engines/gl_common/shader/fragment.glsl
+++ b/src/modules/evas/engines/gl_common/shader/fragment.glsl
@@ -97,6 +97,37 @@ uniform float blur_div;
// ----------------------------------------------------------------------------
+#ifdef SHD_DITHER
+const mat4 dm = mat4(vec4( 0, 8, 2, 10),
+ vec4(12, 4, 14, 6),
+ vec4( 3, 11, 1, 9),
+ vec4(15, 7, 13, 5));
+
+float dither_closest(vec2 pos, float val)
+{
+ float limit = dm[int(pos.x)][int(pos.y)] / 16.0;
+ if (val <= limit) return 0.0;
+ return 1.0;
+}
+
+float dither_8bit(vec2 modpos, float val)
+{
+ float val_quant = float(floor(val * 255.0)) / 255.0;
+ float val_delta = (val - val_quant) / (1.0 / 256.0);
+ float val_roundup = dither_closest(modpos, val_delta);
+ return val_quant + (val_roundup * (1.0 / 256.0));
+}
+
+vec4 dither(vec4 col, vec2 pos)
+{
+ vec2 modpos = vec2(mod(float(pos.x), 4.0), mod(float(pos.y), 4.0));
+ return vec4(dither_8bit(modpos, col.r),
+ dither_8bit(modpos, col.g),
+ dither_8bit(modpos, col.b),
+ dither_8bit(modpos, col.a));
+}
+#endif
+
#ifndef SHD_FILTER_BLUR
void main()
{
@@ -243,6 +274,9 @@ vec4 fetch_pixel(float ox, float oy)
#ifndef SHD_FILTER_BLUR
gl_FragColor =
+#ifdef SHD_DITHER
+ dither(
+#endif
c
#ifndef SHD_NOMUL
* col
@@ -253,6 +287,9 @@ vec4 fetch_pixel(float ox, float oy)
#ifdef SHD_FILTER_DISPLACE
* fa
#endif
+#ifdef SHD_DITHER
+ , gl_FragCoord.xy)
+#endif
;
}
@@ -312,9 +349,25 @@ void main()
}
#ifndef SHD_NOMUL
- gl_FragColor = (acc / blur_div) * col;
+ gl_FragColor =
+#ifdef SHD_DITHER
+ dither(
+#endif
+ (acc / blur_div) * col, gl_FragCoord.xy
+#ifdef SHD_DITHER
+ )
+#endif
+ ;
#else
- gl_FragColor = (acc / blur_div);
+ gl_FragColor =
+#ifdef SHD_DITHER
+ dither(
+#endif
+ (acc / blur_div), gl_FragCoord.xy
+#ifdef SHD_DITHER
+ )
+#endif
+ ;
#endif
}
diff --git a/src/modules/evas/engines/gl_common/shader/gen_shaders.sh b/src/modules/evas/engines/gl_common/shader/gen_shaders.sh
index 7c2fec1e47..c477ee4dbe 100755
--- a/src/modules/evas/engines/gl_common/shader/gen_shaders.sh
+++ b/src/modules/evas/engines/gl_common/shader/gen_shaders.sh
@@ -3,7 +3,7 @@
# This script will generate a C file containing all the shaders used by Evas
DIR=`dirname $0`
-cd $DIR/../../../../../
+#cd $DIR/../../../../../
OUTPUT="$DIR/evas_gl_shaders.x"