Forum Discussion
Slopey
13 years agoHonored Guest
GUIText/HUD - best way to implement with the rift
Hi there,
I've got a simple little project running where I can render models in a landscape and use one of the Rift cameras for hit detection with raycasting.
I want to display details about the object the ray has collided with using a simple hud - which so far I've got working with GUIText on a single camera (the right currently).
What's the best way to go about this with the rift? It works with a GUILayer on one of the cameras, but obviously it gets a bit tricky if I tried to get the GUIText on both and align them.
Or would it be better to render text onto a 3d plane/texture/object which is placed in front of the cameras a certain distance, much like a cockpit display on some of the space demos?
Anyone have any good strategies for HUDs with the Rift? I've not had a change to look at NGUI yet, but that's next on the list.
Cheers,
S.
I've got a simple little project running where I can render models in a landscape and use one of the Rift cameras for hit detection with raycasting.
I want to display details about the object the ray has collided with using a simple hud - which so far I've got working with GUIText on a single camera (the right currently).
What's the best way to go about this with the rift? It works with a GUILayer on one of the cameras, but obviously it gets a bit tricky if I tried to get the GUIText on both and align them.
Or would it be better to render text onto a 3d plane/texture/object which is placed in front of the cameras a certain distance, much like a cockpit display on some of the space demos?
Anyone have any good strategies for HUDs with the Rift? I've not had a change to look at NGUI yet, but that's next on the list.
Cheers,
S.
8 Replies
Replies have been turned off for this discussion
- BoffExplorerFor speed/simplicity, I would go with rendering the text onto a 3D obect as you suggested. That's been my plan anyway.
...But I'm a complete beginner with Unity, so I'm sure there'll be someone a lot more knowledgable than me along with better advice.
Cheers
Boff - MartinSchultzHonored GuestNGUI is the way to go, works very good. And it is today 50% off in the Asset Store.
I used NGUI for Rift Racer -> http://www.decane.net/game/oculus-rift/riftracer/ - sh0v0rProtegeGenerally the best solution is to use a Camera with a Render Target then attach a Plane to the Cameras with a material using that Texture. This is what NGUI does but you'll need to modify it so the Camera targets a Render Texture, so you can position it optimally.
You can use Text Meshes in your scene as well.
For 3D Icons I place an Empty Game Object where the centre of the eyes are then attached a child object plane with the Icon on it and offset it at the desired distance, facing the eyes. Then I make the parent object 'look at' the object of interest. This way the icon is always facing towards the eyes. For important Icons you can use a render last shader so it renders on top of everything else.
I use a combination of these things, you can see them in this video(Note I'm not using NGUI...yet):
The Monitor on the Left is a Render Target, as is the Pitch Ladder.
The Velocity Vector(Small Circle) is a 3D icon as described above.
The other HUD Text readouts are TextMeshes in the scene. - CosbyTronHonored Guest
"Boff" wrote:
For speed/simplicity, I would go with rendering the text onto a 3D obect as you suggested. That's been my plan anyway.
...But I'm a complete beginner with Unity, so I'm sure there'll be someone a lot more knowledgable than me along with better advice.
Cheers
Boff
I can second that, its simple and works well. There is also a sort of quick and dirty way of doing it with Unity's built in GUI text. Make an empty, attach a GUIStyle component, and add a simple script like:
GUIStyle gStyle;
float boxWidth, boxHeight = 100.0f;
text displayText = "Hello";
void Start(){
gStyle = gameObject.GetComponent<GUIStyle>();
}
void OnGUI(){
GUI.Box( new Rect( Screen.width / 6, Screen.height / 2, boxWidth, boxHeight), displayText, gStyle );
GUI.Box( new Rect( Screen.width / 3, Screen.height / 2, boxWidth, boxHeight), displayText, gStyle );
}
Don't take that script to the bank, it's just off the top of my head, but that's the idea :-). You are just drawing 2 GUI boxes at different X locations (you'll need to experiment with those values to dial it in). This is not the "right" solution, but it's what I use when I need to display some debug info in-game in the Rift. - SlopeyHonored GuestI've been able to get pretty good results simply by using TextMeshes parented to the Left Camera. The Right camera "sees" them also, and they appear correctly in the user's visual field - works pretty well.
I'm not doing graphics just yet - just text, but so far it's working as intended. It's enough for my proof of concept anyway, and I'll work on making the UI a bit more functional in the future, but it doesn't necessarily need to be.
(It's a visualisation tool for process/plant commissioning, i.e. you get a 3D model of a refinery etc, and you can wander around with a FPS player object, and looking at any given mesh (via a simple raycast and collider) retrieves info on that equipment item from an SQL database. Works really well so far.) - petergiokarisProtegeI would recommend rendering to a render texture and attaching an object with that render texture to the Right Camera.
The current integration does this already, please see OVRMainMenu.cs as an example on how to do this.
note: Previous versions of the integration wrote directly to the camera buffers render texture. This is still a viable option, and gives 'crisper' results. However, since this process happens after the full-screen lens distortion and since you have to render your GUI objects twice in a 2D field, it is not recommended.
All future examples of Rift GUI will continue to render to 3D objects placed in the camera view.
Again to re-iterate, please attach to the Right Camera; there are access functions available in OVRCameraController to help enforce this. - drashHeroic ExplorerIn Titans of Space, I used a third-party asset called Textbox from Catlike Coding, which creates meshes in realtime based on whatever font you set up (it comes with instructions on bringing any font you want into it). These meshes you can position wherever you want and in any size you want of course, with some options like outline, smoothing, modifiers like coloring text within braces (or whatever pair of characters you choose, etc). The code and shaders are all editable if you need to do something different.
I haven't used NGUI to compare with any of this, though! - bullardoHonored GuestI have been using Daikon forge for the same behavior. Works pretty well with the same method by using the render texture. To get the widgets to display the alpha property I had to use NGUI transparent texture and rip out the ColorMask RGB value. I did a video explaining the process for Daikon Forge at https://www.youtube.com/watch?v=_GP7lpOPcFc
This method will work well for NGUI also. I do know the developer of DF has told me he plans on fixing this so it works with his product in the coming weeks. He just got a developer kit for this very purpose. Feel free to reach out to me if you have any troubles in Unity getting GUI working.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device