From d3032e3e67ef834c98e386d88e8ceccaaf0c45d8 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 14 Jan 2013 11:44:54 +0000 Subject: [PATCH] color: slightly better HSVToRGB routine. --- src/lol/image/color.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lol/image/color.h b/src/lol/image/color.h index d0dcd031..b9c9603c 100644 --- a/src/lol/image/color.h +++ b/src/lol/image/color.h @@ -70,8 +70,10 @@ public: */ static vec3 HSVToRGB(vec3 src) { - vec3 tmp = abs(fract(vec3(src.x) + vec3(3.f, 2.f, 1.f) / 3.f) * 6.f - vec3(3.f)); - return mix(vec3(1.f), clamp(tmp - vec3(1.f), 0.f, 1.f), src.y) * src.z; + vec3 tmp = vec3(-1.f + abs(6.f * src.x - 3.f), + 2.f - abs(6.f * src.x - 2.f), + 2.f - abs(6.f * src.x - 4.f)); + return src.z * mix(vec3(1.f), clamp(tmp, 0.f, 1.f), src.y); } static vec4 HSVToRGB(vec4 src)