Virtual Reality
Caution The feature discussed below is currently considered experimental, i.e. must be considered proof-of-concept for the time being. VR support in flightgear still comes with a number of caveats. It's just to showcase what's being worked on. If you'd like to learn more, please get in touch via the developers mailing list. |
Started in | 07/2021 |
---|---|
Description | Virtual Reality support using osgXR / OpenXR |
Contributor(s) | James Hogan [1] |
Status | Active |
Changelog | https://sourceforge.net/u/amalon/profile/feed.rss |
The Virtual Reality project aims to add immersive VR support to FlightGear. This is done using the OpenXR[2] API, via an external library called osgXR[3] for handling OpenXR and OpenSceneGraph specifics, which is being developed in parallel.
Background
A previous attempt to support some form of VR is described in OculusImplementation.
The portable OpenXR API now seems to be getting widespread adoption, which will allow FlightGear to support a variety of VR devices across multiple platforms.
Source code
- osgXR source can be found on github[3], or the version included in the flightgear 3rdparty directory can be used.
- On ArchLinux, you can install the osgxr AUR package [4] to get the version needed by FlightGear's next branches.
- Some VR code can now be found in FlightGear's next branches (see below for details).
- On ArchLinux, you can use the -git AUR packages, i.e. flightgear-git, simgear-git, flightgear-data-git.
- On Windows, you can use the Windows nightly builds.
- More FlightGear changes can be found on James Hogan's osgxr branch[5] (non-rebased branch), or osgxr_clean branch[6] (clean history, may be rebased). A mirror is available on github for issue tracking[7].
- More SimGear changes can be found in James Hogan's osgxr branch[8] (non-rebased branch), or osgxr_clean branch[9] (clean history, may be rebased).
- More FGData changes can be found on James Hogan's osgxr branch[10] (non-rebased branch), or osgxr_clean branch[11] (clean history, may be rebased).
Building & Packaging Notes
When CMake runs for FlightGear (next or osgxr/osgxr_clean branches), by default it will attempt to enable VR on Windows and Linux (same as -DENABLE_VR=ON
). It will do the following:
- Look for the osgXR library, and if found it will link against that (same as
-DSYSTEM_OSGXR=ON
). - If no osgXR library is found it will check for OpenXR and if found it will build its own static built-in copy of osgXR to use.
- If no OpenXR is found it will disable VR support.
In any case it will print a message along the lines of -- VR support enabled/disabled...
.
To avoid implicit dependencies when packaging, packagers may need to do ONE of the following:
- preferably depend upon an osgXR package providing the osgXR dynamic library
- OR depend on OpenXR and GLX, and explicitly pass `-DSYSTEM_OSGXR=OFF` to CMake so the built-in osgXR is built statically
- OR explicitly pass `-DENABLE_VR=OFF` to CMake to disable VR support altogether
Status
Last updated: 31st March 2024
Highly experimental, partially in next, partly out of tree. Development in progress.
Working in next branch (e.g. Windows nightly builds):
- Enable/disable at startup via --enable-vr / --disable-vr command line options, or from GUI (View->VR Options).
- VR friendly splash screen.
- Displaying stereo images on the HMD.
- Motion tracking updates HMD views (but doesn't move main camera).
- Configurable VR mirror (see View->VR Settings) shown in default camera view (blank, left, right, side-by-side left & right).
- Visibility mask support.
Working in osgxr/osgxr_clean branch:
- Controller support for flight (helicopter collective in left hand, helicopter cyclic in right).
- Controller pointing support with some mouse emulation.
- Rendering of controllers (as basic cuboids).
Current priorities:
- Support HDR Pipeline and accelerated multiview rendering.
- Continue to polish controller flight support, add haptics etc.
- Get started on other controller interaction and controller rendering.
Known issues
Splash screen is rendered directly onto the left eye viewport which isn't very pleasant in VR.- Performance could be better so crank down the graphics if frame rate is low.
- Shadows are broken:
- When shadows are enabled, the FlightGear window doesn't appear to refresh even though buffers are swapped, but VR output works.
- Sun position is fixed relative to head, presumably because shadow maps are rendered based on master camera, but osgXR only moves slave cams.
- Spotlights (taxi/landing lights) are relative to camera in default mode
- Affects default / scene view mode (
--prop:/sim/vr/mode=AUTOMATIC
), as stereo callbacks position cameras - Doesn't affect slave cameras mode (
--prop:/sim/vr/mode=SLAVE_CAMERAS
), as slave cameras are positioned correctly
- Affects default / scene view mode (
- ALS filters appear to operate in screen space but don't take into account side by side rendering
- HDR Pipeline is unsupported, but work to support it is in progress
- Still some Monado issues:
Saturated output due to not using SRGB textures(use osgXR 0.3.8)Suboptimal depth format used(osgXR 0.3.8 should end up using GL_DEPTH32F_STENCIL8)- Warnings about suggesting bindings of attached action sets when restarting VR (looks like a monado issue at first glance)
- Multiple SteamVR issues on Linux:
- If it doesn't close cleanly on Linux it may be due to a SteamVR bug[12], but a ctrl+c / SIGINT on the command line should close it.
- osgXR doesn't support Direct3D graphics bindings for WMR (it isn't a priority for me). Contributions welcome.
Testing
VR has been tested with the following hardware & software configurations:
- HTC Vive, SteamVR, Linux/X11 (ArchLinux), nVidia proprietary -- Amalon (talk) 21:43, 27 August 2021 (UTC)
- Oculus Quest 2, SteamVR (ALVR), Linux/X11 (Fedora 34) -- vezza (talk) 16:30 27 August 2021 (UTC)
- Oculus Quest 2, Oculus App, Windows 10 --Necolatis (talk) 13:22, 7 June 2023 (UTC)
- Works fine, shadows gets rendered, but move when turning the head.
- Eye view point is about 0.2 meter above where the view is defined, so I have to duck my head to look out through the HUD and stuff.
- Oculus Quest 2, SteamVR via Virtual Streamer App, Windows 10, Nightly build --User:Skyclmbr 18:17, 11 October 2023 (UTC)
- Head tracking works fine, but right eye screen flickers constantly throughout flight
- Starting head position is off, depending on how much I move around while it's loading on the SteamVR page.
- HTC Vive, Monado (to window), Linux/X11 (ArchLinux), nVidia proprietary -- Amalon (talk) 22:36, 17 December 2021 (UTC)
- only basic display to window tested
- osgXR master
- Monado dummy driver, Linux/X11 (ArchLinux), Intel mesa -- Amalon (talk) 22:36, 17 December 2021 (UTC)
- only basic display to window tested
- osgXR master
- /sim/vr/depth-info=false
- Monado Dummy HMD, Linux/X11 (Debian), AMD Mesa Drivers Nia (talk) 23:27, 17 December 2021 (UTC)
- Applying the following patch:
diff --git a/src/XRState.cpp b/src/XRState.cpp index ce09bcd..5bcbbca 100644 --- a/src/XRState.cpp +++ b/src/XRState.cpp @@ -1017,7 +1017,7 @@ XRState::UpResult XRState::upSession() unsigned int thisDepthBits = 0; switch (format) { - case GL_RGBA16: + case GL_RGB10_A2: // FIXME This one will do for now... if (!chosenSwapchainFormat) chosenSwapchainFormat = format;
- Applying the following patch:
- HP Reverb G2, Gigabyte (AMD) RX 6700 XT, Windows 10, SteamVR -- Gastcan (talk) 02:15, 09 July 2023 (UTC)
- (Using the Windows nightly build 08-Jul-23)
- The view follows the direction of the headset, but the image stutters; outside scenery and within the cockpit
- HP Reverb G2, Gigabyte (AMD) RX 6700 XT, Debian (Trixie), Monado -- Gastcan (talk) 16:15, 14 August 2023 (UTC)
- Compiled from sources: OpenXR-SDK-Source, Monado, osgXR (amalon), SimGear (amalon), FlightGear (amalon)
- The view follows the direction of the headset with minor stuttering.
The viewpoint/perspective drifts clockwise, to the right.<- Drifting is virtually eliminated by adding 'Basalt for Monado' (provides 6DoF).
If you've got VR working, feel free to add your configuration above.
The following testing is desired:
- SteamVR, Linux, AMD graphics:
- Test that motion smoothing works (its unsupported on NVidia)
- moving head side to side should reproject using depth buffer
- try suspending fgfs with Ctrl+Z in terminal (resume with fg) to force reprojection
- Monado, Linux:
- May be awkward to test as it crashes in latest NVidia proprietary drivers[13].
- There's now a workaround mentioned in that ticket that allows for basic testing
- Use at least osgXR 0.3.6 for monado workaround, or
--disable-vr
and enable VR with GUI
- May be awkward to test as it crashes in latest NVidia proprietary drivers[13].
- SteamVR, Windows, with a headset (I've only attempted to null driver, and it at least partly worked):
- Needs building with at least osgXR 0.3.7 for Windows bindings, and my osgxr/osgxr_clean branch of flightgear/fgdata/simgear
- May need --disable-sentry
- Test headset output and controllers
Issues can be reported:
- On the flightgear-devel mailing list
- To the FlightGear bug tracker if the issue is reproducible on the next branch
- To the flightgear-vr issue tracker
- To the osgXR issue tracker if it is known to be a non-flightgear specific bug in osgXR
But please be aware of the known caveats mentioned above, and the roadmap below.
Performance
Here are some pointers to get the best VR experience.
- Ensure your runtime supports asynchronous reprojection, which may alleviate the nausea induced by lower frame rates.
- On Linux / SteamVR / NVidia proprietary driver, ensure you have at least driver version 270.
- If your frame rate is being capped at the refresh rate of your desktop monitor, try disabling VSync in both flightgear settings and your driver settings
- On Linux / NVidia proprietary driver, its found in OpenGL settings in nvidia-settings.
- If FlightGear is getting throttled by SteamVR (to try and ensure a consistent, if slow, frame rate), consider switching to fixed throttling (in per-application video settings) and playing with the sliders. You may prefer no frame rate throttling but a higher predicted frame time.
- Enabling multithreading may get you better performance, e.g.
--prop:/sim/rendering/multithreading-mode=CullThreadPerCameraDrawThreadPerContext
- If using an AMD GPU, use CoreCtrl and set the GPU to the "Virtual Reality" power profile with GPU and memory clocked to max. You may also benefit from changing the CPU frequency governor to Performance.
Implementation Details
Concepts
Interaction Modes
Interaction modes are a way of describing (via XML) how a VR controller should look and behave in a particular context. It roughly corresponds to a virtual control you can hold (and let go of), for example:
- When you're holding a helicopter collective control, the pitch angle of the controller should control the collective pitch (and look like a collective in your hand).
- When you're pointing the controller at a GUI or cockpit controls it should pick along a line, rendered in a specific way, and emulate mouse events to those controls (and look like a small laser pointer control or a pointing hand/glove).
- When you're teleporting around, it should pick along a parabolic arc, rendered a specific way, and teleport there when the button is released.
- When you're using the flight recorder it should treat the controller trackpad as a rewind/fast forward (and look like a fancy TV remote or something).
The definition of interaction modes should be generic enough that custom ones can be provided with aircraft, or defined separately and work with any aircraft, but also powerful enough that a complex and intuitive control can be defined with a minimum of Nasal scripting.
Roadmap
Development targets
- Merge stable & minimally functional code into next (MR #253 (flightgear), MR #238 (fgdata)) Done
- Merge some form of desktop mirroring of VR view (MR #260 (flightgear), MR #241 (fgdata)) Done
- Merge visibility mask support (MR #98 (simgear), MR #264 (flightgear), MR #244 (fgdata)) Done
- Polish Not done
- Functionality
General tasks
- Stability Done
- Resolve questions around VR mirror switching Done
- Performance
- Handle shouldRender=false by somehow disabling VR cameras (maybe setting cull mask to 0) Not done
- SceneView mode: Combine culling traversal Not done
- Check why update isn't proceeding in parallel with multithreading Not done
- Use OpenXR visibility mask extension to avoid rendering to invisible fragments Done
- Sound
User facing features
- Display
- Show views on HMD Done
- Configurable mirror on desktop window Done
- General HDR Pipeline Support
- Geometry shader multi viewport (HDR Pipeline)
- OVR_multiview2 with OSG branch (HDR Pipeline)
- Motion tracking
- Settings
- Platform support
- Splash screen
- GUI
- Launcher Not done
- Controller support
- Basic action support in osgXR API Done
- Tie osgXR actions into FG's input system Done
- Helicopter flight controls (can use for planes too) Done
- Plane flight controls Not done
- Render controllers
- Hand tracking (robot hand)
- Render skinned hand Not done
- Basic interaction with controls
- Advanced interaction with animated controls
- Haptic feedback Not done
- Walker VR locomotion / Room scale
Aircraft compatibility
This section is largely about how usable controls are in VR with direct manipulation.
Cessna 172P
- Controls
Eurocopter EC130 B4
- Engine start
- Take off & flight
- Controls
McDonnell Douglas F-15 Eagle
Robinson R22
- Controls