3
\$\begingroup\$

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?)

\$\endgroup\$
  • \$\begingroup\$ Using SteamVR or something else? \$\endgroup\$ – MichaelHouse Aug 10 '17 at 21:14
  • \$\begingroup\$ @MichaelHouse using Unity with the Oculus SDK \$\endgroup\$ – Phildo Aug 10 '17 at 21:17
  • \$\begingroup\$ 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? \$\endgroup\$ – jzx Aug 10 '17 at 23:54
  • \$\begingroup\$ @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. \$\endgroup\$ – Phildo Aug 11 '17 at 15:16
1
\$\begingroup\$

The best I've been able to come up with (not 100% perfect) is to just set the FOV of the render-to-texture cameras to be 96.5 (the main camera is set to 60). I just came up with this number experimentally. I'm not sure if under the hood it's just auto-setting the fov of the main to something similar to 96.5, but I can't find any hard info...

edit: Ok! I found hard info. Looks like it just auto-sets the fov of the main camera during runtime to exactly 96.01604. So, either set your render-to-texture cameras to that, or assign it at runtime from the main camera.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.