Created
December 13, 2019 22:52
-
-
Save misyltoad/3ab15cab5469766b1748f260bc9a3ca7 to your computer and use it in GitHub Desktop.
Convert from hue saturation value / lightness (alpha) to red green blue (alpha)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static RGBA HSVAToRGBA(float h, float s, float v, float a) { | |
float hh = std::fmodf(h, 360.0f) / 60.0f; | |
uint32_t i = static_cast<uint32_t>(hh); | |
float ff = hh - float(i); | |
float p = v * (1.0f - s); | |
float q = v * (1.0f - (s * ff)); | |
float t = v * (1.0f - (s * (1.0f - ff))); | |
switch (i) { | |
case 0: return { v, t, p, a }; | |
case 1: return { q, v, p, a }; | |
case 2: return { p, v, t, a }; | |
case 3: return { p, q, v, a }; | |
case 4: return { t, p, v, a }; | |
default: | |
case 5: return { v, p, q, a }; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment