From eac0665b8dd2398c15aaa347ca8e5496e0dc5f2b Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 22 Dec 2015 23:14:47 +0100 Subject: vo_opengl: blend transparent video against tiles by default Add a "blend-tiles" choice to the "alpha" sub-option. This is pretty simplistic and uses the GL raster position to derive the tiles. A weird consequence is that using --vo=opengl and --vo=opengl-hq gives different scaling behavior (screenspace pixel size vs. source video pixel size 16x16 tiles), but it seems we don't have easy access to the original texture coordinates. Using the rasterpos is probably simpler. Make this option the default. --- DOCS/man/vo.rst | 6 ++++-- video/out/opengl/video.c | 13 +++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/DOCS/man/vo.rst b/DOCS/man/vo.rst index 0b3742c4d7..bc0dd9fd12 100644 --- a/DOCS/man/vo.rst +++ b/DOCS/man/vo.rst @@ -957,9 +957,11 @@ Available video output drivers are: things like softsubbed ASS signs to match the video colors, but may cause SRT subtitles or similar to look slightly off. - ``alpha=`` - Decides what to do if the input has an alpha component (default: blend). + ``alpha=`` + Decides what to do if the input has an alpha component. + blend-tiles + Blend the frame against a 16x16 gray/white tiles background (default). blend Blend the frame against a black background. yes diff --git a/video/out/opengl/video.c b/video/out/opengl/video.c index 7266d1063a..980867b8cc 100644 --- a/video/out/opengl/video.c +++ b/video/out/opengl/video.c @@ -345,7 +345,7 @@ const struct gl_video_opts gl_video_opts_def = { .clamp = 1, }, // tscale }, .scaler_lut_size = 6, - .alpha_mode = 2, + .alpha_mode = 3, .background = {0, 0, 0, 255}, .gamma = 1.0f, .prescale_passes = 1, @@ -369,7 +369,7 @@ const struct gl_video_opts gl_video_opts_hq_def = { .clamp = 1, }, // tscale }, .scaler_lut_size = 6, - .alpha_mode = 2, + .alpha_mode = 3, .background = {0, 0, 0, 255}, .gamma = 1.0f, .blend_subs = 0, @@ -441,7 +441,8 @@ const struct m_sub_options gl_video_conf = { OPT_CHOICE("alpha", alpha_mode, 0, ({"no", 0}, {"yes", 1}, - {"blend", 2})), + {"blend", 2}, + {"blend-tiles", 3})), OPT_FLAG("rectangle-textures", use_rectangle, 0), OPT_COLOR("background", background, 0), OPT_FLAG("interpolation", interpolation, 0), @@ -1532,8 +1533,12 @@ static void pass_convert_yuv(struct gl_video *p) if (!p->has_alpha || p->opts.alpha_mode == 0) { // none GLSL(color.a = 1.0;) - } else if (p->opts.alpha_mode == 2) { // blend + } else if (p->opts.alpha_mode == 2) { // blend against black GLSL(color = vec4(color.rgb * color.a, 1.0);) + } else if (p->opts.alpha_mode == 3) { // blend against tiles + GLSL(bvec2 tile = lessThan(fract(gl_FragCoord.xy / 32.0), vec2(0.5));) + GLSL(vec3 background = vec3(mix(0.75, 1.0, tile.x != tile.y));) + GLSL(color.rgb = color.rgb * color.a + background * (1.0 - color.a);) } else if (p->gl->fb_premultiplied) { GLSL(color = vec4(color.rgb * color.a, color.a);) } -- cgit v1.2.3