Skip to content

shaders/colorspace: complete refactor of tone mapping pipeline

Niklas Haas requested to merge haasn/libplacebo:gamut_mapping_v4 into master

This refactors the code to take advantage of the new gamut mapping API. In the process, it has also been substantially rewritten.

The new basic approach is to use our own custom-designed colorspace, IPTPQc4 (a variant of IPT-1998, ICtCp, Dolby IPTPQc2, Jzazbz and friends), for the entire pipeline. This allows us to take full advantage of whatever math we want, and is both extensible and higher quality. The downside is a slightly more expensive conversion function, but the quality gained is worth it.

Since the old PL_TONE_MAP_* modes cannot be directly translated to the new system, and also have decreasing amounts of relevance as the default tone-mapping gets improved, I decided to nuke this option and just hard-code one default tone mapping function, improving it where necessary.

The basic approach is to tone-map directly on the IPTPQc4 intensity (I) channel. But since this has a tendency to overexpose very bright/saturated highlights, and since monochromatic desaturation tends to look strange for these, we regain some of the old HYBRID behavior by tone-mapping in LMS space (rather than RGB), and using that clipped result to shift the hue (keeping the tone-mapped intensity unchanged). This requires hard-clipping our inputs to the claimed source range, though, to avoid throwing off LMS balance too much. (Alternatively, we could normalize the LMS before passing it into the tone-mapper, but I prefer just clipping "illegal" input values)

After this, we pass it into a gamut mapping 3DLUT which is equipped to handle both wide gamut source colors and saturated highlights (as a consequence of HDR tone-mapping).

As a consequence of the increasing intertwinedness between the tone-mapping and gamut mapping pipelines, I have merged them all into a single function. This is required to avoid e.g. breaking the tone mapping visualization and clipping highlight features.

TODO:

  • investigate and fix bad artifact on butterfly sample
  • fix general brightness raising issues
  • double-check numerical precision near low-end (black -> 0)
Edited by Niklas Haas

Merge request reports