Created
November 19, 2024 18:25
-
-
Save k0ffinz/8f77d0c53a45525ed0d51fc1d644ee37 to your computer and use it in GitHub Desktop.
HLSL shader code to convert HSL to RGB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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