Godot 4 OpenXR Getting Started

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hello everyone and welcome to another Godot XR tutorial. Apologies for the silence on my channel but I've been hard at work doing my part in getting Godot 4 towards beta. I will be back to making more videos soon. Now that Godot 4 is in beta and has OpenXR support nearly on par with Godot 3 I can do a quick video on setting things up in Godot 4 as things are slightly different. We will do this by setting up a very basic project. For this video we will be using Godot 4 beta 2. While OpenXR support has been available in Godot 4 for some time now, beta 2 adds support for OpenXR on Android. At this time only support for the Meta Quest is available but we should soon add support for other Android based devices as well. We will also be using the mobile Vulkan renderer, even for VR on desktop. The desktop renderer works in VR as well but will require beefier hardware. On mobile hardware there are still a number of performance issues that we hope to solve in the very near future. You can find the download of the beta version of Godot 4 on the news article page, I've linked it in the description below however you may wish to check for newer versions. Scroll down the page to find the link to the download page. We will download the standard build. On the next page download the version of Godot you need, I'll be using the Windows version. Open up the zip file and copy the executable in a place of your choice. Now we open Godot. We start by creating a new project. And we select the folder we want to create our project in. We give our project a name and press the create folder button to create a folder for our project. And as mentioned before select the mobile renderer for our project. And we press create. First we open up our project settings. There is a bug in Beta 2 that has already been fixed where the renderer settings aren't fully applied so we go to the renderer tab and make sure the mobile renderer is selected for the mobile platform. Next there is a new section for XR settings. We go to shaders first. Enabling our shaders setting tells Godot to compile the shaders needed for stereoscopic rendering. These are not compiled by default as most games won't need them. Finally we select the OpenXR settings to enable OpenXR. This is needed because on Vulkan, initialisation of OpenXR needs to happen very early on in the startup process. This also means that OpenXR will be initialised automatically the moment your game or application starts. Now we press save and restart so these new settings take effect. Now we can start setting up our main scene, this is nearly identical to how things were in Godot 3 however our nodes have new names. We create a new 3D scene and rename this. As always I save the scene right away, save your changes often! We start with adding our XROrigin3D node. And we add an XRCamera3D node as well. Next we add an XRController3D node and rename this to left hand. Here is our first difference, controllers are now identified by named trackers. We select our left hand tracker. Each controller now also identifie multiple locations on the controller called poses. We thus need to select the pose we want. Default is the pose the XR interface identifies as the default, for OpenXR this generally matches the grip pose. The aim pose is a pose generally placed at the front of the controller pointing forward. This is the pose we will be using today. The grip pose is a pose generally placed on the grips of the controller often orientated flush with the body of the controller. The skeleton pose is a pose providing a base for the bone armature for hand tracking. This is only available if hand tracking is supported. In beta 3 a new pose will become available called the palm pose which, if supported by the XR platform, gives the location of the palm of the hand of the player. We need to add a second XRController3D node. We rename this to right hand select our right hand tracker and our aim pose. Even though the position of these nodes are controller by the XR system, I like to position these nodes in physical positions to make it easier to interact with our scene. I will do this off camera. Just to visualise the hands we'll add cubes to each hand. Simply add a MeshInstance3D node Create a box mesh for this node And size it appropriately. Then repeat for the other hand. We'll also create a MeshInstance3D node to represent our floor. We'll create a plane mesh for this and size it appropriately. We also need to create a script to do a little bit of initialisation. This code is very similar to that in Godot 3 however since our OpenXR interface is automatically initialised we only need to check for successful initialisation. We first find our OpenXR interface. Then we check if it was found and if it is initialised. If so we obtain our viewport. And enable the XR mode on this viewport. One big change in Godot 4 is that we no longer have a default environment. The background and lighting we have in our editor is not part of our scene. We thus add a WorldEnvironment node and create a new environment. We set our background mode to sky. And we create a PhysicalSkyMaterial which gives us a nicer more natural background. Next we add a directional light to our scene. This light interacts with our background. Now when we run our project. As my SteamVR is still starting in the background there is a brief moment where we have no tracking data and our head is on the floor, hence we only see our background. As soon as tracking starts we can look around and move our hands around and we see that everything works. Godot does not provide any default logic for controlling your player in VR outside of physical movement. This is up to the game developer to develop. However we do have a toolkit available for those who want to hit the ground running. I will leave a link in the description below to this toolkit. Note that its master branch and the release in the asset library are for Godot 3. The master branch contains a full demo of the functionality offered by this toolkit. There is a 4.0 development branch that contains a version of this toolkit ported to Godot 4. This does not yet contain the demo but we are working on porting this to Godot 4 as well. Covering this toolkit is beyond the scope of this tutorial video but I will be making future videos related to the toolkit soon. For exporting to android devices a few extra steps need to be taken. The first is making sure the supporting toolset is installed and properly configured. I've linked to the documentation page on the official website that covers this setup. In Godot itself the first thing we need to do is ensure that the export templates are installed. Go to the editor menu and select Manage Export Templates. In the popup window there is simply a download and install button that will install the correct version of the export templates. After this we need to go to the project menu and select Install Android Build Template. Godots default Android export is easy to use but fairly limited. Installing the Android build template in the project folder creates a new folder called android and populates it with a build setup that allows us to create more complex android packages. One of the features this enables is for us to add the plugin that we need in our project. The plugin we need is our OpenXR loaders plugin which we find on Github. This plugin currently only contains the OpenXR loader for the Meta Quest but will soon contain other loaders as well. This plugin will be made available through the asset library in due time but for now we can download it through the releases page. Simply download the godotopenxrloaders zip file found here. Once downloaded we open the zip file and go down into the plugin folder. Here we find the files and folders we need to copy into the plugin folder in our project. Back in Godot we need to configure our export, for this we open up the export menu and select Export. Here we press Add to add our Android export preset. We'll change the name of this export to indicate this entry is for our Meta Quest, once we support other devices we'll need to add an entry for each device. Next we'll tick the Use Custom Build tickbox, And then select our Godot OpenXR Meta plugin, eventually we'll have entries here for each device and you should only select a single one! Now we scroll down until we find our XR features section, here we need to select OpenXR in the XR Mode dropdown. The other settings here may be important if you wish to use those features, for now we will leave those alone. Making sure that our Quest is attached to our computer using a USB cable you should now see an Android icon in the top right hand side of the window. Pressing this icon will build our project and export it to the Quest. Make sure to wear the Quest before the project is pushed to the Quest or it may not start and you'll have to try again. And presto it is running on the Quest. That is where we'll leave things today. I'm planning a number of videos related to the new XR features in Godot 4 so if you don't want to miss those, subscribe to my channel if you haven't already, or follow me on twitter. If you want to support my work financially, please consider becoming a member of my channel. A like on this video if you enjoyed the content is always appreciated. Until next time!
Info
Channel: Bastiaan Olij
Views: 6,064
Rating: undefined out of 5
Keywords:
Id: wDXnsy2IH1A
Channel Id: undefined
Length: 10min 53sec (653 seconds)
Published: Fri Oct 07 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.