Skip to content

Instantly share code, notes, and snippets.

@ForeverZer0
Created March 1, 2020 21:29
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 ForeverZer0/f4f3ce84fe8a58d3ab8d16feb73b3509 to your computer and use it in GitHub Desktop.
Save ForeverZer0/f4f3ce84fe8a58d3ab8d16feb73b3509 to your computer and use it in GitHub Desktop.
Simple and efficient hue-shift function for a GLSL fragment shader.
/**
* @brief Applies a hue-shift in a GLSL fragment shader.
*
* @param color The color of the fragment to shift.
* @param hue The amount of hue-shift to apply, in radians. Use GLSL radians function to convert from degrees if needed.
*
* @return The hue-shifted fragment color.
*/
vec3 hueShift(vec3 color, float hue) {
const vec3 k = vec3(0.57735, 0.57735, 0.57735);
float cosAngle = cos(hue);
return vec3(col * cosAngle + cross(k, col) * sin(hue) + k * dot(k, col) * (1.0 - cosAngle));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment