Created
November 22, 2023 16:27
-
-
Save spajus/5240b358b103e2970ff3403202c56c74 to your computer and use it in GitHub Desktop.
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
float3 RGBtoHSV(float3 In) | |
{ | |
float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); | |
float4 P = lerp(float4(In.bg, K.wz), float4(In.gb, K.xy), step(In.b, In.g)); | |
float4 Q = lerp(float4(P.xyw, In.r), float4(In.r, P.yzx), step(P.x, In.r)); | |
float D = Q.x - min(Q.w, Q.y); | |
float E = 1e-10; | |
return float3(abs(Q.z + (Q.w - Q.y)/(6.0 * D + E)), D / (Q.x + E), Q.x); | |
} | |
float3 HSVtoRGB(float3 In) | |
{ | |
float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); | |
float3 P = abs(frac(In.xxx + K.xyz) * 6.0 - K.www); | |
return In.z * lerp(K.xxx, saturate(P - K.xxx), In.y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment