summaryrefslogtreecommitdiffstats
path: root/video/out/gpu/video_shaders.c
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.xyz>2020-06-19 08:03:46 +0200
committerNiklas Haas <git@haasn.xyz>2020-06-19 08:09:19 +0200
commitdc24a437fb9ba2485bc8c5866542bd36254410d4 (patch)
tree35a8090178cc19bc4e302389a46b006c8cf75845 /video/out/gpu/video_shaders.c
parentae5ac7e90a96c02f66b3eb5b63ed960bfffa3fdb (diff)
downloadmpv-dc24a437fb9ba2485bc8c5866542bd36254410d4.tar.bz2
mpv-dc24a437fb9ba2485bc8c5866542bd36254410d4.tar.xz
vo_gpu: add better gamut clipping option
See https://code.videolan.org/videolan/libplacebo/-/commit/d63eeb1ecc204 Enabled by default because I think it looks better. YMMV.
Diffstat (limited to 'video/out/gpu/video_shaders.c')
-rw-r--r--video/out/gpu/video_shaders.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/video/out/gpu/video_shaders.c b/video/out/gpu/video_shaders.c
index 5bc32dcd3b..19b002170d 100644
--- a/video/out/gpu/video_shaders.c
+++ b/video/out/gpu/video_shaders.c
@@ -870,6 +870,17 @@ void pass_color_map(struct gl_shader_cache *sc, bool is_linear,
mp_get_cms_matrix(csp_src, csp_dst, MP_INTENT_RELATIVE_COLORIMETRIC, m);
gl_sc_uniform_mat3(sc, "cms_matrix", true, &m[0][0]);
GLSL(color.rgb = cms_matrix * color.rgb;)
+
+ if (opts->gamut_clipping) {
+ GLSL(float cmin = min(min(color.r, color.g), color.b);)
+ GLSL(if (cmin < 0.0) {
+ float luma = dot(dst_luma, color.rgb);
+ float coeff = cmin / (cmin - luma);
+ color.rgb = mix(color.rgb, vec3(luma), coeff);
+ })
+ GLSL(float cmax = max(max(color.r, color.g), color.b);)
+ GLSL(if (cmax > 1.0) color.rgb /= cmax;)
+ }
}
if (need_ootf)