summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2016-03-17 16:30:24 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2016-03-17 16:30:24 +0900
commitaa9a0b2bedb7b29fb0df5283d4bdef68006ee3ab (patch)
tree2b9c43194cd598529d06e603bbd07008b2558d9f
parent0ac87d6a917419f7b5b361235c8f33b310021201 (diff)
Evas GL shaders: Add random noise in the fragment shaderdevs/jpeg/dithering
This small noise, added to the fragment shader's output color, makes smooth up-scaling of gradient images look very good. Gradient images that are zoomed in a lot show some banding or blocks, that are the dithering pixels (good for the original size, terrible when upscaled). The simplest solution is to add noise, not even using a proper dithering pattern. This patch adds noise everytime there is a texture, without any smart logic. Still looks beautiful.
-rw-r--r--src/modules/evas/engines/gl_common/shader/evas_gl_shaders.x18
-rw-r--r--src/modules/evas/engines/gl_common/shader/fragment.glsl21
2 files changed, 38 insertions, 1 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 558531a50b..dec8aa93bc 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
@@ -26,9 +26,11 @@ static const char fragment_glsl[] =
26 "#ifdef SHD_EXTERNAL\n" 26 "#ifdef SHD_EXTERNAL\n"
27 "uniform SAMPLER_EXTERNAL_OES tex;\n" 27 "uniform SAMPLER_EXTERNAL_OES tex;\n"
28 "varying vec2 tex_c;\n" 28 "varying vec2 tex_c;\n"
29 "#define ADD_NOISE 1\n"
29 "#elif defined(SHD_TEX)\n" 30 "#elif defined(SHD_TEX)\n"
30 "uniform sampler2D tex;\n" 31 "uniform sampler2D tex;\n"
31 "varying vec2 tex_c;\n" 32 "varying vec2 tex_c;\n"
33 "#define ADD_NOISE 1\n"
32 "#endif\n" 34 "#endif\n"
33 "#if defined(SHD_NV12) || defined(SHD_YUY2)\n" 35 "#if defined(SHD_NV12) || defined(SHD_YUY2)\n"
34 "uniform sampler2D texuv;\n" 36 "uniform sampler2D texuv;\n"
@@ -80,6 +82,14 @@ static const char fragment_glsl[] =
80 "# endif\n" 82 "# endif\n"
81 "# endif\n" 83 "# endif\n"
82 "#endif\n" 84 "#endif\n"
85 "#ifdef ADD_NOISE\n"
86 "float rand(vec2 co)\n"
87 "{\n"
88 " /* Magic 'random' number in range [0..1]. 'co' should be random coordinate.\n"
89 " * Distribution is not great. Falls apart with lowp float. */\n"
90 " return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453) - 0.5;\n"
91 "}\n"
92 "#endif\n"
83 "void main()\n" 93 "void main()\n"
84 "{\n" 94 "{\n"
85 " vec4 c;\n" 95 " vec4 c;\n"
@@ -130,6 +140,11 @@ static const char fragment_glsl[] =
130 "#else\n" 140 "#else\n"
131 " c = vec4(1, 1, 1, 1);\n" 141 " c = vec4(1, 1, 1, 1);\n"
132 "#endif\n" 142 "#endif\n"
143 "#ifdef ADD_NOISE\n"
144 " vec4 noise = vec4(rand(tex_c) / 256.0, rand(tex_c + vec2(1, 1)) / 256.0, rand(tex_c + vec2(2, 2)) / 256.0, 0);\n"
145 " noise.a = max(noise.r, noise.g);\n"
146 " noise.a = max(noise.a, noise.b);\n"
147 "#endif\n"
133 "#ifdef SHD_MASK\n" 148 "#ifdef SHD_MASK\n"
134 " float ma;\n" 149 " float ma;\n"
135 "# if defined(SHD_MASKSAM12) || defined(SHD_MASKSAM21)\n" 150 "# if defined(SHD_MASKSAM12) || defined(SHD_MASKSAM21)\n"
@@ -160,6 +175,9 @@ static const char fragment_glsl[] =
160 "#ifdef SHD_TEXA\n" 175 "#ifdef SHD_TEXA\n"
161 " * texture2D(texa, tex_a).r\n" 176 " * texture2D(texa, tex_a).r\n"
162 "#endif\n" 177 "#endif\n"
178 "#ifdef ADD_NOISE\n"
179 " + noise\n"
180 "#endif\n"
163 " ;\n" 181 " ;\n"
164 "}\n"; 182 "}\n";
165 183
diff --git a/src/modules/evas/engines/gl_common/shader/fragment.glsl b/src/modules/evas/engines/gl_common/shader/fragment.glsl
index b534961300..8436298bfe 100644
--- a/src/modules/evas/engines/gl_common/shader/fragment.glsl
+++ b/src/modules/evas/engines/gl_common/shader/fragment.glsl
@@ -13,9 +13,11 @@ varying vec4 col;
13#ifdef SHD_EXTERNAL 13#ifdef SHD_EXTERNAL
14uniform SAMPLER_EXTERNAL_OES tex; 14uniform SAMPLER_EXTERNAL_OES tex;
15varying vec2 tex_c; 15varying vec2 tex_c;
16#define ADD_NOISE 1
16#elif defined(SHD_TEX) 17#elif defined(SHD_TEX)
17uniform sampler2D tex; 18uniform sampler2D tex;
18varying vec2 tex_c; 19varying vec2 tex_c;
20#define ADD_NOISE 1
19#endif 21#endif
20 22
21#if defined(SHD_NV12) || defined(SHD_YUY2) 23#if defined(SHD_NV12) || defined(SHD_YUY2)
@@ -74,6 +76,15 @@ varying vec2 masktex_s[4];
74# endif 76# endif
75#endif 77#endif
76 78
79#ifdef ADD_NOISE
80float rand(vec2 co)
81{
82 /* Magic 'random' number in range [0..1]. 'co' should be random coordinate.
83 * Distribution is not great. Falls apart with lowp float. */
84 return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453) - 0.5;
85}
86#endif
87
77void main() 88void main()
78{ 89{
79 vec4 c; 90 vec4 c;
@@ -126,11 +137,16 @@ void main()
126 137
127#elif defined(SHD_TEX) || defined(SHD_EXTERNAL) 138#elif defined(SHD_TEX) || defined(SHD_EXTERNAL)
128 c = texture2D(tex, tex_c).SWZ; 139 c = texture2D(tex, tex_c).SWZ;
129
130#else 140#else
131 c = vec4(1, 1, 1, 1); 141 c = vec4(1, 1, 1, 1);
132#endif 142#endif
133 143
144#ifdef ADD_NOISE
145 vec4 noise = vec4(rand(tex_c) / 256.0, rand(tex_c + vec2(1, 1)) / 256.0, rand(tex_c + vec2(2, 2)) / 256.0, 0);
146 noise.a = max(noise.r, noise.g);
147 noise.a = max(noise.a, noise.b);
148#endif
149
134#ifdef SHD_MASK 150#ifdef SHD_MASK
135 float ma; 151 float ma;
136# if defined(SHD_MASKSAM12) || defined(SHD_MASKSAM21) 152# if defined(SHD_MASKSAM12) || defined(SHD_MASKSAM21)
@@ -163,6 +179,9 @@ void main()
163#ifdef SHD_TEXA 179#ifdef SHD_TEXA
164 * texture2D(texa, tex_a).r 180 * texture2D(texa, tex_a).r
165#endif 181#endif
182#ifdef ADD_NOISE
183 + noise
184#endif
166 ; 185 ;
167} 186}
168 187