lygia
/color
/space
/rgb2hcy
)Convert from linear RGB to HCY (Hue, Chroma, Luminance) HCY is a cylindrica. From: https://github.com/tobspr/GLSL-Color-Spaces/blob/master/ColorSpaces.inc.glsl
Dependencies:
Use:
<vec3|vec4> rgb2hcy(<vec3|vec4> rgb)
#ifndef HCY_EPSILON
#define HCY_EPSILON 1e-10
#endif
#ifndef FNC_RGB2HCY
#define FNC_RGB2HCY
vec3 rgb2hcy(const in vec3 rgb) {
const vec3 HCYwts = vec3(0.299, 0.587, 0.114);
// Corrected by David Schaeffer
vec3 HCV = rgb2hcv(rgb);
float Y = dot(rgb, HCYwts);
float Z = dot(hue2rgb(HCV.x), HCYwts);
if (Y < Z) {
HCV.y *= Z / (HCY_EPSILON + Y);
} else {
HCV.y *= (1.0 - Z) / (HCY_EPSILON + 1.0 - Y);
}
return vec3(HCV.x, HCV.y, Y);
}
vec4 rgb2hcy(vec4 rgb) { return vec4(rgb2hcy(rgb.rgb), rgb.a);}
#endif
Dependencies:
Use:
<float3|float4> rgb2hcy(<float3|float4> rgb)
#ifndef HCY_EPSILON
#define HCY_EPSILON 1e-10
#endif
#ifndef FNC_RGB2HCY
#define FNC_RGB2HCY
float3 rgb2hcy(float3 rgb) {
const float3 HCYwts = float3(0.299, 0.587, 0.114);
// Corrected by David Schaeffer
float3 HCV = rgb2hcv(rgb);
float Y = dot(rgb, HCYwts);
float Z = dot(hue2rgb(HCV.x), HCYwts);
if (Y < Z) {
HCV.y *= Z / (HCY_EPSILON + Y);
} else {
HCV.y *= (1.0 - Z) / (HCY_EPSILON + 1.0 - Y);
}
return float3(HCV.x, HCV.y, Y);
}
float4 rgb2hcy(float4 rgb) { return float4(rgb2hcy(rgb.rgb), rgb.a);}
#endif
Dependencies:
Use:
<float3|float4> rgb2hcy(<float3|float4> rgb)
#ifndef HCY_EPSILON
#define HCY_EPSILON 1e-10
#endif
#ifndef FNC_RGB2HCY
#define FNC_RGB2HCY
float3 rgb2hcy( float3 rgb) {
constant float3 HCYwts = float3(0.299, 0.587, 0.114);
// Corrected by David Schaeffer
float3 HCV = rgb2hcv(rgb);
float Y = dot(rgb, HCYwts);
float Z = dot(hue2rgb(HCV.x), HCYwts);
if (Y < Z) {
HCV.y *= Z / (HCY_EPSILON + Y);
} else {
HCV.y *= (1.0 - Z) / (HCY_EPSILON + 1.0 - Y);
}
return float3(HCV.x, HCV.y, Y);
}
float4 rgb2hcy(float4 rgb) { return float4(rgb2hcy(rgb.rgb), rgb.a);}
#endif
Dependencies:
fn rgb2hcy(rgb: vec3f) -> vec3f {
let HCYwts = vec3f(0.299, 0.587, 0.114);
// Corrected by David Schaeffer
var HCV = rgb2hcv(rgb);
let Y = dot(rgb, HCYwts);
let Z = dot(hue2rgb(HCV.x), HCYwts);
if (Y < Z) {
HCV.y *= Z / (HCY_EPSILON + Y);
} else {
HCV.y *= (1.0 - Z) / (HCY_EPSILON + 1.0 - Y);
}
return vec3f(HCV.x, HCV.y, 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.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository