Skip to content

Commit

Permalink
shaders/colorspace: scale down saturation when raising brightness
Browse files Browse the repository at this point in the history
Avoids excessively over-saturating when tone mapping upwards in
brightness, which generally leads to an unnatural effect. Tested with
both black point compensation and inverse tone mapping.

Fixes: https://code.videolan.org/videolan/libplacebo/-/issues/280
  • Loading branch information
haasn committed Jun 18, 2023
1 parent fea6619 commit f06efc7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/shaders/colorspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,8 @@ void pl_shader_color_map_ex(pl_shader sh, const struct pl_color_map_params *para
"lmspq = (vec3(%f) + %f * lmspq) \n"
" / (vec3(1.0) + %f * lmspq); \n"
"lmspq = pow(lmspq, vec3(%f)); \n"
"vec3 ipt = "$" * lmspq; \n",
"vec3 ipt = "$" * lmspq; \n"
"float i_orig = ipt.x; \n",
SH_FLOAT(pl_hdr_rescale(PL_HDR_PQ, PL_HDR_NORM, tone.input_min)),
SH_FLOAT_DYN(pl_hdr_rescale(PL_HDR_PQ, PL_HDR_NORM, tone.input_max)),
SH_MAT3(rgb2lms),
Expand Down Expand Up @@ -1865,6 +1866,9 @@ void pl_shader_color_map_ex(pl_shader sh, const struct pl_color_map_params *para
GLSL("ipt.x = tone_map(ipt.x); \n");
}

// Avoid raising saturation excessively when raising brightness
GLSL("ipt.yz *= min(i_orig / ipt.x, 1.0); \n");

if (hybrid_mix > 0) {
GLSL("vec3 lmsclip = lmspq; \n"
"lmsclip.x = tone_map(lmsclip.x); \n"
Expand Down

0 comments on commit f06efc7

Please sign in to comment.