Enable and use Application SpaceWarp
To enable and use Application SpaceWarp in your project, complete the following steps:
- Enable the OpenXR SpaceWarp feature in the Editor.
- Control SpaceWarp at runtime.
- Choose compatible URP shaders and modify custom shaders to support SpaceWarp, if necessary.
- Configure Materials for SpaceWarp.
Important
Android XR devices use right-handed normalized device coordinates (NDC) for motion vectors. Right-handed NDC for motion vectors are only supported in Unity 6000.1.13f1+ and OpenXR 1.15.1+. If unsure of your device's NDC requirements, refer to the device specifications for more information.
Enable the OpenXR SpaceWarp feature in the Editor
To enable Application SpaceWarp, do the following:
Open your Project Settings in the Unity Editor (menu: Edit > Project Settings).
Select the XR Plug-in Management settings.
Choose the tab at the top corresponding to your current XR device.
Enable the OpenXR checkbox, if necessary.
Enable the appropriate checkbox under the OpenXR checkbox according to the feature group for your device:
Select the OpenXR Plug-in and correct feature group for the current deviceNote
If the options to enable the feature group for your device are missing, you might need to install an OpenXR device package. Refer to Prerequisites for more information.
Switch to the OpenXR settings page (underneath XR Plug-in Management).
Choose the tab at the top corresponding to your current XR device.
Select the All Features group.
Enable the Application SpaceWarp feature.
Enable the Application SpaceWarp featureNote
If using Unity 6000.1.13f1+ and OpenXR 1.15.1+, there will be a gear icon to the right of the feature name.
If a gear icon is present to the right of the feature, click it to reveal a window and a checkbox that says Use Right Handed NDC. Your XR device may require right-handed normalized device coordinates (NDC) for its motion vectors in order for SpaceWarp to work properly. Refer to Enable and use Application SpaceWarp for more information. If your device does require right-handed NDC, make sure the Use Right Handed NDC box is checked, otherwise, uncheck it.
Important
After enabling Application SpaceWarp in the Editor, you must also use the runtime API to turn the feature on at start up and update the camera position and rotation every frame. Refer to Control SpaceWarp at runtime for more information.
Control SpaceWarp at runtime
To use Application SpaceWarp, you need to:
Turn the feature on at runtime with the SpaceWarpFeature.SetSpaceWarp(bool) method.
Update the camera position and runtime every frame with:
The following MonoBehaviour script, which you attach to the main camera in your scene, illustrates how to do this:
using UnityEngine;
using UnityEngine.XR.OpenXR;
using UnityEngine.XR.OpenXR.Features;
namespace UnityEngine.XR.OpenXR.CodeSamples.Editor.Tests
{
// Add to main scene camera
public class SpaceWarpController : MonoBehaviour
{
// The SpaceWarpFeature object that corresponds to the
// feature "Application SpaceWarp" in:
// "Project Settings -> XR Plug-in Management -> OpenXR"
private SpaceWarpFeature m_SpaceWarpFeature = null;
// true if "Application SpaceWarp" feature is enabled
// in Project Settings
private bool m_SpaceWarpFeatureEnabled = false;
void Start()
{
// Turn on SpaceWarp when scene loads if it is
// enabled in Project Settings
m_SpaceWarpFeature =
OpenXRSettings.Instance.GetFeature<SpaceWarpFeature>();
if (m_SpaceWarpFeature != null)
m_SpaceWarpFeatureEnabled = m_SpaceWarpFeature.enabled;
SpaceWarpFeature.SetSpaceWarp(m_SpaceWarpFeatureEnabled);
}
void Update()
{
// Update SpaceWarp with camera position and rotation
// if it is enabled in Project Settings.
// Note, Depending on the headset, SpaceWarp may not need
// to be updated with the main camera’s current position
// or rotation. Refer to the headset’s specifications to
// determine if it’s required. If the headset *does not*
// require SpaceWarp to be updated with the main camera's
// current position and rotation, then comment out the
// following code.
if (m_SpaceWarpFeatureEnabled)
{
SpaceWarpFeature.SetAppSpacePosition(transform.position);
SpaceWarpFeature.SetAppSpaceRotation(transform.rotation);
}
}
}
}
Tip
You can use SpaceWarpFeature.SetSpaceWarp(bool) to turn SpaceWarp on and off for sequences of content that do not work well under Application SpaceWarp.