lygia
/color
/space
/rgb2hue
)Convert a color from RGB to HSL color space.
Use:
<float> rgb2hue(<vec3|vec4> color)
#ifndef HUE_EPSILON
#define HUE_EPSILON 1e-10
#endif
#ifndef FNC_RGB2HUE
#define FNC_RGB2HUE
float rgb2hue(const in vec3 c) {
vec4 K = vec4(0.0, -0.33333333333333333333, 0.6666666666666666666, -1.0);
vec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);
vec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);
float d = q.x - min(q.w, q.y);
return abs(q.z + (q.w - q.y) / (6. * d + HUE_EPSILON));
}
float rgb2hue(const in vec4 c) { return rgb2hue(c.rgb); }
#endif
Use:
<float> rgb2hue(<float3|float4> color)
#ifndef HUE_EPSILON
#define HUE_EPSILON 1e-10
#endif
#ifndef FNC_RGB2HUE
#define FNC_RGB2HUE
float rgb2hue(in float3 c) {
float4 K = float4(0.0, -0.33333333333333333333, 0.6666666666666666666, -1.0);
float4 p = c.g < c.b ? float4(c.bg, K.wz) : float4(c.gb, K.xy);
float4 q = c.r < p.x ? float4(p.xyw, c.r) : float4(c.r, p.yzx);
float d = q.x - min(q.w, q.y);
return abs(q.z + (q.w - q.y) / (6.0 * d + HUE_EPSILON));
}
float rgb2hue(in float4 c) { return rgb2hue(c.rgb); }
#endif
Use:
<float> rgb2hue(<float3|float4> color)
#ifndef HUE_EPSILON
#define HUE_EPSILON 1e-10
#endif
#ifndef FNC_RGB2HUE
#define FNC_RGB2HUE
float rgb2hue( float3 c) {
float4 K = float4(0.0, -0.33333333333333333333, 0.6666666666666666666, -1.0);
float4 p = c.g < c.b ? float4(c.bg, K.wz) : float4(c.gb, K.xy);
float4 q = c.r < p.x ? float4(p.xyw, c.r) : float4(c.r, p.yzx);
float d = q.x - min(q.w, q.y);
return abs(q.z + (q.w - q.y) / (6. * d + HUE_EPSILON));
}
float rgb2hue( float4 c) { return rgb2hue(c.rgb); }
#endif
fn rgb2hue(rgb: vec3f) -> f32 {
let K = vec4ff(0.0, -0.33333333333333333333, 0.6666666666666666666, -1.0);
let p = rgb.g < rgb.b ? vec4f(rgb.bg, K.wz) : vec4f(rgb.gb, K.xy);
let q = rgb.r < p.x ? vec4f(p.xyw, rgb.r) : vec4f(rgb.r, p.yzx);
let d = q.x - min(q.w, q.y);
return abs(q.z + (q.w - q.y) / (6. * d + 1e-10));
}
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.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository