summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.xyz>2017-09-03 21:51:48 +0200
committerNiklas Haas <git@haasn.xyz>2017-09-03 21:51:48 +0200
commitf589a3bd78efbc16e8025bff0809ac3c16b8ea2b (patch)
tree90d027ff59b7e9026591594ccd79726743fae732
parent9a28088e7457a41c61be7f534618c69b4307d693 (diff)
downloadmpv-f589a3bd78efbc16e8025bff0809ac3c16b8ea2b.tar.bz2
mpv-f589a3bd78efbc16e8025bff0809ac3c16b8ea2b.tar.xz
vo_opengl: scale deband-grain to the signal range
This prevents blowing up for high dynamic range sources, where a noise level of 48 can suddenly mean 4800.
-rw-r--r--video/out/opengl/video.c3
-rw-r--r--video/out/opengl/video_shaders.c7
-rw-r--r--video/out/opengl/video_shaders.h2
3 files changed, 8 insertions, 4 deletions
diff --git a/video/out/opengl/video.c b/video/out/opengl/video.c
index 48477fe18d..f0a8635c56 100644
--- a/video/out/opengl/video.c
+++ b/video/out/opengl/video.c
@@ -1792,7 +1792,8 @@ static void deband_hook(struct gl_video *p, struct img_tex tex,
struct gl_transform *trans, void *priv)
{
pass_describe(p, "debanding (%s)", plane_names[tex.type]);
- pass_sample_deband(p->sc, p->opts.deband_opts, &p->lfg);
+ pass_sample_deband(p->sc, p->opts.deband_opts, &p->lfg,
+ p->image_params.color.gamma);
}
static void unsharp_hook(struct gl_video *p, struct img_tex tex,
diff --git a/video/out/opengl/video_shaders.c b/video/out/opengl/video_shaders.c
index a7b253249a..40c5e98729 100644
--- a/video/out/opengl/video_shaders.c
+++ b/video/out/opengl/video_shaders.c
@@ -808,7 +808,7 @@ const struct m_sub_options deband_conf = {
// Stochastically sample a debanded result from a hooked texture.
void pass_sample_deband(struct gl_shader_cache *sc, struct deband_opts *opts,
- AVLFG *lfg)
+ AVLFG *lfg, enum mp_csp_trc trc)
{
// Initialize the PRNG
GLSLF("{\n");
@@ -850,7 +850,10 @@ void pass_sample_deband(struct gl_shader_cache *sc, struct deband_opts *opts,
GLSL(noise.x = rand(h); h = permute(h);)
GLSL(noise.y = rand(h); h = permute(h);)
GLSL(noise.z = rand(h); h = permute(h);)
- GLSLF("color.xyz += %f * (noise - vec3(0.5));\n", opts->grain/8192.0);
+
+ // Noise is scaled to the signal level to prevent extreme noise for HDR
+ float gain = opts->grain/8192.0 / mp_trc_nom_peak(trc);
+ GLSLF("color.xyz += %f * (noise - vec3(0.5));\n", gain);
GLSLF("}\n");
}
diff --git a/video/out/opengl/video_shaders.h b/video/out/opengl/video_shaders.h
index f6edff6d2b..1fae830720 100644
--- a/video/out/opengl/video_shaders.h
+++ b/video/out/opengl/video_shaders.h
@@ -49,7 +49,7 @@ void pass_color_map(struct gl_shader_cache *sc,
bool is_linear);
void pass_sample_deband(struct gl_shader_cache *sc, struct deband_opts *opts,
- AVLFG *lfg);
+ AVLFG *lfg, enum mp_csp_trc trc);
void pass_sample_unsharp(struct gl_shader_cache *sc, float param);