However, I would like to replace a certain color (greenscreen) with transparency. So that the resulting picture would have greenscreen replaced with transparency.
An example screen of the picture where I am trying to convert green to transparent:
I tried using a for loop:
foreach (Color pxl in screenShot.GetPixels())
{
if (pxl.r == 0 && pxl.g == 1 && pxl.b == 0)
{
Debug.Log("True"); // Replace this with changing to alpha.
}
}
This however froze Unity as it is too slow for a picture with resolution 1920x1080.
Setting the camera’s background color to transparent, or Culling to depth does make the background transparent in Unity. However, a black color still remains in the resulting image file.
I got it working in a sense that I can take screenshots. I had to change the Texture2D-s format to ARBG32.
When taking a screenshot, my camera’s clear flag is set to Depth only. This means when taking pictures there’s a black background, which is registered as transparent. The shader in the link you gave me simply makes the item white. However I see that it does help with removing the 1 pixel edge. Even if just a little bit.
However, when taking a screenshot, I get a 1 pixel black edge (with a standard shader). The result can be seen here: ScreenShot
I would need to remove the 1 pixel black border. Any ideas on how to do that?