From 5c001a2c1078a88b9129a344e2e594aee12de69a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Gro=C3=9F?= Date: Fri, 24 Jul 2026 12:03:54 +0200 Subject: [PATCH] Revert improved culling frustum in OpenVR. Fixes https://github.com/overte-org/overte/issues/2242 Reverts the OpenVR part of fcf5981e98a234fb1104f3053dda0fac30d059e9 --- plugins/openvr/src/OpenVrDisplayPlugin.cpp | 69 ++++------------------ 1 file changed, 10 insertions(+), 59 deletions(-) diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index 76a2b5498ff..d24107978d1 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -362,67 +362,17 @@ glm::mat4 OpenVrDisplayPlugin::getEyeProjection(Eye eye, const glm::mat4& basePr } } -inline static glm::mat4 fovToCullingProjection(const std::array fov, const float _near, const float _far) { - const float left = fov[0]; - const float right = fov[1]; - const float down = fov[2]; - const float up = fov[3]; - - const float width = right - left; - const float height = up - down; - - const float m11 = 2 / width; - const float m22 = 2 / height; - const float m33 = -(_far + _near) / (_far - _near); - - const float m31 = (right + left) / width; - const float m32 = (up + down) / height; - const float m43 = -(_far * (_near + _near)) / (_far - _near); - - // clang-format off - const float mat[16] = { - m11, 0 , 0 , 0, - 0 , m22, 0 , 0, - m31, m32, m33, -1, - 0 , 0 , m43, 0, - }; - // clang-format on - - return glm::make_mat4(mat); -} - glm::mat4 OpenVrDisplayPlugin::getCullingProjection(const glm::mat4& baseProjection) const { - if (!_system) { + if (_system) { + ViewFrustum baseFrustum; + baseFrustum.setProjection(baseProjection); + float baseNearClip = baseFrustum.getNearClip(); + float baseFarClip = baseFrustum.getFarClip(); + // FIXME Calculate the proper combined projection by using GetProjectionRaw values from both eyes + return toGlm(_system->GetProjectionMatrix((vr::EVREye)0, baseNearClip, baseFarClip)); + } else { return baseProjection; } - - std::array, 2> fovs; - - for (auto i = 0; i < 2; i++) { - _system->GetProjectionRaw( - (vr::EVREye)i, - &fovs[i][0], - &fovs[i][1], - &fovs[i][2], - &fovs[i][3] - ); - } - - // FIXME: OpenVR gives us tan(angle), how can we clamp - // this to within ~170° when multiplied by margin? - // const float maxAngle = 0.9f * PI; - const float margin = 1.0f; - - std::array fovMax = { - std::min(fovs[0][0], fovs[1][0]) * margin, // left - std::max(fovs[0][1], fovs[1][1]) * margin, // right - std::min(fovs[0][2], fovs[1][2]) * margin, // bottom (flipped) - std::max(fovs[0][3], fovs[1][3]) * margin, // top (flipped) - }; - - ViewFrustum frustum; - frustum.setProjection(baseProjection); - return fovToCullingProjection(fovMax, frustum.getNearClip(), frustum.getFarClip()); } float OpenVrDisplayPlugin::getTargetFrameRate() const { @@ -510,7 +460,8 @@ bool OpenVrDisplayPlugin::internalActivate() { _eyeOffsets[eye] = toGlm(_system->GetEyeToHeadTransform(eye)); _eyeProjections[eye] = toGlm(_system->GetProjectionMatrix(eye, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP)); }); - _cullingProjection = getCullingProjection(_eyeProjections[0]); + // FIXME Calculate the proper combined projection by using GetProjectionRaw values from both eyes + _cullingProjection = _eyeProjections[0]; }); // enable async time warp