2013-09-23 05:15:01 +00:00
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
uniform sampler2D inputTexture;
|
2013-09-23 05:15:01 +00:00
|
|
|
uniform float hueAdjust;
|
|
|
|
|
|
|
|
varying vec2 v_texCoord;
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
void main ()
|
|
|
|
{
|
|
|
|
const vec4 kRGBToYPrime = vec4 (0.299, 0.587, 0.114, 0.0);
|
2013-09-23 05:15:01 +00:00
|
|
|
const vec4 kRGBToI = vec4 (0.596, -0.275, -0.321, 0.0);
|
|
|
|
const vec4 kRGBToQ = vec4 (0.212, -0.523, 0.311, 0.0);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
const vec4 kYIQToR = vec4 (1.0, 0.956, 0.621, 0.0);
|
|
|
|
const vec4 kYIQToG = vec4 (1.0, -0.272, -0.647, 0.0);
|
|
|
|
const vec4 kYIQToB = vec4 (1.0, -1.107, 1.704, 0.0);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
/* Sample the input pixel */
|
|
|
|
vec4 color = texture2D (inputTexture, v_texCoord.xy);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
/* Convert to YIQ */
|
|
|
|
float YPrime = dot (color, kRGBToYPrime);
|
|
|
|
float I = dot (color, kRGBToI);
|
|
|
|
float Q = dot (color, kRGBToQ);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
/* Calculate the hue and chroma */
|
2013-09-01 14:27:21 +00:00
|
|
|
float hue = atan (Q, I);
|
|
|
|
float chroma = sqrt (I * I + Q * Q);
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
/* Make the user's adjustments */
|
2013-09-01 14:27:21 +00:00
|
|
|
hue += hueAdjust;
|
|
|
|
|
|
|
|
// Convert back to YIQ
|
|
|
|
Q = chroma * sin (hue);
|
|
|
|
I = chroma * cos (hue);
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
/* Convert back to RGB */
|
|
|
|
vec4 yIQ = vec4 (YPrime, I, Q, 0.0);
|
|
|
|
color.r = dot (yIQ, kYIQToR);
|
|
|
|
color.g = dot (yIQ, kYIQToG);
|
|
|
|
color.b = dot (yIQ, kYIQToB);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
/* Save the result */
|
|
|
|
gl_FragColor = color;
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|