From 2cba7b37bf0688ffa391c8554bcb33615cb21698 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 10 Sep 2014 13:51:14 -0700 Subject: [PATCH] Attempting to fix 3DTV/Oculus deferred lighting/ambient occlusion. --- interface/src/Application.cpp | 7 +++++++ interface/src/devices/OculusManager.cpp | 17 +++++++++++++++++ interface/src/devices/OculusManager.h | 4 ++++ interface/src/devices/TV3DManager.cpp | 16 +++++++++++++++- interface/src/devices/TV3DManager.h | 5 +++++ 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 7c7c455d1d..f781c9765d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2971,7 +2971,14 @@ void Application::getProjectionMatrix(glm::dmat4* projectionMatrix) { void Application::computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal, float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const { + // allow 3DTV/Oculus to override parameters from camera _viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); + if (OculusManager::isConnected()) { + OculusManager::overrideOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); + + } else if (TV3DManager::isConnected()) { + TV3DManager::overrideOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); + } } glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index bc6dc842ce..e46f2f3182 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -53,6 +53,7 @@ unsigned int OculusManager::_frameIndex = 0; bool OculusManager::_frameTimingActive = false; bool OculusManager::_programInitialized = false; Camera* OculusManager::_camera = NULL; +int OculusManager::_activeEyeIndex = -1; #endif @@ -330,6 +331,8 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p //Render each eye into an fbo for (int eyeIndex = 0; eyeIndex < ovrEye_Count; eyeIndex++) { + _activeEyeIndex = eyeIndex; + #if defined(__APPLE__) || defined(_WIN32) ovrEyeType eye = _ovrHmd->EyeRenderOrder[eyeIndex]; #else @@ -363,6 +366,7 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p Application::getInstance()->displaySide(*_camera); applicationOverlay.displayOverlayTextureOculus(*_camera); + _activeEyeIndex = -1; } //Wait till time-warp to reduce latency @@ -528,3 +532,16 @@ QSize OculusManager::getRenderTargetSize() { return QSize(100, 100); #endif } + +void OculusManager::overrideOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal, + float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) { +#ifdef HAVE_LIBOVR + if (_activeEyeIndex != -1) { + float extent = nearVal * glm::tan(_eyeRenderDesc[_activeEyeIndex].Fov / 2.0f); + right = extent; + left = -extent; + top = extent; + bottom = -extent; + } +#endif +} diff --git a/interface/src/devices/OculusManager.h b/interface/src/devices/OculusManager.h index 3959ea1ab7..d8e55647b4 100644 --- a/interface/src/devices/OculusManager.h +++ b/interface/src/devices/OculusManager.h @@ -43,6 +43,9 @@ public: static glm::vec3 getRelativePosition(); static QSize getRenderTargetSize(); + static void overrideOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal, + float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane); + private: #ifdef HAVE_LIBOVR static void generateDistortionMesh(); @@ -92,6 +95,7 @@ private: static bool _frameTimingActive; static bool _programInitialized; static Camera* _camera; + static int _activeEyeIndex; #endif }; diff --git a/interface/src/devices/TV3DManager.cpp b/interface/src/devices/TV3DManager.cpp index 005f7133f0..e8644c00d0 100644 --- a/interface/src/devices/TV3DManager.cpp +++ b/interface/src/devices/TV3DManager.cpp @@ -25,6 +25,7 @@ int TV3DManager::_screenHeight = 1; double TV3DManager::_aspect = 1.0; eyeFrustum TV3DManager::_leftEye; eyeFrustum TV3DManager::_rightEye; +eyeFrustum* TV3DManager::_activeEye = NULL; bool TV3DManager::isConnected() { @@ -111,7 +112,7 @@ void TV3DManager::display(Camera& whichCamera) { glPushMatrix(); { - + _activeEye = &_leftEye; glMatrixMode(GL_PROJECTION); glLoadIdentity(); // reset projection matrix glFrustum(_leftEye.left, _leftEye.right, _leftEye.bottom, _leftEye.top, nearZ, farZ); // set left view frustum @@ -128,6 +129,7 @@ void TV3DManager::display(Camera& whichCamera) { if (displayOverlays) { applicationOverlay.displayOverlayTexture3DTV(whichCamera, _aspect, fov); } + _activeEye = NULL; } glPopMatrix(); glDisable(GL_SCISSOR_TEST); @@ -140,6 +142,7 @@ void TV3DManager::display(Camera& whichCamera) { glScissor(portalX, portalY, portalW, portalH); glPushMatrix(); { + _activeEye = &_rightEye; glMatrixMode(GL_PROJECTION); glLoadIdentity(); // reset projection matrix glFrustum(_rightEye.left, _rightEye.right, _rightEye.bottom, _rightEye.top, nearZ, farZ); // set left view frustum @@ -156,6 +159,7 @@ void TV3DManager::display(Camera& whichCamera) { if (displayOverlays) { applicationOverlay.displayOverlayTexture3DTV(whichCamera, _aspect, fov); } + _activeEye = NULL; } glPopMatrix(); glDisable(GL_SCISSOR_TEST); @@ -166,3 +170,13 @@ void TV3DManager::display(Camera& whichCamera) { Application::getInstance()->getGlowEffect()->render(); } + +void TV3DManager::overrideOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal, + float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) { + if (_activeEye) { + left = _activeEye->left; + right = _activeEye->right; + bottom = _activeEye->bottom; + top = _activeEye->top; + } +} diff --git a/interface/src/devices/TV3DManager.h b/interface/src/devices/TV3DManager.h index 91a78e9bce..2b2b9e0aa1 100644 --- a/interface/src/devices/TV3DManager.h +++ b/interface/src/devices/TV3DManager.h @@ -14,6 +14,8 @@ #include +#include + class Camera; struct eyeFrustum { @@ -32,6 +34,8 @@ public: static bool isConnected(); static void configureCamera(Camera& camera, int screenWidth, int screenHeight); static void display(Camera& whichCamera); + static void overrideOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal, + float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane); private: static void setFrustum(Camera& whichCamera); static int _screenWidth; @@ -39,6 +43,7 @@ private: static double _aspect; static eyeFrustum _leftEye; static eyeFrustum _rightEye; + static eyeFrustum* _activeEye; }; #endif // hifi_TV3DManager_h