X-Git-Url: http://git.localhorst.tv/?p=blobs.git;a=blobdiff_plain;f=src%2Fmath%2Fglm.hpp;fp=src%2Fmath%2Fglm.hpp;h=76472e8baa2b166d90243b4e3ce11811ce331222;hp=0d344e6e7879bbb4786aecb64266060854154f7a;hb=01cc65097f27ad657130fb58a10813e8d5c09fe7;hpb=99bac662c454fcf3680fa9c080c90e24319d8d3d diff --git a/src/math/glm.hpp b/src/math/glm.hpp index 0d344e6..76472e8 100644 --- a/src/math/glm.hpp +++ b/src/math/glm.hpp @@ -51,29 +51,4 @@ inline Vec limit(const Vec &v, typename Vec::value_type max) noexcept { } } -template -inline T rgb2hsl(const T &rgb) { - using Vec4 = glm::tvec4; - const Vec4 K(0.0, -1.0/3.0, 2.0/3.0, -1.0); - const Vec4 p(glm::mix(Vec4(rgb.z, rgb.y, K.w, K.z), Vec4(rgb.y, rgb.z, K.x, K.y), rgb.y < rgb.z ? 0.0 : 1.0)); - const Vec4 q(glm::mix(Vec4(p.x, p.y, p.w, rgb.x), Vec4(rgb.x, p.y, p.z, p.x), rgb.x < p.x ? 0.0 : 1.0)); - const typename T::value_type d = q.x - std::min(q.w, q.y); - const typename T::value_type e = 1.0e-10; - T hsl = rgb; - hsl.x = std::abs(q.z + (q.w - q.y) / (6.0 * d + e)); - hsl.y = d / (q.x + e); - hsl.z = q.x; - return hsl; -} - -template -inline T hsl2rgb(const T &hsl) { - using Vec3 = glm::tvec3; - using Vec4 = glm::tvec4; - const Vec4 K(1.0, 2.0/3.0, 1.0/3.0, 3.0); - const Vec3 p(glm::abs(glm::fract(Vec3(hsl.x) + Vec3(K)) * 6.0 - Vec3(K.w))); - T rgb = hsl.z * glm::mix(Vec3(K.x), glm::clamp(p - Vec3(K.x), 0.0, 1.0), hsl.y); - return rgb; -} - #endif