Search Unity

Camera viewport rect overwritten by SteamVR Plugin?

Discussion in 'AR/VR (XR) Discussion' started by lauchsuppe, Mar 20, 2017.

  1. lauchsuppe

    lauchsuppe

    Joined:
    Dec 6, 2014
    Posts:
    39
    Hey,

    I want to have a second Camera placed over my main camera that should only render a specific layer. This works fine, however, if I change my second camera's viewport rect ( I want it to be smaller than my main camera's), it won't have any effect when using my vive headset. It will still cover the whole screen just as if the viewport rect was (1,1)(1,1). Ironically, it shows up correctly in my Unity Editor's Game Window.
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,532
    What are you creating that extra camera to do? If it's for VR then you'll be rendering it multi pass stereo and be the wrong size, if it isn't then the matrix will never match up with anything happening through the Vive, so whats the use case?
     
  3. lauchsuppe

    lauchsuppe

    Joined:
    Dec 6, 2014
    Posts:
    39
    I want to create a small overlay window that would display additional objects in the scene - both text and 3d objects. The overlay window however should only make up a small portion (maybe 1/3 or 1/4) of the actual view. Somewhat similar to wearing a hololens.


    Would it be somehow possible to render the camera view from the game window (pre hmd) and place it onto a texture I could then use for getting the effect I'm looking for.
     
    Last edited: Mar 20, 2017
  4. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,532
    Yeah it sounds like a RenderTexture is what you may want. Make a new camera, setup the layer culling etc and toggle VR off, output to RT, push RT to a plane in worldspace.

    Keep in mind, sticking stuff to people's faces in VR is a bad idea.
     
  5. lauchsuppe

    lauchsuppe

    Joined:
    Dec 6, 2014
    Posts:
    39
    Yup, I just got it working this way!
     
  6. lauchsuppe

    lauchsuppe

    Joined:
    Dec 6, 2014
    Posts:
    39
    Okay, so the previously mentioned solution worked. However, since the 3D environment was projected on a 2D Plane floating in front of the player's eyes, positioning of the holograms was slightly inaccurate; especially if far away from the view center. It made for a cool effect but wasn't accurate enough for my purposes.

    What I came up with instead was using shaders to achieve a similar effect (but with reiable projection accuracy (because there was no projection involved). Instead of using multiple cameras and layers, I created 2 shaders: one for the hololens floating in front of the player's sight. And another one for objects (the holograms) which should only be displayed when looking through the hololens.
    It was actually pretty easy following this detailed yet simple explanation:
    http://answers.unity3d.com/questions/590800/how-to-cullrender-to-through-a-window.html

    I wanted to leave this here just in case anyone might ever stumble upon a similar problem.