Created
March 1, 2020 21:29
-
-
Save ForeverZer0/f4f3ce84fe8a58d3ab8d16feb73b3509 to your computer and use it in GitHub Desktop.
Simple and efficient hue-shift function for a GLSL fragment shader.
This file contains 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
/** | |
* @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