Skip to content

Instantly share code, notes, and snippets.

@iUltimateLP
Created March 4, 2016 14:50
Show Gist options
  • Save iUltimateLP/5129149bf82757b31542 to your computer and use it in GitHub Desktop.
Save iUltimateLP/5129149bf82757b31542 to your computer and use it in GitHub Desktop.
A simple HLSL shader code to convert HSV to RGB colors.
float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 p = abs(frac(input.xxx + K.xyz) * 6.0 - K.www);
return input.z * lerp(K.xxx, clamp(p - K.xxx, 0.0, 1.0), input.y);
@Devaniti
Copy link

Devaniti commented Mar 2, 2021

clamp(..., 0.0, 1.0) can be replaced with saturate
It would also be nice to cite original source, if I'm not mistaken it's https://web.archive.org/web/20200207113336/http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment