Search Unity

Multiple Layered Cameras with Varying FOVs in VR (Oculus with VRTK)

Discussion in 'AR/VR (XR) Discussion' started by krougeau, Apr 27, 2018.

  1. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    I'm having a bit of trouble wrapping my head around just how to accomplish something in VR that would be fairly straight forward in most other Unity projects and am hoping someone out there can assist me in finding a solution.

    In short, I'm creating an outer space environment and want to have multiple cameras setup with varying FOVs (on varying layers) to make distant objects (suns, planets, etc.) appear larger in the main camera view than they really are.

    I have this working in a non-VR test scene just fine, but can't replicate it in VR because the FOVs on all cameras are being systematically overridden to the hardcoded FOV settings that Oculus have implemented.

    It was suggested by a VRTK user that I might change the "Target Eye" of my additional cameras and then somehow use Graphics.Blit() to send information from the additional overlay cameras to the main VR camera. I've tried a few ways myself but can't seem to get my brain around the proper workflow and am not entirely sure I'm going about things the right way.

    If any of you would be so kind as to point me in the correct direction, I'd certainly appreciate it. If I can supply any additional information, please let me know! Thanks :D
     
    Last edited: Apr 27, 2018
  2. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    I have the very same problem with my Vive and SteamVR, and it's a total blocker. Not every camera is the hmd, Unity devs!!

    You might just try resizing your scaled space so the apparent size matches? I've done this to render faraway planets in the background, I just left them at scale space size but scaled their positions closer/further from the scale space camera. I've not yet put in any rigorous testing to see if it holds up to real scrutiny, but it looks ok if you just need a massive planet as a backdrop. I am very interested in hearing what others are doing!

    I also think my HUD, which depends on render textures and an orthographic camera is going to be broken, too.
     
  3. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Hi Innovine,

    Thanks for responding! I know the FOV lock was put in place with the best of intentions (primarily to keep us from making our users ill with poorly chosen settings), but I think they failed to realized that a lot of "fixes" and "workarounds" out there require us to make use of those settings. Not having access to alter these settings makes it cumbersome to overcome what would usually be fairly trivial limitations in Unity. From the looks of things, Oculus is at least considering opening the values up to us in a future release. In the meantime, I've got to find a workaround for a workaround. Grr! :/

    I appreciate your suggestion, as well, and will try tinkering with altering the scale and position of the objects in question. I can see how this might achieve the desired effect, but am not sure I'm thinking the logic through correctly. I presume I'd want to render "distant" planets close up to a 2nd camera until the player reaches a certain point near them, then move them away from the player and scale their size up, repeating as needed until the player is actually in range of the planet (which, in my case, can be landed on, explored, etc.). If I'm thinking about it all wrong, please do let me know! :)

    As for the HUD elements, I think you'll be alright for the most part, so long as you don't intend the additional cameras to use varying FOVs or anything else the SDKs have locked out. I've seen a few tutorials on VR HUD design and they're all using secondary cameras and render textures set to cull various layers.

    Thanks again!
    - Ken

    ETA: Looking into this Oculus feature as a potential workaround for my issue. Head is fairly swimming already though and it's not making a lot of sense to me. Still, something else to tinker with, I suppose... https://developer.oculus.com/documentation/unity/latest/concepts/unity-ovroverlay/
     
    Last edited: Apr 27, 2018
  4. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    I'm working towards this myself, and don't have all the details worked out yet.
    But from a few experiments and tests I can say the following.
    If you just want to have a large planet in the background, it works fine to make a really small one, and put the scale space camera closer or further away, so it fills the appropriate amount of the scale space camera frustum, then you just layer the cameras and presto you have a gigantic planet in the background.
    To transition out of scale space, our solutions vary a bit. When I get to within a certain distance, I deactivate the scale space model (and/or camera) and just activate the real model (visible by the standard camera) with its LODs and so on. In my tests, this was millions of units away from the player, so instead of increasing the view distance of the main camera, i actually use two cameras simultaneously, one for very close range (e.g. 2km) and one for far range (2km to millions of km).
    As I fly towards it, I've been using Planetary Terrain which is a quadtree planet terrain generator so I can go right down to the surface, so its generating more polys all the time as I get closer. I do have a bit of a jerk in the scale space to real space transition which I need to work on, and not having control of the FOV here certainly does not help.

    Here's hoping. It's been a while since I looked at that, but I think I had the camera orthographic, or with a really narrow FOV to prevent distortion. Hopefully it will work.
     
  5. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Thanks again Innovine! :) Sounds like this is just the starting point I needed. Oddly, it's one I'd tried before deciding to use the multi FOV trick, but couldn't quite sort out how to get it working properly as I was using someone elses example code (see video).



    Now that I have a better idea of just what I want happening where, I can most likely dissect that same code and retool it to work with my setup (which I'm retooling anyway since I've decided keeping the player locked at (0, 0, 0) will likely be less jerky than shifting everything in the scene every few km (it's not terribly noticeable unless I'm firing Trail Renderer lasers or if I'm traveling at "warp" speed, which really freaks things out a bit haha).

    I'll have my fingers crossed for you on the UI elements! :D Pretty sure that if they're set to World Space you can put 'em just about anywhere you want, any way you want, minus altering the FOV of course. I've only tinkered a bit with standard Unity UI stuff in VR so far, and almost nothing HUDwise other than a simple crosshair in the center of the player view (which I'll eventually constrict to the front cockpit window... sooner or later... definitely maybe...).

    Since we're working with projects along similar lines, feel free to drop me a line if you ever need to bounce ideas or problems off of someone. I'm no great shakes, but I have my moments. :p