Skip to content

Commit 0d8f194

Browse files
authored
Merge pull request #19361 from lvonasek/feature-openxr-antiflickering
OpenXR - Anti-flickering rendering flow added
2 parents a0299e1 + 0f313e1 commit 0d8f194

52 files changed

Lines changed: 89 additions & 91 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Common/VR/PPSSPPVR.cpp

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,9 @@ void UpdateVRInput(bool haptics, float dp_xscale, float dp_yscale) {
388388
g_Config.fCameraHeight = clampFloat(g_Config.fCameraHeight, -150.0f, 150.0f);
389389
break;
390390
case JOYSTICK_AXIS_Z:
391-
if (g_Config.bEnableVR) {
392-
if (axis.second < -0.75f) g_Config.fHeadUpDisplayScale -= 0.01f;
393-
if (axis.second > 0.75f) g_Config.fHeadUpDisplayScale += 0.01f;
394-
g_Config.fHeadUpDisplayScale = clampFloat(g_Config.fHeadUpDisplayScale, 0.0f, 1.5f);
395-
} else {
396-
if (axis.second < -0.75f) g_Config.fCanvas3DDistance += 0.1f;
397-
if (axis.second > 0.75f) g_Config.fCanvas3DDistance -= 0.1f;
398-
g_Config.fCanvas3DDistance = clampFloat(g_Config.fCanvas3DDistance, 1.0f, 15.0f);
399-
}
391+
if (axis.second < -0.75f) g_Config.fCameraPitch -= 0.5f;
392+
if (axis.second > 0.75f) g_Config.fCameraPitch += 0.5f;
393+
g_Config.fCameraPitch = clampFloat(g_Config.fCameraPitch, -90.0f, 90.0f);
400394
break;
401395
case JOYSTICK_AXIS_RZ:
402396
if (axis.second > 0.75f) g_Config.fCameraDistance -= 0.1f;
@@ -539,11 +533,10 @@ bool UpdateVRKeys(const KeyInput &key) {
539533

540534
// Reset camera adjust
541535
if (pspKeys[VIRTKEY_VR_CAMERA_ADJUST] && pspKeys[VIRTKEY_VR_CAMERA_RESET]) {
542-
g_Config.fCanvas3DDistance = 3.0f;
543536
g_Config.fCameraHeight = 0;
544537
g_Config.fCameraSide = 0;
545538
g_Config.fCameraDistance = 0;
546-
g_Config.fHeadUpDisplayScale = 0.3f;
539+
g_Config.fCameraPitch = 0;
547540
}
548541

549542
//block keys by camera adjust
@@ -667,12 +660,16 @@ bool StartVRRender() {
667660
M[10] = -1;
668661
M[11] = -(fovHack + fovHack);
669662
M[14] = -(nearZ + nearZ);
663+
if (g_Config.bAntiFlickeringFlow) {
664+
M[0] /= 2.0f;
665+
}
670666
memcpy(vrMatrix[VR_PROJECTION_MATRIX], M, sizeof(float) * 16);
671667

672668
// Decide if the scene is 3D or not
673669
VR_SetConfigFloat(VR_CONFIG_CANVAS_ASPECT, 480.0f / 272.0f);
674670
if (g_Config.bEnableVR && !vrIncompatibleGame && (appMode == VR_GAME_MODE) && vrScene) {
675671
VR_SetConfig(VR_CONFIG_MODE, vrStereo ? VR_MODE_STEREO_6DOF : VR_MODE_MONO_6DOF);
672+
VR_SetConfig(VR_CONFIG_REPROJECTION, g_Config.bAntiFlickeringFlow ? 0 : 1);
676673
vrFlatGame = false;
677674
} else if (appMode == VR_GAME_MODE) {
678675
VR_SetConfig(VR_CONFIG_MODE, vrStereo ? VR_MODE_STEREO_SCREEN : VR_MODE_MONO_SCREEN);
@@ -689,7 +686,7 @@ bool StartVRRender() {
689686

690687
// Set customizations
691688
VR_SetConfigFloat(VR_CONFIG_CANVAS_DISTANCE, vrScene && (appMode == VR_GAME_MODE) ? g_Config.fCanvas3DDistance : g_Config.fCanvasDistance);
692-
VR_SetConfig(VR_CONFIG_PASSTHROUGH, g_Config.bPassthrough);
689+
VR_SetConfig(VR_CONFIG_PASSTHROUGH, g_Config.bPassthrough && IsPassthroughSupported());
693690
return true;
694691
}
695692
return false;
@@ -874,23 +871,13 @@ void UpdateVRViewMatrices() {
874871
invView = XrPosef_Inverse(invView);
875872
}
876873

877-
// apply camera pitch offset
874+
// apply camera pitch
875+
float s = sin(ToRadians(g_Config.fCameraPitch));
876+
float c = cos(ToRadians(g_Config.fCameraPitch));
878877
XrVector3f positionOffset = {g_Config.fCameraSide, g_Config.fCameraHeight, g_Config.fCameraDistance};
879-
if (!flatScreen) {
880-
float pitchOffset = 0;
881-
switch (g_Config.iCameraPitch) {
882-
case 1: //Top view -> First person
883-
pitchOffset = 90;
884-
positionOffset = {positionOffset.x, positionOffset.z, -positionOffset.y};
885-
break;
886-
case 2: //First person -> Top view
887-
pitchOffset = -90;
888-
positionOffset = {positionOffset.x, -positionOffset.z + 20, positionOffset.y};
889-
break;
890-
}
891-
XrQuaternionf rotationOffset = XrQuaternionf_CreateFromVectorAngle({1, 0, 0}, ToRadians(pitchOffset));
892-
invView.orientation = XrQuaternionf_Multiply(rotationOffset, invView.orientation);
893-
}
878+
positionOffset = {positionOffset.x, s * positionOffset.z + c * positionOffset.y, c * positionOffset.z - s * positionOffset.y};
879+
XrQuaternionf rotationOffset = XrQuaternionf_CreateFromVectorAngle({1, 0, 0}, ToRadians(g_Config.fCameraPitch));
880+
invView.orientation = XrQuaternionf_Multiply(rotationOffset, invView.orientation);
894881

895882
// decompose rotation
896883
XrVector3f rotation = XrQuaternionf_ToEulerAngles(invView.orientation);
@@ -906,12 +893,16 @@ void UpdateVRViewMatrices() {
906893
XrQuaternionf yaw = XrQuaternionf_CreateFromVectorAngle({0, 1, 0}, mYaw);
907894
XrQuaternionf roll = XrQuaternionf_CreateFromVectorAngle({0, 0, 1}, mRoll);
908895
invView.orientation = XrQuaternionf_Multiply(roll, XrQuaternionf_Multiply(pitch, yaw));
896+
if (!VR_GetConfig(VR_CONFIG_REPROJECTION)) {
897+
float axis = vrMirroring[VR_MIRRORING_PITCH] ? -1.0f : 1.0f;
898+
invView.orientation = XrQuaternionf_CreateFromVectorAngle({axis, 0, 0}, ToRadians(g_Config.fCameraPitch));
899+
}
909900

910901
float M[16];
911902
XrQuaternionf_ToMatrix4f(&invView.orientation, M);
912903

913904
// Apply 6Dof head movement
914-
if (g_Config.bEnable6DoF && !g_Config.bHeadRotationEnabled && (g_Config.iCameraPitch == 0)) {
905+
if (g_Config.bEnable6DoF && !g_Config.bHeadRotationEnabled) {
915906
M[3] -= vrView[0].pose.position.x * (vrMirroring[VR_MIRRORING_AXIS_X] ? -1.0f : 1.0f) * scale;
916907
M[7] -= vrView[0].pose.position.y * (vrMirroring[VR_MIRRORING_AXIS_Y] ? -1.0f : 1.0f) * scale;
917908
M[11] -= vrView[0].pose.position.z * (vrMirroring[VR_MIRRORING_AXIS_Z] ? -1.0f : 1.0f) * scale;

Common/VR/VRRenderer.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,9 @@ void VR_EndFrame( engine_t* engine ) {
384384
void VR_FinishFrame( engine_t* engine ) {
385385
int vrMode = vrConfig[VR_CONFIG_MODE];
386386
XrCompositionLayerProjectionView projection_layer_elements[2] = {};
387-
if ((vrMode == VR_MODE_MONO_6DOF) || (vrMode == VR_MODE_SBS_6DOF) || (vrMode == VR_MODE_STEREO_6DOF)) {
387+
bool headTracking = (vrMode == VR_MODE_MONO_6DOF) || (vrMode == VR_MODE_SBS_6DOF) || (vrMode == VR_MODE_STEREO_6DOF);
388+
bool reprojection = vrConfig[VR_CONFIG_REPROJECTION];
389+
if (headTracking && reprojection) {
388390
VR_SetConfigFloat(VR_CONFIG_MENU_YAW, hmdorientation.y);
389391

390392
for (int eye = 0; eye < ovrMaxNumEyes; eye++) {;
@@ -427,7 +429,7 @@ void VR_FinishFrame( engine_t* engine ) {
427429
projection_layer.views = projection_layer_elements;
428430

429431
engine->appState.Layers[engine->appState.LayerCount++].Projection = projection_layer;
430-
} else if ((vrMode == VR_MODE_MONO_SCREEN) || (vrMode == VR_MODE_SBS_SCREEN) || (vrMode == VR_MODE_STEREO_SCREEN)) {
432+
} else {
431433

432434
// Flat screen pose
433435
float distance = VR_GetConfigFloat(VR_CONFIG_CANVAS_DISTANCE) / 4.0f - 1.0f;
@@ -459,12 +461,18 @@ void VR_FinishFrame( engine_t* engine ) {
459461
cylinder_layer.radius = 2.0f;
460462
cylinder_layer.centralAngle = (float)(M_PI * 0.5);
461463
cylinder_layer.aspectRatio = VR_GetConfigFloat(VR_CONFIG_CANVAS_ASPECT);
464+
if (headTracking && !reprojection) {
465+
float width = engine->appState.ViewConfigurationView[0].recommendedImageRectWidth;
466+
float height = engine->appState.ViewConfigurationView[0].recommendedImageRectHeight;
467+
cylinder_layer.aspectRatio = 2.0f * width / height;
468+
cylinder_layer.centralAngle = (float)(M_PI);
469+
}
462470

463471
// Build the cylinder layer
464-
if (vrMode == VR_MODE_MONO_SCREEN) {
472+
if ((vrMode == VR_MODE_MONO_SCREEN) || (vrMode == VR_MODE_MONO_6DOF)) {
465473
cylinder_layer.eyeVisibility = XR_EYE_VISIBILITY_BOTH;
466474
engine->appState.Layers[engine->appState.LayerCount++].Cylinder = cylinder_layer;
467-
} else if (vrMode == VR_MODE_SBS_SCREEN) {
475+
} else if ((vrMode == VR_MODE_SBS_SCREEN) || (vrMode == VR_MODE_SBS_6DOF)) {
468476
cylinder_layer.eyeVisibility = XR_EYE_VISIBILITY_LEFT;
469477
cylinder_layer.subImage.imageRect.extent.width /= 2;
470478
engine->appState.Layers[engine->appState.LayerCount++].Cylinder = cylinder_layer;
@@ -478,8 +486,6 @@ void VR_FinishFrame( engine_t* engine ) {
478486
cylinder_layer.subImage.swapchain = engine->appState.Renderer.FrameBuffer[1].ColorSwapChain.Handle;
479487
engine->appState.Layers[engine->appState.LayerCount++].Cylinder = cylinder_layer;
480488
}
481-
} else {
482-
assert(false);
483489
}
484490

485491
// Compose the layers for this frame.

Common/VR/VRRenderer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
enum VRConfig {
77
//switching between mode
8-
VR_CONFIG_MODE, VR_CONFIG_PASSTHROUGH, VR_CONFIG_CANVAS_6DOF,
8+
VR_CONFIG_MODE, VR_CONFIG_PASSTHROUGH, VR_CONFIG_CANVAS_6DOF, VR_CONFIG_REPROJECTION,
99
//mouse cursor
1010
VR_CONFIG_MOUSE_SIZE, VR_CONFIG_MOUSE_X, VR_CONFIG_MOUSE_Y,
1111
//viewport setup

Core/Config.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,17 +954,18 @@ static const ConfigSetting themeSettings[] = {
954954

955955
static const ConfigSetting vrSettings[] = {
956956
ConfigSetting("VREnable", &g_Config.bEnableVR, true, CfgFlag::PER_GAME),
957-
ConfigSetting("VREnable6DoF", &g_Config.bEnable6DoF, true, CfgFlag::PER_GAME),
957+
ConfigSetting("VREnable6DoF", &g_Config.bEnable6DoF, false, CfgFlag::PER_GAME),
958958
ConfigSetting("VREnableStereo", &g_Config.bEnableStereo, false, CfgFlag::PER_GAME),
959959
ConfigSetting("VREnableMotions", &g_Config.bEnableMotions, true, CfgFlag::PER_GAME),
960960
ConfigSetting("VRForce72Hz", &g_Config.bForce72Hz, true, CfgFlag::PER_GAME),
961+
ConfigSetting("VRAntiFlickeringFlow", &g_Config.bAntiFlickeringFlow, true, CfgFlag::PER_GAME),
961962
ConfigSetting("VRManualForceVR", &g_Config.bManualForceVR, false, CfgFlag::PER_GAME),
962963
ConfigSetting("VRPassthrough", &g_Config.bPassthrough, false, CfgFlag::PER_GAME),
963964
ConfigSetting("VRRescaleHUD", &g_Config.bRescaleHUD, true, CfgFlag::PER_GAME),
964965
ConfigSetting("VRCameraDistance", &g_Config.fCameraDistance, 0.0f, CfgFlag::PER_GAME),
965966
ConfigSetting("VRCameraHeight", &g_Config.fCameraHeight, 0.0f, CfgFlag::PER_GAME),
966967
ConfigSetting("VRCameraSide", &g_Config.fCameraSide, 0.0f, CfgFlag::PER_GAME),
967-
ConfigSetting("VRCameraPitch", &g_Config.iCameraPitch, 0, CfgFlag::PER_GAME),
968+
ConfigSetting("VRCameraPitch", &g_Config.fCameraPitch, 0.0f, CfgFlag::PER_GAME),
968969
ConfigSetting("VRCanvasDistance", &g_Config.fCanvasDistance, 12.0f, CfgFlag::DEFAULT),
969970
ConfigSetting("VRCanvas3DDistance", &g_Config.fCanvas3DDistance, 3.0f, CfgFlag::DEFAULT),
970971
ConfigSetting("VRFieldOfView", &g_Config.fFieldOfViewPercentage, 100.0f, CfgFlag::PER_GAME),

Core/Config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,15 @@ struct Config {
482482
bool bEnable6DoF;
483483
bool bEnableStereo;
484484
bool bEnableMotions;
485+
bool bAntiFlickeringFlow;
485486
bool bForce72Hz;
486487
bool bManualForceVR;
487488
bool bPassthrough;
488489
bool bRescaleHUD;
489490
float fCameraDistance;
490491
float fCameraHeight;
491492
float fCameraSide;
493+
float fCameraPitch;
492494
float fCanvasDistance;
493495
float fCanvas3DDistance;
494496
float fFieldOfViewPercentage;
@@ -497,7 +499,6 @@ struct Config {
497499
float fHeadRotationScale;
498500
bool bHeadRotationEnabled;
499501
bool bHeadRotationSmoothing;
500-
int iCameraPitch;
501502

502503
// Debugger
503504
int iDisasmWindowX;

GPU/Common/FramebufferManagerCommon.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,13 +1664,13 @@ void FramebufferManagerCommon::CopyDisplayToOutput(bool reallyDirty) {
16641664

16651665
//clip the VR framebuffer to keep the aspect ratio
16661666
if (IsVREnabled() && !IsFlatVRGame() && !IsGameVRScene()) {
1667-
float aspect = 272.0f / 480.0f;
1667+
float aspect = 272.0f / 480.0f * (g_Config.bAntiFlickeringFlow ? 2.0f : 1.0f);
16681668
float clipY = 272.0f * (1.0f - aspect) / 2.0f;
16691669
v0 = (clipY + offsetY) / (float)vfb->bufferHeight;
16701670
v1 = (272.0f - clipY + offsetY) / (float)vfb->bufferHeight;
16711671

16721672
//zoom inside
1673-
float zoom = 0.1f;
1673+
float zoom = g_Config.bAntiFlickeringFlow ? 0.4f : 0.1f;
16741674
u0 += zoom / aspect;
16751675
u1 -= zoom / aspect;
16761676
v0 += zoom;

GPU/GLES/ShaderManagerGLES.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ void LinkedShader::UpdateUniforms(const ShaderID &vsid, bool useBufferedRenderin
412412
// Set HUD mode
413413
if (gstate_c.Use(GPU_USE_VIRTUAL_REALITY)) {
414414
if (GuessVRDrawingHUD(is2D, flatScreen)) {
415-
render_->SetUniformF1(&u_scaleX, g_Config.fHeadUpDisplayScale * 480.0f / 272.0f);
415+
float aspect = 480.0f / 272.0f * (g_Config.bAntiFlickeringFlow ? 0.5f : 1.0f);
416+
render_->SetUniformF1(&u_scaleX, g_Config.fHeadUpDisplayScale * aspect);
416417
render_->SetUniformF1(&u_scaleY, g_Config.fHeadUpDisplayScale);
417418
} else {
418419
render_->SetUniformF1(&u_scaleX, 1.0f);

UI/GameSettingsScreen.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,9 @@ void GameSettingsScreen::CreateVRSettings(UI::ViewGroup *vrSettings) {
12851285
vrSettings->Add(new CheckBox(&g_Config.bEnableVR, vr->T("Virtual reality")));
12861286
vrSettings->Add(new CheckBox(&g_Config.bEnable6DoF, vr->T("6DoF movement")));
12871287
vrSettings->Add(new CheckBox(&g_Config.bEnableStereo, vr->T("Stereoscopic vision (Experimental)")));
1288+
CheckBox* antiFlickering = new CheckBox(&g_Config.bAntiFlickeringFlow, vr->T("Anti-flickering flow"));
1289+
antiFlickering->SetEnabledPtr(&g_Config.bEnableVR);
1290+
vrSettings->Add(antiFlickering);
12881291
vrSettings->Add(new CheckBox(&g_Config.bForce72Hz, vr->T("Force 72Hz update")));
12891292
if (IsPassthroughSupported()) {
12901293
vrSettings->Add(new CheckBox(&g_Config.bPassthrough, vr->T("Enable passthrough")));
@@ -1308,8 +1311,6 @@ void GameSettingsScreen::CreateVRSettings(UI::ViewGroup *vrSettings) {
13081311
vrSettings->Add(new CheckBox(&g_Config.bEnableMotions, vr->T("Map controller movements to keys")));
13091312
PopupSliderChoiceFloat *vrMotions = vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fMotionLength, 0.3f, 1.0f, 0.5f, vr->T("Motion needed to generate action"), 0.1f, screenManager(), vr->T("m")));
13101313
vrMotions->SetEnabledPtr(&g_Config.bEnableMotions);
1311-
static const char *cameraPitchModes[] = { "Disabled", "Top view -> First person", "First person -> Top view" };
1312-
vrSettings->Add(new PopupMultiChoice(&g_Config.iCameraPitch, vr->T("Camera type"), cameraPitchModes, 0, 3, I18NCat::NONE, screenManager()));
13131314
}
13141315

13151316
UI::EventReturn GameSettingsScreen::OnAutoFrameskip(UI::EventParams &e) {

assets/lang/ar_AE.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ New version of PPSSPP available = ‎تتوفر نسخة جديدة من الب
14181418
[VR]
14191419
% of native FoV = % of native FoV
14201420
6DoF movement = 6DoF movement
1421-
Camera type = وضع الكاميرا
1421+
Anti-flickering flow = Anti-flickering flow
14221422
Distance to 2D menus and scenes = Distance to 2D menus and scenes
14231423
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
14241424
Experts only = Experts only

assets/lang/az_AZ.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ New version of PPSSPP available = New version of PPSSPP available
14101410
[VR]
14111411
% of native FoV = % of native FoV
14121412
6DoF movement = 6DoF movement
1413-
Camera type = Camera type
1413+
Anti-flickering flow = Anti-flickering flow
14141414
Distance to 2D menus and scenes = Distance to 2D menus and scenes
14151415
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
14161416
Experts only = Experts only

0 commit comments

Comments
 (0)