Getting major Performance issues when Loading Large 2D images into a unity project on the Vive.

Hi Guys so I am developing a project for the Vive that makes heavy use of 2D sterescopic images. We are porting the project from the Gear VR into The vive and yet somehow our performance On the vive and PC is far far worse than the performance was on GearVR and the PC used to develop with it . We considered maybe it was a Hardware issue but unfortunately we tested it on another vive-compatible PC and ran into comparable issues.

Here is a snippet of the code we use to load the images for one of the eyes

 string[] leftShutterPath = PathConstructer.GetSpinPaths(index * 10, 1, 1, Downloader.CurrentIDEntry, true);
            //Debug.Log("Left Eye Path: " + leftShutterPath[0]);
            //leftShutter.texture = PortalCache.LoadImageFromCache(downloader.DownloaderImageLibrary.leftSpinPaths[index]);
            Texture2D leftTex = new Texture2D(2, 2);
            leftTex.LoadImage(File.ReadAllBytes(leftShutterPath[0]));
           
            leftShutter.texture = leftTex;

The core of the issue is that when we update the image being rendered the Vive Briefly exits the Program into the Main blue Vive room and then upon the finished load reenters the Actual in-engine scene . We ran it through the profiler and the issue is definitely occurring during rendering however I’m at a loss on whether or not it’s this actual image loading code that’s causing issues ( because we use it several other places in our GearVR app with no issue) or the actual project itself. Any and all advice on this is appreciated. Thank you very much !

using Texture2D.LoadImage with a large texture could cause freezes due to the fact it has to upload it to the GPU. This doesn’t happen async.
work arounds for this are using Asset Bundles to load the image(s), use a preformatted image (DXT for example) and load it through the Texture2D.LoadRawTextureData (though the size of the file may expand quite a lot) or last but not least use the Resources.LoadAsync to load it from the resources folder.

1 Like

Thank you very much I’m going to try loading from Resources That’ something I hadn’t even thought of .

Thanks again MaskedMouse that was definitely the source of my issues . Loading Asynchronously absolutely removed the performance issues.

1 Like

Glad I could help :slight_smile:

If you use Resources.LoadAsync don’t forget to use Resources.Unload(textureReference) to unload it from memory when it is not needed anymore.

1 Like