- Home /
VR: how to render gameobject in one eye only?
Back in the early days [TM] of 360º video in Unity we had to have two cameras and use layers to control which eye different gameobjects would render into. There have been considerable enhancements made and a lot of that happens under the hood now. I know I can manually make a stereo rig with two cameras and set their render eyes individually, but is there a way to set a gameobject to render in one eye or the other with the current XR setup using only one camera? Is this a shader-only thing?
Answer by OutOfRam · Jul 27, 2018 at 03:58 PM
Hello, Sadly there is no way to do this with the current single camera XR rigs, I have looked into this issue extensively for my own projects (even going so far as to directly ask the HTC people) and came up empty handed. The only way I know is the manual stereo rig, or shaders, which for the sake of anyone else who is looking for the solution i will also post here. If you are using the SteamVR cameraRig there is a fairly easy way to do this, however it is not completely bug free. You are going to want to add another camera to the rig as shown below. Camera (eye Left) will also contain a steamVR_Camera Component, and its regular camera component will be set to render to only the left eye. from there you can set to layers in your project RightEye and LeftEye and use the cameras individual culling masks to not render the respective layer
The downside to this, which shouldnt have any effect on the actual game but will make debuging a bit of a nightmare, is that while running a scene with this set up your console may be spammed with an error message saying something about an invalid Matrix. This can be ignored but can make it hard for you to find the real error messages to debug.
Does anyone have any experience with the shader approach? Is this as simple as adding an attribute or a flag to a regular shader, or does this require a totally specialized shader?
I absolutly suck at writing shaders, but if you have $20 you could check out this https://assetstore.unity.com/packages/vfx/shaders/fullscreen-camera-effects/vr-eye-shaders-88499
Answer by hawken · Aug 17, 2020 at 09:15 AM
if it is only for simple things, just set up two layers, "left" and "right" then make the left camera only see the left layer, right camera only see right. Only works in multipass, not single pass