3 ms·
This seems (http://www.chilliant.com/rgb2hsv.html http://www.chilliant.com/rgb2hsv.html) to have a few implementations of color space conversions (in HLSL but t
by yoklov 11y ago
This seems (http://www.chilliant.com/rgb2hsv.html http://www.chilliant.com/rgb2hsv.html) to have a few implementations of color space conversions (in HLSL but that shouldn't be a difficult translation). They're not perfect but they're a good starting point.
With some inlining and algebraic simplification (the kind that, unfortunately, can't safely be done by a compiler most of the time) you can get even simpler than the ones linked. For example, I've used something similar to the following for hsl to rgb before.
l + (1.0 - abs(2.0 * l - 1.0)) * s * (clamp(abs(mod(h + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0) - 0.5)