summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/video_shaders.c
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 /video/out/opengl/video_shaders.c
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.
Diffstat (limited to 'video/out/opengl/video_shaders.c')
-rw-r--r--video/out/opengl/video_shaders.c7
1 files changed, 5 insertions, 2 deletions
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");
}