Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How To Show Different Content for Left and Right Eyes of Oculus Quest 2 With OpenXR?

Discussion in 'VR' started by GerenMeric, Aug 11, 2023.

  1. GerenMeric

    GerenMeric

    Joined:
    May 15, 2023
    Posts:
    47
    Hi everyone,

    I want to see different canvases inside left and right eyes (displays) of the Oculus Quest 2. I have created two identical canvases called left canvas (which is want it to be shown in left eye) and right canvas (which is want it to be shown in right eye) with only difference left one has a text that it tells it's the left canvas. Then, i have added an XR Origin and duplicated them so that they are in the exact same place just like canvases. Then, created 2 layers. One for left eye and one for right eye and set layers of canvases and culling masks of cameras accordingly. But, i couldn't find left and right targeting eye options and currently i can only see left canvas on the Oculus Quest 2 in Unity's playmode. Here is the camera settings when i select targeting eye of both left and right cameras:


    This is the left camera:




    And this is the right camera:





    Here is my left canvas settings:





    Here is my right canvas settings:





    After setting canvases and cameras and testing them in playmode, i wrote a code for doing
    Debug.Log()
    for both cameras and here are the result for both cameras:




    Is it impossible to show different things for each eye using OpenXR? Can i use a single camera with targeting on "Both" and render left and right eyes at the same time into left and right halfs of the camera view?
     
    Last edited: Aug 11, 2023
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,362
  3. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,362
    You can try, but you might be locked to legacy VR systems.
    I have no experience with those, so can't say much about it.

    I'd try the shader approach if possible
     
    GerenMeric likes this.
  4. GerenMeric

    GerenMeric

    Joined:
    May 15, 2023
    Posts:
    47
    Just tried to open the project with 2018.1.6.f1 and Unity have crashed. What about the shader approach? Does shaders have effect on entire canvas o should i apply the shader to each GUI element (i am asking since i am a complete beginner in shaders)
     
    Last edited: Aug 11, 2023
  5. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,362
    I sent a link to the shader graph implementation.

    And you need to start a fresh project in 2018 if you want to use it. Downgrading is not supported
     
    GerenMeric likes this.
  6. GerenMeric

    GerenMeric

    Joined:
    May 15, 2023
    Posts:
    47
    Thanks. Just checked on Oculus Integration. Is it true that it can work without any issues with Oculus XR Plugin, OpenXR Plugin, XR Interaction Toolkit and XR Interaction Manager? And that the only thing i need to do is to switch XR Origin with OVRCameraRig? (My concern was if i was going to change eveything about input when using OVR instead of OpenXR)
     
    Last edited: Aug 11, 2023
  7. GerenMeric

    GerenMeric

    Joined:
    May 15, 2023
    Posts:
    47

    Thanks for the link you have sent, i just removed URP from my project and it worked. Now, i can select target eye for my both cameras (even though i stayed on XR and didn't switch to OVR) and see different canvases without even setting and assigning layers in 2021.3.25f1 (LTS). Thanks again for all the advice and suggestions you have offered.
     
  8. Deltigre

    Deltigre

    Unity Technologies

    Joined:
    Sep 13, 2022
    Posts:
    30
    If you would prefer to use URP, this is something I played with in a personal project a little. In my example, I had a custom shader graph that used an input texture where the Red channel was the multiplier for the left eye and the Green channel was the multiplier for the right eye. I used this as a custom node in a shader graph:
    Code (csharp):
    1.  
    2. #ifndef VRVT_VR_STEREO_MASK
    3. #define VRVT_VR_STEREO_MASK
    4.  
    5. void StereoMask_float(float RightMask, float LeftMask, out float Mask) {
    6.     if (unity_StereoEyeIndex == 0) {
    7.         Mask = LeftMask;
    8.     } else {
    9.         Mask = RightMask;
    10.     }
    11. }
    12.  
    13. #endif
    14.  
    The important bit is that you can do something like set output color alpha to zero when the eye ID (unity_StereoEyeIndex) doesn't match the eye you want. I believe 0 is typically left, 1 typically is right.
     
    GerenMeric likes this.
  9. GerenMeric

    GerenMeric

    Joined:
    May 15, 2023
    Posts:
    47

    Sorry for my tardiness. Thanks for the advice and sharing the custom node you have used.