AR/VR Grundlagen

Dieses Anleitung gibt Ihnen eine Einführung in die Welt von AR (Augmented Reality) und VR (Virtual Reality) in der Godot-Game-Engine.

In Godot 3 wurde eine neue Architektur namens AR/VR Server eingeführt. Zusätzlich zu dieser Architektur stehen bestimmte Implementierungen als Schnittstellen zur Verfügung, von denen die meisten Plugins sind, die auf GDNative basieren. Diese Anleitung konzentriert sich ausschließlich auf die Kernelemente, die von der Kernarchitektur abstrahiert werden. Diese Architektur verfügt über genügend Funktionen, um eine vollständige VR-Erfahrung zu erstellen, die dann für verschiedene Schnittstellen bereitgestellt werden kann. Jede Plattform verfügt jedoch häufig über einige einzigartige Funktionen, die nicht abstrahiert werden können. Solche Merkmale werden auf den relevanten Schnittstellen dokumentiert und fallen nicht in den Geltungsbereich dieser Anleitung.

AR/VR Server

Wenn Godot gestartet wird, macht sich jede verfügbare Schnittstelle dem AR/VR-Server bekannt. GDNative-Schnittstellen werden als Singletons eingerichtet. Solange sie zur Liste der GDNative-Singletons in Ihrem Projekt hinzugefügt wurden, werden sie dem Server bekannt gegeben.

You can use the function get_interfaces() to return a list of available interfaces, but for this tutorial, we're going to use the native mobile VR interface in our examples. This interface is a straightforward implementation that uses the 3DOF sensors on your phone for orientation and outputs a stereoscopic image to the screen. It is also available in the Godot core and outputs to screen on desktop, which makes it ideal for prototyping or a tutorial such as this one.

Führen Sie folgenden Code aus, um ein Interface zu aktivieren:

var arvr_interface = ARVRServer.find_interface("Native mobile")
if arvr_interface and arvr_interface.initialize():
    get_viewport().arvr = true

Dieser Code findet die Schnittstelle, die wir verwenden möchten, initialisiert sie und wenn dies erfolgreich ist wird das Hauptansichtsfenster an die Schnittstelle gebunden. Dieser letzte Schritt gibt der Benutzeroberfläche eine gewisse Kontrolle über das Ansichtsfenster, wodurch automatisch Dinge wie das stereoskopische Rendern im Ansichtsfenster aktiviert werden.

For our mobile VR interface, and any interface where the main input is directly displayed on screen, the main viewport needs to be the viewport where arvr is set to true. But for interfaces that render on an externally attached device, you can use a secondary viewport. In the latter case, a viewport that shows its output on screen will show an undistorted version of the left eye, while showing the fully processed stereoscopic output on the device.

Finally, you should only initialize an interface once; switching scenes and reinitializing interfaces will just introduce a lot of overhead. If you want to turn the headset off temporarily, just disable the viewport or set arvr to false on the viewport. In most scenarios though, you wouldn't disable the headset once you're in VR, this can be disconcerting to the gamer.

neue AR/VR Nodes

Es wurden drei neue Node-Typen zur Unterstützung von AR und VR und ein zusätzlicher Node-Typ speziell für AR in Godot hinzugefügt. Diese sind:

  • ARVROrigin - unser Ursprungspunkt in der Welt

  • ARVRCamera - eine spezielle Unterklasse der Kamera, die positionell verfolgt wird

  • ARVRController - eine neue räumliche Klasse, die den Standort eines Controllers verfolgt

  • ARVRAnchor - an anchor point for an AR implementation mapping a real world location into your virtual world

Die ersten beiden müssen in Ihrer Szene vorhanden sein, damit AR/VR funktioniert, und diese Anleitung konzentriert sich ausschließlich auf diese.

ARVROrigin ist ein wichtiger Knoten, Sie müssen irgendwo in Ihrer Szene einen (und nur einen) davon haben. Dieser Knoten ordnet das Zentrum Ihrer realen Welt einem Ort in Ihrer virtuellen Welt zu. Alles andere wird positionell relativ zu diesem Punkt in Verbindung gebracht. Wo genau dieser Punkt liegt, unterscheidet sich von Implementierung zu Implementierung, aber das beste Beispiel, um zu verstehen, wie dieser Knoten funktioniert, ist ein Blick auf einen Raummaßstab. Während wir Funktionen haben, um den Punkt so einzustellen, dass er standardmäßig auf dem Player zentriert wird, ist der Ursprungspunkt der Mittelpunkt des Raums, in dem Sie sich befinden. Während Sie physisch durch den Raum gehen, wird der Ort des HMD in Bezug auf diese Mittelposition verfolgt.

To keep things simple, when you physically move around your room, the ARVR Origin point stays where it is, the position of the camera and controllers will be adjusted according to your movements. When you move through the virtual world, either through controller input or when you implement a teleport system, it is the position of the origin point which you will have to adjust.

ARVRCamera is the second node that must always be a part of your scene and it must always be a child node of your origin node. It is a subclass of Godot's normal camera. However, its position is automatically updated each frame based on the physical orientation and position of the HMD. Also due to the precision required for rendering to an HMD or rendering an AR overlay over a real world camera, most of the standard camera properties are ignored. The only properties of the camera that are used are the near and far plane settings. The FOV, aspect ratio and projection mode are all ignored.

Note that, for our native mobile VR implementation, there is no positional tracking, only the orientation of the phone and by extension, the HMD is tracked. This implementation artificially places the camera at a height (Y) of 1.85.

Fazit: Ihre minimale Vorbereitung, um AR oder VR zu unterstützen, sollte so aussehen:

../../_images/minimum_setup.png

Und das ist alles was Sie brauchen, um mit der nativen mobilen Oberfläche zu beginnen. Natürlich müssen Sie Ihrer Szene etwas mehr hinzufügen, damit es etwas zu sehen gibt. Danach können Sie das Spiel auf ein Telefon Ihrer Wahl exportieren, es in einen Viewer einfügen und los geht's.

Offizielle Plugins und Ressourcen

As mentioned earlier, Godot does not support the various VR and AR SDKs out of the box, you need a plugin for the specific SDK you want to use. There are several official plugins available in the GodotVR Repository.

  • Godot OpenXR: This is the official XR plugin starting with Godot 3.4. It supports OpenXR, an open standard for designing and building cross-platform VR and AR software. Tested with SteamVR, Monada and Oculus OpenXR (desktop and mobile) runtimes.

  • Godot Oculus Mobile provides support for the Meta Quest.

    • Note: This plugin has been deprecated starting with Godot 3.4. We recommend migrating to the Godot OpenXR plugin instead.

  • Godot OpenVR (not to be confused with OpenXR) supports the OpenVR SDK used by Steam.

  • Godot Oculus supports the Oculus SDK (desktop headsets only).

    • Note: This plugin has been deprecated starting with Godot 3.4. We recommend migrating to the Godot OpenXR plugin instead.

  • Godot OpenHMD supports OpenHMD, an open source API and drivers for headsets.

Diese Plugins können von Github runtergeladen werden oder aus der Godot Bestandsbibliothek.

Zusätzlich zu den Plugins gibt es noch einige offizielle Beispielprogramme.

Weitere Dinge zu beachten

There are a few other subjects that we need to briefly touch upon in this primer that are important to know.

Die ersten sind unsere Einheiten. In normalen 3D-Spielen müssen Sie nicht viel über Einheiten nachdenken. Solange alles im gleichen Maßstab ist, kann eine Kiste mit einer Größe von 1 Einheit mal 1 Einheit mal 1 Einheit eine beliebige Größe haben, von einem Jungen, den Sie in der Hand halten kann, bis zu etwas so großem wie einem Gebäudes. In AR und VR ändert sich dies, weil Dinge in Ihrer virtuellen Welt auf Dinge in der realen Welt abgebildet werden. Wenn Sie in der realen Welt 1 Meter vorwärts gehen, in Ihrer virtuellen Welt jedoch nur 1 cm, haben Sie ein Problem. Das gleiche gilt für die Position Ihrer Controller. Wenn sie nicht im richtigen relativen Raum erscheinen, kann der Nutzer nicht vollkommen ins Spiel eintauchen. Die meisten VR-Plattformen, einschließlich unseres AR/VR-Servers, gehen von 1 Einheit = 1 Meter aus. Der AR/VR-Server verfügt jedoch über eine Eigenschaft, die der Einfachheit halber auch auf dem ARVROrigin-Node namens Welt-Skalierung verfügbar ist. Wenn Sie diesen Wert beispielsweise auf 10 setzen, ändert sich unser Koordinatensystem so, dass 10 Einheiten = 1 Meter sind.

Performance is another thing that needs to be carefully considered. Especially VR taxes your game a lot more than most people realize. For mobile VR, you have to be extra careful here, but even for desktop games, there are three factors that make life extra difficult:

  • You are rendering stereoscopic, two for the price of one. While not exactly doubling the work load and with things in the pipeline such as supporting the new MultiView OpenGL extension in mind, there still is an extra workload in rendering images for both eyes

  • A normal game will run acceptably on 30fps and ideally manages 60fps. That gives you a big range to play with between lower end and higher end hardware. For any HMD application of AR or VR, however, 60fps is the absolute minimum and you should target your games to run at a stable 90fps to ensure your users don't get motion sickness right off the bat.

  • The high FOV and related lens distortion effect require many VR experiences to render at double the resolution. Yes a VIVE may only have a resolution of 1080x1200 per eye, we're rendering each eye at 2160x2400 as a result. This is less of an issue for most AR applications.

All in all, the workload your GPU has in comparison with a normal 3D game is a fair amount higher. While things are in the pipeline to improve this, such as MultiView and foveated rendering, these aren't supported on all devices. This is why you see many VR games using a more art style and if you pay close attention to those VR games that go for realism, you'll probably notice they're a bit more conservative on the effects or use some good old optical trickery.