cancel
Showing results for 
Search instead for 
Did you mean: 

Failed to use ReadPixels to capture the screenshot in Unity 2021.3.6 Vulkan

YanHong.0812
Honored Guest

Unity 2021.3.6
I want to implement the function of partial screenshots by the following method

 public static void SaveRenderTexture(RenderTexture rt, string folderName)
{
     var saveDir = Application.persistentDataPath + "/" + folderName + "/";
     if (!Directory.Exists(saveDir))
     {
         Directory.CreateDirectory(saveDir);
     }
     var prev = RenderTexture.active;
     RenderTexture.active = rt;
     var png = new Texture2D(rt.width, rt.height, TextureFormat.ARGB32, false);
     png.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
     var bytes = png.EncodeToPNG();
     var pathNow = saveDir + DateTime.Now.Ticks + ".png";
     var file = File.Open(pathNow, FileMode.Create);
     var writer = new BinaryWriter(file);
     writer.Write(bytes);
     file.Close();
     Object.DestroyImmediate(png);
     RenderTexture.active = prev;
 }

1. In the case of Vulkan, only half or part of the image that is packaged to Quset is displayed, and the rest is black, but this function is normal in editor mode.
2. Using OpenGLES3 can also display normally, but it will cause the rendering level of the rest of the model to be wrong, and some models are not displayed. The unity message "Symmetric Projection is only supported on Quest 2 and QuestPro with Vulkan and Multiview."

0 REPLIES 0