OpenXR 设置
OpenXR 有一套自己的设置,这些设置会在 OpenXR 启动时应用。尽管能通过插件实现的 OpenXR 扩展以添加额外设置,但在这里我们只讨论 Godot 核心中的设置。

Enabled
此设置决定了在 Godot 启动时是否启用 OpenXR。当使用 Vulkan 后端时,该选项必须打开。对于其他后端,可随时通过调用 OpenXRInterface 类的 initialize
来启用 OpenXR。
如果要访问动作映射编辑器,该选项也需启用。
你可以使用 --xr-mode on
命令行指令以强制启用该模式。
默认动作映射
该选项指定了 OpenXR 将加载并与 XR 运行时通信的操作映射文件的路径。
构成因素
该选项指定了你的游戏是为以下哪种设备设计的:
Head Mounted
头戴式设备,如 Meta Quest、Valve Index 或 Magic Leap,Handheld
手持设备,例如手机。
如果运行游戏的设备与此处不匹配,OpenXR 将无法初始化。
视图配置
该选项指定了游戏是为哪种视图配置而设计的:
Mono
, your game provides a single image output. E.g. phone based AR;Stereo
, your game provides stereo image output. E.g. head mounted devices.
如果运行游戏的设备与此处不匹配,OpenXR 将无法初始化。
备注
Godot 暂不支持 OpenXR 中针对特定设备的额外视图配置。例如,Varjo 头显有一个四视图配置,可以输出两组立体图像。这些特例可能会在不久的将来得到支持。
参照空间
在 XR 中,玩家的头部和手部等所有元素的追踪都在一个追踪体积内进行。这个追踪体积的基点是将虚拟空间映射到现实空间的原点。根据使用的 XR 系统的不同,该点会被放置在不同的位置。在 OpenXR 中,这些场景被明确定义,并通过设置参考空间来选择。
Local(本地)
本地参照空间默认将原点放置在玩家的头部。一些 XR 运行时会在游戏启动时重设该位置,而其他则会让该位置在多个会话中保持不变。
然而,这种参照空间并不会阻止用户走开,因此如果你希望阻止用户离开他们正在控制的部件(这可能会破坏游戏),则需要检测用户是否离开。
本地参照空间是飞行模拟器或赛车模拟器的最佳选择,这类游戏通常希望将 XROrigin3D 节点放置在玩家头部应在的位置。
当用户在其耳机上启用重新居中选项时(该方法因 XR 运行时而异),XR 运行时会将 XRCamera3D 移动到 XROrigin3D 节点。OpenXRInterface 还将发出 pose_recentered
信号,以便你的游戏可以做出相应的反应。
备注
其他 XR 追踪元素,如控制器、锚点,也将相应调整,以保持和重置后的玩家位置一致。
警告
在使用此参照空间时,不应调用 center_on_hmd
。
Stage(暂存区)
Stage 参照空间是默认参照空间设置,此选项将原点放置在游戏空间的中心。对于允许用户绘制防护边界的 XR 运行时来说,这个位置及其方向通常由用户设置,而其他 XR 运行时可能会通过其他方式来决定该点位置。不过原点在现实世界中还是静态不动的。
该参照空间最适合在游戏涉及房间尺度,并且用户预计会在较大空间中活动时使用。同样也适合需要在多种模式中切换的游戏。有关详细信息,请参见 XR 中的房间尺度。
当用户在其头戴设备上执行重置时(重置在不同 XR 运行时中有所不同), XR 运行时不会更改原点。OpenXRInterface 将发出 pose_recentered
信号,游戏需要根据此信号做出适当反应。未正确处理可能导致游戏无法通过分销平台的完整性审核。
在 Godot 中,可以调用 XRServer 上的 center_on_hmd
函数来实现:
调用
XRServer.center_on_hmd(XRServer.RESET_BUT_KEEP_TILT, true)
会将 XRCamera3D 节点移动到 XROrigin3D 节点,类似于 “Local” 参考空间。Calling
XRServer.center_on_hmd(XRServer.RESET_BUT_KEEP_TILT, true)
will move the XRCamera3D node above the XROrigin3D node keeping the player's height, similar to theLocal Floor
reference space.
备注
其他 XR 追踪元素,如控制器、锚点,也将相应调整,以保持和重置后的玩家位置一致。
Local Floor
The local floor reference space is similar to the local reference space as it positions the origin point where the player is. In this mode however the height of the player is kept. Same as with the local reference space, some XR runtimes will persist this location over sessions.
因此,不能保证玩家会站在原点上,唯一的保证是当用户最后一次回到中心时,他们站在那里。玩家因此也可以自由离开。
该参考空间是期望用户站在相同位置的游戏的最佳选项,或者对于 AR 类型的游戏,其中用户的界面元素被绑定到原点节点,并被快速放置在玩家的位置上。
When the user enacts the recenter option on their headset, the method of which is different per XR runtime,
the XR runtime will move the XRCamera3D above the XROrigin3D node
but keeping the player's height.
The OpenXRInterface will also emit the pose_recentered
signal
so your game can react accordingly.
警告
Be careful using this mode in combination with virtual movement of the player.
The user recentering in this scenario can be unpredictable unless you counter the move when handling the recenter signal.
This can even be game breaking as the effect in this scenario would be the player teleporting to whatever abstract location
the origin point was placed at during virtual movement, including the ability for players teleporting into
locations that should be off limits.
It is better to use the Stage mode in this scenario and limit resetting to orientation only when a pose_recentered
signal is received.
备注
其他 XR 追踪元素,如控制器、锚点,也将相应调整,以保持和重置后的玩家位置一致。
警告
在使用此参照空间时,不应调用 center_on_hmd
。
环境混合模式
环境混合模式定义了我们的渲染输出如何混合到“真实世界”中,前提是耳机支持。
Opaque
means our output obscures the real world, we are in VR mode.Additive
means our output is added to the real world, this is an AR mode where optics do not allow us to fully obscure the real world (e.g. Hololens),Alpha
means our output is blended with the real world using the alpha output (viewport should have transparent background enabled), this is an AR mode where optics can fully obscure the real world (Magic Leap, all pass through devices, etc.).
如果选择了耳机不支持的模式,将选择第一个可用的模式。
备注
Some OpenXR devices have separate systems for enabling/disabling passthrough. From Godot 4.3 onwards selecting the alpha blend mode will also perform these extra steps. This does require the latest vendor plugin to be installed.
注视点级别
Sets the foveation level used when rendering provided this feature is supported by the hardware used. Foveation is a technique where the further away from the center of the viewport we render content, the lower resolution we render at. Most XR runtimes only support fixed foveation, but some will take eye tracking into account and use the focal point for this effect.
级别越高,性能增益越好,但是用户周边视觉的质量下降也越多。
备注
Compatibility renderer only,
for Mobile and Forward+ renderer, set the vrs_mode
property on Viewport to VRS_XR
.
警告
This feature is disabled if post effects are used such as glow, bloom, or DOF.
动态注视点
启用后,视野水平将根据当前的GPU负载自动调整。它将在低和先前设置中选择的视野水平之间调整。因此,最好将此设置与设置为高的视野等级相结合。
备注
Compatibility renderer only
提交深度缓冲区
如果启用,将在渲染时使用 OpenXR 提供的深度缓冲区,该缓冲区与渲染图像一起提交。XR 运行时可以利用这一点来改进重新投影。
备注
Enabling this feature will disable stencil support during rendering. Not many XR runtimes make use of this, it is advised to leave this setting off unless it provides noticeable benefits for your use case.
启动警报
If enabled, this will result in an alert message presented to the user if OpenXR fails to start. We don't always receive feedback from the XR system as to why starting fails. If we do, we log this to the console. Common failure reasons are:
主机系统上没有安装 OpenXR 运行时。
微软的WMR OpenXR运行时当前处于活动状态,它仅支持 DirectX,如果使用 OpenGL 或 Vulkan 将会失败。
使用了 SteamVR,但没有连接/打开耳机。
Disable this if you support a fallback mode in your game so it can be played in desktop mode when no VR headset is connected,
or if you're handling the failure condition yourself by checking OpenXRInterface.is_initialized()
.
拓展选项
本小节提供了对各种可选的 OpenXR 扩展的访问。
手部跟踪
This enables the hand tracking extension when supported by the device used. This is on by default for legacy reasons. The hand tracking extension provides access to data that allows you to visualise the user's hands with correct finger positions. Depending on platform capabilities the hand tracking data can be inferred from controller inputs, come from data gloves, come from optical hand tracking sensors or any other applicable source.
如果你的游戏只支持控制器,这应该被关闭。
详情见手部跟踪章节。
眼动交互
This enables the eye gaze interaction extension when supported by the device used. When enabled we will get feedback from eye tracking through a pose situated between the user's eyes orientated in the direction the user is looking. This will be a unified orientation.
In order to use this functionality you need to edit your action map and add a new pose action,
say eye_pose
.
Now add a new interaction profile for the eye gaze interaction and map the eye_pose
:

别忘了保存!
Next add a new XRController3D node to your origin node
and set its tracker
property to /user/eyes_ext
and set its pose
property to eye_pose
.
现在你可以添加一些东西到这个控制器节点,比如光线投射,并且用你的眼睛控制东西。