Skip to content

Instantly share code, notes, and snippets.

@k0ffinz
Created November 19, 2024 18:25
Show Gist options
  • Select an option

  • Save k0ffinz/8f77d0c53a45525ed0d51fc1d644ee37 to your computer and use it in GitHub Desktop.

Select an option

Save k0ffinz/8f77d0c53a45525ed0d51fc1d644ee37 to your computer and use it in GitHub Desktop.
HLSL shader code to convert HSL to RGB
// adapted from https://labex.io/tutorials/28378
float3 HSL2RGB(float h, float s, float l) {
float a = s * min(l, 1. - l);
return float3(
l - a * max(-1., min(((h / 30.) % 12.) - 3., min(9. - ((h / 30.) % 12.), 1.))),
l - a * max(-1., min(((8. + h / 30.) % 12.) - 3., min(9. - ((8. + h / 30.) % 12.), 1.))),
l - a * max(-1., min(((4. + h / 30.) % 12.) - 3., min(9. - ((4. + h / 30.) % 12.), 1.)))
);
}
float3 HSL2RGB(float3 hsl) {
return HSL2RGB(hsl.x, hsl.y, hsl.z);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment