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 - Gran Turismo camera shaking workaround #18536

Closed
wants to merge 1 commit into from
Closed
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
30 changes: 25 additions & 5 deletions Common/VR/PPSSPPVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static int vr3DGeometryCount = 0;
static long vrCompat[VR_COMPAT_MAX];
static bool vrFlatForced = false;
static bool vrFlatGame = false;
static double vrFov[2] = {};
static float vrLensProj[16] = {};
static bool vrMirroring[VR_MIRRORING_COUNT];
static int vrMirroringVariant = 0;
static float vrViewMatrix[2][16];
Expand Down Expand Up @@ -644,8 +644,18 @@ bool StartVRRender() {
fov.angleUp += eye.fov.angleUp / 2.0f;
fov.angleDown += eye.fov.angleDown / 2.0f;
}
vrFov[0] = 2.0 / (tan(fov.angleRight) - tan(fov.angleLeft));
vrFov[1] = 2.0 / (tan(fov.angleUp) - tan(fov.angleDown));
float tanAngleLeft = tanf(fov.angleLeft);
float tanAngleRight = tanf(fov.angleRight);
float tanAngleDown = tanf(fov.angleDown);
float tanAngleUp = tanf(fov.angleUp);
memset(vrLensProj, 0, 16 * sizeof(float));
vrLensProj[0] = 2 / (tanAngleRight - tanAngleLeft);
vrLensProj[2] = (tanAngleRight + tanAngleLeft) / (tanAngleRight - tanAngleLeft);
vrLensProj[5] = 2 / (tanAngleUp - tanAngleDown);
vrLensProj[6] = (tanAngleUp + tanAngleDown) / (tanAngleUp - tanAngleDown);
vrLensProj[10] = -1;
vrLensProj[11] = -1;
vrLensProj[14] = -1;

// Decide if the scene is 3D or not
VR_SetConfigFloat(VR_CONFIG_CANVAS_ASPECT, 480.0f / 272.0f);
Expand Down Expand Up @@ -792,8 +802,18 @@ void UpdateVRParams(float* projMatrix) {
void UpdateVRProjection(float* projMatrix, float* leftEye, float* rightEye) {
float hmdProjection[16];
memcpy(hmdProjection, projMatrix, 16 * sizeof(float));
hmdProjection[0] = vrFov[0];
hmdProjection[5] = vrFov[1];
if (PSP_CoreParameter().compat.vrCompat().UnstableProjection) {
for (int i = 0; i < 16; i++) {
if ((hmdProjection[i] > 0) == (vrLensProj[i] > 0)) {
hmdProjection[i] = vrLensProj[i];
} else {
hmdProjection[i] = -vrLensProj[i];
}
}
} else {
hmdProjection[0] = vrLensProj[0];
hmdProjection[5] = vrLensProj[5];
}
memcpy(leftEye, hmdProjection, 16 * sizeof(float));
memcpy(rightEye, hmdProjection, 16 * sizeof(float));
}
Expand Down
1 change: 1 addition & 0 deletions Core/Compatibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void Compatibility::CheckVRSettings(IniFile &iniFile, const std::string &gameID)
CheckSetting(iniFile, gameID, "MirroringVariant", &vrCompat_.MirroringVariant);
CheckSetting(iniFile, gameID, "Skyplane", &vrCompat_.Skyplane);
CheckSetting(iniFile, gameID, "UnitsPerMeter", &vrCompat_.UnitsPerMeter);
CheckSetting(iniFile, gameID, "UnstableProjection", &vrCompat_.UnstableProjection);

NOTICE_LOG(G3D, "UnitsPerMeter for %s: %f", gameID.c_str(), vrCompat_.UnitsPerMeter);
}
Expand Down
1 change: 1 addition & 0 deletions Core/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ struct VRCompat {
int MirroringVariant;
bool Skyplane;
float UnitsPerMeter;
bool UnstableProjection;
};

class IniFile;
Expand Down
12 changes: 12 additions & 0 deletions assets/compatvr.ini
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ ULJM05884 = true
ULUS10160 = true


[UnstableProjection]
# Workaround for projection matrix which is changing fast.
# Note that in some games this might cause graphics glitches on Meta Quest 3

# Gran Turismo: The Real Driving Simulator
NPJG00027 = true
UCAS40265 = true
UCES01245 = true
UCJS10100 = true
UCUS98632 = true


[UnitsPerMeter]
# 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)
Expand Down