Screenshot turning some objects white

I have a problem that when I take a screenshot of the camera with the following script:

IEnumerator SaveScreen() {
        yield return new WaitForEndOfFrame();
		
        int width = Screen.width;
        int height = Screen.height;
        Texture2D tex = new Texture2D(width, height, TextureFormat.ARGB32, false);
		
        tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
        tex.Apply();

		// Encode texture into PNG
		var bytes = tex.EncodeToPNG();
		Destroy (tex);

		// For testing purposes, also write to a file in the project folder
		File.WriteAllBytes(Application.dataPath + "/../SavedScreen.png", bytes);
	}

Some objects turns white on the final image. Here is what I mean:
18190-savedscreen.png

The lower part which is a turret has Mobile/Diffuse shader, the tree has Nature/Tree Creator Leaves Fast for the leaves and Nature/Tree Creator Bark for the trunk.

Any Idea why do they turn out white on the rendered image? In game they look as they should, it’s only like this on the saved screenshot.

This is most likely occurring because the screen output also has an alpha channel, and that alpha channel is being included in your screenshot image. When you then view the image, the areas which had alpha values of less than maximum show as transparent, and areas with zero alpha show as white.

Some shaders output alpha information to the screen’s alpha channel, which is not normally visible when viewing the game - but when capturing the screen buffer to an image file, and then viewing in another app, the alpha channel information may be rendered as actual transparency. This is occuring with the shader that is drawing the trees in your scene.

The solution is to use a texture format which omits the alpha channel altogether (i.e. RGB24 rather than ARGB32). This means you will only encode the colour values and not the alpha channel information in your saved image. Or - has has been mentioned in a comment, the function “Application.CaptureScreenshot” provides a direct and easy way to put the image straight to a file, if your sole purpose is to capture a screenshot.