lygia
/v1.1.6
/color
/space
/rgb2hsv
)pass a color in RGB and get HSB color. From http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl
Use:
rgb2hsv(<vec3|vec4> color)
#ifndef FNC_RGB2HSV
#define FNC_RGB2HSV
vec3 rgb2hsv(in vec3 c) {
vec4 K = vec4(0., -.33333333333333333333, .6666666666666666666, -1.);
#ifdef RGB2HSV_MIX
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
#else
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);
#endif
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6. * d + e)),
d / (q.x + e),
q.x);
}
vec4 rgb2hsv(in vec4 c) {
return vec4(rgb2hsv(c.rgb), c.a);
}
#endif
Use:
rgb2hsv(<float3|float4> color)
#ifndef FNC_RGB2HSV
#define FNC_RGB2HSV
float3 rgb2hsv(in float3 c) {
float4 K = float4(0., -.33333333333333333333, .6666666666666666666, -1.);
#ifdef RGB2HSV_MIX
float4 p = lerp(float4(c.bg, K.wz), float4(c.gb, K.xy), step(c.b, c.g));
float4 q = lerp(float4(p.xyw, c.r), float4(c.r, p.yzx), step(p.x, c.r));
#else
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);
#endif
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return float3( abs(q.z + (q.w - q.y) / (6. * d + e)),
d / (q.x + e),
q.x );
}
float4 rgb2hsv(in float4 c) {
return float4(rgb2hsv(c.rgb), c.a);
}
#endif
fn rgb2hsv(c: vec3<f32>) -> vec3<f32> {
let K = vec4<f32>(0.0, -0.33333333333333333333, 0.6666666666666666666, -1.0);
// #ifdef RGB2HSV_MIX
let p = mix(vec4<f32>(c.bg, K.wz), vec4<f32>(c.gb, K.xy), step(c.b, c.g));
let q = mix(vec4<f32>(p.xyw, c.r), vec4<f32>(c.r, p.yzx), step(p.x, c.r));
// #else
// 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);
// #endif
let d = q.x - min(q.w, q.y);
let e = 1.0e-10;
return vec3<f32>(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
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