diff options
author | Niklas Haas <git@nand.wakku.to> | 2016-05-30 19:56:58 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-05-30 20:17:33 +0200 |
commit | 45c3e0f0d0c836158ab38db53156bb6461ad7437 (patch) | |
tree | fa74784173edcbc2771b045947e0d64ed1b44bd9 /video/out/opengl/video_shaders.c | |
parent | 098ff4174c6c9cc59e65c6f09b23b3adaee03983 (diff) | |
download | mpv-45c3e0f0d0c836158ab38db53156bb6461ad7437.tar.bz2 mpv-45c3e0f0d0c836158ab38db53156bb6461ad7437.tar.xz |
vo_opengl: refactor HDR mechanism
Instead of doing HDR tone mapping on an ad-hoc basis inside
pass_colormanage, the reference peak of an image is now part of the
image params (alongside colorspace, gamma, etc.) and tone mapping is
done whenever peak_src != peak_dst.
To get sensible behavior when mixing HDR and SDR content and displays,
target-brightness is a generic filler for "the assumed brightness of SDR
content".
This gets rid of the weird display_scaled hack, sets the framework
for multiple HDR functions with difference reference peaks, and allows
us to (in a future commit) autodetect the right source peak from
the HDR metadata.
(Apart from metadata, the source peak can also be controlled via
vf_format. For HDR content this adjusts the overall image brightness,
for SDR content it's like simulating a different exposure)
Diffstat (limited to 'video/out/opengl/video_shaders.c')
-rw-r--r-- | video/out/opengl/video_shaders.c | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/video/out/opengl/video_shaders.c b/video/out/opengl/video_shaders.c index d940c415e8..1f37f4fed1 100644 --- a/video/out/opengl/video_shaders.c +++ b/video/out/opengl/video_shaders.c @@ -313,15 +313,10 @@ void pass_delinearize(struct gl_shader_cache *sc, enum mp_csp_trc trc) } } -// Tone map from one brightness to another -void pass_tone_map(struct gl_shader_cache *sc, float peak_src, float peak_dst, +// Tone map from a known peak brightness to the range [0,1] +void pass_tone_map(struct gl_shader_cache *sc, float peak, enum tone_mapping algo, float param) { - // First we renormalize to the output range - float scale = peak_src / peak_dst; - GLSLF("color.rgb *= vec3(%f);\n", scale); - - // Then we use some algorithm to map back to [0,1] switch (algo) { case TONE_MAPPING_CLIP: GLSL(color.rgb = clamp(color.rgb, 0.0, 1.0);) @@ -331,7 +326,7 @@ void pass_tone_map(struct gl_shader_cache *sc, float peak_src, float peak_dst, float contrast = isnan(param) ? 0.5 : param, offset = (1.0 - contrast) / contrast; GLSLF("color.rgb = color.rgb / (color.rgb + vec3(%f));\n", offset); - GLSLF("color.rgb *= vec3(%f);\n", (scale + offset) / scale); + GLSLF("color.rgb *= vec3(%f);\n", (peak + offset) / peak); break; } @@ -342,20 +337,20 @@ void pass_tone_map(struct gl_shader_cache *sc, float peak_src, float peak_dst, A, C*B, D*E, A, B, D*F, E/F); GLSLHF("}\n"); - GLSLF("color.rgb = hable(color.rgb) / hable(vec3(%f));\n", scale); + GLSLF("color.rgb = hable(color.rgb) / hable(vec3(%f));\n", peak); break; } case TONE_MAPPING_GAMMA: { float gamma = isnan(param) ? 1.8 : param; GLSLF("color.rgb = pow(color.rgb / vec3(%f), vec3(%f));\n", - scale, 1.0/gamma); + peak, 1.0/gamma); break; } case TONE_MAPPING_LINEAR: { float coeff = isnan(param) ? 1.0 : param; - GLSLF("color.rgb = vec3(%f) * color.rgb;\n", coeff / scale); + GLSLF("color.rgb = vec3(%f) * color.rgb;\n", coeff / peak); break; } |