title: How to change hue of a texture with GLSL?
body: <p>Is there a way to efficiently change hue of a 2D OpenGL texture using GLSL (fragment shader)?</p>
  
  <p>Do someone have some code for it?</p>
  
  <p><strong>UPDATE:</strong> This is the code resulting from user1118321 suggestion:</p>
  
  <pre><code>uniform sampler2DRect texture;
  const mat3 rgb2yiq = mat3(0.299, 0.587, 0.114, 0.595716, -0.274453, -0.321263, 0.211456, -0.522591, 0.311135);
  const mat3 yiq2rgb = mat3(1.0, 0.9563, 0.6210, 1.0, -0.2721, -0.6474, 1.0, -1.1070, 1.7046);
  uniform float hue;
  
  void main() {
  
  vec3 yColor = rgb2yiq * texture2DRect(texture, gl_TexCoord[0].st).rgb; 
  
  float originalHue = atan(yColor.b, yColor.g);
  float finalHue = originalHue + hue;
  
  float chroma = sqrt(yColor.b*yColor.b+yColor.g*yColor.g);
  
  vec3 yFinalColor = vec3(yColor.r, chroma * cos(finalHue), chroma * sin(finalHue));
  gl_FragColor    = vec4(yiq2rgb*yFinalColor, 1.0);
  }
  </code></pre>
  
  <p>And this is the result compared with a reference:</p>
  
  <p><img src="https://i.stack.imgur.com/iaNhR.jpg" alt="enter image description here"></p>
  
  <p>I have tried to switch I with Q inside atan but the result is wrong even around 0°</p>
  
  <p>Have you got any hint?</p>
  
  <p>If needed for comparison, this is the original unmodified image:
  <img src="https://i.stack.imgur.com/XNQDL.jpg" alt="enter image description here"></p>