Merge pull request #16437 from lvonasek/feature_openxr_hud_improvement

OpenXR - HUD improvements
This commit is contained in:
Henrik Rydgård 2022-11-25 21:21:57 +01:00 committed by GitHub
commit 9c033fb57c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 15 deletions

View File

@ -316,9 +316,9 @@ void UpdateVRInput(bool(*NativeAxis)(const AxisInput &axis), bool(*NativeKey)(co
g_Config.fCameraHeight = clampFloat(g_Config.fCameraHeight, -50.0f, 50.0f);
break;
case JOYSTICK_AXIS_Z:
if (axis.second < -0.75f) g_Config.fFieldOfViewPercentage -= 1.0f;
if (axis.second > 0.75f) g_Config.fFieldOfViewPercentage += 1.0f;
g_Config.fFieldOfViewPercentage = clampFloat(g_Config.fFieldOfViewPercentage, 100.0f, 200.0f);
if (axis.second < -0.75f) g_Config.fHeadUpDisplayScale -= 0.01f;
if (axis.second > 0.75f) g_Config.fHeadUpDisplayScale += 0.01f;
g_Config.fHeadUpDisplayScale = clampFloat(g_Config.fHeadUpDisplayScale, 0.2f, 1.0f);
break;
case JOYSTICK_AXIS_RZ:
if (axis.second > 0.75f) g_Config.fCameraDistance -= 0.1f;
@ -430,7 +430,7 @@ bool UpdateVRKeys(const KeyInput &key) {
g_Config.fCameraHeight = 0;
g_Config.fCameraSide = 0;
g_Config.fCameraDistance = 0;
g_Config.fFieldOfViewPercentage = 100;
g_Config.fHeadUpDisplayScale = 0.3f;
}
//block keys by camera adjust
@ -727,7 +727,7 @@ bool Is2DVRObject(float* projMatrix, bool ortho) {
if (!identity && !ortho) {
vr3DGeometryCount++;
}
return identity;
return identity || ortho;
}
void UpdateVRParams(float* projMatrix, float* viewMatrix) {

View File

@ -1214,6 +1214,7 @@ static ConfigSetting vrSettings[] = {
ConfigSetting("VRCameraSide", &g_Config.fCameraSide, 0.0f),
ConfigSetting("VRCanvasDistance", &g_Config.fCanvasDistance, 6.0f),
ConfigSetting("VRFieldOfView", &g_Config.fFieldOfViewPercentage, 100.0f),
ConfigSetting("VRHeadUpDisplayScale", &g_Config.fHeadUpDisplayScale, 0.3f),
ConfigSetting("VRMotionLength", &g_Config.fMotionLength, 0.5f),
ConfigSetting(false),

View File

@ -471,6 +471,7 @@ public:
float fCameraSide;
float fCanvasDistance;
float fFieldOfViewPercentage;
float fHeadUpDisplayScale;
float fMotionLength;
// Debugger

View File

@ -353,6 +353,33 @@ static inline void FlipProjMatrix(Matrix4x4 &in, bool useBufferedRendering) {
}
}
static inline bool GuessVRDrawingHUD(bool is2D, bool flatScreen) {
bool hud = true;
//HUD cannot be rendered in flatscreen
if (flatScreen) hud = false;
//HUD has to be 2D
else if (!is2D) hud = false;
//HUD has to be blended
else if (!gstate.isAlphaBlendEnabled()) hud = false;
//HUD cannot be rendered with clear color mask
else if (gstate.isClearModeColorMask()) hud = false;
//HUD cannot be rendered with fog on
else if (gstate.isFogEnabled()) hud = false;
//HUD cannot be rendered with lights on
else if (gstate.isLightingEnabled()) hud = false;
//HUD texture has to contain alpha channel
else if (!gstate.isTextureAlphaUsed()) hud = false;
//HUD cannot have full alpha
else if (gstate_c.textureFullAlpha) hud = false;
//HUD cannot render FB screenshot
else if (gstate_c.curTextureHeight == 272) hud = false;
//HUD cannot render far plane
else if ((fabs(gstate.viewMatrix[9]) > 100) || (fabs(gstate.viewMatrix[11]) > 100)) hud = false;
return hud;
}
void LinkedShader::use(const ShaderID &VSID) {
render_->BindProgram(program);
// Note that we no longer track attr masks here - we do it for the input layouts instead.
@ -385,16 +412,9 @@ void LinkedShader::UpdateUniforms(u32 vertType, const ShaderID &vsid, bool useBu
// Set HUD mode
if (gstate_c.Use(GPU_USE_VIRTUAL_REALITY)) {
bool is3D = gstate.isDepthWriteEnabled();
bool hud = is2D && !is3D && !flatScreen &&
gstate.isModeThrough() && //2D content requires orthographic projection
gstate.isAlphaBlendEnabled() && //2D content has to be blended
!gstate.isLightingEnabled() && //2D content cannot be rendered with lights on
!gstate.isFogEnabled(); //2D content cannot be rendered with fog on
if (hud) {
float scale = 0.5f;
render_->SetUniformF1(&u_scaleX, scale);
render_->SetUniformF1(&u_scaleY, scale / 480.0f * 272.0f);
if (GuessVRDrawingHUD(is2D, flatScreen)) {
render_->SetUniformF1(&u_scaleX, g_Config.fHeadUpDisplayScale * 480.0f / 272.0f);
render_->SetUniformF1(&u_scaleY, g_Config.fHeadUpDisplayScale);
} else {
render_->SetUniformF1(&u_scaleX, 1.0f);
render_->SetUniformF1(&u_scaleY, 1.0f);

View File

@ -1055,6 +1055,7 @@ void GameSettingsScreen::CreateViews() {
vrSettings->Add(new ItemHeader(vr->T("VR camera")));
vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCanvasDistance, 1.0f, 15.0f, vr->T("Distance to 2D menus and scenes"), 1.0f, screenManager(), ""));
vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fFieldOfViewPercentage, 100.0f, 200.0f, vr->T("Field of view scale"), 10.0f, screenManager(), vr->T("% of native FoV")));
vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fHeadUpDisplayScale, 0.2f, 1.0f, vr->T("Heads-up display scale"), 0.1f, screenManager(), ""));
vrSettings->Add(new ItemHeader(vr->T("VR controllers")));
vrSettings->Add(new CheckBox(&g_Config.bEnableMotions, vr->T("Map controller movements to keys")));