| 1 |
void main() |
| 2 |
{ |
| 3 |
//Changethis to increase the number of colors. |
| 4 |
int numColors =8; |
| 5 |
|
| 6 |
float4 to_gray = float4(0.3,0.59,0.11,0); |
| 7 |
float x1 = dot(to_gray, SampleOffset(int2( 1, 1))); |
| 8 |
float x0 = dot(to_gray, SampleOffset(int2(-1,-1))); |
| 9 |
float x3 = dot(to_gray, SampleOffset(int2( 1,-1))); |
| 10 |
float x2 = dot(to_gray, SampleOffset(int2(-1, 1))); |
| 11 |
float edge = (x1 - x0) * (x1 - x0) + (x3 - x2) * (x3 - x2); |
| 12 |
float4 color = Sample(); |
| 13 |
|
| 14 |
float4 c0 = color - float4(edge, edge, edge, edge) * 12.0; |
| 15 |
|
| 16 |
float red = 0.0; |
| 17 |
float green = 0.0; |
| 18 |
float blue = 0.0; |
| 19 |
bool rr = false; |
| 20 |
bool bb = false; |
| 21 |
bool gg = false; |
| 22 |
int count = 1; |
| 23 |
|
| 24 |
float colorN = 0.0; |
| 25 |
float colorB = 0.0; |
| 26 |
|
| 27 |
for (count = 1; count <= numColors; count++) |
| 28 |
{ |
| 29 |
colorN = float(count / numColors); |
| 30 |
|
| 31 |
if ( c0.r <= colorN && c0.r >= colorB && rr == false ) |
| 32 |
{ |
| 33 |
if (count == 1) |
| 34 |
{ |
| 35 |
if (colorN >= 0.1) |
| 36 |
red = 0.01; |
| 37 |
else |
| 38 |
red = colorN; |
| 39 |
} |
| 40 |
else if (count == numColors) |
| 41 |
red = 0.95; |
| 42 |
else |
| 43 |
red = colorN; |
| 44 |
|
| 45 |
rr = true; |
| 46 |
} |
| 47 |
|
| 48 |
if (c0.b <= colorN && c0.b >= colorB && bb == false) |
| 49 |
{ |
| 50 |
if (count == 1) |
| 51 |
{ |
| 52 |
if (colorN >= 0.1) |
| 53 |
blue = 0.01; |
| 54 |
else |
| 55 |
blue = colorN; |
| 56 |
} |
| 57 |
else if (count == numColors) |
| 58 |
blue = 0.95; |
| 59 |
else |
| 60 |
blue = colorN ; |
| 61 |
|
| 62 |
bb = true; |
| 63 |
} |
| 64 |
|
| 65 |
if (c0.g <= colorN && c0.g >= colorB && gg == false) |
| 66 |
{ |
| 67 |
if (count == 1) |
| 68 |
{ |
| 69 |
if (colorN >= 0.1) |
| 70 |
green = 0.01; |
| 71 |
else |
| 72 |
green = colorN; |
| 73 |
} |
| 74 |
else if (count == numColors) |
| 75 |
green = 0.95; |
| 76 |
else |
| 77 |
green = colorN; |
| 78 |
gg = true; |
| 79 |
} |
| 80 |
|
| 81 |
colorB = float(count / numColors); |
| 82 |
|
| 83 |
if (rr == true && bb == true && gg == true) |
| 84 |
break; |
| 85 |
} |
| 86 |
|
| 87 |
SetOutput(float4(red, green, blue, c0.a)); |
| 88 |
} |