lygia
/v1.2.0
/color
/space
/hcy2rgb
)Converts a HCY color to linear RGB
Dependencies:
Use:
<vec3|vec4> hcy2rgb(<vec3|vec4> hsl)
#ifndef FNC_HCY2RGB
#define FNC_HCY2RGB
vec3 hcy2rgb(vec3 hcy) {
const vec3 HCYwts = vec3(0.299, 0.587, 0.114);
vec3 RGB = hue2rgb(hcy.x);
float Z = dot(RGB, HCYwts);
if (hcy.z < Z) {
hcy.y *= hcy.z / Z;
} else if (Z < 1.0) {
hcy.y *= (1.0 - hcy.z) / (1.0 - Z);
}
return (RGB - Z) * hcy.y + hcy.z;
}
vec4 hcy2rgb(vec4 hcy) { return vec4(hcy2rgb(hcy.rgb), hcy.a); }
#endif
Dependencies:
Use:
<float3|float4> hcy2rgb(<float3|float4> hsl)
#ifndef FNC_HCY2RGB
#define FNC_HCY2RGB
float3 hcy2rgb(float3 hcy) {
const float3 HCYwts = float3(0.299, 0.587, 0.114);
float3 RGB = hue2rgb(hcy.x);
float Z = dot(RGB, HCYwts);
if (hcy.z < Z) {
hcy.y *= hcy.z / Z;
} else if (Z < 1.0) {
hcy.y *= (1.0 - hcy.z) / (1.0 - Z);
}
return (RGB - Z) * hcy.y + hcy.z;
}
float4 hcy2rgb(float4 hcy) { return float4(hcy2rgb(hcy.rgb), hcy.a); }
#endif
Dependencies:
fn hcy2rgb(hcy: vec3f) -> vec3f {
var rta = hcy;
let HCYwts = vec3f(0.299, 0.587, 0.114);
let RGB = hue2rgb(hcy.x);
let Z = dot(RGB, HCYwts);
if (hcy.z < Z) {
rta.y *= hcy.z / Z;
} else if (Z < 1.0) {
rta.y *= (1.0 - hcy.z) / (1.0 - Z);
}
return (RGB - Z) * rta.y + rta.z;
}
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