How to fix the aspect ratio in VR...

The following code works for fixing the camera aspect ratio in non VR but it breaks when VR is in use (specifically an HTC Vive Pro Eye).

using UnityEngine;
public class CameraFixedAspectRatio : MonoBehaviour
{
    private Camera mainCam = new Camera();

    public float targetAspectRatio = 1f;
    private void Start()
    {
        mainCam = BackendResourceManager.Instance.mainCamera;
    }
   
    private void Update()
    {
        float w = Screen.width;
        float h = Screen.height;
        float a = w / h;
        Rect r;
        if (a > targetAspectRatio)
        {
            float tw = h * targetAspectRatio;
            float o = (w - tw) * 0.5f;
            r = new Rect(o,0,tw,h);
        }
        else
        {
            float th = w / targetAspectRatio;
            float o = (h - th) * 0.5f;
            r = new Rect(0, o, w, th);
        }
        mainCam.pixelRect = r;

    }
}

I’m building a simulation and need the x-resolution and y-resolution to match… Ideally, I’d like to only render an 800x800 screen to the headset. Is this possible? Thanks in advance!

Why do you want to “fix” the aspect ratio of the headset?
And also doing it in every frame.

You can’t AFAIK, but maybe you could use render textures?

I’m running a simulation of bionic vision and a limitation of the software we’re using to pre-calculate neuronal information is a fixed aspect ratio.

So you basically have some precalculated image data, and want to watch it in 3D. Why not just put it in a Texture at the size of choice in front of your camera in the scene? There are a lot of tutorials for viewing images on flat, or curved meshes.