2013-03-07 11:51:57 -07:00
|
|
|
void main()
|
2010-07-05 16:31:03 -06:00
|
|
|
{
|
2014-05-20 21:43:56 -06:00
|
|
|
//Changethis to increase the number of colors.
|
|
|
|
int numColors =8;
|
|
|
|
|
|
|
|
float4 to_gray = float4(0.3,0.59,0.11,0);
|
2014-07-29 11:08:57 -06:00
|
|
|
float x1 = dot(to_gray, SampleOffset(int2( 1, 1)));
|
|
|
|
float x0 = dot(to_gray, SampleOffset(int2(-1,-1)));
|
|
|
|
float x3 = dot(to_gray, SampleOffset(int2( 1,-1)));
|
|
|
|
float x2 = dot(to_gray, SampleOffset(int2(-1, 1)));
|
2014-05-20 21:43:56 -06:00
|
|
|
float edge = (x1 - x0) * (x1 - x0) + (x3 - x2) * (x3 - x2);
|
2014-07-29 11:08:57 -06:00
|
|
|
float4 color = Sample();
|
2014-05-20 21:43:56 -06:00
|
|
|
|
|
|
|
float4 c0 = color - float4(edge, edge, edge, edge) * 12.0;
|
|
|
|
|
|
|
|
float red = 0.0;
|
|
|
|
float green = 0.0;
|
|
|
|
float blue = 0.0;
|
|
|
|
bool rr = false;
|
|
|
|
bool bb = false;
|
|
|
|
bool gg = false;
|
|
|
|
int count = 1;
|
|
|
|
|
|
|
|
float colorN = 0.0;
|
|
|
|
float colorB = 0.0;
|
|
|
|
|
|
|
|
for (count = 1; count <= numColors; count++)
|
|
|
|
{
|
|
|
|
colorN = float(count / numColors);
|
|
|
|
|
|
|
|
if ( c0.r <= colorN && c0.r >= colorB && rr == false )
|
|
|
|
{
|
|
|
|
if (count == 1)
|
|
|
|
{
|
|
|
|
if (colorN >= 0.1)
|
2010-07-05 16:31:03 -06:00
|
|
|
red = 0.01;
|
|
|
|
else
|
|
|
|
red = colorN;
|
|
|
|
}
|
|
|
|
else if (count == numColors)
|
|
|
|
red = 0.95;
|
|
|
|
else
|
2014-05-20 21:43:56 -06:00
|
|
|
red = colorN;
|
|
|
|
|
2010-07-05 16:31:03 -06:00
|
|
|
rr = true;
|
|
|
|
}
|
2011-01-30 17:08:06 -07:00
|
|
|
|
2014-05-20 21:43:56 -06:00
|
|
|
if (c0.b <= colorN && c0.b >= colorB && bb == false)
|
|
|
|
{
|
|
|
|
if (count == 1)
|
|
|
|
{
|
2014-05-20 22:06:38 -06:00
|
|
|
if (colorN >= 0.1)
|
2010-07-05 16:31:03 -06:00
|
|
|
blue = 0.01;
|
|
|
|
else
|
|
|
|
blue = colorN;
|
|
|
|
}
|
|
|
|
else if (count == numColors)
|
|
|
|
blue = 0.95;
|
|
|
|
else
|
|
|
|
blue = colorN ;
|
2014-07-29 11:08:57 -06:00
|
|
|
|
2014-05-20 22:06:38 -06:00
|
|
|
bb = true;
|
2010-07-05 16:31:03 -06:00
|
|
|
}
|
2011-01-30 17:08:06 -07:00
|
|
|
|
2014-05-20 21:43:56 -06:00
|
|
|
if (c0.g <= colorN && c0.g >= colorB && gg == false)
|
|
|
|
{
|
|
|
|
if (count == 1)
|
|
|
|
{
|
2014-05-20 22:06:38 -06:00
|
|
|
if (colorN >= 0.1)
|
2010-07-05 16:31:03 -06:00
|
|
|
green = 0.01;
|
|
|
|
else
|
|
|
|
green = colorN;
|
|
|
|
}
|
|
|
|
else if (count == numColors)
|
2014-05-20 21:43:56 -06:00
|
|
|
green = 0.95;
|
2010-07-05 16:31:03 -06:00
|
|
|
else
|
2014-05-20 21:43:56 -06:00
|
|
|
green = colorN;
|
|
|
|
gg = true;
|
2010-07-05 16:31:03 -06:00
|
|
|
}
|
2014-05-20 21:43:56 -06:00
|
|
|
|
2014-05-05 14:59:49 -06:00
|
|
|
colorB = float(count / numColors);
|
2014-05-20 21:43:56 -06:00
|
|
|
|
2014-05-20 22:06:38 -06:00
|
|
|
if (rr == true && bb == true && gg == true)
|
2010-07-05 16:31:03 -06:00
|
|
|
break;
|
|
|
|
}
|
2011-01-30 17:08:06 -07:00
|
|
|
|
2014-07-29 11:08:57 -06:00
|
|
|
SetOutput(float4(red, green, blue, c0.a));
|
2014-05-05 14:59:49 -06:00
|
|
|
}
|