diff options
Diffstat (limited to 'src/modules/evas/engines/gl_common/shader')
3 files changed, 108 insertions, 6 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 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" |