Skip to content

Instantly share code, notes, and snippets.

@litefeel
Created July 27, 2018 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save litefeel/3344786f17001b35274bbe7ebe209828 to your computer and use it in GitHub Desktop.
Save litefeel/3344786f17001b35274bbe7ebe209828 to your computer and use it in GitHub Desktop.
shader: HSV <-> RGB
// https://blog.csdn.net/mobilebbki399/article/details/50603461
float3 RGB2HSV(float3 c)
{
float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
float4 p = lerp(float4(c.bg, K.wz), float4(c.gb, K.xy), step(c.b, c.g));
float4 q = lerp(float4(p.xyw, c.r), float4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
float3 HSV2RGB(float3 c)
{
float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * lerp(K.xxx, saturate(p - K.xxx), c.y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment