Skip to content

Commit aedbe30

Browse files
committed
Add hsl_to_rgb GLSL utility function
(Used elsewhere in a custom shader, but useful to have built-in)
1 parent 2466348 commit aedbe30

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/flitter/render/window/glsl/color_functions.glsl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,14 @@ vec3 hsv_to_rgb(vec3 color) {
8080
vec3 p = abs(fract(color.xxx + K.xyz) * 6.0 - K.www);
8181
return color.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), color.y);
8282
}
83+
84+
vec3 hsl_to_rgb(vec3 color) {
85+
vec3 hsl = clamp(color, vec3(0.0), vec3(1.0));
86+
if (hsl.y == 0.0) {
87+
return hsv_to_rgb(hsl);
88+
} else {
89+
float v = min(1.0, hsl.z / (1.0 - hsl.y / 2.0));
90+
float s = (hsl.z == 0 || hsl.z == 1.0) ? 0.0 : (v - hsl.z) / min(hsl.z / 2.0, 1.0 - hsl.z / 2.0);
91+
return hsv_to_rgb(vec3(hsl.x, s, v));
92+
}
93+
}

0 commit comments

Comments
 (0)