2013-09-23 05:15:01 +00:00
|
|
|
|
2016-10-04 13:16:57 +00:00
|
|
|
uniform sampler2D texture;
|
|
|
|
uniform mediump float hueAdjust;
|
2013-09-23 05:15:01 +00:00
|
|
|
|
|
|
|
varying vec2 v_texCoord;
|
|
|
|
|
2016-10-04 13:16:57 +00:00
|
|
|
/* Source: gamedev.stackexchange.com/a/59808/24839 */
|
|
|
|
vec3 rgb2hsv(vec3 c)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2016-10-04 13:16:57 +00:00
|
|
|
const vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
|
|
|
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
|
|
|
|
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2016-10-04 13:16:57 +00:00
|
|
|
float d = q.x - min(q.w, q.y);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2016-10-04 13:16:57 +00:00
|
|
|
/* Avoid divide-by-zero situations by adding a very tiny delta.
|
|
|
|
* Since we always deal with underlying 8-Bit color values, this
|
|
|
|
* should never mask a real value */
|
|
|
|
const float eps = 1.0e-10;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2016-10-04 13:16:57 +00:00
|
|
|
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + eps)), d / (q.x + eps), q.x);
|
|
|
|
}
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2016-10-04 13:16:57 +00:00
|
|
|
vec3 hsv2rgb(vec3 c)
|
|
|
|
{
|
|
|
|
const vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
|
|
|
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
|
|
|
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
|
|
|
}
|
2014-12-31 15:02:10 +00:00
|
|
|
|
2016-10-04 13:16:57 +00:00
|
|
|
void main ()
|
|
|
|
{
|
|
|
|
vec4 color = texture2D (texture, v_texCoord.xy);
|
|
|
|
vec3 hsv = rgb2hsv(color.rgb);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2016-10-04 13:16:57 +00:00
|
|
|
hsv.x += hueAdjust;
|
|
|
|
color.rgb = hsv2rgb(hsv);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2016-10-04 13:16:57 +00:00
|
|
|
gl_FragColor = color;
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|