Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  3. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

SteamVR - How to display content in left/right eye?

Discussion in 'AR/VR (XR) Discussion' started by iebaz, Apr 7, 2016.

  1. iebaz

    iebaz

    Joined:
    Apr 13, 2015
    Posts:
    9
    Question was:
    SteamVR - How to display content in left/right eye?

    Solution is:
    By manually adding a GameObject with the SteamVR_Render component on it to your scene, you can specify a left and right culling mask to use to control rendering per eye if necessary.
     
    Last edited: Apr 7, 2016
  2. getwilde

    getwilde

    Joined:
    May 4, 2016
    Posts:
    18
    When I look at the SteamVR_Render script, I see fields for External Camera and Tracking Space, etc, but I'm not seeing anything related to culling mask per eye. Can you provide more detail?

    UPDATE: I figured it out. See my reply below.
     

    Attached Files:

    Last edited: May 22, 2016
  3. getwilde

    getwilde

    Joined:
    May 4, 2016
    Posts:
    18
    Here's the solution (as of Unity 5.4.0b17, with SteamVR 1.1.0 plugin):

    1. Drag SteamVR "CameraRig" prefab onto the scene, per usual.
    2. Add two empty gameobjects to the scene. I named them CamLeft and CamRight, but they can be anything.
    3. Set both of them to the exact same coordinates in the scene.
    4. Add a SteamVR_Camera script component to each. I found it in SteamVR/Scripts/SteamVR_Camera.
    5. Create two new layers: "LeftEye" and "RightEye" (or equivalent)
    6. On the first object, in inspector, set Target Eye: Left, and Culling Mask: "LeftEye". Likewise on the second gameobject, set "Left" and "LeftEye"
    7. Ensure that whatever objects you want viewed with left or right eye are assigned to the appropriate layers, and at the same coordinates.
     
    Last edited: May 24, 2016
  4. slims

    slims

    Joined:
    Dec 31, 2013
    Posts:
    22
    I don't see Target Eye on the camera. There is only Target Display.

    EDIT: Nevermind, figured it out: you have to enable VR Supported to see that option on the camera.
     
  5. getwilde

    getwilde

    Joined:
    May 4, 2016
    Posts:
    18
    My "solution" posted above worked for about a day, but now I cannot get it to work without having two exception thrown, (one for each eye camera): "MissingComponentException: There is no 'Camera' attached to the "CamRight (head)" game object, but a script is trying to access it."
    Not sure what's going on...

    UPDATE: If the instructions above aren't working for you, see my next post for a solution. Good luck!
     
    Last edited: May 28, 2016
  6. getwilde

    getwilde

    Joined:
    May 4, 2016
    Posts:
    18
    For some reason the emptys that I created (as mentioned above) weren't instantiating(?) cameras at runtime. So here are updated steps:

    1. Drag SteamVR "CameraRig" prefab onto the scene, per usual.
    2. Add two empty gameobjects to the scene. I named them CamLeft and CamRight, but they can be anything.
    3. Set both of them to the exact same coordinates in the scene.
    4. Add a SteamVR_Camera script component to each. (I found the script in Assets/SteamVR/Scripts/SteamVR_Camera.)
    5. In the inspector, on the "SteamVR Camera" component you just added, click the "Expand" button. It ought to create three new nested objects in your scene: "CamLeft (origin) > CamLeft (head) > CamLeft (eye)". (See attached screenshot.)
    6. For some reason, the first time I click Expand, it only creates two objects and the third is missing. But clicking the same button a second time creates another set of objects with the correct hierarchy (and also causes my empty to disappear, which is fine). I then also deleted the incorrect "CamLeft (orig)" that only had one child.
    7. Repeat steps 5-6 for CamRight. Now you should have your two cameras set up correctly.
    8. Create two new layers: "LeftEye" and "RightEye" (or equivalent)
    9. In Heirarchy, drill down to the "CamLeft (eye)". In inspector, set Target Eye: Left, and in Culling Mask, untick "RightEye" Do the equivalent for "CamRight (eye)" with opposite values.
    10. Ensure that whatever objects you want viewed with left or right eye are assigned to the appropriate layers, and are positioned the same coordinates.

    In the end, your hierarchy ought to look like the attached screenshot. Good luck!
     

    Attached Files:

    Last edited: May 28, 2016
    AlexSbysh and laurachen like this.
  7. slims

    slims

    Joined:
    Dec 31, 2013
    Posts:
    22
  8. slims

    slims

    Joined:
    Dec 31, 2013
    Posts:
    22
    I figured it out, I just had to also add a steam vr camera object to my skybox camera. I could then set the camera rig's eye camera to depth only and use proper layering.
     
  9. Carl007

    Carl007

    Joined:
    Jan 27, 2014
    Posts:
    1
    Getwilde, you are the light of my day with this solution. Anyway, I did not get it to work, perhaps you can share a working Unity file with this configuration? I must inform that I am a newbie in Unity development.

    Well Thanks again. It works if I use beta build 5.4!
     
    Last edited: Jun 10, 2016
  10. vicator

    vicator

    Joined:
    Oct 12, 2014
    Posts:
    27
    Doing this makes the gameobject that i've added a steam vr camera to to rotate with the head. Any way to disable this?
     
  11. Stankiem

    Stankiem

    Joined:
    Dec 4, 2013
    Posts:
    115
    I am really struggling with this also. Where in the hierarchy is you skybox camera located? Is it a child to the Camera(eye) object?

    Also whenever I have a second SteamVR Camera attached to any camera in the scene the editor won't run the game.
     
  12. MrMetwurst2

    MrMetwurst2

    Joined:
    Jul 16, 2009
    Posts:
    253
    Thankyou so much.
    I tried doing this directly on the rig and it kept crashing.
    I don't know why it works this way but it does. Thanks again :)
     
  13. Deleted User

    Deleted User

    Guest

    Sorry, what do you mean by "create two new layers"?
     
  14. Selzier

    Selzier

    Joined:
    Sep 23, 2014
    Posts:
    644
  15. HappyGoCrazee

    HappyGoCrazee

    Joined:
    May 16, 2017
    Posts:
    3
    It seems like adding in the [CameraRig] to your scene initially doesn't really do anything. Once the process of setting up the two new cameras is complete, it seems redundant, as disabling still allows everything to work properly. Am I missing something, or is it not needed?
     
  16. sylvie_

    sylvie_

    Joined:
    Mar 14, 2017
    Posts:
    1
    I followed these steps but only 1 cam, CamLeft (GameObject) is shown, Even in the Hierarchy, CamLeft is placed after CamRight. I think it's overriden. Still stuck with it.
    Also my GameObject not only have this --> "CamLeft (origin) > CamLeft (head) > CamLeft (eye)", but there was also (ear), so I deleted it. Is it okay ?
     
  17. MaeL0000

    MaeL0000

    Joined:
    Aug 8, 2015
    Posts:
    35
    Does anybody know if you can do this without enabling native virtual reality support? I'm building an overlay only app targeting openvr and afaik I have to disable unity's native openvr support to be able to do this, but I've gotten to a point where I need to hide certain layers for each eye.

    Edit: Just to be clear, if you don't enable native vr support there is no Target Eye field in the Camera component mentioned above, rendering the previous advice unusable.
     
  18. gprime0

    gprime0

    Joined:
    Sep 29, 2020
    Posts:
    2
    Hey guys,
    Sorry for bumping up an old thread but I don't have permission to make a new one.

    I'm looking to do the same thing and I'm trying to create an app for my Oculus Quest.

    As the most basic level I want the left eye to see a blue cube where the right eye sees a red one.

    I've been in successful in having separate left/right eye content if I use the OVRPlayerController/OVRCameraRig style projects because it has distinct cameras and I can easily separate the content through layers.

    However, newer tutorials mention that we should be using the "XR" style collections now, such as the "XR Rig". These seem much nicer to work with, but I cannot for the life of figure out how to create separate left/right eye content because it seems to just be a single camera.

    Things I've tried:

    1) Creating multiple cameras (each targetting just one eye) as children to a parent object and binding that parent object to the XR Rig. This was a fail. It seems any camera that doesn't target "both" eyes doesn't work at all.

    2) Creating a custom shader to apply a different material, depending on the eye. I looked at some old shaders as a baseline and apparently a lot of events are no longer triggered (such as OnPreRender) in modern versions of Unity (or maybe because of XR?). It makes it not possible to distinguish between the left/right eye content. So this was a bust as well.

    Is there anything else I can try? I'm OK with getting a little advanced if that's what it takes. Worst case I can stick with the older "OVR" style objects.

    Thank you!

    John
     
  19. gprime0

    gprime0

    Joined:
    Sep 29, 2020
    Posts:
    2
    So, I finally got something working with the single camera XR Rig. I read through so many different posts about people trying to solve this issue and most of the answers were "Well that's not supported yet, but you can probably create a shader", but no one seemed to be able to point to one. I don't really know anything about shaders but I scraped something together and attached it here. It's extremely simple but it works for the use-case outlined in my previous post.

    Also attached a screenshot of the shader parameters. You can attach a different texture to each eye and also set the opacity of each eye. If you want to show two completely different objects for each eye, you can basically just set one of the opacity to 0 for the eye that you don't want to see it, and then do the same for the other eye.

    Hope this helps someone.

    John
     

    Attached Files:

    Last edited: Sep 30, 2020
    dtaddis likes this.
unityunity