Skip to main content
Up and Coming
July 15, 2013

OVRCameraController - change clipping planes at runtime

Hi,
We need to change the clipping planes in the OVRCamera - for a short period of time to see a close-up. Then back to normal to render the rest of the scene with finer Depth Buffer in the higher distances.

Normally this works with
Camera cameraVar;
camVar.nearClipPlane = X.XXf;
in C#

With the Oculus Rift Cameras from the OVRCameraController prefab, I didn't find a way to adjust that value directly in runtime.
Tried the following:
OVRCameraController ovrCameraControllerVar;
OVRCamera ovrCameraVar;
Camera cameraVar;

void FixedUpdate () {
oVRCameraControllerVar.NearClipPlane = X.XXf;
oVRCameraControllerVar.camera.nearClipPlane = X.XXf;
oVRCameraVar.camera.nearClipPlane = X.XXf;
cameraVar.nearClipPlane = X.XXf;
}

It did show the change in the Camera's public NearClipPlane variable, but it clipped away the close up object anyway.

The work-around to this problem is to set-up two OVRCameraController prefabs with the according clip planes and then set the GameObjects active/inactive.

However, I'd be grateful if setting the clipping planes would work the same way it does with the standard Camera.
    This topic has been closed for replies.

    9 replies

    Inspiring
    July 15, 2013
    There is a way to do this, unfortunately it's not very straight-forward. We hope to have accessor functions that will make this easy, but they are not there yet. For now here is a work-around.

    Make a function that will manually find the left and right cameras, then adjust the near/far plane on them. If you look at the Awake() function in OVRCameraController, that is a good place to copy the code from. Then just make a new function that will adjust the clipping planes.

    Let me know if this works for you.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    psykomikeAuthor
    Up and Coming
    July 21, 2013
    Hi,
    thanks for the fast answer. Sadly, the workaround doesn't work.

    tried the following:
    GameObject myLeftCam = GameObject.Find("CameraLeft");
    GameObject myRightCam = GameObject.Find("CameraRight");
    myLeftCam.camera.nearClipPlane = 0.01f;
    myRightCam.camera.nearClipPlane = 0.01f;


    and then similar to Awake()
    Camera[] cameras = GameObject.Find("OVRCameraController").GetComponentsInChildren<Camera>();
    Camera CameraLeft = new Camera();
    Camera CameraRight = new Camera();
    for (int i = 0; i < cameras.Length; i++)
    {
    if(cameras[i].name == "CameraLeft")
    CameraLeft = cameras[i];

    if(cameras[i].name == "CameraRight")
    CameraRight = cameras[i];
    }
    CameraLeft.nearClipPlane = 0.01f;
    CameraRight.nearClipPlane = 0.01f;


    That is, the clipping plane DID change according to the Inspector, but there was no effect in the Game View. No changes in the Depth Buffer and still clipping through the shoulder.

    Perhaps my understanding of how to find something manually was wrong?
    Also my Project can't convert to anything higher than Unity 4.0.1f2 Does this functionality need 4.1?
    Rift Ramps VRJam Topic www.forked-up.com www.facebook.com/forkeduponline
    Inspiring
    July 23, 2013
    There are currently no access functions to the Near/FarClipPlane variables. This will be included in the next release (as well as for BackgroundColor).

    For now, you can add the following functions into OVRCameraController and use them to access the clip planes:

    // Get/Set NearClipPlane
    public void GetNearClipLane(ref float nearClipPlane)
    {
    nearClipPlane = NearClipPlane;
    }
    public void SetNearClipLane(float nearClipPlane)
    {
    NearClipPlane= nearClipPlane;
    UpdateCamerasDirtyFlag = true;
    }


    Repeat the above for FarClipPlane (as well as for BackgroundColor).

    Note that the key here is to set UpdateCameraDirtyFlag to trigger the camera to apply changes in the next update.
    Peter Giokaris Senior Software Engineer
    Inspiring
    July 23, 2013
    Note: setNearClipPlane should be SetNearClipPlane :)
    Peter Giokaris Senior Software Engineer
    psykomikeAuthor
    Up and Coming
    August 3, 2013
    Thanks for your suggestion, but UpdateCamerasDirtyFlag didn't change much.

    The problem was i didn't put VRMenu into the scene. Somehow updating the Cameras only works with VRMenu present.
    Rift Ramps VRJam Topic www.forked-up.com www.facebook.com/forkeduponline
    Up and Coming
    November 6, 2013
    Oh weird... I tried adding the OVRMainMenu.cs script to my scene as well and it fixed my issues too...

    Issues were discussed here: https://developer.oculusvr.com/forums/viewtopic.php?f=37&t=3676&p=67540#p67540

    Is it possible to get the clipping to work without the OVRMainMenu script?
    Seeing is believing
    Up and Coming
    November 7, 2013
    When the OVRMainMenu is active, it causes the cameras to be reconfigured every frame. I'm not sure if this is desired behavior, but that's what happens currently. I'm trying to create a fix that doesn't require the menu.
    Up and Coming
    November 8, 2013
    To fix this issue, you will need to modify the ConfigureCamera() method of the OVRCameraController to be:


    bool ConfigureCamera(ref Camera camera, float distOffset, float perspOffset, float eyePositionOffset)
    {
    Vector3 PerspOffset = Vector3.zero;
    Vector3 EyePosition = EyeCenterPosition;

    // Vertical FOV
    camera.fieldOfView = VerticalFOV;

    // Aspect ratio
    camera.aspect = AspectRatio;

    // Centre of lens correction
    camera.GetComponent<OVRLensCorrection>()._Center.x = distOffset;
    ConfigureCameraLensCorrection(ref camera);

    // Clip Planes
    camera.nearClipPlane = NearClipPlane;
    camera.farClipPlane = FarClipPlane;

    // Perspective offset for image
    PerspOffset.x = perspOffset;
    camera.GetComponent<OVRCamera>().SetPerspectiveOffset(ref PerspOffset);

    // Set camera variables that pertain to the neck and eye position
    // NOTE: We will want to add a scale vlue here in the event that the player
    // grows or shrinks in the world. This keeps head modelling behaviour
    // accurate
    camera.GetComponent<OVRCamera>().NeckPosition = NeckPosition;
    EyePosition.x = eyePositionOffset;

    camera.GetComponent<OVRCamera>().EyePosition = EyePosition;

    // Background color
    camera.backgroundColor = BackgroundColor;

    return true;
    }


    The difference here is that the clip planes are set before the SetPerspectiveOffset() call. With this change, you shouldn't need the OVRMainMenu.
    Up and Coming
    December 4, 2013