NeoSpark314 / godot_oculus_quest_toolkit

An easy to use VR toolkit for Oculus Quest development using the Godot game engine
MIT License
367 stars 38 forks source link

How to make HUD UI elements? #78

Closed nightblade9 closed 2 years ago

nightblade9 commented 2 years ago

How do I make a UI-facing label that's always facing the camera and always on-screen? I want to use it to display the number of points.

I got labels working via an OQ_UI2DLabel instance. But, it only faces one direction, and doesn't move around. I tried placing it as a child of the controller (works great in the VR simulator), camera, origin, etc. but it simply stays in place.

To be clear, I would like it to always be on-screen and facing the camera, like any other HUD element. In 2D, I could achieve this with a CanvasLayer and a label sub-control.

nightblade9 commented 2 years ago

I figured out a hack of sorts. You can put OQ_UILabel2D nodes under the camera node, albeit you need to set a proper Z translation, like -0.5. It's ugly, but it works. Is there a better/preferred way?

NeoSpark314 commented 2 years ago

I think what you describe is a good solution in VR and not ugly :-). I can't think of a better way right now that would not be technically equivalent to the UILabel2D. And you want to have verything a real object in 3D space to have it rendered correct for both eyes.

nightblade9 commented 2 years ago

Hmm. Maybe it's just me (new to 3D games as well as XR), but the solution is not immediately obvious; not only that you can't use a regular Label, but that it lives in 3D space instead of screen-space by default.

I don't know much about Godot's internals. It seems to me that the XR camera node you provided in the toolkit, renders to a viewport. Shouldn't it be possible to, say, add a CanvasLayer to that, and then add controls in "screen space" as usual?

The current process takes a lot of manual tweaking/iteration to get things to appear correctly (very painful to make a non-trivial HUD), not sure if it might be affected by lighting, environment, etc. nodes - which would be unexpected.

NeoSpark314 commented 2 years ago

The problem with VR is that you need to render a separate image for each eye; these two images are different to keep up the illusion of a 3d scene. If this is not correct you will confuse the brain and induce sickness very quickly. So a simple 2d canvas will not work well. But I agree that it is not easy to setup; and usally also very application specific to have a UI; most VR games and applications that I remeber did not use static huds but tried to add elements either into the world (like a menu screen that you can walk to) or make elements appear when you look at your wrist for example.

nightblade9 commented 2 years ago

Makes sense. There's probably nothing more to do here, then. Thanks for the input.