Skip to content

Commit

Permalink
OpenXR - Use per game stereo separation file
Browse files Browse the repository at this point in the history
  • Loading branch information
lvonasek committed Sep 12, 2022
1 parent 93202e4 commit bdde5f0
Show file tree
Hide file tree
Showing 13 changed files with 669 additions and 25 deletions.
18 changes: 14 additions & 4 deletions Common/VR/PPSSPPVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Core/HLE/sceDisplay.h"
#include "Core/Config.h"
#include "Core/KeyMap.h"
#include "Core/System.h"


/*
Expand Down Expand Up @@ -239,7 +240,6 @@ bool PreVRRender() {
VR_SetConfig(VR_CONFIG_6DOF_ENABLED, g_Config.bEnable6DoF);
VR_SetConfig(VR_CONFIG_CANVAS_DISTANCE, g_Config.iCanvasDistance);
VR_SetConfig(VR_CONFIG_FOV_SCALE, g_Config.iFieldOfViewPercentage);
VR_SetConfig(VR_CONFIG_STEREO_SEPARATION, g_Config.iStereoSeparation);
return true;
}
return false;
Expand Down Expand Up @@ -285,9 +285,19 @@ void UpdateVRProjection(float* projMatrix, float* leftEye, float* rightEye) {
VR_TweakProjection(projMatrix, leftEye, VR_PROJECTION_MATRIX_LEFT_EYE);
VR_TweakProjection(projMatrix, rightEye, VR_PROJECTION_MATRIX_RIGHT_EYE);
VR_TweakMirroring(projMatrix);

// Set 6DoF scale
float scale = pow(fabs(projMatrix[14]), 1.15f);
if (PSP_CoreParameter().compat.vrCompat().UnitsPerMeter > 0) {
scale = PSP_CoreParameter().compat.vrCompat().UnitsPerMeter;
VR_SetConfig(VR_CONFIG_6DOF_PRECISE, true);
} else {
VR_SetConfig(VR_CONFIG_6DOF_PRECISE, false);
}
VR_SetConfig(VR_CONFIG_6DOF_SCALE, (int)(scale * 1000000));
}

void UpdateVRView(float* projMatrix, float* leftEye, float* rightEye) {
VR_TweakView(leftEye, projMatrix, VR_VIEW_MATRIX_LEFT_EYE);
VR_TweakView(rightEye, projMatrix, VR_VIEW_MATRIX_RIGHT_EYE);
void UpdateVRView(float* leftEye, float* rightEye) {
VR_TweakView(leftEye, VR_VIEW_MATRIX_LEFT_EYE);
VR_TweakView(rightEye, VR_VIEW_MATRIX_RIGHT_EYE);
}
4 changes: 2 additions & 2 deletions Common/VR/PPSSPPVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ bool IsMultiviewSupported();
bool IsFlatVRScene();
bool Is2DVRObject(float* projMatrix, bool ortho);
void UpdateVRProjection(float* projMatrix, float* leftEye, float* rightEye);
void UpdateVRView(float* projMatrix, float* leftEye, float* rightEye);
void UpdateVRView(float* leftEye, float* rightEye);

#else //dummy integration

Expand All @@ -47,6 +47,6 @@ inline bool IsMultiviewSupported() { return false; }
inline bool IsFlatVRScene() { return true; }
inline bool Is2DVRObject(float* projMatrix, bool ortho) { return false; }
inline void UpdateVRProjection(float* projMatrix, float* leftEye, float* rightEye) {}
inline void UpdateVRView(float* projMatrix, float* leftEye, float* rightEye) {}
inline void UpdateVRView(float* leftEye, float* rightEye) {}

#endif
11 changes: 5 additions & 6 deletions Common/VR/VRRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,17 +493,16 @@ ovrMatrix4f VR_GetMatrix( VRMatrix matrix ) {
}

output = ovrMatrix4f_CreateFromQuaternion(&invView.orientation);
float scale = (float)VR_GetConfig(VR_CONFIG_6DOF_SCALE) * 0.001f;
float scale = (float)VR_GetConfig(VR_CONFIG_6DOF_SCALE) * 0.000001f;
if (vrConfig[VR_CONFIG_6DOF_ENABLED]) {
output.M[0][3] -= hmdposition.x * (vrConfig[VR_CONFIG_MIRROR_AXIS_X] ? -1.0f : 1.0f) * scale;
output.M[1][3] -= hmdposition.y * (vrConfig[VR_CONFIG_MIRROR_AXIS_Y] ? -1.0f : 1.0f) * scale;
output.M[2][3] -= hmdposition.z * (vrConfig[VR_CONFIG_MIRROR_AXIS_Z] ? -1.0f : 1.0f) * scale;
}
if (matrix == VR_VIEW_MATRIX_RIGHT_EYE) {
float ipdScale = (float)vrConfig[VR_CONFIG_STEREO_SEPARATION] * 0.1f * scale;
output.M[0][3] += (invViewTransform[1].position.x - invViewTransform[0].position.x) * ipdScale;
output.M[1][3] += (invViewTransform[1].position.y - invViewTransform[0].position.y) * ipdScale;
output.M[2][3] += (invViewTransform[1].position.z - invViewTransform[0].position.z) * ipdScale;
if (vrConfig[VR_CONFIG_6DOF_PRECISE] && (matrix == VR_VIEW_MATRIX_RIGHT_EYE)) {
output.M[0][3] += (invViewTransform[1].position.x - invViewTransform[0].position.x) * scale;
output.M[1][3] += (invViewTransform[1].position.y - invViewTransform[0].position.y) * scale;
output.M[2][3] += (invViewTransform[1].position.z - invViewTransform[0].position.z) * scale;
}
} else {
assert(false);
Expand Down
4 changes: 2 additions & 2 deletions Common/VR/VRRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ enum VRConfig {
//switching between 2D and 3D
VR_CONFIG_MODE, VR_CONFIG_3D_GEOMETRY_COUNT, VR_CONFIG_FORCE_2D,
//camera setup
VR_CONFIG_FOV_SCALE, VR_CONFIG_CANVAS_DISTANCE, VR_CONFIG_STEREO_SEPARATION,
VR_CONFIG_FOV_SCALE, VR_CONFIG_CANVAS_DISTANCE,
//6DoF
VR_CONFIG_6DOF_ENABLED, VR_CONFIG_6DOF_SCALE,
VR_CONFIG_6DOF_ENABLED, VR_CONFIG_6DOF_SCALE, VR_CONFIG_6DOF_PRECISE,
VR_CONFIG_MIRROR_AXIS_X, VR_CONFIG_MIRROR_AXIS_Y, VR_CONFIG_MIRROR_AXIS_Z,
VR_CONFIG_MIRROR_PITCH, VR_CONFIG_MIRROR_YAW, VR_CONFIG_MIRROR_ROLL,
//2D canvas positioning
Expand Down
6 changes: 1 addition & 5 deletions Common/VR/VRTweaks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,11 @@ void VR_TweakProjection(float* src, float* dst, VRMatrix matrix) {
memcpy(dst, hmdProjection.M, 16 * sizeof(float));
}

void VR_TweakView(float* view, float* projMatrix, VRMatrix matrix) {
void VR_TweakView(float* view, VRMatrix matrix) {
// Get view matrix from the game
ovrMatrix4f gameView;
memcpy(gameView.M, view, 16 * sizeof(float));

// Set 6DoF scale
float scale = pow(fabs(projMatrix[14]), 1.15f);
VR_SetConfig(VR_CONFIG_6DOF_SCALE, (int)(scale * 1000));

// Get view matrix from the headset
ovrMatrix4f hmdView = VR_GetMatrix(matrix);

Expand Down
2 changes: 1 addition & 1 deletion Common/VR/VRTweaks.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ bool VR_TweakIsMatrixOneScale(float* matrix);
bool VR_TweakIsMatrixOneTransform(float* matrix);
void VR_TweakMirroring(float* projMatrix);
void VR_TweakProjection(float* src, float* dst, VRMatrix matrix);
void VR_TweakView(float* view, float* projMatrix, VRMatrix matrix);
void VR_TweakView(float* view, VRMatrix matrix);
15 changes: 15 additions & 0 deletions Core/Compatibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ void Compatibility::Load(const std::string &gameID) {
}
}

{
IniFile compat;
// This loads from assets.
if (compat.LoadFromVFS("compatvr.ini")) {
CheckSetting(compat, gameID, "UnitsPerMeter", &vrCompat_.UnitsPerMeter);
}
}

{
IniFile compat2;
// This one is user-editable. Need to load it after the system one.
Expand All @@ -54,6 +62,7 @@ void Compatibility::Load(const std::string &gameID) {

void Compatibility::Clear() {
memset(&flags_, 0, sizeof(flags_));
memset(&vrCompat_, 0, sizeof(vrCompat_));
}

void Compatibility::CheckSettings(IniFile &iniFile, const std::string &gameID) {
Expand Down Expand Up @@ -110,3 +119,9 @@ void Compatibility::CheckSetting(IniFile &iniFile, const std::string &gameID, co
*flag |= all;
}
}

void Compatibility::CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, float *flag) {
std::string value;
iniFile.Get(option, gameID.c_str(), &value, "0");
*flag = stof(value);
}
8 changes: 8 additions & 0 deletions Core/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ struct CompatFlags {
bool ForceLowerResolutionForEffectsOn;
};

struct VRCompat {
float UnitsPerMeter;
};

class IniFile;

class Compatibility {
Expand All @@ -101,13 +105,17 @@ class Compatibility {
// Flags enforced read-only through const. Only way to change them is to load assets/compat.ini.
const CompatFlags &flags() const { return flags_; }

const VRCompat &vrCompat() const { return vrCompat_; }

void Load(const std::string &gameID);

private:
void Clear();
void CheckSettings(IniFile &iniFile, const std::string &gameID);
void CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, bool *flag);
void CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, float *value);

CompatFlags flags_{};
VRCompat vrCompat_{};
std::set<std::string> ignored_;
};
1 change: 0 additions & 1 deletion Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,6 @@ static ConfigSetting vrSettings[] = {
ConfigSetting("VREnableStereo", &g_Config.bEnableStereo, false),
ConfigSetting("VRCanvasDistance", &g_Config.iCanvasDistance, 6),
ConfigSetting("VRFieldOfView", &g_Config.iFieldOfViewPercentage, 100),
ConfigSetting("VRStereoSeparation", &g_Config.iStereoSeparation, 10),

ConfigSetting(false),
};
Expand Down
1 change: 0 additions & 1 deletion Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ struct Config {
bool bEnableStereo;
int iCanvasDistance;
int iFieldOfViewPercentage;
int iStereoSeparation;

// Debugger
int iDisasmWindowX;
Expand Down
2 changes: 1 addition & 1 deletion GPU/GLES/ShaderManagerGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ void LinkedShader::UpdateUniforms(u32 vertType, const ShaderID &vsid, bool useBu
ConvertMatrix4x3To4x4Transposed(leftEyeView, gstate.viewMatrix);
ConvertMatrix4x3To4x4Transposed(rightEyeView, gstate.viewMatrix);
if (!flatScreen && !is2D) {
UpdateVRView(gstate.projMatrix, leftEyeView, rightEyeView);
UpdateVRView(leftEyeView, rightEyeView);
}
render_->SetUniformM4x4Stereo("u_view", &u_view, leftEyeView, rightEyeView);
} else {
Expand Down
2 changes: 0 additions & 2 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,8 +1122,6 @@ void GameSettingsScreen::CreateViews() {
vrFieldOfView->SetEnabledPtr(&g_Config.bEnableVR);
CheckBox *vrStereo = vrSettings->Add(new CheckBox(&g_Config.bEnableStereo, vr->T("Enable stereoscopic vision (Experimental)")));
vrStereo->SetEnabledPtr(&g_Config.bEnableVR);
PopupSliderChoice *vrStereoSepararation = vrSettings->Add(new PopupSliderChoice(&g_Config.iStereoSeparation, 1, 50, vr->T("Stereo separation (differs per game)", "Stereo separation (differs per game)"), 1, screenManager(), "x"));
vrStereoSepararation->SetEnabledPtr(&g_Config.bEnableStereo);
}
}

Expand Down
Loading

0 comments on commit bdde5f0

Please sign in to comment.