Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to change Field of View in VR?

Discussion in 'AR/VR (XR) Discussion' started by TOES2, Jan 19, 2017.

  1. TOES2

    TOES2

    Joined:
    May 20, 2013
    Posts:
    135
    In my company's GearVR project we use a panorama background texture, wrapped to a sphere. It looks OK when the panorama scene is far away, like a typical skybox.

    However, we also need to support panorama backgrounds of close environments, such as the inside of a car. What happens with the default FoV setting is that everything looks grossly scaled up, and you get an unrealistic claustrophobic scene that is far from a presentable result.

    To fix this issue, we can normally just change the cameras FoV. In the example of a car interior, we would need to increase it. Normally, setting the vertical field of view can be achieved by:

    Camera.main.fieldOfView=x;

    But when running the app on the GearVR device after enabling VR in Unity, this setting is ignored.

    In the Unity manual

    https://docs.unity3d.com/Manual/VROverview.html

    The Unity team states "You can manually set the FoV to a specific value". But how?

    After searching around for an answer, I could not find anything concrete. There is mention about this being possible after unity 5.3, also some speak of some internal Oculus settings that you might be able to get at. However, I can not find any single functional example on how to change the FoV through Unity / GearVR.

    If we cannot change the FoV, we have to can the whole project. Which will carry a huge cost. We never expected this to be so hard. So, hopefully there is a way to achieve this with Unity...
     
    Last edited: Jan 19, 2017
    Akhillogon likes this.
  2. TOES2

    TOES2

    Joined:
    May 20, 2013
    Posts:
    135
    Answering my own question in case others have some issue like this:

    First of all, the FoV cannot be set only once. It has to be refreshed constantly for each redraw in Update.

    Secondly, I wrongly assumed I could read the correct FoV in the Start method using this:

    fov=Camera.main.fieldOfView;

    But, it will give you a fov of 0, which is and undefined FoV.

    I was basing my tests on the assumption this value was correct, and I set the newFoV to a percentage of the detected value. However, turns out I was then setting the FoV to 0. Which is illegal, and caused an invisible exception and seemingly no change to the FoV, like the setting it was ignored. It took some effort to pinpoint this issue, as you have no proper debugging tools when running an app on a device.

    To get the right FoV, you need to do this:

    IEnumerator Start()
    {
    yield return new WaitForEndOfFrame();
    fov = activeCamera.fieldOfView;
    }
     
    Hobodi and Harinezumi like this.
  3. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    I would imagine that like SteamVR, whatever GearVR plugin you are using overrides the camera's FOV and sets it every frame. You'd need to find the component that does that and disable/toggle/stop it from doing so.
     
    jterry likes this.
  4. yaffa

    yaffa

    Joined:
    Nov 21, 2016
    Posts:
    41
    Can you Elaborate on how you changed the FOV?
     
    info-360-vid-ca likes this.
  5. Bettaxis

    Bettaxis

    Joined:
    Feb 15, 2017
    Posts:
    1
    Any updates to this? Trying to edit the FOV for Unity 2019.2 for the Oculus SDK.
     
  6. Matt_D_work

    Matt_D_work

    Unity Technologies

    Joined:
    Nov 30, 2016
    Posts:
    202
    the rational behind not being able to modify the FOV is that you're effectively rendering to a piece of hardware which has a fixed FOV.

    modifying the rendered FOV may not lead to positive results. what is the actual desired result?
     
  7. BroncoBilli

    BroncoBilli

    Joined:
    Oct 8, 2017
    Posts:
    90
    Matt_D, I'm also curious about modifying the FOV for the Mixed Reality Headset. We're seeing this issue where the headset and the controllers map correctly from real world to VR world space coordinates. But what the user sees in the headset is scaled down about 30% from "real world" vision. i.e. if you look at a VR representation of a VR object of a "thing in front of you", then look at the REAL thing in front of you by taking off your headset, the radians spanned by the real life object is a lot bigger than the object in VR space. in other words, Unity "shrinks" everything in world space. We're not sure why. Say for example I model my office which contains only a computer, a chair, and 6 walls and put that into VR space and align it. When sit in the middle of a wall and look at the far wall, I point my hand to where it feels like the corner of a wall is. If I remove the glasses, but keep my eyes pointed the same direction, they're focused right on my finger. But the REAL corner of the wall is BIGGER. It's farther, more pushed out. Unity's view shows me a slightly scaled down version of real world. In fact, about 30% smaller.

    If I was able to mess w/ the FOV for the headset, I could magnify the entire scene so it matched real life more closely..

    Oh yeah, WHY do I want to do this? Because we're bringing in live video and calibrating it to the headset, and we want VR objects to match real life objects exactly. We need Unity to draw "exactly what we give it". No scaling.
     
    DevSpur and Akhillogon like this.
  8. DevSpur

    DevSpur

    Joined:
    Jul 19, 2014
    Posts:
    20
     
  9. DevSpur

    DevSpur

    Joined:
    Jul 19, 2014
    Posts:
    20
    This is quite a serious problem, has anyone got a resolution or work around.
     
  10. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    And what is that suppose to mean? I need full control of camera, not that "rule of vr headset" nonsense. I have a mechanic with binocular zoom. How can I do this now?
     
    float and nbmlaw like this.
  11. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    782
    Last edited: Dec 7, 2019
  12. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    833
    If you change the fixed FOV of the cameras, you'll break the illusion of VR.

    If you are finding that the scale doesn't feel right (not personally encountered this, but VR is granular on the case by case user experience) - try scaling the parent object of the camera.
     
  13. jeromeWork

    jeromeWork

    Joined:
    Sep 1, 2015
    Posts:
    426
    I want to be able to do this for artistic reasons - to make the player feel as if their perception is being altered.
    Is there a way of simulating an FOV change using a screenspace effect? Ideally something that would be performant and work with single pass on Quest?
     
    float likes this.
  14. Adrien_Triangles

    Adrien_Triangles

    Joined:
    Feb 4, 2016
    Posts:
    35
    Maybe shrink the player? In Pavlov when you're dead you can resize yourself to watch the end of the game, and it gives this feeling.
     
    pedroareias16 likes this.
  15. jeromeWork

    jeromeWork

    Joined:
    Sep 1, 2015
    Posts:
    426
    Thanks. I know what you mean but it's more of a barrel distortion effect that I'm after.
    I know it's not the kind of thing you're meant to do but it's for a psychology research experiment
     
    float likes this.
  16. Adrien_Triangles

    Adrien_Triangles

    Joined:
    Feb 4, 2016
    Posts:
    35
    Maybe add the equivalent of a lens to your cameras ? Like really adding a lens element (either geometry, either plane with normal map) just facing it. Using refraction in your material And to quickly be able to change the lens without updating models all the time you could go with normal maps and playing with themselves and their intensitiy ? I don't know if shadergraph lets you convert a height to normal but if it doesn't just exporting a lens atlas and scrolling through it could do. And then editing normal intensity realtime could be fun and get you F***ed up distortions :)
     
    jeromeWork likes this.
  17. jeromeWork

    jeromeWork

    Joined:
    Sep 1, 2015
    Posts:
    426
    What a cool idea! Thanks for the inspiration
     
  18. Adrien_Triangles

    Adrien_Triangles

    Joined:
    Feb 4, 2016
    Posts:
    35
    I'm very curious about your results ! Either in real life, or in VR, such thing would be fun to have, will experiment on this as well in some future I think :) Could you share results if you go over it ? :)

    EDIT: Now I think of it I don't think this would really increase the FOV as if it's not rendered it's not rendered right? It could warp your current FOV and get a similar feeling tho ? Gotta try :/
     
    Last edited: Feb 13, 2020
  19. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,924
    I was just bitten by this ... I see the rationale, but I dislike how it was implemented.

    1. It needs to be converted from Warning to Error, since you are effectively changing the source code that was written - that's a much bigger thing than a warning!

    (guess who :) didn't notice that Unity was putting this tiny "warning" in the console log, until he'd spent thirty minutes debugging a broken FOV?)

    2. The obvious use-case that bit me was: I'm rendering to texture. This has nothing to do with VR / eyes / headset -- it's going to be texturemapped into the scene, where the "actual" VR Camera will then pick it up.

    (IMHO the error message should be changed to add the text " - if you're rendering to texture, maybe you should set the eye mode to none?")

    FYI if anyone else comes here from Google (it's a top hit for the warning message), you want:

    camera.stereoTargetEye = StereoTargetEyeMask.None; // by default, Unity turns ALL new camearas into VR cameras, even if you never intend to use them for VR :(
     
    KillerFirefly, glenneroo and Recluse like this.