Skip to content

Commit

Permalink
Merge pull request #16374 from lvonasek/compat_openxr_tonyhawk
Browse files Browse the repository at this point in the history
OpenXR - Compatibility with Tony Hawk games
  • Loading branch information
hrydgard authored Nov 12, 2022
2 parents 7c5ddce + 97d63a3 commit 2e3dce3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 25 deletions.
71 changes: 48 additions & 23 deletions Common/VR/PPSSPPVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,13 +485,11 @@ bool StartVRRender() {
}

// create updated quaternion
if (mx + my + mz < 3 - EPSILON) {
XrVector3f rotation = XrQuaternionf_ToEulerAngles(invView.orientation);
XrQuaternionf pitch = XrQuaternionf_CreateFromVectorAngle({1, 0, 0}, mx * ToRadians(rotation.x));
XrQuaternionf yaw = XrQuaternionf_CreateFromVectorAngle({0, 1, 0}, my * ToRadians(rotation.y));
XrQuaternionf roll = XrQuaternionf_CreateFromVectorAngle({0, 0, 1}, mz * ToRadians(rotation.z));
invView.orientation = XrQuaternionf_Multiply(roll, XrQuaternionf_Multiply(pitch, yaw));
}
XrVector3f rotation = XrQuaternionf_ToEulerAngles(invView.orientation);
XrQuaternionf pitch = XrQuaternionf_CreateFromVectorAngle({1, 0, 0}, mx * ToRadians(rotation.x));
XrQuaternionf yaw = XrQuaternionf_CreateFromVectorAngle({0, 1, 0}, my * ToRadians(rotation.y));
XrQuaternionf roll = XrQuaternionf_CreateFromVectorAngle({0, 0, 1}, mz * ToRadians(rotation.z));
invView.orientation = XrQuaternionf_Multiply(roll, XrQuaternionf_Multiply(pitch, yaw));

float M[16];
XrQuaternionf_ToMatrix4f(&invView.orientation, M);
Expand Down Expand Up @@ -661,22 +659,49 @@ void UpdateVRParams(float* projMatrix, float* viewMatrix) {
vrMirroring[VR_MIRRORING_AXIS_X] = projMatrix[0] < 0;
vrMirroring[VR_MIRRORING_AXIS_Y] = projMatrix[5] < 0;
vrMirroring[VR_MIRRORING_AXIS_Z] = projMatrix[10] > 0;
if ((projMatrix[0] < 0) && (projMatrix[10] < 0)) { //e.g. Dante's inferno
vrMirroring[VR_MIRRORING_PITCH] = true;
vrMirroring[VR_MIRRORING_YAW] = true;
vrMirroring[VR_MIRRORING_ROLL] = false;
} else if (projMatrix[10] < 0) { //e.g. GTA - Liberty city
vrMirroring[VR_MIRRORING_PITCH] = false;
vrMirroring[VR_MIRRORING_YAW] = false;
vrMirroring[VR_MIRRORING_ROLL] = false;
} else if (projMatrix[5] < 0) { //e.g. PES 2014
vrMirroring[VR_MIRRORING_PITCH] = true;
vrMirroring[VR_MIRRORING_YAW] = true;
vrMirroring[VR_MIRRORING_ROLL] = false;
} else { //e.g. Lego Pirates
vrMirroring[VR_MIRRORING_PITCH] = false;
vrMirroring[VR_MIRRORING_YAW] = true;
vrMirroring[VR_MIRRORING_ROLL] = true;

float up = 0;
for (int i = 4; i < 7; i++) {
up += viewMatrix[i];
}

int variant = projMatrix[0] < 0;
variant += (projMatrix[5] < 0) << 1;
variant += (projMatrix[10] < 0) << 2;
variant += (up < 0) << 3;

switch (variant) {
case 0: //e.g. ATV
case 1: //untested
vrMirroring[VR_MIRRORING_PITCH] = false;
vrMirroring[VR_MIRRORING_YAW] = true;
vrMirroring[VR_MIRRORING_ROLL] = true;
break;
case 2: //e.g.PES 2014
case 3: //untested
case 5: //e.g Dante's Inferno
case 7: //untested
case 8: //untested
case 9: //untested
case 10: //untested
case 11: //untested
case 13: //untested
case 15: //untested
vrMirroring[VR_MIRRORING_PITCH] = true;
vrMirroring[VR_MIRRORING_YAW] = true;
vrMirroring[VR_MIRRORING_ROLL] = false;
break;
case 4: //e.g. Assassins Creed
case 6: //e.g. Ghost in the shell
case 12: //e.g. GTA Vice City
case 14: //untested
vrMirroring[VR_MIRRORING_PITCH] = true;
vrMirroring[VR_MIRRORING_YAW] = false;
vrMirroring[VR_MIRRORING_ROLL] = true;
break;
default:
assert(false);
std::exit(1);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/VertexShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag
WRITE(p, " }\n");
}

if (vertexRangeCulling) {
if (vertexRangeCulling && !gstate_c.Use(GPU_USE_VIRTUAL_REALITY)) {
WRITE(p, " vec3 projPos = outPos.xyz / outPos.w;\n");
WRITE(p, " float projZ = (projPos.z - u_depthRange.z) * u_depthRange.w;\n");

Expand Down
2 changes: 1 addition & 1 deletion GPU/GPUCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (canClipOrCull || canDiscardVertex) {
// We'll dynamically use the parts that are supported, to reduce artifacts as much as possible.
features |= GPU_USE_VS_RANGE_CULLING;
}
Expand Down

0 comments on commit 2e3dce3

Please sign in to comment.