Skip to main content
Up and Coming
August 2, 2013

WHY !! Gui elements only visible in one eye ??

I have noticed all of my Gui elements only render to one camera. Why & how can I rectify this ??

I'm hoping there's a simple function in the SDK or a tag I can apply that will duplicate them automatically over so they're visible in both Left & Right cameras ?
    This topic has been closed for replies.

    27 replies

    Up and Coming
    August 21, 2013
    So I used sinoth's tips to set up a GUI using a RenderTexture on a Quad. And I added in an unlit overlay shader using tips from the page klyemar linked to.

    Once thing I notice is that while the GUI is showing, if I move around the text disappears until I stop moving. Anyone know why this happens and how to stop it?
    Up and Coming
    August 22, 2013
    .
    New Participant
    August 23, 2013
    Extremely helpful post. :)

    However, I'm curious how everyone is using the GUIs on the Render Texture. Are these informational only? How would you interact with Buttons or Input Text?

    I've managed to get the OVRCrosshair to turn on using the OVRMainMenu script, but other than show me where the mouse is in relation to each camera, I'm not entirely sure how it helps me. Is there a way to make the crosshair interact with the GUI elements on the Render Texture?
    Up and Coming
    August 23, 2013
    I am only using it to give some tips on what to do. I haven't tried using form elements at all.
    New Participant
    August 24, 2013
    i've managed to get some integration using the OVRMainMenu script, pulling out what i need for my project.

    At this point all i'm trying to do is show some simple gui elements on screen. I made a gui.box 1024,1024 (same as my render texture) but it seems to be offset centrally left eye to right. With the left seemingly ok but the right side scewed to the left.

    The GUI Object is parented to the right camera.

    If someone was feeling generous they would make a nice tutorial...(which was my initial intention but i got stuck) :(
    MickmanAuthor
    Up and Coming
    August 26, 2013
    Thx so much for the reply...

    This has helped not only myself but from the response on this thread, it seems others have gained a little insight.
    http://www.mickbanks.com
    Participant
    September 6, 2013
    Even though the Thread title discouraged me to take this Thread serious, I eventually decided to post my solution.
    It's quite simple, I took a look at the OVRGui and OVRMainMenu Class, and took what was needed.
    If you want other Elements than the StereoBox, write a new class which extends the OVRGui Class
    and place your own stereoscopic elements there.


    /*
    OculusStereoGui code by OculusVR
    Rearranged by Daniel "Dakor" Korgel

    Renders Gui Elements in Stereoscopic 3D if placed below the marked line.
    If you want other Elements than the StereoBox, write a new class which extends the OVRGui Class
    and place your own stereoscopic elements there

    */

    using UnityEngine;
    using System.Collections;
    public class OculusSeteoGui: MonoBehaviour {

    private OVRGUI GuiHelper = new OVRGUI();
    private GameObject GUIRenderObject = null;
    private RenderTexture GUIRenderTexture = null;

    // Handle to OVRCameraController
    private OVRCameraController CameraController = null;
    public Font FontReplace = null;


    // Awake
    void Awake()
    {
    CameraController = GetComponentInChildren(typeof(OVRCameraController)) as OVRCameraController;
    if(CameraController==null){
    Debug.LogWarning("Single Method Failed!");
    // Find camera controller
    OVRCameraController[] CameraControllers;
    CameraControllers = gameObject.GetComponentsInChildren<OVRCameraController>();


    if(CameraControllers.Length == 0)
    Debug.LogWarning("OVRMainMenu: No OVRCameraController attached.");
    else if (CameraControllers.Length > 1)
    Debug.LogWarning("OVRMainMenu: More then 1 OVRCameraController attached.");
    else
    CameraController = CameraControllers[0];
    }
    }

    // Use this for initialization
    void Start () {
    // Ensure that camera controller variables have been properly
    // initialized before we start reading them
    if(CameraController != null)
    {
    CameraController.InitCameraControllerVariables();
    GuiHelper.SetCameraController(ref CameraController);
    }

    // Set the GUI target
    GUIRenderObject = GameObject.Instantiate(Resources.Load("OVRGUIObjectMain")) as GameObject;

    if(GUIRenderObject != null)
    {
    if(GUIRenderTexture == null)
    {
    int w = Screen.width;
    int h = Screen.height;

    if(CameraController.PortraitMode == true)
    {
    int t = h;
    h = w;
    w = t;
    }

    // We don't need a depth buffer on this texture
    GUIRenderTexture = new RenderTexture(w, h, 0);
    GuiHelper.SetPixelResolution(w, h);
    GuiHelper.SetDisplayResolution(OVRDevice.HResolution, OVRDevice.VResolution);
    }
    }

    // Attach GUI texture to GUI object and GUI object to Camera
    if(GUIRenderTexture != null && GUIRenderObject != null)
    {
    GUIRenderObject.renderer.material.mainTexture = GUIRenderTexture;

    if(CameraController != null)
    {
    // Grab transform of GUI object
    Transform t = GUIRenderObject.transform;
    // Attach the GUI object to the camera
    CameraController.AttachGameObjectToCamera(ref GUIRenderObject);
    // Reset the transform values (we will be maintaining state of the GUI object
    // in local state)
    OVRUtils.SetLocalTransform(ref GUIRenderObject, ref t);
    // Deactivate object until we have completed the fade-in
    // Also, we may want to deactive the render object if there is nothing being rendered
    // into the UI
    // we will move the position of everything over to the left, so get
    // IPD / 2 and position camera towards negative X
    Vector3 lp = GUIRenderObject.transform.localPosition;
    float ipd = 0.0f;
    CameraController.GetIPD(ref ipd);
    lp.x -= ipd * 0.5f;
    GUIRenderObject.transform.localPosition = lp;

    GUIRenderObject.SetActive(false);
    }
    }
    }

    // Update is called once per frame
    void Update () {

    }


    void OnGUI () {
    // Important to keep from skipping render events
    if (Event.current.type != EventType.Repaint)
    return;


    // We can turn on the render object so we can render the on-screen menu
    if(GUIRenderObject != null)
    {
    GUIRenderObject.SetActive(true);
    /* if (ScenesVisible || ShowVRVars || Crosshair.IsCrosshairVisible() ||
    RiftPresentTimeout > 0.0f || DeviceDetectionTimeout > 0.0f ||
    ((MagCal.Disabled () == false) && (MagCal.Ready () == false))
    )
    GUIRenderObject.SetActive(true);
    else
    GUIRenderObject.SetActive(false);*/
    }
    //***
    // Set the GUI matrix to deal with portrait mode
    Vector3 scale = Vector3.one;
    if(CameraController.PortraitMode == true)
    {
    float h = OVRDevice.HResolution;
    float v = OVRDevice.VResolution;
    scale.x = v / h; // calculate hor scale
    scale.y = h / v; // calculate vert scale
    }
    Matrix4x4 svMat = GUI.matrix; // save current matrix
    // substitute matrix - only scale is altered from standard
    GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);

    // Cache current active render texture
    RenderTexture previousActive = RenderTexture.active;

    // if set, we will render to this texture
    if(GUIRenderTexture != null)
    {
    RenderTexture.active = GUIRenderTexture;
    GL.Clear (false, true, new Color (0.0f, 0.0f, 0.0f, 0.0f));
    }

    // Update OVRGUI functions (will be deprecated eventually when 2D renderingc
    // is removed from GUI)
    GuiHelper.SetFontReplace(FontReplace);


    if(CameraController!=null){
    /* *************************************************** */
    /* ******* PLACE YOUR GUI CODE BELOW ******* */
    string test= "TESTING...";
    GuiHelper.StereoBox (400, 300, 200, 50, ref test, Color.red);
    /* ******************************************************* */
    }

    // Restore active render texture
    RenderTexture.active = previousActive;

    // ***
    // Restore previous GUI matrix
    GUI.matrix = svMat;


    }

    }


    }




    PS: There might be some lines in this script which are not necessary, I just took it form my game and removed my own GUI code but I might missed some vars / lines
    Writer for Bloculus.de the German Virtual Reality Developer Blog Professional software developer for VR, Collector of old Gaming Hardware
    Up and Coming
    October 16, 2013
    Thanks for sharing that, I'll see if I can apply it to my gui problems :)
    New Participant
    October 30, 2013
    Hi guys... I have moreless the same problem. When I create an Gui element (i.e. button, box) and try to show with the OVRCameraController, this one is showed only on the right camera. I tried every hint , but nothing I don't able to fix my problem.

    Someone that help me??? Thank you.
    Participant
    October 30, 2013
    Not really a gui but if you just want to display some text I find a 3D text object handy, just plonk it on a left or right camera and position it in front of the player. And walah done and dusted!