Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenXR - Projection matrix on Quest 3 fixed #18438

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 18 additions & 39 deletions Common/VR/PPSSPPVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@
#include "Core/KeyMap.h"
#include "Core/System.h"

enum VRMatrix {
VR_PROJECTION_MATRIX,
VR_VIEW_MATRIX_LEFT_EYE,
VR_VIEW_MATRIX_RIGHT_EYE,
VR_MATRIX_COUNT
};

enum VRMirroring {
VR_MIRRORING_AXIS_X,
VR_MIRRORING_AXIS_Y,
Expand All @@ -51,9 +44,10 @@ static int vr3DGeometryCount = 0;
static long vrCompat[VR_COMPAT_MAX];
static bool vrFlatForced = false;
static bool vrFlatGame = false;
static float vrMatrix[VR_MATRIX_COUNT][16];
static double vrFov[2] = {};
static bool vrMirroring[VR_MIRRORING_COUNT];
static int vrMirroringVariant = 0;
static float vrViewMatrix[2][16];
static XrView vrView[2];

static void (*cbNativeAxis)(const AxisInput *axis, size_t count);
Expand Down Expand Up @@ -642,28 +636,16 @@ bool StartVRRender() {
}
UpdateVRViewMatrices();

// Update projection matrix
// Calculate field of view
XrFovf fov = {};
for (int eye = 0; eye < ovrMaxNumEyes; eye++) {
fov.angleLeft += vrView[eye].fov.angleLeft / 2.0f;
fov.angleRight += vrView[eye].fov.angleRight / 2.0f;
fov.angleUp += vrView[eye].fov.angleUp / 2.0f;
fov.angleDown += vrView[eye].fov.angleDown / 2.0f;
for (auto & eye : vrView) {
fov.angleLeft += eye.fov.angleLeft / 2.0f;
fov.angleRight += eye.fov.angleRight / 2.0f;
fov.angleUp += eye.fov.angleUp / 2.0f;
fov.angleDown += eye.fov.angleDown / 2.0f;
}
float nearZ = g_Config.fFieldOfViewPercentage / 200.0f;
float tanAngleLeft = tanf(fov.angleLeft);
float tanAngleRight = tanf(fov.angleRight);
float tanAngleDown = tanf(fov.angleDown);
float tanAngleUp = tanf(fov.angleUp);
float M[16] = {};
M[0] = 2 / (tanAngleRight - tanAngleLeft);
M[2] = (tanAngleRight + tanAngleLeft) / (tanAngleRight - tanAngleLeft);
M[5] = 2 / (tanAngleUp - tanAngleDown);
M[6] = (tanAngleUp + tanAngleDown) / (tanAngleUp - tanAngleDown);
M[10] = -1;
M[11] = -(nearZ + nearZ);
M[14] = -1;
memcpy(vrMatrix[VR_PROJECTION_MATRIX], M, sizeof(float) * 16);
vrFov[0] = 2.0 / (tan(fov.angleRight) - tan(fov.angleLeft));
vrFov[1] = 2.0 / (tan(fov.angleUp) - tan(fov.angleDown));

// Decide if the scene is 3D or not
VR_SetConfigFloat(VR_CONFIG_CANVAS_ASPECT, 480.0f / 272.0f);
Expand Down Expand Up @@ -808,19 +790,16 @@ void UpdateVRParams(float* projMatrix) {
}

void UpdateVRProjection(float* projMatrix, float* leftEye, float* rightEye) {
float* hmdProjection = vrMatrix[VR_PROJECTION_MATRIX];
for (int i = 0; i < 16; i++) {
if ((hmdProjection[i] > 0) != (projMatrix[i] > 0)) {
hmdProjection[i] *= -1.0f;
}
}
float hmdProjection[16];
memcpy(hmdProjection, projMatrix, 16 * sizeof(float));
hmdProjection[0] = vrFov[0];
hmdProjection[5] = vrFov[1];
memcpy(leftEye, hmdProjection, 16 * sizeof(float));
memcpy(rightEye, hmdProjection, 16 * sizeof(float));
}

void UpdateVRView(float* leftEye, float* rightEye) {
float* dst[] = {leftEye, rightEye};
float* matrix[] = {vrMatrix[VR_VIEW_MATRIX_LEFT_EYE], vrMatrix[VR_VIEW_MATRIX_RIGHT_EYE]};
for (int index = 0; index < 2; index++) {

// Validate the view matrix
Expand All @@ -834,7 +813,7 @@ void UpdateVRView(float* leftEye, float* rightEye) {

// Get view matrix from the headset
Lin::Matrix4x4 hmdView = {};
memcpy(hmdView.m, matrix[index], 16 * sizeof(float));
memcpy(hmdView.m, vrViewMatrix[index], 16 * sizeof(float));

// Combine the matrices
Lin::Matrix4x4 renderView = hmdView * gameView;
Expand Down Expand Up @@ -943,12 +922,12 @@ void UpdateVRViewMatrices() {
M[11] += side.z;
}

for (int matrix = VR_VIEW_MATRIX_LEFT_EYE; matrix <= VR_VIEW_MATRIX_RIGHT_EYE; matrix++) {
for (int eye = 0; eye < ovrMaxNumEyes; eye++) {

// Stereoscopy
bool vrStereo = !PSP_CoreParameter().compat.vrCompat().ForceMono && g_Config.bEnableStereo;
if (vrStereo) {
bool mirrored = vrMirroring[VR_MIRRORING_AXIS_Z] ^ (matrix == VR_VIEW_MATRIX_RIGHT_EYE);
bool mirrored = vrMirroring[VR_MIRRORING_AXIS_Z] ^ (eye == 1);
float dx = fabs(vrView[1].pose.position.x - vrView[0].pose.position.x);
float dy = fabs(vrView[1].pose.position.y - vrView[0].pose.position.y);
float dz = fabs(vrView[1].pose.position.z - vrView[0].pose.position.z);
Expand All @@ -961,6 +940,6 @@ void UpdateVRViewMatrices() {
M[11] += separation.z;
}

memcpy(vrMatrix[matrix], M, sizeof(float) * 16);
memcpy(vrViewMatrix[eye], M, sizeof(float) * 16);
}
}
1 change: 0 additions & 1 deletion Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,6 @@ static const ConfigSetting vrSettings[] = {
ConfigSetting("VRCameraPitch", &g_Config.iCameraPitch, 0, CfgFlag::PER_GAME),
ConfigSetting("VRCanvasDistance", &g_Config.fCanvasDistance, 12.0f, CfgFlag::DEFAULT),
ConfigSetting("VRCanvas3DDistance", &g_Config.fCanvas3DDistance, 3.0f, CfgFlag::DEFAULT),
ConfigSetting("VRFieldOfView", &g_Config.fFieldOfViewPercentage, 100.0f, CfgFlag::PER_GAME),
ConfigSetting("VRHeadUpDisplayScale", &g_Config.fHeadUpDisplayScale, 0.3f, CfgFlag::PER_GAME),
ConfigSetting("VRMotionLength", &g_Config.fMotionLength, 0.5f, CfgFlag::DEFAULT),
ConfigSetting("VRHeadRotationScale", &g_Config.fHeadRotationScale, 5.0f, CfgFlag::PER_GAME),
Expand Down
1 change: 0 additions & 1 deletion Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ struct Config {
float fCameraSide;
float fCanvasDistance;
float fCanvas3DDistance;
float fFieldOfViewPercentage;
float fHeadUpDisplayScale;
float fMotionLength;
float fHeadRotationScale;
Expand Down
1 change: 0 additions & 1 deletion UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,6 @@ void GameSettingsScreen::CreateVRSettings(UI::ViewGroup *vrSettings) {
vrSettings->Add(new ItemHeader(vr->T("VR camera")));
vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCanvasDistance, 1.0f, 15.0f, 12.0f, vr->T("Distance to 2D menus and scenes"), 1.0f, screenManager(), ""));
vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCanvas3DDistance, 1.0f, 15.0f, 3.0f, vr->T("Distance to 3D scenes when VR disabled"), 1.0f, screenManager(), ""));
vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fFieldOfViewPercentage, 100.0f, 200.0f, 100.0f, vr->T("Field of view scale"), 10.0f, screenManager(), vr->T("% of native FoV")));
vrSettings->Add(new CheckBox(&g_Config.bRescaleHUD, vr->T("Heads-up display detection")));
PopupSliderChoiceFloat* vrHudScale = vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fHeadUpDisplayScale, 0.0f, 1.5f, 0.3f, vr->T("Heads-up display scale"), 0.1f, screenManager(), ""));
vrHudScale->SetEnabledPtr(&g_Config.bRescaleHUD);
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/ar_AE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1361,13 +1361,11 @@ Download = ‎تحميل
New version of PPSSPP available = ‎تتوفر نسخة جديدة من البرنامج

[VR]
% of native FoV = % of native FoV
6DoF movement = 6DoF movement
Camera type = Camera type
Distance to 2D menus and scenes = Distance to 2D menus and scenes
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Field of view scale = Field of view scale
Force 72Hz update = Force 72Hz update
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/az_AZ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,11 @@ Download = Download
New version of PPSSPP available = New version of PPSSPP available

[VR]
% of native FoV = % of native FoV
6DoF movement = 6DoF movement
Camera type = Camera type
Distance to 2D menus and scenes = Distance to 2D menus and scenes
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Field of view scale = Field of view scale
Force 72Hz update = Force 72Hz update
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/bg_BG.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,11 @@ Download = Свали
New version of PPSSPP available = Налична е нова версия на PPSSPP

[VR]
% of native FoV = % of native FoV
6DoF movement = 6DoF movement
Camera type = Camera type
Distance to 2D menus and scenes = Distance to 2D menus and scenes
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Field of view scale = Field of view scale
Force 72Hz update = Force 72Hz update
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/ca_ES.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,11 @@ Download = Descarregar
New version of PPSSPP available = Nova versió de PPSSPP disponible

[VR]
% of native FoV = % of native FoV
6DoF movement = 6DoF movement
Camera type = Camera type
Distance to 2D menus and scenes = Distance to 2D menus and scenes
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Field of view scale = Field of view scale
Force 72Hz update = Force 72Hz update
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/cz_CZ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,11 @@ Download = Stáhnout
New version of PPSSPP available = Je dostupná nová verze PPSSPP

[VR]
% of native FoV = % of native FoV
6DoF movement = 6DoF movement
Camera type = Camera type
Distance to 2D menus and scenes = Distance to 2D menus and scenes
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Field of view scale = Field of view scale
Force 72Hz update = Force 72Hz update
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/da_DK.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,11 @@ Download = Download
New version of PPSSPP available = Ny version af PPSSPP tilgængelig

[VR]
% of native FoV = % of native FoV
6DoF movement = 6DoF movement
Camera type = Camera type
Distance to 2D menus and scenes = Distance to 2D menus and scenes
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Field of view scale = Field of view scale
Force 72Hz update = Force 72Hz update
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/de_DE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,11 @@ Download = Herunterladen
New version of PPSSPP available = Neue PPSSPP Version verfügbar

[VR]
% of native FoV = % of native FoV
6DoF movement = 6DoF movement
Camera type = Camera type
Distance to 2D menus and scenes = Distance to 2D menus and scenes
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Field of view scale = Field of view scale
Force 72Hz update = Force 72Hz update
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/dr_ID.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,11 @@ Download = Download
New version of PPSSPP available = New version of PPSSPP available

[VR]
% of native FoV = % of native FoV
6DoF movement = 6DoF movement
Camera type = Camera type
Distance to 2D menus and scenes = Distance to 2D menus and scenes
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Field of view scale = Field of view scale
Force 72Hz update = Force 72Hz update
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/en_US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1378,14 +1378,12 @@ Progress: %1% = Progress: %1%
Screen representation = Screen representation

[VR]
% of native FoV = % of native FoV
6DoF movement = 6DoF movement
Distance to 2D menus and scenes = Distance to 2D menus and scenes
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Field of view scale = Field of view scale
Force 72Hz update = Force 72Hz update
Heads-up display scale = Heads-up display scale
Heads-up display detection = Heads-up display detection
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/es_ES.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1355,13 +1355,11 @@ Download = Descargar
New version of PPSSPP available = Nueva versión de PPSSPP disponible

[VR]
% of native FoV = % de campo de visión nativo
6DoF movement = Movimiento 6DoF
Camera type = Camera type
Distance to 2D menus and scenes = Distancia de los menús y escenas 2D
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Field of view scale = Escala de campo de visión
Force 72Hz update = Forzar actualizar a 72Hz
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/es_LA.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1355,13 +1355,11 @@ Download = Descargar
New version of PPSSPP available = Nueva versión de PPSSPP disponible

[VR]
% of native FoV = % of native FoV
6DoF movement = 6DoF movement
Camera type = Camera type
Distance to 2D menus and scenes = Distance to 2D menus and scenes
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Field of view scale = Field of view scale
Force 72Hz update = Force 72Hz update
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/fa_IR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,11 @@ Download = دانلود
New version of PPSSPP available = ورژن جدیدی از ppsspp موجود است

[VR]
% of native FoV = % of native FoV
6DoF movement = 6DoF movement
Camera type = Camera type
Distance to 2D menus and scenes = Distance to 2D menus and scenes
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Field of view scale = Field of view scale
Force 72Hz update = Force 72Hz update
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/fi_FI.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,11 @@ Download = Download
New version of PPSSPP available = New version of PPSSPP available

[VR]
% of native FoV = % of native FoV
6DoF movement = 6DoF movement
Camera type = Camera type
Distance to 2D menus and scenes = Distance to 2D menus and scenes
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Field of view scale = Field of view scale
Force 72Hz update = Force 72Hz update
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/fr_FR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1344,13 +1344,11 @@ Download = Télécharger
New version of PPSSPP available = Nouvelle version de PPSSPP disponible

[VR]
% of native FoV = % of native FoV
6DoF movement = 6DoF movement
Camera type = Camera type
Distance to 2D menus and scenes = Distance to 2D menus and scenes
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Field of view scale = Field of view scale
Force 72Hz update = Force 72Hz update
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/gl_ES.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,11 @@ Download = Descargar
New version of PPSSPP available = Nova versión de PPSSPP dispoñible

[VR]
% of native FoV = % of native FoV
6DoF movement = 6DoF movement
Camera type = Camera type
Distance to 2D menus and scenes = Distance to 2D menus and scenes
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Field of view scale = Field of view scale
Force 72Hz update = Force 72Hz update
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/gr_EL.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,11 @@ Download = Κατέβασμα
New version of PPSSPP available = Νέα διαθέσιμη έκδοση PPSSPP

[VR]
% of native FoV = % of native FoV
6DoF movement = 6DoF movement
Camera type = Camera type
Distance to 2D menus and scenes = Distance to 2D menus and scenes
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Field of view scale = Field of view scale
Force 72Hz update = Force 72Hz update
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/he_IL.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,11 @@ Download = Download
New version of PPSSPP available = New version of PPSSPP available

[VR]
% of native FoV = % of native FoV
6DoF movement = 6DoF movement
Camera type = Camera type
Distance to 2D menus and scenes = Distance to 2D menus and scenes
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Field of view scale = Field of view scale
Force 72Hz update = Force 72Hz update
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Expand Down
2 changes: 0 additions & 2 deletions assets/lang/he_IL_invert.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,11 @@ Download = Download
New version of PPSSPP available = New version of PPSSPP available

[VR]
% of native FoV = % of native FoV
6DoF movement = 6DoF movement
Camera type = Camera type
Distance to 2D menus and scenes = Distance to 2D menus and scenes
Distance to 3D scenes when VR disabled = Distance to 3D scenes when VR disabled
Experts only = Experts only
Field of view scale = Field of view scale
Force 72Hz update = Force 72Hz update
Game camera rotation step per frame = Game camera rotation step per frame
Game camera uses rotation smoothing = Game camera uses rotation smoothing
Expand Down
Loading