lygia
/color
/space
/rgb2hsl
)Convert from linear RGB to HSL. Based on work by Sam Hocevar and Emil Persson
Dependencies:
Use:
<vec3|vec4> rgb2hsl(<vec3|vec4> rgb)
#ifndef HSL_EPSILON
#define HSL_EPSILON 1e-10
#endif
#ifndef FNC_RGB2HSL
#define FNC_RGB2HSL
vec3 rgb2hsl(const in vec3 rgb) {
vec3 HCV = rgb2hcv(rgb);
float L = HCV.z - HCV.y * 0.5;
float S = HCV.y / (1.0 - abs(L * 2.0 - 1.0) + HSL_EPSILON);
return vec3(HCV.x, S, L);
}
vec4 rgb2hsl(const in vec4 rgb) { return vec4(rgb2hsl(rgb.xyz),rgb.a);}
#endif
Dependencies:
Use:
<float3|float4> rgb2hsl(<float3|float4> rgb)
#ifndef HSL_EPSILON
#define HSL_EPSILON 1e-10
#endif
#ifndef FNC_RGB2HSL
#define FNC_RGB2HSL
float3 rgb2hsl(float3 rgb) {
float3 HCV = rgb2hcv(rgb);
float L = HCV.z - HCV.y * 0.5;
float S = HCV.y / (1.0 - abs(L * 2.0 - 1.0) + HSL_EPSILON);
return float3(HCV.x, S, L);
}
float4 rgb2hsl(float4 rgb) { return float4(rgb2hsl(rgb.xyz),rgb.a);}
#endif
Dependencies:
Use:
<float3|float4> rgb2hsl(<float3|float4> rgb)
#ifndef HSL_EPSILON
#define HSL_EPSILON 1e-10
#endif
#ifndef FNC_RGB2HSL
#define FNC_RGB2HSL
float3 rgb2hsl( float3 rgb) {
float3 HCV = rgb2hcv(rgb);
float L = HCV.z - HCV.y * 0.5;
float S = HCV.y / (1.0 - abs(L * 2.0 - 1.0) + HSL_EPSILON);
return float3(HCV.x, S, L);
}
float4 rgb2hsl( float4 rgb) { return float4(rgb2hsl(rgb.xyz),rgb.a);}
#endif
Dependencies:
fn rgb2hsl(rgb: vec3f) -> vec3f {
let HCV = rgb2hcv(rgb);
let L = HCV.z - HCV.y * 0.5;
let S = HCV.y / (1.0 - abs(L * 2.0 - 1.0) + 1e-10);
return vec3f(HCV.x, S, L);
}
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