From 4475bb89d554cdaeced2d8534c50bf527aa625fa Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 3 Nov 2014 12:13:08 -0800 Subject: [PATCH 1/4] Fix for 3DTV mode with non-unity render scale. --- interface/src/devices/TV3DManager.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/interface/src/devices/TV3DManager.cpp b/interface/src/devices/TV3DManager.cpp index e8644c00d0..872f4ce7e6 100644 --- a/interface/src/devices/TV3DManager.cpp +++ b/interface/src/devices/TV3DManager.cpp @@ -91,8 +91,10 @@ void TV3DManager::display(Camera& whichCamera) { // left eye portal int portalX = 0; int portalY = 0; - int portalW = Application::getInstance()->getGLWidget()->getDeviceWidth() / 2; - int portalH = Application::getInstance()->getGLWidget()->getDeviceHeight(); + QSize deviceSize = Application::getInstance()->getGLWidget()->getDeviceSize() * + Application::getInstance()->getRenderResolutionScale(); + int portalW = deviceSize.width() / 2; + int portalH = deviceSize.height(); ApplicationOverlay& applicationOverlay = Application::getInstance()->getApplicationOverlay(); @@ -135,7 +137,7 @@ void TV3DManager::display(Camera& whichCamera) { glDisable(GL_SCISSOR_TEST); // render right side view - portalX = Application::getInstance()->getGLWidget()->getDeviceWidth() / 2; + portalX = deviceSize.width() / 2; glEnable(GL_SCISSOR_TEST); // render left side view glViewport(portalX, portalY, portalW, portalH); @@ -165,8 +167,7 @@ void TV3DManager::display(Camera& whichCamera) { glDisable(GL_SCISSOR_TEST); // reset the viewport to how we started - glViewport(0, 0, Application::getInstance()->getGLWidget()->getDeviceWidth(), - Application::getInstance()->getGLWidget()->getDeviceHeight()); + glViewport(0, 0, deviceSize.width(), deviceSize.height()); Application::getInstance()->getGlowEffect()->render(); } From e76a8c2234c886fc7a87ed3444c505493177ef1e Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 3 Nov 2014 17:36:10 -0800 Subject: [PATCH 2/4] Fix for ambient occlusion in 3DTV mode. --- interface/resources/shaders/ambient_occlusion.frag | 12 ++++-------- interface/src/renderer/AmbientOcclusionEffect.cpp | 9 +-------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/interface/resources/shaders/ambient_occlusion.frag b/interface/resources/shaders/ambient_occlusion.frag index 621b123966..512922ca43 100644 --- a/interface/resources/shaders/ambient_occlusion.frag +++ b/interface/resources/shaders/ambient_occlusion.frag @@ -14,9 +14,6 @@ // the depth texture uniform sampler2D depthTexture; -// the normal texture -uniform sampler2D normalTexture; - // the random rotation texture uniform sampler2D rotationTexture; @@ -60,11 +57,10 @@ vec3 texCoordToViewSpace(vec2 texCoord) { } void main(void) { - vec3 rotationZ = texture2D(normalTexture, gl_TexCoord[0].st).xyz * 2.0 - vec3(1.0, 1.0, 1.0); - vec3 rotationY = normalize(cross(rotationZ, texture2D(rotationTexture, - gl_TexCoord[0].st * noiseScale).xyz - vec3(0.5, 0.5, 0.5))); - mat3 rotation = mat3(cross(rotationY, rotationZ), rotationY, rotationZ); - + vec3 rotationX = texture2D(rotationTexture, gl_TexCoord[0].st * noiseScale).rgb; + vec3 rotationY = normalize(cross(rotationX, vec3(0.0, 0.0, 1.0))); + mat3 rotation = mat3(rotationX, rotationY, cross(rotationX, rotationY)); + vec3 center = texCoordToViewSpace(gl_TexCoord[0].st); vec2 rdenominator = 1.0 / (rightTop - leftBottom); diff --git a/interface/src/renderer/AmbientOcclusionEffect.cpp b/interface/src/renderer/AmbientOcclusionEffect.cpp index 33a0b6e77d..f75ed7e8c3 100644 --- a/interface/src/renderer/AmbientOcclusionEffect.cpp +++ b/interface/src/renderer/AmbientOcclusionEffect.cpp @@ -51,8 +51,7 @@ void AmbientOcclusionEffect::init() { _occlusionProgram->bind(); _occlusionProgram->setUniformValue("depthTexture", 0); - _occlusionProgram->setUniformValue("normalTexture", 1); - _occlusionProgram->setUniformValue("rotationTexture", 2); + _occlusionProgram->setUniformValue("rotationTexture", 1); _occlusionProgram->setUniformValueArray("sampleKernel", sampleKernel, SAMPLE_KERNEL_SIZE); _occlusionProgram->setUniformValue("radius", 0.1f); _occlusionProgram->release(); @@ -102,9 +101,6 @@ void AmbientOcclusionEffect::render() { glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getPrimaryDepthTextureID()); glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getPrimaryNormalTextureID()); - - glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, _rotationTextureID); // render with the occlusion shader to the secondary/tertiary buffer @@ -142,9 +138,6 @@ void AmbientOcclusionEffect::render() { glBindTexture(GL_TEXTURE_2D, 0); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, 0); - glActiveTexture(GL_TEXTURE0); // now render secondary to primary with 4x4 blur From 3ba3299e35a398ddb3ea97640a78ee44374b8403 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 3 Nov 2014 21:13:01 -0800 Subject: [PATCH 3/4] Use glFrustum rather than Oculus's projection utility method, which seems to be returning weird results. --- interface/src/devices/OculusManager.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index 709080e354..b7884705e1 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -420,7 +420,7 @@ void OculusManager::endFrameTiming() { //Sets the camera FoV and aspect ratio void OculusManager::configureCamera(Camera& camera, int screenWidth, int screenHeight) { #ifdef HAVE_LIBOVR - camera.setAspectRatio(_renderTargetSize.w / _renderTargetSize.h); + camera.setAspectRatio((float)_renderTargetSize.w / _renderTargetSize.h); camera.setFieldOfView(atan(_eyeFov[0].UpTan) * DEGREES_PER_RADIAN * 2.0f); #endif } @@ -511,12 +511,12 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p _camera->update(1.0f / Application::getInstance()->getFps()); - Matrix4f proj = ovrMatrix4f_Projection(_eyeRenderDesc[eye].Fov, whichCamera.getNearClip(), whichCamera.getFarClip(), true); - proj.Transpose(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glLoadMatrixf((GLfloat *)proj.M); - + const ovrFovPort& port = _eyeFov[_activeEyeIndex]; + float near = whichCamera.getNearClip(), far = whichCamera.getFarClip(); + glFrustum(-near * port.LeftTan, near * port.RightTan, -near * port.DownTan, near * port.UpTan, near, far); + glViewport(_eyeRenderViewport[eye].Pos.x, _eyeRenderViewport[eye].Pos.y, _eyeRenderViewport[eye].Size.w, _eyeRenderViewport[eye].Size.h); From 03ce8081a4815def879dec40914f4acc7ce8852a Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 4 Nov 2014 11:44:47 -0800 Subject: [PATCH 4/4] Oh, when will I learn not to use "near" and "far" as variable names? --- interface/src/devices/OculusManager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index b7884705e1..23cd52d946 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -514,8 +514,9 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p glMatrixMode(GL_PROJECTION); glLoadIdentity(); const ovrFovPort& port = _eyeFov[_activeEyeIndex]; - float near = whichCamera.getNearClip(), far = whichCamera.getFarClip(); - glFrustum(-near * port.LeftTan, near * port.RightTan, -near * port.DownTan, near * port.UpTan, near, far); + float nearClip = whichCamera.getNearClip(), farClip = whichCamera.getFarClip(); + glFrustum(-nearClip * port.LeftTan, nearClip * port.RightTan, -nearClip * port.DownTan, + nearClip * port.UpTan, nearClip, farClip); glViewport(_eyeRenderViewport[eye].Pos.x, _eyeRenderViewport[eye].Pos.y, _eyeRenderViewport[eye].Size.w, _eyeRenderViewport[eye].Size.h);