[GLSL] HSV 转为 RGB

vec3 rgb(float h, float s, float v)
{
    int hi = int(mod(floor(h / 60), 6));
    float f = h / 60 - hi;
    float p = v * (1 - s);
    float q = v * (1 - f * s);
    float t = v * (1 - (1 - f) * s);
    switch(hi)
    {
    case 0:
        return vec3(v, t, p);
    case 1:
        return vec3(q, v, p);
    case 2:
        return vec3(p, v, t);
    case 3:
        return vec3(p, q, v);
    case 4:
        return vec3(t, p, v);
    case 5:
        return vec3(v, p, q);
    }
}

参考:颜色空间RGB与HSV(HSL)的转换_jiangxinyu的专栏-CSDN博客

发表评论