Unity- how to render-to-texture with VR distortion

I've also asked the question here http://answers.unity3d.com/questions/1392099/how-to-set-a-render-to-texture-camera-to-be-a-vr-c.html (but it's currently "under moderation")

So, I want to do some post processing effects in VR. I put a camera as a child of the Main Camera and set it to render-to-texture. Then, I take what is rendered, and display it (with my post-proc shader) on a quad in front of the Main Camera (The main camera and the child camera render different layers, so I don't render the same thing twice). (Also worth noting- I know that the depth will be collapsed out of the rendered-to-texture content; this is intentional.) The problem is, in this process, the positional data (that was rendered to texture) gets misaligned.

I've already fixed a problem where I have to manually set camera_project.GetComponent<Camera>().aspect = main_camera.GetComponent<Camera>().aspect; every frame. (Changing/setting the screen size auto sets the aspect ratio of the main camera- it does not automatically set the aspect ratio of the child camera.

So, with just that, everything lines up great and looks fine when it isn't in VR. But, when it is in VR, it appears that maybe some distortion is happening to the main camera that isn't happening to the render-to-texture camera, and thus, the overlay (the post-proc'd content) isn't lining up.

So what can I do to emulate the VR distortion in the child camera? Are there other properties of the Main Camera that are getting auto-set in VR that I can manually copy to the Main Camera? (I also noticed that aspect wasn't listed in the camera documentation [https://docs.unity3d.com/Manual/class-Camera.html] unless you knew to search for it explicitly, so I think it might be likely there is some other property I'm missing?)

• Using SteamVR or something else? – MichaelHouse Aug 10 '17 at 21:14
• @MichaelHouse using Unity with the Oculus SDK – Phildo Aug 10 '17 at 21:17
• Are you referring to the slight curve VR rendering has? The one that's there to compensate for the distortion the VR lenses introduce? Also, are you aware of the Post-processing stack? – jzx Aug 10 '17 at 23:54
• @jzx I think so? But I'm not sure. All I know is I'm rendering two things from two cameras with (afaik) the same exact perspective, but the rendered contents don't perfectly line up when in VR. So, if there were something unity were doing under the hood explicitly to the Main Camera (and no other cameras) when in VR (like applying the slight curve), that would explain it. So any steps to either 1. List my other camera as "a vr camera" or 2. manually reproduce the effect via a shader, should solve this. and I wasn't aware of pps, but need this functionality for other purposes as well anyways. – Phildo Aug 11 '17 at 15:16