16[[nodiscard]]
inline glm::vec3
hsv_to_rgb(glm::vec3 hsv)
noexcept
18 const float hue = hsv.x - std::floor(hsv.x);
19 const float saturation = std::clamp(hsv.y, 0.F, 1.F);
20 const float value = std::clamp(hsv.z, 0.F, 1.F);
21 const float sector = hue * 6.F;
23 const auto channel = [&](
float offset) {
24 const float k = std::fmod(
offset + sector, 6.F);
25 return value -
value * saturation * std::clamp(std::min(k, 4.F - k), 0.F, 1.F);
28 return { channel(5.F), channel(3.F), channel(1.F) };
39[[nodiscard]]
inline glm::vec3
rgb_to_hsv(glm::vec3 rgb)
noexcept
41 const float cmax = std::max({ rgb.x, rgb.y, rgb.z });
42 const float cmin = std::min({ rgb.x, rgb.y, rgb.z });
43 const float delta = cmax - cmin;
48 hue = std::fmod((rgb.y - rgb.z) / delta, 6.F);
49 }
else if (cmax == rgb.y) {
50 hue = (rgb.z - rgb.x) / delta + 2.F;
52 hue = (rgb.x - rgb.y) / delta + 4.F;
59 return { hue, cmax > 0.F ? delta / cmax : 0.F, cmax };