This is some simple GLSL hue shift shader i wrote for TDC, it has some additional stuff for alpha opacity control and it uses uniforms to specify hue shift and alpha control values.
Code:
// This source code contains modified/translated code
// from Jedi Component Library, which is used under terms of MPL - Mozilla Public License.
// Portions of this source code are based on online mathematical formulas from easyrgb website:
// http://www.easyrgb.com/math.php?MATH=M19#text19
// This is a simple hue shift fragment shader with alpha color component control.
uniform sampler2D Texture1;
uniform float AddHue, AddSat, AddLit;
uniform float ShadeMode;
float Hue_2_RGB(float v1, float v2, float vH )
{
float result;
if ( vH <0> 1.0 ) vH -= 1.0;
if ( ( 6.0 * vH ) < 1.0 ) { result = ( v1 + ( v2 - v1 ) * 6.0 * vH ); }
else if ( ( 2.0 * vH ) < 1.0 ) { result = ( v2 ); }
else if ( ( 3.0 * vH ) <2> 0.0 )
{
gl_FragColor = vec4(0,0,0, (color.a * ShadeMode) );
}
else
{
R = color.r;
G = color.g;
B = color.b;
// properly process white color which cannot be properly converted to hsl and back (ends up black)
if ((R == 1.0) && (G == 1.0) && (B == 1.0))
{
gl_FragColor = vec4(color.r, color.g, color.b, color.a);
}
else
{
// convert to HSL
Cmax = max (R, max (G, B));
Cmin = min (R, min (G, B));
// calculate lightness
L = (Cmax + Cmin) / 2.0;
if (Cmax == Cmin) // it's grey
{
H = 0.0; // it's actually undefined
S = 0.0;
}
else
{
D = Cmax - Cmin;
}
// calculate Saturation
if (L < 0.5)
{
S = D / (Cmax + Cmin);
}
else
{
S = D / (2.0 - Cmax - Cmin);
}
// calculate Hue
if (R == Cmax)
{
H = (G - B) / D;
}
else
{
if (G == Cmax)
{
H = 2.0 + (B - R) /D;
}
else
{
H = 4.0 + (R - G) / D;
}
}
H = H / 6.0;
if (H < 0.0)
{
H = H + 1.0;
}
// modify H/S/L values
H += AddHue;
S += AddSat;
L += AddLit;
// convert back to RGB
float var_2, var_1;
if (S == 0.0)
{
R = L;
G = L;
B = L;
}
else
{
if ( L < 0.5 )
{
var_2 = L * ( 1.0 + S );
}
else
{
var_2 = ( L + S ) - ( S * L );
}
var_1 = 2.0 * L - var_2;
R = Hue_2_RGB( var_1, var_2, H + ( 1.0 / 3.0 ) );
G = Hue_2_RGB( var_1, var_2, H );
B = Hue_2_RGB( var_1, var_2, H - ( 1.0 / 3.0 ) );
}
gl_FragColor = vec4(R,G,B, color.a);
} // white color check
} // not shadow mode
}
Bookmarks