uniform vec3 hsv;
uniform sampler2D texture;

vec3 shift_col(vec3 rgb, vec3 hsv)
{
    vec3 result = vec3(rgb);
    float vsu = hsv.z*hsv.y*cos(hsv.x*3.14159265/180.0);
    float vsw = hsv.z*hsv.y*sin(hsv.x*3.14159265/180.0);

    result.x = (.299*hsv.z + .701*vsu + .168*vsw)*rgb.x
            + (.587*hsv.z - .587*vsu+.330*vsw)*rgb.y
            + (.114*hsv.z - .114*vsu - .497*vsw)*rgb.z;
    result.y = (.299*hsv.z - .299*vsu - .328*vsw)*rgb.x
            + (.587*hsv.z + .413*vsu + .035*vsw)*rgb.y
            + (.114*hsv.z - .114*vsu + .292*vsw)*rgb.z;
    result.z = (.299*hsv.z - .3*vsu + 1.25*vsw)*rgb.x
            + (.587*hsv.z - .588*vsu - 1.05*vsw)*rgb.y
            + (.114*hsv.z + .886*vsu - .203*vsw)*rgb.z;
    return result;
}

void main(void)
{
    vec4 color = texture2D(texture, gl_TexCoord[0].st);
    gl_FragColor = vec4(shift_col(color.rgb, hsv), gl_Color.a * color.a);
}
