From 13ee4b6c694faa92a9670a7e5859a593d89c6ab8 Mon Sep 17 00:00:00 2001 From: Bastiaan Olij Date: Mon, 18 Mar 2024 13:37:22 +1100 Subject: [PATCH] Add VRS/Foveated rendering to XR start script --- tutorials/xr/a_better_xr_start_script.rst | 33 ++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/tutorials/xr/a_better_xr_start_script.rst b/tutorials/xr/a_better_xr_start_script.rst index 7f8aeaecb..4d9b10385 100644 --- a/tutorials/xr/a_better_xr_start_script.rst +++ b/tutorials/xr/a_better_xr_start_script.rst @@ -91,7 +91,16 @@ We introduce a few new variables to our script as well: Our updated ready function -------------------------- -The ready function mostly remains the same but we hook up a number of signals that will be emitted by the :ref:`XRInterface `. +We add a few things to the ready function. + +If we're using the mobile or forward+ renderer we set the viewports ``vrs_mode`` to ``VRS_XR``. +On platforms that support this, this will enable foveated rendering. + +If we're using the compatibility renderer, we check if the OpenXR foveated rendering settings +are configured and if not, we output a warning. +See :ref:`OpenXR Settings ` for further details. + +We hook up a number of signals that will be emitted by the :ref:`XRInterface `. We'll provide more detail about these signals as we implement them. We also quit our application if we couldn't successfully initialise OpenXR. @@ -119,12 +128,18 @@ it is nicer to exit on failure than to hang the system. # Make sure v-sync is off, v-sync is handled by OpenXR DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_DISABLED) + # Enable VRS + if RenderingServer.get_rendering_device(): + vp.vrs_mode = Viewport.VRS_XR + elif int(ProjectSettings.get_setting("xr/openxr/foveation_level")) == 0: + push_warning("OpenXR: Recommend setting Foveation level to High in Project Settings") + # Connect the OpenXR events - xr_interface.connect("session_begun", _on_openxr_session_begun) - xr_interface.connect("session_visible", _on_openxr_visible_state) - xr_interface.connect("session_focussed", _on_openxr_focused_state) - xr_interface.connect("session_stopping", _on_openxr_stopping) - xr_interface.connect("pose_recentered", _on_openxr_pose_recentered) + xr_interface.session_begun.connect(_on_openxr_session_begun) + xr_interface.session_visible.connect(_on_openxr_visible_state) + xr_interface.session_focussed.connect(_on_openxr_focused_state) + xr_interface.session_stopping.connect(_on_openxr_stopping) + xr_interface.pose_recentered.connect(_on_openxr_pose_recentered) else: # We couldn't start OpenXR. print("OpenXR not instantiated!") @@ -153,6 +168,12 @@ it is nicer to exit on failure than to hang the system. // Make sure v-sync is off, v-sync is handled by OpenXR DisplayServer.WindowSetVsyncMode(DisplayServer.VSyncMode.Disabled); + // Enable VRS + if (RenderingServer.GetRenderingDevice() != null) + vp.VrsMode = Viewport.VrsModeEnum.XR; + else if ((int)ProjectSettings.GetSetting("xr/openxr/foveation_level") == 0) + GD.PushWarning("OpenXR: Recommend setting Foveation level to High in Project Settings"); + // Connect the OpenXR events _xrInterface.SessionBegun += OnOpenXRSessionBegun; _xrInterface.SessionVisible += OnOpenXRVisibleState;