Skip to content

Commit

Permalink
Merge pull request #14768 from hrydgard/cardboard-vr-math-fix
Browse files Browse the repository at this point in the history
Fix the math in cardboard VR mode for wide aspect ratios
  • Loading branch information
hrydgard committed Aug 28, 2021
2 parents b87b212 + c0d80b6 commit 2735b09
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions GPU/Common/PresentationCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ void PresentationCommon::GetCardboardSettings(CardboardSettings *cardboardSettin
cardboardSettings->enabled = false;
return;
}

// Calculate Cardboard Settings
float cardboardScreenScale = g_Config.iCardboardScreenSize / 100.0f;
float cardboardScreenWidth = pixelWidth_ / 2.0f * cardboardScreenScale;
float cardboardScreenHeight = pixelHeight_ / 2.0f * cardboardScreenScale;
float cardboardScreenHeight = pixelHeight_ * cardboardScreenScale;
float cardboardMaxXShift = (pixelWidth_ / 2.0f - cardboardScreenWidth) / 2.0f;
float cardboardUserXShift = g_Config.iCardboardXShift / 100.0f * cardboardMaxXShift;
float cardboardLeftEyeX = cardboardMaxXShift + cardboardUserXShift;
Expand Down Expand Up @@ -563,8 +564,17 @@ void PresentationCommon::CopyToOutput(OutputFlags flags, int uvRotation, float u
int lastWidth = srcWidth_;
int lastHeight = srcHeight_;

int pixelWidth = pixelWidth_;
int pixelHeight = pixelHeight_;

// These are the output coordinates.
FRect frame = GetScreenFrame((float)pixelWidth_, (float)pixelHeight_);
FRect frame = GetScreenFrame((float)pixelWidth, (float)pixelHeight);
// Note: In cardboard mode, we halve the width here to compensate
// for splitting the window in half, while still reusing normal centering.
if (g_Config.bEnableCardboardVR) {
frame.w /= 2.0;
pixelWidth /= 2;
}
FRect rc;
CenterDisplayOutputRect(&rc, 480.0f, 272.0f, frame, uvRotation);

Expand All @@ -587,8 +597,8 @@ void PresentationCommon::CopyToOutput(OutputFlags flags, int uvRotation, float u
{ rc.x + rc.w, rc.y, 0, u1, v0, 0xFFFFFFFF }, // TR
};

float invDestW = 1.0f / (pixelWidth_ * 0.5f);
float invDestH = 1.0f / (pixelHeight_ * 0.5f);
float invDestW = 2.0f / pixelWidth;
float invDestH = 2.0f / pixelHeight;
for (int i = 0; i < 4; i++) {
verts[i].x = verts[i].x * invDestW - 1.0f;
verts[i].y = verts[i].y * invDestH - 1.0f;
Expand Down Expand Up @@ -689,9 +699,9 @@ void PresentationCommon::CopyToOutput(OutputFlags flags, int uvRotation, float u
float post_v0 = !flipped ? 1.0f : 0.0f;
float post_v1 = !flipped ? 0.0f : 1.0f;
verts[4] = { -1, -1, 0, 0, post_v1, 0xFFFFFFFF }; // TL
verts[5] = { -1, 1, 0, 0, post_v0, 0xFFFFFFFF }; // BL
verts[6] = { 1, 1, 0, 1, post_v0, 0xFFFFFFFF }; // BR
verts[7] = { 1, -1, 0, 1, post_v1, 0xFFFFFFFF }; // TR
verts[5] = { -1, 1, 0, 0, post_v0, 0xFFFFFFFF }; // BL
verts[6] = { 1, 1, 0, 1, post_v0, 0xFFFFFFFF }; // BR
verts[7] = { 1, -1, 0, 1, post_v1, 0xFFFFFFFF }; // TR
draw_->UpdateBuffer(vdata_, (const uint8_t *)verts, 0, sizeof(verts), Draw::UPDATE_DISCARD);

for (size_t i = 0; i < postShaderFramebuffers_.size(); ++i) {
Expand Down

0 comments on commit 2735b09

Please sign in to comment.