Code: Select all
sampler s0 : register(s0);
float4 p0 : register(c0);
float4 p1 : register(c1);
#define width (p0[0])
#define height (p0[1])
#define counter (p0[2])
#define clock (p0[3])
#define one_over_width (p1[0])
#define one_over_height (p1[1])
float3 rgb2hsv(float3 c)
{
float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
float4 p = lerp(float4(c.bg, K.wz), float4(c.gb, K.xy), step(c.b, c.g));
float4 q = lerp(float4(p.xyw, c.r), float4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
float3 hsv2rgb(float3 c)
{
float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * lerp(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
//Source: http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl
//Bounds for interpolation//
static float r_x_b[2]={0,1};static float r_y_b[2]={0,1};static float g_x_b[2]={0,1};static float g_y_b[2]={0,1};static float b_x_b[2]={0,1};static float b_y_b[2]={0,1};static float h_x_b[2]={0,1};static float h_y_b[2]={0,1};static float s_x_b[2]={0,1};static float s_y_b[2]={0,1};static float v_x_b[2]={0,1};static float v_y_b[2]={0,1};
static float2 r[3] = {
0, 0, // row 1; x,y
128,128,
255,255
};
static float2 g[3] = {
0, 0, // row 1; x,y
128,128,
255,255
};
static float2 b[3] = {
0, 0, // row 1; x,y
128,128,
255,255
};
static float2 h[7] = {
0, 0, // row 1; x,y
10,10,
120,128,
185,183,
294,302,
302,310,
360,360
};
static float2 s[3] = {
0, 0, // row 1; x,y
69,80,
100,100
};
static float2 v[4]= {
0, 0, // row 1; x,y
35,34,
77,84,
100,100
};
float red_map(float red){int i=0;int exact=0;for (i=0; i<34; i++) {if (r[i][0]/255 == red ){red=r[i][1]/255;exact=1;break;}else if (r[i][0]/255 < red && r[i][0]/255>r_x_b[0]){r_x_b[0]=r[i][0]/255;r_y_b[0]=r[i][1]/255;}else if(r[i][0]/255 > red && r[i][0]/255<r_x_b[1]){r_x_b[1]=r[i][0]/255;r_y_b[1]=r[i][1]/255;}}if(exact=0){red=red;}else{red=r_y_b[0] + (red-r_x_b[0])*((r_y_b[1]-r_y_b[0])/(r_x_b[1]-r_x_b[0]));}return red;}
// i < no. of rows
float green_map(float green){int i=0;int exact=0;for (i=0; i<34; i++) {if (g[i][0]/255 == green ){green=g[i][1]/255;exact=1;break;}else if (g[i][0]/255 < green && g[i][0]/255>g_x_b[0]){g_x_b[0]=g[i][0]/255;g_y_b[0]=g[i][1]/255;}else if(g[i][0]/255 > green && g[i][0]/255<g_x_b[1]){g_x_b[1]=g[i][0]/255;g_y_b[1]=g[i][1]/255;}}if(exact=0){green=green;}else{green=g_y_b[0] + (green-g_x_b[0])*((g_y_b[1]-g_y_b[0])/(g_x_b[1]-g_x_b[0]));}return green;}
// i < no. of rows
float blue_map(float blue){int i=0;int exact=0;for (i=0; i<34; i++) {if (b[i][0]/255 == blue ){blue=b[i][1]/255;exact=1;break;}else if (b[i][0]/255 < blue && b[i][0]/255>b_x_b[0]){b_x_b[0]=b[i][0]/255;b_y_b[0]=b[i][1]/255;}else if(b[i][0]/255 > blue && b[i][0]/255<b_x_b[1]){b_x_b[1]=b[i][0]/255;b_y_b[1]=b[i][1]/255;}}if(exact=0){blue=blue;}else{blue=b_y_b[0] + (blue-b_x_b[0])*((b_y_b[1]-b_y_b[0])/(b_x_b[1]-b_x_b[0]));}return blue;}
// i < no. of rows
// i < no. of rows
float hue_map(float hue) { int i = 0; int exact = 0; for (i = 0; i < 34; i++) { if (h[i][0] / 360 == hue) { hue = h[i][1] / 360; exact = 1; break; } else if (h[i][0] / 360 < hue && h[i][0] / 360 > h_x_b[0]) { h_x_b[0] = h[i][0] / 360; h_y_b[0] = h[i][1] / 360; } else if (h[i][0] / 360 > hue && h[i][0] / 360 < h_x_b[1]) { h_x_b[1] = h[i][0] / 360; h_y_b[1] = h[i][1] / 360; } } if (exact = 0) { hue = hue; } else { hue = h_y_b[0] + (hue - h_x_b[0]) * ((h_y_b[1] - h_y_b[0]) / (h_x_b[1] - h_x_b[0])); } return hue; }
float sat_map(float sat) { int i = 0; int exact = 0; for (i = 0; i < 34; i++) { if (s[i][0] / 100 == sat) { sat = s[i][1] / 100; exact = 1; break; } else if (s[i][0] / 100 < sat && s[i][0] / 100 > s_x_b[0]) { s_x_b[0] = s[i][0] / 100; s_y_b[0] = s[i][1] / 100; } else if (s[i][0] / 100 > sat && s[i][0] / 100 < s_x_b[1]) { s_x_b[1] = s[i][0] / 100; s_y_b[1] = s[i][1] / 100; } } if (exact = 0) { sat = sat; } else { sat = s_y_b[0] + (sat - s_x_b[0]) * ((s_y_b[1] - s_y_b[0]) / (s_x_b[1] - s_x_b[0])); } return sat; }
// i < no. of rows
float val_map(float val) { int i = 0; int exact = 0; for (i = 0; i < 34; i++) { if (v[i][0] / 100 == val) { val = v[i][1] / 100; exact = 1; break; } else if (v[i][0] / 100 < val && v[i][0] / 100 > v_x_b[0]) { v_x_b[0] = v[i][0] / 100; v_y_b[0] = v[i][1] / 100; } else if (v[i][0] / 100 > val && v[i][0] / 100 < v_x_b[1]) { v_x_b[1] = v[i][0] / 100; v_y_b[1] = v[i][1] / 100; } } if (exact = 0) { val = val; } else { val = v_y_b[0] + (val - v_x_b[0]) * ((v_y_b[1] - v_y_b[0]) / (v_x_b[1] - v_x_b[0])); } return val; }
// i < no. of rows
float4 main(float2 tex : TEXCOORD0) : COLOR {
float4 c0 = tex2D(s0, tex);
//c0.r=red_map(c0.r); //red
//c0.g=green_map(c0.g); //green
//c0.b=blue_map(c0.b); //blue
float3 colorHSV= rgb2hsv(c0.rgb);
colorHSV.x=hue_map(colorHSV.x); c0.rgb=hsv2rgb(colorHSV); colorHSV= rgb2hsv(c0.rgb); //hue
colorHSV.y=sat_map(colorHSV.y); c0.rgb=hsv2rgb(colorHSV); colorHSV= rgb2hsv(c0.rgb); //sat
colorHSV.z=val_map(colorHSV.z); c0.rgb=hsv2rgb(colorHSV); colorHSV= rgb2hsv(c0.rgb); //val
return c0;
}
http://www.framecompare.com/screenshotc ... n/WYD7NNNX
Shows you just how much green is in there...