LYGIA Shader Library

hsv2rgb (lygia/v1.1.6/color/space/hsv2rgb)

pass a color in HSB and get RGB color. Also use as reference http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl

Use:

hsv2rgb(<vec3|vec4> color)

Check it on Github


#ifndef FNC_HSV2RGB
#define FNC_HSV2RGB
vec3 hsv2rgb(in vec3 hsb) {
    vec3 rgb = clamp(abs(mod(hsb.x * 6. + vec3(0., 4., 2.), 
                            6.) - 3.) - 1.,
                      0.,
                      1.);
    #ifdef HSV2RGB_SMOOTH
    rgb = rgb*rgb*(3. - 2. * rgb);
    #endif
    return hsb.z * mix(vec3(1.), rgb, hsb.y);
}

vec4 hsv2rgb(in vec4 hsb) {
    return vec4(hsv2rgb(hsb.rgb), hsb.a);
}
#endif

Use:

hsv2rgb(<float3|float4> color)

Check it on Github


#ifndef FNC_HSV2RGB
#define FNC_HSV2RGB
float3 hsv2rgb(in float3 hsb) {
    float3 rgb = clamp(abs(fmod(hsb.x * 6. + float3(0., 4., 2.), 
                            6.) - 3.) - 1.,
                      0.,
                      1.);
    #ifdef HSV2RGB_SMOOTH
    rgb = rgb*rgb*(3. - 2. * rgb);
    #endif
    return hsb.z * lerp(float3(1., 1., 1.), rgb, hsb.y);
}

float4 hsv2rgb(in float4 hsb) {
    return float4(hsv2rgb(hsb.rgb), hsb.a);
}
#endif

Check it on Github

fn hsv2rgb(hsb : vec3<f32>) -> vec3<f32> {
    var rgb = saturate(abs(mod(hsb.x * 6.0 + vec3<f32>(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0);
    // #ifdef HSV2RGB_SMOOTH
    // rgb = rgb*rgb*(3. - 2. * rgb);
    // #endif
    return hsb.z * mix(vec3(1.), rgb, hsb.y);
}

LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.

Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).

It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository