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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to set near/far clipping planes on "built in" VR camera(s)?

Discussion in 'AR/VR (XR) Discussion' started by Bren, Nov 30, 2015.

  1. Bren

    Bren

    Joined:
    Aug 28, 2008
    Posts:
    191
    Hi all,

    I'm using Unity 5.2.3f1 with "built in" VR support (enabled with the Player Settings->Virtual Reality Supported check box) and I'm trying to adjust the clipping planes of the VR cameras. I have my Main Camera set so it looks correct in the editor, however on the Gear the settings don't seem to come over.

    I tried grabbing any/all cameras in Start() and setting them directly, but that didn't seem to work either. Not sure exactly what's going on in there tho, as debugging Gear while running isn't possible?

    I see others talking about setting values on the OVRCameraController prefab, but of course there's no such animal with the built in solution.

    Any suggestions?
     
  2. UnityAvater

    UnityAvater

    Joined:
    Jul 8, 2013
    Posts:
    3
    VR devices reset camera params. All you set in the Editor will be useless in VR.
     
  3. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    So there's absolutely no way to configure a camera in any way for Gear VR?
     
  4. SpreadcampShay

    SpreadcampShay

    Joined:
    Dec 9, 2010
    Posts:
    180
    EDIT: I might have misunderstood the OP slightly in that he apparently has a problem manipulating the VR Camera in the first place, whereas I thought it was a graphical issue. The example in the original post below is about a particular issue with far clip in VR, please use it only if your display seems to cut off too soon. If you merely want to manipulate your VR camera, you'll simply have to get a reference to your Main Camera like you'd normally do in a nonVR Game too, there shouldn't be anything special you need to do for it. Any change to the Transform, variables on the Camera component of your Main Camera, or Image Effects you attach to your Main Camera should all automatically apply to both the VR cameras, too, so it shouldn't be a problem.
    ----
    Original Post:
    It sounds like something that I've experienced with my Oculus Desktop Project. My workaround for it was to double my far clip plane from script. Try in your Start() function to do something like
    Code (csharp):
    1. camTarget = GetComponent<Camera>();
    2. camTarget.farClipPlane = camTarget.farClipPlane * 2;
    I wouldn't call this a fix and it probably comes at a performance cost, but it let me keep going in my project without it looking all glitched and that's all I cared about.
     
    Last edited: Dec 1, 2015
  5. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    OK I'll try something like that.

    Is it setting it to a fixed value, or halving the starting farclip?
     
  6. Bren

    Bren

    Joined:
    Aug 28, 2008
    Posts:
    191
    @darky, I tried something like that, but the only camera found by FindObjectsOfType<Camera>() (entire scene) and GetComponentsInChildren<Camera>() (gameobject containing Main Camera) is the Main Camera. I can't seem to find the VR cameras at all at runtime.

    Again, this is using "built in" VR support in 5.2.3f1 for Gear VR.

    EDIT: Camera.allCameras only contains the Main Camera, as well.
     
    Last edited: Dec 1, 2015
  7. SpreadcampShay

    SpreadcampShay

    Joined:
    Dec 9, 2010
    Posts:
    180
    I don't see the problem, it seems to be the correct behavior unless there is a fundamental difference in the nativeVR between the Rift and the GearVR - but I don't think there is. The native VR in Unity essentially uses that Main Camera to create both the VR cameras automatically "by magic" (sorta) and any changes you do to your Main Camera should automatically reflect on both the VR cameras, too. That means not only the Transform of the Camera, but also the variables on the Camera component itself and even Image Effects that you might attach to it. This is also why the native VR is so much more convenient to use compared to the SDK from a year ago, since you only need to worry about one camera. The only exception to this is if you'd intentionally create two cameras, with each one rendering for only 1 Eye, but you REALLY don't wanna do that unless you got a damn good reason. So in short just leave things how they are, make use of your Main Camera by getting a reference to it like you'd do in a nonVR game, and if you should see an issue with far clip planes try out the doubling trick from the original example :) I adjusted my original post in light of this, since the fix for the issue I was talking about may not really apply to you after all. You can still take it as a basis to insert your own custom values though, as long you do it on your Main Camera.

    OK a little more explanation. You might find what I wrote to Bren above interesting, too, in regards to manipulating your VR camera. The example that I wrote is about a particular problem with far clip and I might have misunderstood his bigger problem a bit, but it's good to know about this nevertheless. The example is used in the Start() function of a component that should be attached to the main camera. It's DOUBLING the far clip value on the Main Camera at Start and it will stay at that doubled value unless you change it again at a later point, for example from another script. Reason: In my own project I need to use a different far clip value for each Room my player can enter and I require these to be a VERY small value specific to each room, and the numbers I got work really good In-Editor and in NonVR Playback, but my display was cut off too soon once viewing it in VR. In VR display the far clip appears to be essentially halved so a already small far clip value will be even smaller and you might not see anything correctly, depending on your project/scene. Since it looked like it's half of what it should be I just doubled the desired far clip value as a cheap workaround and that's what I recommend to try if you see something like this. In my project this means basically whenever my player enters another room, the Main Camera gets the desired far clip value from a variable on my Roomstate component which itself was optimized for in-editor and for nonVR viewing and I just double that number when in VR to avoid my issues. The big takeaway is to try out if doubling it helps you if you're seeing a too early cutoff with it. But only do this if it is an actual issue to you :) For everything else, make use of your Main Camera as you'd always do in a nonVR game too, as described above. It should just work, really.
     
    Last edited: Dec 1, 2015
  8. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    OK that makes sense, I'll try it out. I was playing around with making a flight sim for Gear VR and since you need a pretty large farclip, I was noticing it was not correct. Interesting how it seems to decide to make the farclip half when in VR. I'll try the double thing though and see if that makes it all better.

    Thanks for your insight!
     
  9. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    Also, has anyone been able to do Screen.SetResolution to change the resolution? Maybe I am doing it at the wrong time or something, but it seems to turn my screen black when I do it...