Colorimetrically clip after gamut mapping
The simplest way to do this is probably by just linearly desaturating towards vec3(luma)
until all three components are within bounds.
Questions:
- Do 'out of gamut' colors ever contain components above 1, or is just negative values that we need to worry about?
- How hard would it be to do something smarter like L*Ch? In what ways does scaling C differentiate from mixing with
vec3(luma)
? - How to detect whether one triangle lies fully inside another? (my guess is something like "check whether all three points of the inner tri are on the same side of all three sides of the outer tri")
We could also do something smarter like soft-knee in the future, which might require somehow bringing our desaturation coefficient into a parameter space where [0-1] represent in-gamut values and values above 1 represent "out of gamut".