Commit 7c11bcf2 authored by Niklas Haas's avatar Niklas Haas Committed by Thomas Guillem
Browse files

opengl: add support for dithering

This uses libplacebo's high quality blue noise algorithm. The lut_size
is chosen as 4 because the method of embedding (literal LUT) is not that
great. Larger texture sizes would require OpenGL/RA support, which is
not currently in the scope of VLC+libplacebo. (Alternatively, we could
try and use a uniform float array instead of a constant array - but it
doesn't seem to matter much)

In theory, we could also try making VLC forwards-compatible with GLSL 130+ and
then enabling the fixed-function ordered dither where available.

Note by Thomas Guillem:
Dithering is disabled by default since it can have an impact on performances
depending on OSses / GL extensions / GPU.
Modified-by: Thomas Guillem's avatarThomas Guillem <>
Signed-off-by: Thomas Guillem's avatarThomas Guillem <>
parent 8f1a8a15
......@@ -621,7 +621,37 @@ opengl_fragment_shader_init_impl(opengl_tex_converter_t *tc, GLenum tex_target,
dst_space, NULL, false);
struct pl_shader_obj *dither_state = NULL;
int method = var_InheritInteger(tc->gl, "dither-algo");
if (method >= 0) {
unsigned out_bits = 0;
int override = var_InheritInteger(tc->gl, "dither-depth");
if (override > 0)
out_bits = override;
GLint fb_depth = 0;
#if !defined(USE_OPENGL_ES2)
/* fetch framebuffer depth (we are already bound to the default one). */
if (tc->vt->GetFramebufferAttachmentParameteriv != NULL)
tc->vt->GetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_BACK_LEFT,
if (fb_depth <= 0)
fb_depth = 8;
out_bits = fb_depth;
pl_shader_dither(sh, out_bits, &dither_state, &(struct pl_dither_params) {
.method = method,
.lut_size = 4, // avoid too large values, since this gets embedded
const struct pl_shader_res *res = tc->pl_sh_res = pl_shader_finalize(sh);
tc->uloc.pl_vars = calloc(res->num_variables, sizeof(GLint));
......@@ -178,6 +178,26 @@ static const char * const tone_text[] = {
#define TONEMAP_WARN_TEXT N_("Highlight clipped pixels")
#define TONEMAP_WARN_LONGTEXT N_("Debugging tool to indicate which pixels were clipped as part of the tone mapping process.")
#define DITHER_TEXT N_("Dithering algorithm")
#define DITHER_LONGTEXT N_("The algorithm to use when dithering to a lower bit depth (degrades performance on some platforms).")
static const int dither_values[] = {
-1, // no dithering
static const char * const dither_text[] = {
"Blue noise",
"White noise",
"Bayer matrix (ordered dither)",
#define DEPTH_TEXT N_("Dither depth override (0 = framebuffer depth)")
#define DEPTH_LONGTEXT N_("Overrides the detected framebuffer depth. Useful to dither to lower bit depths than otherwise required.")
#define add_glopts_placebo() \
set_section(N_("Colorspace conversion"), NULL) \
add_integer("rendering-intent", pl_color_map_default_params.intent, \
......@@ -195,7 +215,11 @@ static const char * const tone_text[] = {
add_float("tone-mapping-desat", pl_color_map_default_params.tone_mapping_desaturate, \
add_bool("tone-mapping-warn", false, TONEMAP_WARN_TEXT, TONEMAP_WARN_LONGTEXT, false)
add_bool("tone-mapping-warn", false, TONEMAP_WARN_TEXT, TONEMAP_WARN_LONGTEXT, false) \
set_section(N_("Dithering"), NULL) \
add_integer("dither-algo", -1, DITHER_TEXT, DITHER_LONGTEXT, false) \
change_integer_list(dither_values, dither_text) \
add_integer_with_range("dither-depth", 0, 0, 16, DEPTH_TEXT, DEPTH_LONGTEXT, false)
#define add_glopts_placebo()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment