Merge pull request #16370 from lvonasek/compat_openxr_sonic

OpenXR - Sonic Rivals fixed
This commit is contained in:
Henrik Rydgård 2022-11-09 21:28:34 +01:00 committed by GitHub
commit 2886c33c06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 17 deletions

View file

@ -644,30 +644,19 @@ bool Is2DVRObject(float* projMatrix, bool ortho) {
return true; return true;
} }
// Chceck if the projection matrix is identity
bool identity = true;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
float value = projMatrix[i * 4 + j];
// Other number than zero on non-diagonale
if ((i != j) && (fabs(value) > EPSILON)) identity = false;
// Other number than one on diagonale
if ((i == j) && (fabs(value - 1.0f) > EPSILON)) identity = false;
}
}
// Update 3D geometry count // Update 3D geometry count
bool identity = IsMatrixIdentity(projMatrix);
if (!identity && !ortho) { if (!identity && !ortho) {
vr3DGeometryCount++; vr3DGeometryCount++;
} }
return identity; return identity;
} }
void UpdateVRParams(float* projMatrix) { void UpdateVRParams(float* projMatrix, float* viewMatrix) {
// Set mirroring of axes // Set mirroring of axes
if (!vrMirroring[VR_MIRRORING_UPDATED]) { bool identityView = PSP_CoreParameter().compat.vrCompat().IdentityViewHack && IsMatrixIdentity(viewMatrix);
if (!vrMirroring[VR_MIRRORING_UPDATED] && !IsMatrixIdentity(projMatrix) && !identityView) {
vrMirroring[VR_MIRRORING_UPDATED] = true; vrMirroring[VR_MIRRORING_UPDATED] = true;
vrMirroring[VR_MIRRORING_AXIS_X] = projMatrix[0] < 0; vrMirroring[VR_MIRRORING_AXIS_X] = projMatrix[0] < 0;
vrMirroring[VR_MIRRORING_AXIS_Y] = projMatrix[5] < 0; vrMirroring[VR_MIRRORING_AXIS_Y] = projMatrix[5] < 0;
@ -708,6 +697,11 @@ void UpdateVRView(float* leftEye, float* rightEye) {
float* matrix[] = {vrMatrix[VR_VIEW_MATRIX_LEFT_EYE], vrMatrix[VR_VIEW_MATRIX_RIGHT_EYE]}; float* matrix[] = {vrMatrix[VR_VIEW_MATRIX_LEFT_EYE], vrMatrix[VR_VIEW_MATRIX_RIGHT_EYE]};
for (int index = 0; index < 2; index++) { for (int index = 0; index < 2; index++) {
// Validate the view matrix
if (PSP_CoreParameter().compat.vrCompat().IdentityViewHack && IsMatrixIdentity(dst[index])) {
return;
}
// Get view matrix from the game // Get view matrix from the game
Lin::Matrix4x4 gameView = {}; Lin::Matrix4x4 gameView = {};
memcpy(gameView.m, dst[index], 16 * sizeof(float)); memcpy(gameView.m, dst[index], 16 * sizeof(float));

View file

@ -40,6 +40,6 @@ int GetVRPassesCount();
bool IsMultiviewSupported(); bool IsMultiviewSupported();
bool IsFlatVRScene(); bool IsFlatVRScene();
bool Is2DVRObject(float* projMatrix, bool ortho); bool Is2DVRObject(float* projMatrix, bool ortho);
void UpdateVRParams(float* projMatrix); void UpdateVRParams(float* projMatrix, float* viewMatrix);
void UpdateVRProjection(float* projMatrix, float* leftEye, float* rightEye); void UpdateVRProjection(float* projMatrix, float* leftEye, float* rightEye);
void UpdateVRView(float* leftEye, float* rightEye); void UpdateVRView(float* leftEye, float* rightEye);

View file

@ -13,6 +13,20 @@ float ToRadians(float deg) {
return (float)(deg * M_PI / 180.0f); return (float)(deg * M_PI / 180.0f);
} }
bool IsMatrixIdentity(float* matrix) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
float value = matrix[i * 4 + j];
// Other number than zero on non-diagonale
if ((i != j) && (fabs(value) > EPSILON)) return false;
// Other number than one on diagonale
if ((i == j) && (fabs(value - 1.0f) > EPSILON)) return false;
}
}
return true;
}
/* /*
================================================================================ ================================================================================

View file

@ -9,6 +9,7 @@
float ToDegrees(float rad); float ToDegrees(float rad);
float ToRadians(float deg); float ToRadians(float deg);
bool IsMatrixIdentity(float* matrix);
// XrPosef // XrPosef
XrPosef XrPosef_Identity(); XrPosef XrPosef_Identity();

View file

@ -122,6 +122,7 @@ void Compatibility::CheckSettings(IniFile &iniFile, const std::string &gameID) {
} }
void Compatibility::CheckVRSettings(IniFile &iniFile, const std::string &gameID) { void Compatibility::CheckVRSettings(IniFile &iniFile, const std::string &gameID) {
CheckSetting(iniFile, gameID, "IdentityViewHack", &vrCompat_.IdentityViewHack);
CheckSetting(iniFile, gameID, "Skyplane", &vrCompat_.Skyplane); CheckSetting(iniFile, gameID, "Skyplane", &vrCompat_.Skyplane);
CheckSetting(iniFile, gameID, "UnitsPerMeter", &vrCompat_.UnitsPerMeter); CheckSetting(iniFile, gameID, "UnitsPerMeter", &vrCompat_.UnitsPerMeter);

View file

@ -93,6 +93,7 @@ struct CompatFlags {
}; };
struct VRCompat { struct VRCompat {
bool IdentityViewHack;
bool Skyplane; bool Skyplane;
float UnitsPerMeter; float UnitsPerMeter;
}; };

View file

@ -411,7 +411,9 @@ void LinkedShader::UpdateUniforms(u32 vertType, const ShaderID &vsid, bool useBu
} else { } else {
UpdateVRProjection(gstate.projMatrix, leftEyeMatrix.m, rightEyeMatrix.m); UpdateVRProjection(gstate.projMatrix, leftEyeMatrix.m, rightEyeMatrix.m);
} }
UpdateVRParams(gstate.projMatrix); float m4x4[16];
ConvertMatrix4x3To4x4Transposed(m4x4, gstate.viewMatrix);
UpdateVRParams(gstate.projMatrix, m4x4);
FlipProjMatrix(leftEyeMatrix, useBufferedRendering); FlipProjMatrix(leftEyeMatrix, useBufferedRendering);
FlipProjMatrix(rightEyeMatrix, useBufferedRendering); FlipProjMatrix(rightEyeMatrix, useBufferedRendering);

View file

@ -30,6 +30,18 @@
# ======================================================================================== # ========================================================================================
[IdentityViewHack]
# Disables head tracking for render passes where view matrix is Identity
# Sonic Rivals 1
ULES00622 = true
ULUS10195 = true
# Sonic Rivals 2
ULES00940 = true
ULUS10323 = true
[Skyplane] [Skyplane]
# Workaround to remove the background skyplane and add clearing framebuffer with a fog color. # Workaround to remove the background skyplane and add clearing framebuffer with a fog color.
@ -53,6 +65,7 @@ ULJM05395 = true
ULJM05884 = true ULJM05884 = true
ULUS10160 = true ULUS10160 = true
[UnitsPerMeter] [UnitsPerMeter]
# Scale of game world to convert the world units into meters. This enables following VR features: # Scale of game world to convert the world units into meters. This enables following VR features:
# + 3D stereoscopy (that can work only with accurate values) # + 3D stereoscopy (that can work only with accurate values)