diff options
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; } |