I’m hoping someone can help with this shader I’ve modified/written. It was originally a radial blur shader that I’ve added some RGBtoHSV/HSVtoRGB code to. The idea is to cycle through the different colors over each iteration of a for loop that transforms the fragment in the x y of the texture coordinates. Basically with the end result is each layer of the image is a different hue. I’ve successfully been able to do RGB/HSV conversions but I can’t get the hue to change on each iteration. I’m hoping someone could take a look at my code and maybe point me in the right direction.
I’m trying to shift the hue in the line:
float hueChange = (Hue/360) + HueShift*(float(i)/(nSamples-1.0));
Here’s the whole fragment shader:
uniform sampler2D sInput1;
uniform float Hue;
uniform float Sat;
uniform float Value;
uniform float HueShift;
uniform float BlurStart;
uniform float BlurWidth;
uniform vec2 Center;
uniform float nSamples;
void main()
{
vec4 finalColor;
vec4 c = vec4(0.0);
vec3 grey= vec3(0.0);
vec4 color = vec4(0.0);
float alpha = 0.0;
for(int i=0; i<int(nSamples); i++)
{
float cMax, cMin;
float D;
float H, S, V;
float vR, vG, vB;
float dR,dG,dB;
float scale = BlurStart + BlurWidth*(float(i)/(nSamples-1.0));
c = texture2D(sInput1, gl_TexCoord[0].st*scale + Center);
//convert to single color
float luma = (0.3*c.r+0.59*c.g+0.11*c.b);
//float luma = max(c.r,max(c.g,c.b));
grey = vec3(luma);
if (luma > 0.0)
{
alpha = 1.0;
}
else
{
alpha = 0.0;
}
color += vec4(grey * vec3(1.0,0.0,0.0),alpha);
vR = color.r;
vG = color.g;
vB = color.b;
//gl_FragColor=color;
//return;
// convert to HSV
cMax = max(vR,max(vG,vB));
cMin = min(vR,min(vG,vB));
D = cMax - cMin;
V= cMax;
if (D == 0.0)
{
H = 0.0;
S = 0.0;
}
else
{
S = D/cMax;
dR = (((cMax-vR)/6)+(D/2))/D;
dG = (((cMax-vG)/6)+(D/2))/D;
dB = (((cMax-vB)/6)+(D/2))/D;
if (vR==cMax) H = dB-dG;
else if (vG==cMax) H = (1/3)+dR-dB;
else if (vB==cMax) H = (2/3)+dG-dR;
if (H<0) H += 1;
if (H>1) H -= 1;
}
float hueChange = (Hue/360) + HueShift*(float(i)/(nSamples-1.0));
H += hueChange;
S *= Sat;
V *= Value;
// convert to RGB
float R,G,B;
float vh,vi,vr,vg,vb,v1,v2,v3;
if (S == 0)
{
R = V;
B = V;
}
else
{
vh = H*6;
if (vh==6) vh=0;
vi = int(vh);
v1 = V * (1-S);
v2 = V * (1-S*(vh-vi));
v3 = V * (1-S*(1-(vh-vi)));
if (vi == 0) { vr = V ; vg = v3; vb = v1;}
else if (vi == 1) { vr = v2; vg = V ; vb = v1;}
else if (vi == 2) { vr = v1; vg = V ; vb = v3;}
else if (vi == 3) { vr = v1; vg = v2; vb = V ;}
else if (vi == 4) { vr = v3; vg = v1; vb = V ;}
else { vr = V ; vg = v1; vb = v2;}
R = vr;
G = vg;
B = vb;
finalColor= vec4(R,G,B,1.0);
}
}
finalColor /= nSamples;
gl_FragColor = finalColor;
}
Any help would be greatly appreciated.
Thanks
Keith