Godot Engine – Multi-platform 2D and 3D game engine
OpenXR: Allow flipping Y direction of motion vectors for frame synthesis
David Snopek4f35394962b4
diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xmlindex cceea0e3976..ef329f0a10a 100644--- a/doc/classes/ProjectSettings.xml+++ b/doc/classes/ProjectSettings.xml@@ -3583,6 +3583,10 @@If [code]true[/code] the frame synthesis extension will be activated if supported by the platform.[b]Note:[/b] This feature should not be enabled in conjunction with Application Space Warp, if supported this replaces ASW.</member>+ <member name="xr/openxr/extensions/frame_synthesis/flip_y" type="bool" setter="" getter="" default="false">+ If [code]true[/code] the Y value of the motion vectors submitted to the frame synthesis extension will be flipped.+ [b]Note:[/b] Since this is only needed on some platforms, it should usually be set using a feature tag, for example, to target Android XR: [code]xr/openxr/extensions/frame_synthesis/flip_y.androidxr[/code]+ </member><member name="xr/openxr/extensions/hand_interaction_profile" type="bool" setter="" getter="" default="false">If [code]true[/code] the hand interaction profile extension will be activated if supported by the platform.</member>diff --git a/main/main.cpp b/main/main.cppindex 79fc9e4eb1c..f86f9b3ad4c 100644--- a/main/main.cpp+++ b/main/main.cpp@@ -2884,6 +2884,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_phGLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "xr/openxr/extensions/debug_utils", PROPERTY_HINT_ENUM, "Disabled,Error,Warning,Info,Verbose"), "0");GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "xr/openxr/extensions/debug_message_types", PROPERTY_HINT_FLAGS, "General,Validation,Performance,Conformance"), "15");GLOBAL_DEF_BASIC("xr/openxr/extensions/frame_synthesis", false);+ GLOBAL_DEF_BASIC("xr/openxr/extensions/frame_synthesis/flip_y", false);GLOBAL_DEF_BASIC("xr/openxr/extensions/hand_tracking", false);GLOBAL_DEF_BASIC("xr/openxr/extensions/hand_tracking_unobstructed_data_source", false); // XR_HAND_TRACKING_DATA_SOURCE_UNOBSTRUCTED_EXTGLOBAL_DEF_BASIC("xr/openxr/extensions/hand_tracking_controller_data_source", false); // XR_HAND_TRACKING_DATA_SOURCE_CONTROLLER_EXTdiff --git a/modules/openxr/extensions/openxr_frame_synthesis_extension.cpp b/modules/openxr/extensions/openxr_frame_synthesis_extension.cppindex d67198a2384..9e923d8ed3a 100644--- a/modules/openxr/extensions/openxr_frame_synthesis_extension.cpp+++ b/modules/openxr/extensions/openxr_frame_synthesis_extension.cpp@@ -220,6 +220,12 @@ void OpenXRFrameSynthesisExtension::on_main_swapchains_created() {// Set up our frame synthesis info.render_state.frame_synthesis_info.resize(view_count);+ // Y direction is undefined so we allow users to flip it for conflicting implementations.+ float y_scale = 1.0;+ if (GLOBAL_GET("xr/openxr/extensions/frame_synthesis/flip_y")) {+ y_scale = -1.0;+ }+uint32_t index = 0;for (XrFrameSynthesisInfoEXT &frame_synthesis_info : render_state.frame_synthesis_info) {frame_synthesis_info.type = XR_TYPE_FRAME_SYNTHESIS_INFO_EXT;@@ -234,8 +240,7 @@ void OpenXRFrameSynthesisExtension::on_main_swapchains_created() {frame_synthesis_info.motionVectorSubImage.imageRect.extent.width = width;frame_synthesis_info.motionVectorSubImage.imageRect.extent.height = height;- // Q: this should be 1.0, -1.0, 1.0. We output OpenGL NDC, frame synthesis expects Vulkan NDC, but might be a problem on runtime I'm testing.- frame_synthesis_info.motionVectorScale = { 1.0, 1.0, 1.0, 0.0 };+ frame_synthesis_info.motionVectorScale = { 1.0, y_scale, 1.0, 0.0 };frame_synthesis_info.motionVectorOffset = { 0.0, 0.0, 0.0, 0.0 };frame_synthesis_info.appSpaceDeltaPose = { { 0.0, 0.0, 0.0, 1.0 }, { 0.0, 0.0, 0.0 } };