From cd49dc6627d6933b0e70d4cca45c1b7b3d24fcda Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 7 Nov 2022 17:13:08 +0100 Subject: [PATCH 1/6] OpenXR - Camera adjustment using PSP keys --- Common/VR/PPSSPPVR.cpp | 69 +++++++++++++++--------------------------- Common/VR/PPSSPPVR.h | 2 +- Core/KeyMap.cpp | 1 + Core/KeyMap.h | 1 + UI/NativeApp.cpp | 4 +-- 5 files changed, 30 insertions(+), 47 deletions(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 73fb91f6aa..889aecf778 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -199,18 +199,6 @@ void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(con int status = IN_VRGetButtonState(j); for (ButtonMapping& m : controllerMapping[j]) { - //check if camera key was pressed - bool cameraKey = false; - std::vector nativeKeys; - if (KeyMap::KeyToPspButton(controllerIds[j], m.keycode, &nativeKeys)) { - for (int& nativeKey : nativeKeys) { - if (nativeKey == VIRTKEY_VR_CAMERA_ADJUST) { - cameraKey = true; - break; - } - } - } - //fill KeyInput structure bool pressed = status & m.ovr; keyInput.flags = pressed ? KEY_DOWN : KEY_UP; @@ -222,16 +210,12 @@ void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(con if (pressed && haptics) { INVR_Vibrate(100, j, 1000); } - if (!pspKeys[VIRTKEY_VR_CAMERA_ADJUST] || cameraKey) { - NativeKey(keyInput); - } + NativeKey(keyInput); m.pressed = pressed; m.repeat = 0; } else if (pressed && (m.repeat > 30)) { keyInput.flags |= KEY_IS_REPEAT; - if (!pspKeys[VIRTKEY_VR_CAMERA_ADJUST] || cameraKey) { - NativeKey(keyInput); - } + NativeKey(keyInput); m.repeat = 0; } else { m.repeat++; @@ -339,13 +323,14 @@ void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(con } } -void UpdateVRSpecialKeys(const KeyInput &key) { +bool UpdateVRSpecialKeys(const KeyInput &key) { std::vector nativeKeys; if (KeyMap::KeyToPspButton(key.deviceId, key.keyCode, &nativeKeys)) { for (int& nativeKey : nativeKeys) { pspKeys[nativeKey] = key.flags & KEY_DOWN; } } + return !pspKeys[VIRTKEY_VR_CAMERA_ADJUST]; } /* @@ -577,34 +562,30 @@ bool StartVRRender() { // Camera control if (pspKeys[VIRTKEY_VR_CAMERA_ADJUST]) { //left joystick controls height and side - float height = g_Config.fCameraHeight; - float side = g_Config.fCameraSide; - int status = IN_VRGetButtonState(0); - if (status & ovrButton_Left) side -= 0.05f; - if (status & ovrButton_Right) side += 0.05f; - if (status & ovrButton_Down) height -= 0.05f; - if (status & ovrButton_Up) height += 0.05f; - if (status & ovrButton_LThumb) { - height = 0; - side = 0; - } - g_Config.fCameraHeight = clampFloat(height, -10.0f, 10.0f); - g_Config.fCameraSide = clampFloat(side, -10.0f, 10.0f); + if (pspKeys[CTRL_LEFT]) g_Config.fCameraSide -= 0.05f; + if (pspKeys[CTRL_RIGHT]) g_Config.fCameraSide += 0.05f; + if (pspKeys[CTRL_DOWN]) g_Config.fCameraHeight -= 0.05f; + if (pspKeys[CTRL_UP]) g_Config.fCameraHeight += 0.05f; //right joystick controls distance and fov - float dst = g_Config.fCameraDistance; - float fov = g_Config.fFieldOfViewPercentage; - status = IN_VRGetButtonState(1); - if (status & ovrButton_Left) fov -= 1.0f; - if (status & ovrButton_Right) fov += 1.0f; - if (status & ovrButton_Down) dst -= 0.1f; - if (status & ovrButton_Up) dst += 0.1f; - if (status & ovrButton_RThumb) { - fov = 100; - dst = 0; + if (pspKeys[VIRTKEY_AXIS_X_MIN]) g_Config.fFieldOfViewPercentage -= 1.0f; + if (pspKeys[VIRTKEY_AXIS_X_MAX]) g_Config.fFieldOfViewPercentage += 1.0f; + if (pspKeys[VIRTKEY_AXIS_Y_MIN]) g_Config.fCameraDistance -= 0.1f; + if (pspKeys[VIRTKEY_AXIS_Y_MAX]) g_Config.fCameraDistance += 0.1f; + + // Reset values + if (pspKeys[VIRTKEY_VR_CAMERA_RESET]) { + g_Config.fCameraHeight = 0; + g_Config.fCameraSide = 0; + g_Config.fCameraDistance = 0; + g_Config.fFieldOfViewPercentage = 100; } - g_Config.fCameraDistance = clampFloat(dst, -10.0f, 10.0f); - g_Config.fFieldOfViewPercentage = clampFloat(fov, 100.0f, 200.0f); + + // Clamp values + g_Config.fCameraHeight = clampFloat(g_Config.fCameraHeight, -10.0f, 10.0f); + g_Config.fCameraSide = clampFloat(g_Config.fCameraSide, -10.0f, 10.0f); + g_Config.fCameraDistance = clampFloat(g_Config.fCameraDistance, -10.0f, 10.0f); + g_Config.fFieldOfViewPercentage = clampFloat(g_Config.fFieldOfViewPercentage, 100.0f, 200.0f); } // Set customizations diff --git a/Common/VR/PPSSPPVR.h b/Common/VR/PPSSPPVR.h index 2dd2d1c11f..8dd127a2cb 100644 --- a/Common/VR/PPSSPPVR.h +++ b/Common/VR/PPSSPPVR.h @@ -23,7 +23,7 @@ void InitVROnAndroid(void* vm, void* activity, const char* system, int version, void EnterVR(bool firstStart, void* vulkanContext); void GetVRResolutionPerEye(int* width, int* height); void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(const TouchInput &touch), bool haptics, float dp_xscale, float dp_yscale); -void UpdateVRSpecialKeys(const KeyInput &key); +bool UpdateVRSpecialKeys(const KeyInput &key); // VR games compatibility void PreprocessStepVR(void* step); diff --git a/Core/KeyMap.cpp b/Core/KeyMap.cpp index 8c84be11e1..a853b69dfa 100644 --- a/Core/KeyMap.cpp +++ b/Core/KeyMap.cpp @@ -408,6 +408,7 @@ const KeyMap_IntStrPair psp_button_names[] = { #ifdef OPENXR {VIRTKEY_VR_CAMERA_ADJUST, "VR camera adjust"}, + {VIRTKEY_VR_CAMERA_RESET, "VR camera reset"}, #else {VIRTKEY_SCREEN_ROTATION_VERTICAL, "Display Portrait"}, {VIRTKEY_SCREEN_ROTATION_VERTICAL180, "Display Portrait Reversed"}, diff --git a/Core/KeyMap.h b/Core/KeyMap.h index 74859d3628..c81958ab26 100644 --- a/Core/KeyMap.h +++ b/Core/KeyMap.h @@ -69,6 +69,7 @@ enum { VIRTKEY_SCREEN_ROTATION_HORIZONTAL180 = 0x40000023, VIRTKEY_SPEED_ANALOG = 0x40000024, VIRTKEY_VR_CAMERA_ADJUST = 0x40000025, + VIRTKEY_VR_CAMERA_RESET = 0x40000026, VIRTKEY_LAST, VIRTKEY_COUNT = VIRTKEY_LAST - VIRTKEY_FIRST }; diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index d387e7064b..92bb129f30 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1297,8 +1297,8 @@ bool NativeTouch(const TouchInput &touch) { bool NativeKey(const KeyInput &key) { // Special key VR actions - if (IsVREnabled()) { - UpdateVRSpecialKeys(key); + if (IsVREnabled() && !UpdateVRSpecialKeys(key)) { + return false; } // INFO_LOG(SYSTEM, "Key code: %i flags: %i", key.keyCode, key.flags); From e1baa3d4241eb4fa3be58f5ce39cf1deec62fc8f Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 7 Nov 2022 17:14:27 +0100 Subject: [PATCH 2/6] OpenXR - Camera sliders removed from settings --- UI/GameSettingsScreen.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index e46311870b..f5b6662800 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1165,9 +1165,6 @@ void GameSettingsScreen::CreateViews() { vrSettings->Add(new CheckBox(&g_Config.bForce72Hz, vr->T("Force 72Hz update"))); vrSettings->Add(new ItemHeader(vr->T("VR camera"))); - vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraDistance, -10.0f, 10.0f, vr->T("Camera distance adjust"), 1.0f, screenManager(), "")); - vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraHeight, -10.0f, 10.0f, vr->T("Camera height adjust"), 1.0f, screenManager(), "")); - vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraSide, -10.0f, 10.0f, vr->T("Camera side adjust"), 1.0f, screenManager(), "")); vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCanvasDistance, 1.0f, 10.0f, vr->T("Distance to 2D menus and scenes"), 1.0f, screenManager(), "")); vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fFieldOfViewPercentage, 100.0f, 200.0f, vr->T("Field of view scale"), 10.0f, screenManager(), vr->T("% of native FoV"))); From 81b5a38484aea67f3abb7e3bcdabc9d769c4f66a Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 7 Nov 2022 21:34:09 +0100 Subject: [PATCH 3/6] OpenXR - GTA Liberty city stereo fixed --- assets/compatvr.ini | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/assets/compatvr.ini b/assets/compatvr.ini index bc4e1a6dd1..b54081f4f5 100644 --- a/assets/compatvr.ini +++ b/assets/compatvr.ini @@ -758,15 +758,15 @@ ULJM05604 = 1.0 ULUS10490 = 1.0 # Grand Theft Auto: Liberty City Stories -NPJH50825 = 1.0 -ULES00051 = 1.0 -ULES00151 = 1.0 -ULES00181 = 1.0 -ULES00182 = 1.0 -ULJM05255 = 1.0 -ULJM05359 = 1.0 -ULJM05885 = 1.0 -ULUS10041 = 1.0 +NPJH50825 = 0.5 +ULES00051 = 0.5 +ULES00151 = 0.5 +ULES00181 = 0.5 +ULES00182 = 0.5 +ULJM05255 = 0.5 +ULJM05359 = 0.5 +ULJM05885 = 0.5 +ULUS10041 = 0.5 # Grand Theft Auto: Vice City Stories NPJH50827 = 1.0 From eec414d33134d2769265ea9088446377c5c9fa14 Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 7 Nov 2022 21:40:25 +0100 Subject: [PATCH 4/6] OpenXR - Allow more extreme camera adjusts --- Common/VR/PPSSPPVR.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index b12af503db..8513500b86 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -584,9 +584,9 @@ bool StartVRRender() { } // Clamp values - g_Config.fCameraHeight = clampFloat(g_Config.fCameraHeight, -10.0f, 10.0f); - g_Config.fCameraSide = clampFloat(g_Config.fCameraSide, -10.0f, 10.0f); - g_Config.fCameraDistance = clampFloat(g_Config.fCameraDistance, -10.0f, 10.0f); + g_Config.fCameraHeight = clampFloat(g_Config.fCameraHeight, -50.0f, 50.0f); + g_Config.fCameraSide = clampFloat(g_Config.fCameraSide, -50.0f, 50.0f); + g_Config.fCameraDistance = clampFloat(g_Config.fCameraDistance, -50.0f, 50.0f); g_Config.fFieldOfViewPercentage = clampFloat(g_Config.fFieldOfViewPercentage, 100.0f, 200.0f); } From d1dabd40eea94240fa7d9ba05ca50b8ef6b78757 Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 7 Nov 2022 22:10:12 +0100 Subject: [PATCH 5/6] OpenXR - Disable range culling properly --- GPU/Common/VertexShaderGenerator.cpp | 2 +- GPU/GPUCommon.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GPU/Common/VertexShaderGenerator.cpp b/GPU/Common/VertexShaderGenerator.cpp index fd99a52cd9..0e18ac1361 100644 --- a/GPU/Common/VertexShaderGenerator.cpp +++ b/GPU/Common/VertexShaderGenerator.cpp @@ -1302,7 +1302,7 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag WRITE(p, " }\n"); } - if (vertexRangeCulling && !gstate_c.Use(GPU_USE_VIRTUAL_REALITY)) { + if (vertexRangeCulling) { WRITE(p, " vec3 projPos = outPos.xyz / outPos.w;\n"); WRITE(p, " float projZ = (projPos.z - u_depthRange.z) * u_depthRange.w;\n"); diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index ddaf02bab8..f27dc85c38 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -3338,7 +3338,7 @@ u32 GPUCommon::CheckGPUFeatures() const { bool canClipOrCull = draw_->GetDeviceCaps().clipDistanceSupported || draw_->GetDeviceCaps().cullDistanceSupported; bool canDiscardVertex = draw_->GetBugs().Has(Draw::Bugs::BROKEN_NAN_IN_CONDITIONAL); - if (canClipOrCull || canDiscardVertex) { + if (!gstate_c.Use(GPU_USE_VIRTUAL_REALITY) &&(canClipOrCull || canDiscardVertex)) { // We'll dynamically use the parts that are supported, to reduce artifacts as much as possible. features |= GPU_USE_VS_RANGE_CULLING; } From 92384c285470a8648b517cd48c1ee46b330c8227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Von=C3=A1sek?= Date: Tue, 8 Nov 2022 07:09:27 +0100 Subject: [PATCH 6/6] Space added --- GPU/GPUCommon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index f27dc85c38..ef0cd2d246 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -3338,7 +3338,7 @@ u32 GPUCommon::CheckGPUFeatures() const { bool canClipOrCull = draw_->GetDeviceCaps().clipDistanceSupported || draw_->GetDeviceCaps().cullDistanceSupported; bool canDiscardVertex = draw_->GetBugs().Has(Draw::Bugs::BROKEN_NAN_IN_CONDITIONAL); - if (!gstate_c.Use(GPU_USE_VIRTUAL_REALITY) &&(canClipOrCull || canDiscardVertex)) { + if (!gstate_c.Use(GPU_USE_VIRTUAL_REALITY) && (canClipOrCull || canDiscardVertex)) { // We'll dynamically use the parts that are supported, to reduce artifacts as much as possible. features |= GPU_USE_VS_RANGE_CULLING; }