Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
You can’t perform that action at this time.