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

    sh0v0r
    Up and Coming
    August 3, 2013
    If you're using standard Unity GUI then it is rendered in screen space so you need to draw it once for each eye, this is possible but it's complicated. You're better of doing UI with something like NGUI and have it exist in 3D space.
    Up and Coming
    August 3, 2013
    I use Ngui and it works great. There is a tutorial on the forums somewhere on how to set it up but Ngui is not free.
    DK1 Order #: 48xxx. Status: DK1 Owner since March 29th, 2013. DK2 Order #: DO-0154xxxx. Status: DK2 Owner since July 28th, 2014 My Stygian Abyss Demo Remake Blog http://mrob76u.wordpress.com
    Inspiring
    August 5, 2013
    You can render GUI compnents to a RenderTexture you own.

    Create a new RenderTexture, then set it as the active RenderTarget. After you have rendered to it, you can map it to geometry that is attached to the camera or within the world; provided you have rendered the elements properly to a transparent texture, the GUI elements will be rendered properly in stereo to your view.

    Please see OVRMainMenu.cs for an example on how to do this.
    Peter Giokaris Senior Software Engineer
    MickmanAuthor
    Up and Coming
    August 16, 2013
    Thx for the replies,

    I'll give try Creating a new RenderTexture, then set it as the active RenderTarget. I've actually done this already on a radar system I'm using... I use Depth Masks as well.

    So there's no magic bullet to have a GUI render in stereo... RenderTexture is it.

    I'll check out OVRMainMenu.cs now

    THX again
    http://www.mickbanks.com
    Participant
    August 20, 2013
    I'm having trouble with this too, i created the render texture and extra camera as suggested, but i can't get the GUI to display on the other camera. I've tried fiddling with the depth and masks, but I'm not sure what to do next. the gui just seems to draw to the screen not the camera.

    Having the HUD in one eye is not so great.

    Any advice on what I might be missing? thx
    My first VR Game is in public beta!! Lair Life
    Up and Coming
    August 20, 2013
    Have you guys added the actual GUI layer component to both eyes/cameras?
    Viktor: Yes, he was wrong. But just as some things can be right and useless at the same time, can't something be wrong... and priceless?
    Up and Coming
    August 20, 2013
    For anyone wanting a really hacky solution, you can do something like this (NOTE: this does not allow you to adjust the depth of the text and can be uncomfortable!)

    void OnGui()
    {
    GUI.Label(new Rect(Screen.width / 5 * 1, 500, 200, 50), "Testing!");
    GUI.Label(new Rect(Screen.width / 5 * 3, 500, 200, 50), "Testing!");
    }


    I was able to get a RenderTexture to display a GUI.Label component. The general procedure is this:


    • Create a RenderTexture (might crank its resolution up to say 1024x1024)

    • Create a Material (diffuse) and set its texture to your RenderTexture

    • Create an object that will display your UI (a quad works well)

    • Assign the material created above to your object

    • Attach a script to the object that has something such as:

    using UnityEngine;
    using System.Collections;

    public class draw : MonoBehaviour {

    public RenderTexture myTexture;
    public GUIStyle style;

    void OnGUI()
    {
    RenderTexture.active = myTexture;
    GL.Clear(false, true, new Color(0.0f, 0.0f, 0.0f, 0.0f));

    GUI.Box(new Rect(0.0f, 0.0f, 100.0f, 100.0f), "Test!", style);

    RenderTexture.active = null;
    }
    }


    In the inspector, drag the RenderTexture you created onto the "myTexture" public variable on the above script. Should see some text!
    Up and Coming
    August 20, 2013
    Map the RenderTexture to a quad and parent the quad to the right camera so that if you looked at your player in the editor, it will appear that there's a GUI floating in front of him Minority Report style. The RenderTexture is rendering the GUI onto the quad which is merely a piece of floating geometry in the world space.

    I personally create an empty game object that I attach to the right camera called GUI, and attach an individual quad for each element. I don't use a RenderTexture, I use icons and text meshes each mapped to their own quad. The reason I use separate quads is because once you've grouped them together, you can get some really cool stereoscopic effects by placing text elements slightly closer to the camera. :)

    I do recommend making use of an unlit overlay shader as described here, to prevent the GUI from clipping through geometry.
    Visit my Gargantua SMASH! VR Jam Thread
    Up and Coming
    August 21, 2013
    "sinoth" wrote:

    I was able to get a RenderTexture to display a GUI.Label component. The general procedure is this:


    • Create a RenderTexture (might crank its resolution up to say 1024x1024)

    • Create a Material (diffuse) and set its texture to your RenderTexture

    • Create an object that will display your UI (a quad works well)

    • Assign the material created above to your object

    • Attach a script to the object that has something such as:

    using UnityEngine;
    using System.Collections;

    public class draw : MonoBehaviour {

    public RenderTexture myTexture;
    public GUIStyle style;

    void OnGUI()
    {
    RenderTexture.active = myTexture;
    GL.Clear(false, true, new Color(0.0f, 0.0f, 0.0f, 0.0f));

    GUI.Box(new Rect(0.0f, 0.0f, 100.0f, 100.0f), "Test!", style);

    RenderTexture.active = null;
    }
    }


    In the inspector, drag the RenderTexture you created onto the "myTexture" public variable on the above script. Should see some text!


    Thanks for that, I was a bit lost using a RenderTexture, that made it easy, much appreciated.
    Participant
    August 21, 2013
    Take a look at the "OVRGUI" script which is part of the Rift asset package. You can see an example of it in the Tuscany project folder. The render texture is displayed onto a plane which is parented to the right eye camera. There is also a shader in that same asset package called "OVERGUIShader" that makes the plane visible through walls so you don't have to deal with camera rendering depths which are annoying when dealing with the Rift's stereo rendering.

    Though like the others I would also recommend a third-party add on like NGUI or Textbox from the asset store.