Skip to main content
Version: Next (dev)

Virtual Reality (XR)

PlasmaEngine2 renders to VR headsets through OpenXR. The engine has the XR game state, the stereo render path and the XR components. The connection to the headset comes from the plasma.openxr package, which runs on Direct3D 12 and Vulkan. It works with whichever OpenXR runtime is active on the computer, for example SteamVR, Oculus or Windows Mixed Reality.

PartWhereResponsibility
XR pluginplasma.openxr packageOpens the headset session, reads tracking and controllers, submits the eye images. Ships the OpenXR loader.
OpenXR runtimeheadset vendorInstalled on the computer and set as the active runtime. It is not part of the package.
XR settingsasset profile (plXRConfig)Whether the game starts in XR, the XR render pipeline and the blend mode.
TrackingplStageSpaceComponent, plDeviceTrackingComponentThe play area, and objects that follow the headset and controllers.
Controller modelsplXRControllerModelComponentShows the runtime's model of each controller.
Inputinput action map, XRInteractionProfiles.ddlController buttons as XR input slots, or OpenXR paths on bindings.
Interactionplasma.xrtoolkit package (optional)Grabbing, pointers, teleport and turning, including the comfort fade and vignette.

Setting up a project for XR​

  1. Add the plasma.openxr package to the project in Project > Packages > Package Manager... (see Packages).
  2. Install the runtime of your headset and make it the active OpenXR runtime (in SteamVR, for example, in its OpenXR settings).
  3. To make the exported game start in XR, open Project > Project Settings > Asset Profiles..., select the profile and turn on Enable XR in its XR settings. The editor does not need this: it uses the Play in VR toggle (see below).
  4. Build a player rig: an object with a plStageSpaceComponent (the play area), with one child per tracked device. Give each child a plDeviceTrackingComponent, and put the camera on the child that tracks the HMD.
Property (XR settings)DefaultDescription
Enable XRoffThe game starts a headset session. The -xr command line option overrides it for one launch.
XR Render Pipelinethe engine's XR pipelineThe render pipeline used for the two eye views.
Blend ModeOpaqueOpaque for VR. Additive and AlphaBlend are the see-through modes of AR devices. If the runtime does not support the requested mode, its preferred mode is used.

Turning XR on and off for one launch​

Start the game with -xr on or -xr off to override Enable XR without editing the profile, for example Player.exe -project "ProjectPath" -scene "ScenePath" -xr off to test a VR project on a flat screen. The command line wins over everything else, including the editor's VR toggle.

When XR is on but cannot start, the game does not stop. It logs the reason and plays on a flat screen instead:

  • No XR plugin is loaded: XR is enabled, but no XR plugin is loaded (add the plasma.openxr package to the project). Starting without XR.
  • The plugin is loaded, but no headset or runtime answers: plXRInterface could not be initialized, starting without XR.

Play in VR in the editor​

The scene toolbar has a Play in VR toggle just before Play the Game. While it is on, Play opens a headset session through the project's XR plugin, whatever the asset profile's Enable XR says. While it is off, the editor always plays without XR, even when the profile enables it. The toggle can only change while no game is running, because the session starts with the game. With the toggle on, the Play button's label shows VR instead of the play target.

Where the game plays decides what you see on the monitor:

  • Play In: Selected Viewport: the headset image is mirrored into the viewport the game plays in. The viewport keeps the game's keyboard and mouse input, and Shift+F1 and Shift+Esc work as usual.
  • Play In: Separate Window: the game opens its own window, which mirrors the headset and takes keyboard and mouse input.

The toggle is stored in the play preferences as Play In VR (see Running a Scene), per user for every project.

Status chip and runtime picker​

While Play in VR is on, a VR chip appears in the scene toolbar after Export and Run. It shows the state of the session:

Chip textMeaning
readyNo game is running.
starting...Play was pressed and the session is opening.
headset idleThe session runs, but the headset does not show the game (for example, it is not worn).
headset visibleThe headset shows the game, but another app has the input, such as the runtime's system menu.
headset focusedThe game is in the headset and gets the input.
failedXR could not start. The editor's status line says why, for example that no XR plugin is loaded.

Click the chip to choose the OpenXR runtime the engine process uses:

  • System Default (name) uses the computer's active runtime and shows its name.
  • One entry per installed runtime, read from the OpenXR registry entries. A runtime that only registers itself as the active runtime, as SteamVR does, is listed too.
  • No OpenXR runtime installed appears when none is found.
  • Restart Engine Process applies the choice. The runtime is read once when the engine process creates its XR instance, so a new choice only takes effect after a restart.
  • Play Preferences... opens the editor preferences.

The choice is a per-user editor preference. It does not change the computer's active runtime and has no effect on exported games.

Testing without a headset​

Set the cvar XR.AllowDummy to use a simulated headset (plDummyXR) when no XR plugin is loaded. The project must not load plasma.openxr then, otherwise the real plugin is used. The simulated headset renders both eyes and reports itself as Dummy VR device, so you can check the stereo render path, the rig and the overlays on a normal monitor. In the editor, set the cvar in Panels > CVars before pressing Play with Play in VR on.

CVarDefaultDescription
XR.AllowDummyoffUse the simulated headset when XR is enabled but no XR plugin is loaded. Not saved between sessions.
XR.Dummy.EyeOffset0.05Distance of each eye from the head's centre, in metres.
XR.Dummy.VisibilityMaskoffGives the renderer a test lens mask (corner triangles per eye).
XR.Dummy.RenderModeloffThe simulated controllers report a built-in controller model with a moving trigger.
XR.ForceSkipRenderoffSkips the XR view every frame, as when the runtime reports that frames are not displayed.

Game behaviour in a headset​

CVarDefaultDescription
XR.PauseOnFocusLossonPauses the game when the session loses focus: the headset is taken off or the runtime's system menu opens. Opens the pause menu if the game has one. Otherwise the world clock stops and runs again when focus returns. A pause menu stays open until the player closes it.
XR.ShowStatsoffShows the frame pacing overlay in the top right corner (see below).
XR.RenderScale1.0Fraction of the eye texture that is rendered per axis, clamped to 0.5 - 1.0.

The XR.ShowStats overlay shows the headset and runtime, the display refresh rate and frame period, the rendered eye size against the runtime's eye texture size with the render scale, and how many frames were submitted, not rendered and discarded. The text turns orange red in a frame in which the runtime discarded a frame. The same counters are published as stats under Renderer/XR/.

Tracked devices​

A plDeviceTrackingComponent moves its object to the pose of a headset, controller or other tracked device every frame. Leave Transform Space at Local and make the object a direct child of the plStageSpaceComponent object, so it moves with the play area when the player teleports or turns.

PropertyDefaultDescription
Device TypeHMDThe device to follow: HMD, Left Controller, Right Controller or another tracked device.
Pose LocationGripGrip (where the hand holds the controller), Aim (the pointing ray) or Palm (needs XR.PalmPose).
Transform SpaceLocalLocal sets the local transform to the pose in stage space. Global uses the device's world transform.
RotationonApplies the device's rotation.
ScaleonApplies the device's scale. The Properties panel hides it as unused; click Show unused at the bottom of the panel to see it.
Tracking LostHold Then HideWhat happens to the object while the device is not tracked, see below.
Hide Delay0.5 sWith Hold Then Hide, how long the last pose is kept before the object hides.

Tracking Lost decides what the object does when a controller is switched off, out of view of the sensors, or put down:

  • Hold keeps the object at its last tracked pose.
  • Hide hides the object at once: its other components and its child objects are deactivated until tracking returns.
  • Hold Then Hide keeps the last pose for Hide Delay, then hides. Short drop-outs then cause no flicker.

XR.LateLatch (on by default) moves the rendered transforms of tracked objects and their children to the newest pose right before the frame renders, which cuts the latency of controllers and hands.

Properties of an object with a Device Tracking component set to Right Controller: Pose Location Grip, Transform Space Local, Rotation on, Tracking Lost Hold Then Hide and Hide Delay 0.5

Controller models​

Add a plXRControllerModelComponent to the object that a device tracking component moves with Pose Location: Grip. When the runtime provides a model of the controller, the component builds it as child objects, one per model node, and moves the buttons, triggers and sticks every frame. Until a model arrives, or when the runtime has none, it shows the fallback mesh.

The runtime only hands out models when XR.RenderModels is on. It requests the XR_MSFT_controller_model and XR_FB_render_model extensions, and takes effect when the OpenXR instance is created: restart the game (in the editor, Restart Engine Process) after changing it.

PropertyDefaultDescription
Device TypeLeft ControllerThe controller whose model is shown.
Animate NodesonMoves the animated parts of the model with the controller's inputs.
Fallback MeshnoneStatic mesh shown while no runtime model is available.
Fallback Delay2 sHow long to wait for the runtime model before the fallback mesh shows.

Controller input​

The XR plugin reports the controllers as input slots named xr_hand_left_... and xr_hand_right_..., for example xr_hand_right_trigger_value or xr_hand_left_grip_value. Bind them in an input action map like any other slot. Their bindings belong to the XR scheme.

Data/Base/RuntimeConfigs/XRInteractionProfiles.ddl lists the controllers the plugin suggests bindings for and which of their components drive which slot. The built-in table covers the Khronos simple controller, Windows Mixed Reality, Oculus Touch, Valve Index, HTC Vive, hand interaction, Meta Quest Touch Pro, HTC Vive Cosmos, HTC Vive Focus 3 and Pico Neo3. A profile that needs an OpenXR extension is skipped when the runtime does not enable it. The extensions for Quest Pro, Vive Cosmos, Vive Focus 3, Pico and hand interaction are requested with XR.ExtendedInteractionProfiles.

On controllers whose squeeze button is a plain switch (HTC Vive, Vive Cosmos, Windows Mixed Reality), the button drives both grip_click and grip_value, so components that read the analog grip value, such as the XR Toolkit hand, grab on these controllers too.

OpenXR paths on bindings​

A binding in an input action map can also list XR Paths: OpenXR input paths that drive it directly, for one interaction profile or for every profile that has the path. A binding with XR paths and no slots reads generated slots named xr_action_<context>_<action>. Use this for buttons the built-in table does not map, or for a different layout on one controller.

PropertyDefaultDescription
ProfileemptyInteraction profile path, for example /interaction_profiles/oculus/touch_controller. Empty applies the path to every profile that has it.
PathemptyFull OpenXR input path, for example /user/hand/right/input/a/click.
Dpad Center Region0.5Only for paths ending in /dpad_up, /dpad_down, /dpad_left, /dpad_right or /dpad_center. Radius of the dead centre as a fraction of the stick or trackpad range.
Dpad Wedge Angle90°Dpad paths only. Angle covered by each direction.
Dpad StickyoffDpad paths only. Keeps a direction active while the input stays out of the centre.

Dpad paths split a stick or trackpad into four buttons. They need XR.BindingModification and XR.DpadBinding. When the asset is transformed, the editor checks every path against the profile table and logs a warning for paths that do not start with /user/, unknown profiles and components a profile does not have. Axis3D actions cannot use XR paths, because OpenXR has no 3D axis actions.

Stereo rendering​

Headset views are stereo views, rendered through the XR render pipeline. The settings below control how the renderer treats stereo views. Mono views are not affected.

CVarDefaultDescription
Rendering.Culling.GPU.StereoonGPU culling for stereo views, with the union of both eye frusta. Needs Rendering.Culling.GPU.
Rendering.Culling.GPU.Stereo.OcclusiononHi-Z occlusion culling with one depth pyramid per eye. An object is culled only when it is hidden in both eyes. Needs Rendering.Culling.GPU.Stereo and Rendering.Culling.GPU.Occlusion.
Rendering.VolumetricFog.StereoUnionGridonBuilds the volumetric fog grid over both eye frusta, so the outer edge of the right eye gets fog too.
Rendering.GPUParticles.StereoDepthCollisiononGPU particles collide against the depth of both eyes, not just the left eye.
Rendering.GI.StereoLeftEyeoffOff: stereo views go without screen-space GI, because the right eye would show GI from the wrong viewpoint. On: computes GI for the left eye and uses it for both, for comparison.
Rendering.XR.VisibilityMaskonDraws the lens hidden-area mesh into the depth buffer first, so the pixels the lenses hide are not shaded. Needs XR.VisibilityMask.
XR.VisibilityMaskoffRequests the lens mask from the runtime (XR_KHR_visibility_mask). Takes effect when the OpenXR instance is created.
Rendering.XR.PassthroughAlphaonWhile passthrough shows the real world behind the image, writes coverage into alpha (1 where geometry was drawn, 0 at the far plane), so the camera feed shows where nothing was drawn.
XR.PassthroughoffRequests XR_FB_passthrough for mixed reality on Quest-class headsets. Takes effect when the OpenXR instance is created.

Passes that only render the left eye sit out stereo views: ray-traced direct lighting, probe direct lighting, ReSTIR and path tracing. The XR pipeline renders GPU particles, contact shadows and the view mode visualisations.

The comfort effects of the XR Toolkit, the teleport blink and the turning vignette, are drawn by the renderer on the tonemapped image of each eye, before the UI and debug drawing. Gameplay code can set them through plXRScreenEffects::SetFade and plXRScreenEffects::SetVignette.

Troubleshooting​

ProblemCause and fix
The VR chip shows failed, the status line says no XR plugin is loaded.Add the plasma.openxr package to the project, or turn on XR.AllowDummy to test with the simulated headset.
The chip shows failed: XR could not start (no headset or runtime?).The headset is not connected, the runtime is not running, or no OpenXR runtime is active. Start the runtime (for example SteamVR), check the runtime picker, then Restart Engine Process. The log has the OpenXR error.
The runtime menu says No OpenXR runtime installed.No runtime is registered in the OpenXR registry entries. Install the headset software and set it as the active OpenXR runtime.
A new runtime choice has no effect.The runtime is read when the engine process starts. Choose Restart Engine Process in the chip menu.
The game in the editor plays without XR although the profile has Enable XR on.Intended: in the editor only the Play in VR toggle counts.
The exported game starts in XR, or does not.Check Enable XR in the asset profile, and whether the launch uses -xr on or -xr off.
The game pauses when the headset is taken off.XR.PauseOnFocusLoss is on. Turn it off to keep the game running.
A controller freezes in place or disappears.Tracking was lost. Choose the behaviour with Tracking Lost and Hide Delay on its device tracking component.
Controllers show the fallback mesh or nothing.XR.RenderModels is off, the runtime offers no model for this controller, or the game was not restarted after the cvar changed. Set a Fallback Mesh for runtimes without models.
A binding with XR paths never fires.Check the transform log for path warnings. Profiles that need an extension also need XR.ExtendedInteractionProfiles, and dpad paths need XR.BindingModification and XR.DpadBinding.
Fog, particles or GI differ between the eyes.Check that the stereo cvars above are at their defaults.

See Also​