Skip to content

Commit

Permalink
shaders/colorspace: improve accuracy of desaturation
Browse files Browse the repository at this point in the history
Instead of linearly desaturating, use a third-order polynomial
approximation.
  • Loading branch information
haasn committed Oct 8, 2023
1 parent 5bdad14 commit 72a3fea
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/shaders/colorspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1964,8 +1964,12 @@ 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 changing brightness
GLSL("ipt.yz *= min(i_orig / ipt.x, ipt.x / i_orig); \n");
// Avoid raising saturation excessively when raising brightness, and
// also desaturate when reducing brightness greatly to account for the
// reduction in gamut volume.
GLSL("vec2 hull = vec2(i_orig, ipt.x); \n"
"hull = ((hull - 6.0) * hull + 9.0) * hull; \n"
"ipt.yz *= min(i_orig / ipt.x, hull.y / hull.x); \n");
}

if (need_gamut_map) {
Expand Down

0 comments on commit 72a3fea

Please sign in to comment.