summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/video_shaders.c
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.xyz>2017-06-09 09:16:06 +0200
committerRicardo Constantino <wiiaboo@gmail.com>2017-06-09 11:27:28 +0100
commitd8a3b10f45eb10fb34ce9da3a9a76e3bd8644e3d (patch)
tree80186e11d21707072751d95e055f44da7a36f159 /video/out/opengl/video_shaders.c
parent30cd963b25520089f56417eb2f946c98afeef073 (diff)
downloadmpv-d8a3b10f45eb10fb34ce9da3a9a76e3bd8644e3d.tar.bz2
mpv-d8a3b10f45eb10fb34ce9da3a9a76e3bd8644e3d.tar.xz
vo_opengl: add new HDR tone mapping algorithm
I call it `mobius` because apparently the form f(x) = (cx+a)/(dx+b) is called a Möbius transform, which is the algorithm this is based on. In the extremes it becomes `reinhard` (param=0.0 and `clip` (param=1.0), smoothly transitioning between the two depending on the parameter. This is a useful tone mapping algorithm since the tunable mobius transform allows the user to decide the trade-off between color accuracy and detail preservation on a continuous scale. The default of 0.3 is already far more accurate than `reinhard` while also being reasonably good at preserving highlights, without suffering from the overall brightness drop and color distortion of `hable`. For these reasons, make this the new default. Also expand and improve the documentation for these tone mapping functions.
Diffstat (limited to 'video/out/opengl/video_shaders.c')
-rw-r--r--video/out/opengl/video_shaders.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/video/out/opengl/video_shaders.c b/video/out/opengl/video_shaders.c
index 5421589d06..95ac712f05 100644
--- a/video/out/opengl/video_shaders.c
+++ b/video/out/opengl/video_shaders.c
@@ -377,6 +377,21 @@ static void pass_tone_map(struct gl_shader_cache *sc, float ref_peak,
GLSL(color.rgb = clamp(color.rgb, 0.0, 1.0);)
break;
+ case TONE_MAPPING_MOBIUS: {
+ float j = isnan(param) ? 0.3 : param;
+ // solve for M(j) = j; M(ref_peak) = 1.0; M'(j) = 1.0
+ // where M(x) = scale * (x+a)/(x+b)
+ float a = -j*j * (ref_peak - 1) / (j*j - 2*j + ref_peak),
+ b = (j*j - 2*j*ref_peak + ref_peak) / (ref_peak - 1);
+
+ GLSLF("color.rgb = mix(vec3(%f) * (color.rgb + vec3(%f))\n"
+ " / (color.rgb + vec3(%f)),\n"
+ " color.rgb,\n"
+ " lessThanEqual(color.rgb, vec3(%f)));\n",
+ (b*b + 2*b*j + j*j) / (b - a), a, b, j);
+ break;
+ }
+
case TONE_MAPPING_REINHARD: {
float contrast = isnan(param) ? 0.5 : param,
offset = (1.0 - contrast) / contrast;