Weird issue when setting Camera.backgroundColor = Color.clear

I’m trying to render an image to a texture and save it to disk. I don’t have Unity Pro so I’m using the poor man’s render to texture approach.

The problem comes when I’m setting the properties for the camera that will call the Render method manually. I set its clearFlags to CameraClearFlags.Color. If I set the backgroundColor to a color with no alpha, the image render as is. But if I set the backgroundColor to clear, the image conserves its transparent background but some fine details are lost. The image is drawn using Graphics.DrawTexture in the OnPostRender of an attached behaviour, using the GL.PushMatrix/GL.PopMatrix trick.

From left to right you can see the original image, the correctly rendered image but with a white background and the incorrectly rendered image (pink halo missing)


As always, It was a problem with Unity’s default shaders and their use of ColorMask RGB. Rolling out my own shader for performing the drawing fixed it.