Forum Discussion
Mickman
13 years agoProtege
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 ?
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 ?
27 Replies
Replies have been turned off for this discussion
- sh0v0rProtegeIf 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.
- Mrob76oHonored GuestI 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.
- petergiokarisProtegeYou 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. - MickmanProtegeThx 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 - SmartCarrionHonored GuestI'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 - PrelucidHonored GuestHave you guys added the actual GUI layer component to both eyes/cameras?
- sinothExplorerFor 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! - klyemarHonored GuestMap 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. - KrisperExplorer
"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. - McCaHonored GuestTake 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.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 6 months ago
- 8 months ago