diff --git a/docs/quest.md b/docs/quest.md index 2ab781c2b..067b70892 100644 --- a/docs/quest.md +++ b/docs/quest.md @@ -187,6 +187,12 @@ declaration, the test runtime reported 72/80/90/120 Hz; a fresh normal launch used 72 Hz in both OpenXR telemetry and SteamVR's HMD property. DroidDeck leaves the refresh choice to the runtime. No forced refresh override is included. +The OpenVR driver maps OpenXR's asymmetric eye FOV to OpenVR's lower/upper Y +projection bounds. A live Quest 3 check confirmed that SteamVR and native +OpenXR now report the same vertical projection center; the previous mapping +mirrored that offset. This applies to every VR scene, without game-specific +rendering changes. + ### Experimental flat games in SteamVR Start SteamVR first, then add `droiddeck-steamvr-game %command%` to a flat diff --git a/tools/vr/src/driver_droiddeck.cpp b/tools/vr/src/driver_droiddeck.cpp index 581be289d..b7d56fa0c 100644 --- a/tools/vr/src/driver_droiddeck.cpp +++ b/tools/vr/src/driver_droiddeck.cpp @@ -656,8 +656,7 @@ public: DroidDeckXrTracking xr; if (xrMode_ && xr_.Read(&xr) && XrTrackingFile::Fresh(xr)) { const float *fov = xr.eyes[eye == Eye_Right ? 1 : 0].fov; - *left = std::tan(fov[0]); *right = std::tan(fov[1]); - *top = -std::tan(fov[2]); *bottom = -std::tan(fov[3]); + xr_frame_projection_raw(fov, left, right, top, bottom); return; } *left = -tanHalf_ * eyeAspect_; *right = tanHalf_ * eyeAspect_; diff --git a/tools/vr/src/xr_frame_math.h b/tools/vr/src/xr_frame_math.h index a05543499..a78de7987 100644 --- a/tools/vr/src/xr_frame_math.h +++ b/tools/vr/src/xr_frame_math.h @@ -7,6 +7,12 @@ struct DroidDeckXrRenderView { float fov[4]; }; +inline void xr_frame_projection_raw(const float fov[4], float *left, float *right, float *top, float *bottom) { + *left = std::tan(fov[0]); *right = std::tan(fov[1]); + // OpenVR's top/bottom parameters are the lower/upper Y bounds in its projection formula. + *top = std::tan(fov[3]); *bottom = std::tan(fov[2]); +} + inline void xr_frame_eye_pose(float result[3][4], const float head[3][4], const float eyeToHead[3][4]) { for (int row = 0; row < 3; row++) { for (int column = 0; column < 3; column++) { diff --git a/tools/vr/tests/test_xr_frames.cpp b/tools/vr/tests/test_xr_frames.cpp index f47b4ea56..837a7ce17 100644 --- a/tools/vr/tests/test_xr_frames.cpp +++ b/tools/vr/tests/test_xr_frames.cpp @@ -75,6 +75,16 @@ int main(int argc, char **argv) { valid.projection[0][0][2] = 0.2f; valid.projection[0][1][2] = -0.1f; view = xr_frame_view(valid, 0); assert(std::abs(std::tan(view.fov[0]) + 0.8f) < 0.00001f && std::abs(std::tan(view.fov[2]) - 0.9f) < 0.00001f); + float left, right, top, bottom; + xr_frame_projection_raw(view.fov, &left, &right, &top, &bottom); + float xScale = 2 / (right - left), xOffset = (right + left) / (right - left); + float yScale = 2 / (bottom - top), yOffset = (bottom + top) / (bottom - top); + assert(std::abs(xScale - valid.projection[0][0][0]) < 0.00001f); + assert(std::abs(yScale - valid.projection[0][1][1]) < 0.00001f); + assert(std::abs(xOffset - valid.projection[0][0][2]) < 0.00001f); + assert(std::abs(yOffset - valid.projection[0][1][2]) < 0.00001f); + assert(std::abs(yScale * std::tan(view.fov[2]) - yOffset - 1) < 0.00001f); + assert(std::abs(yScale * std::tan(view.fov[3]) - yOffset + 1) < 0.00001f); XrFrameReceiver receiver; assert(receiver.Start(socketPath)); struct stat status{}; assert(stat(socketPath.c_str(), &status) == 0 && (status.st_mode & 0777) == 0600); XrFrameReceiver other; assert(!other.Start(socketPath));