I used an own script instead of a precompiled shader because I wanted to modify it for my purposes. Another problem occured during the use of a shader, was to get access to static classes. It lags during playing and the execution of the sub.
void OnRenderImage (RenderTexture source, RenderTexture destination)
{
Texture2D texture = new Texture2D (source.width, source.height);
texture.ReadPixels(new Rect(0, 0, source.width, source.height), 0, 0);
//Using a texture2d for manipulation
for (int y = 0; y <= texture.height - 1; y++) //Iterating through all pixels
{
for (int x = 0; x <= texture.width - 1; x++)
{
Color C = texture.GetPixel (x, y);
var hue = ToHue (C); //Using a hue value to identity the color range
if (Content.Green == true)
{
if (hue >= 69 && hue <= 174)
{
continue;
}
}
else if (Content.Brown == true)
{
if (hue >= 0 && hue <= 60)
{
continue;
}
else if (hue == 359)
{
continue;
}
}
else if (Content.Red == true)
{
if (hue >= 0 && hue <= 16)
{
continue;
}
else if (hue >= 337 && hue <= 358)
{
continue;
}
}
else if (Content.Blue == true)
{
if (hue >= 187 && hue <= 254.8)
{
continue;
}
}
else if (Content.Violet == true)
{
if (hue >= 266 && hue <= 333)
{
continue;
}
}
else if (Content.Orange == true)
{
if (hue >= 5 && hue <= 39)
{
continue;
}
else if (hue == 359)
{
continue;
}
}
float gray = (C.r + C.g + C.b) / 3;
Color ColGray = new Color (gray, gray, gray);
texture.SetPixel (x, y, ColGray);
}
}
texture.Apply ();
Graphics.Blit(texture, destination); //Apply output change
}
public float ToHue(Color color)
{
float min = Math.Min(Math.Min(color.r, color.g), color.b);
float max = Math.Max(Math.Max(color.r, color.g), color.b);
float hue = 0f;
if (max == color.r)
{
hue = (color.g - color.b) / (max - min);
}
else if (max == color.g)
{
hue = 2f + (color.b - color.r) / (max - min);
}
else
{
hue = 4f + (color.r - color.g) / (max - min);
}
hue = hue * 60;
if (hue < 0)
{
hue = hue + 360;
}
return float.Parse(Double.Parse(hue.ToString()).ToString());
}