Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Vr mode with mono camera

Discussion in 'AR/VR (XR) Discussion' started by JoseEDC, Jun 22, 2017.

  1. JoseEDC

    JoseEDC

    Joined:
    May 15, 2017
    Posts:
    8
    Hi there.

    Is it possible to enable Unity native VR mode for a given SDK (let's say cardboard) and render in mono mode (like in a non-vr app, with a single camera output across the screan instead the 'left-eye, right-eye' style).

    Specifically what I need for my app is to use the gyro input to rotate the camera but in a non-vr app. In the future I might need to change from non-vr to vr render mode.

    Regards
     
  2. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,094
    Code (CSharp):
    1. VRSettings.enabled = false;
    2. Camera.main.rotation = InputTracker.GetLocalRotation(VRNode.CenterEye);
    Something like that, look up the InputTracker class
    You should have the cardboard SDK loaded though in order for this to work.

    This is called magic window mode, this is somewhere written in the Unity manual under Google VR
     
    JoseEDC likes this.
  3. JoseEDC

    JoseEDC

    Joined:
    May 15, 2017
    Posts:
    8
    It works like a charm. Thanks!!
     
  4. JoseEDC

    JoseEDC

    Joined:
    May 15, 2017
    Posts:
    8
    Camera is rotating properly but something weird is happening when running from the handset. It seems to apply a kinda zoom (I guess decreasing FOV though setting a different FOV at runtime changes nothing) and it also distort the image. The funny thing is that if I lock the handset and then resume the application then camera is working nice, with no distortion neither zoom (see screen captures at the bottom)

    Any idea about what is happening and how it can be resolved?

    Before lock the app:





    As you can see the image is stretched across screen diagonal.

    After blocking and resuming:




    Now there is no zoom neither stretching
     

    Attached Files:

    Heykinox likes this.
  5. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,094
    You can try to fix it by resetting the camera matrix. Though Unity currently has quite some bugs in GVR.
    On iOS this rotation isn't even correct. In the app we're creating the Z axis gets rotated when entering VR etc.
    I've talked about it in some other thread as there are a lot of threads with ppl trying to get to use GVR right. But it is mostly because of bugs that things are not as developers want them to be. Would be nice if the bugs got fixed, ever since release of 5.6 native integration it has been buggy.
     
    Heykinox likes this.
  6. JoseEDC

    JoseEDC

    Joined:
    May 15, 2017
    Posts:
    8
    Thanks. I found that calling to 'camera.ResetAspect()' after setting VrSettings.enabled to false seems to set camera with the proper FOV and no distortion
     
    Heykinox likes this.
  7. fredsa

    fredsa

    Joined:
    May 31, 2015
    Posts:
    19
  8. Esera

    Esera

    Joined:
    Feb 20, 2017
    Posts:
    9
    Hi everyone, so I just found this and wanted to try it myself, 'cause I want a non-stereoscopic view with head tracking applied, but it doesn't work. The Video is "frozen" and I can't move around. Any ideas why this could be?
     
  9. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,094
    The magic window mode requires you to load the cardboard sdk
     
  10. Esera

    Esera

    Joined:
    Feb 20, 2017
    Posts:
    9
    Well, I installed the cardboard sdk.. Should I provide any screenshots? (from code??)
     
  11. Esera

    Esera

    Joined:
    Feb 20, 2017
    Posts:
    9
    Here's the code:

    Code (CSharp):
    1. public class test : MonoBehaviour {
    2.  
    3.     // Use this for initialization
    4.     void Start () {
    5.         VRSettings.enabled = false;
    6.         Camera.main.ResetAspect();
    7.         Camera.main.GetComponent<Transform>().localRotation = InputTracking.GetLocalRotation(VRNode.CenterEye);
    8.     }
    9.    
    10.     // Update is called once per frame
    11.     void Update () {
    12.        
    13.     }
    14. }

    Here are some Screenshots from my project:
     

    Attached Files:

  12. Esera

    Esera

    Joined:
    Feb 20, 2017
    Posts:
    9
    Nevermind. Problem solved by moving the code into the update method
     
    TerekhinDT likes this.
  13. Gabrielius-Krunkauskas

    Gabrielius-Krunkauskas

    Joined:
    May 28, 2015
    Posts:
    3
    Problem with this approach is before screen is loaded, view is stereoscopic, because changes happen only on Start or OnEnable methods. How can I disable stereoscopic view from the beginning? I don't want to use it at all.
     
  14. JoseEDC

    JoseEDC

    Joined:
    May 15, 2017
    Posts:
    8
    You can set 'None' as your first VR SDK in XR settings (VR Settings in older Unity versions) like this:

    upload_2018-2-8_11-54-8.png

    As Unity try to load a proper SDK for your available devices as ordered in the list it always will load 'None' so, when you launch your app, stereoscopic camera should be disabled (the same for any VR behaviour). From here you can set up the vr behaviour (stereo camera, head tracking...) at your will.

    Keep in mind that, at some point, you will need to load your VR SDK. This can be done with XRSettings.LoadDeviceByname (VRSettings.LoadDeviceByName in older unity)
     
    ilmario likes this.
  15. AlexTuduran

    AlexTuduran

    Joined:
    Nov 26, 2016
    Posts:
    27
    Being shot from just one perspective or 2 if in stereo, you can't really move around in a video, right? Rotating should not be a problem though.