From 5410bc0945145772d9101cc4fbc45d89ad2d2d36 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 15 Sep 2015 17:48:55 -0700 Subject: [PATCH] FIx the review comment and trying to fix the simple stereo display plugin projection and eye view matrix --- .../stereo/StereoDisplayPlugin.cpp | 29 ++++++++++++------- libraries/render-utils/src/DeferredBuffer.slh | 2 +- .../src/DeferredLightingEffect.cpp | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp index ae3c1f29e2..77906d1857 100644 --- a/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp @@ -29,33 +29,40 @@ bool StereoDisplayPlugin::isSupported() const { // FIXME make this into a setting that can be adjusted const float DEFAULT_IPD = 0.064f; -const float HALF_DEFAULT_IPD = DEFAULT_IPD / 2.0f; + +// Default physical display width (50cm) +const float DEFAULT_SCREEN_WIDTH = 0.5f; + +// Default separation = ipd / screenWidth +const float DEFAULT_SEPARATION = DEFAULT_IPD / DEFAULT_SCREEN_WIDTH; + +// Default convergence depth: where is the screen plane in the virtual space (which depth) +const float DEFAULT_CONVERGENCE = 0.5f; glm::mat4 StereoDisplayPlugin::getProjection(Eye eye, const glm::mat4& baseProjection) const { // Refer to http://www.nvidia.com/content/gtc-2010/pdfs/2010_gtc2010.pdf on creating // stereo projection matrices. Do NOT use "toe-in", use translation. + // Updated version: http://developer.download.nvidia.com/assets/gamedev/docs/Siggraph2011-Stereoscopy_From_XY_to_Z-SG.pdf if (eye == Mono) { // FIXME provide a combined matrix, needed for proper culling return baseProjection; } - float nearZ = DEFAULT_NEAR_CLIP; // near clipping plane - float screenZ = 0.25f; // screen projection plane - // FIXME verify this is the right calculation - float frustumshift = HALF_DEFAULT_IPD * nearZ / screenZ; + float frustumshift = DEFAULT_SEPARATION; if (eye == Right) { frustumshift = -frustumshift; } - return glm::translate(baseProjection, vec3(frustumshift, 0, 0)); + + + auto eyeProjection = baseProjection; + eyeProjection[2][0] += frustumshift; + eyeProjection[3][0] += frustumshift * DEFAULT_CONVERGENCE; // include the eye offset here + return eyeProjection; } glm::mat4 StereoDisplayPlugin::getEyePose(Eye eye) const { - float modelviewShift = HALF_DEFAULT_IPD; - if (eye == Left) { - modelviewShift = -modelviewShift; - } - return glm::translate(mat4(), vec3(modelviewShift, 0, 0)); + return mat4(); } std::vector _screenActions; diff --git a/libraries/render-utils/src/DeferredBuffer.slh b/libraries/render-utils/src/DeferredBuffer.slh index e3d9593936..89b8b26a4f 100755 --- a/libraries/render-utils/src/DeferredBuffer.slh +++ b/libraries/render-utils/src/DeferredBuffer.slh @@ -40,7 +40,7 @@ DeferredTransform getDeferredTransform() { } bool getStereoMode(DeferredTransform deferredTransform) { - return (deferredTransform.stereoSide_spareABC.x != 0.0); + return (deferredTransform.stereoSide_spareABC.x != 0.0); } float getStereoSide(DeferredTransform deferredTransform) { return (deferredTransform.stereoSide_spareABC.x); diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 55fe4d9ca9..213ce8eed5 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -349,7 +349,7 @@ void DeferredLightingEffect::render(RenderArgs* args) { for (int i = 0; i < numPasses; i++) { // In stereo, the 2 sides are layout side by side in the mono viewport and their width is half - int sideWidth = monoViewport.z * 0.5; + int sideWidth = monoViewport.z >> 1; viewports[i] = ivec4(monoViewport.x + (i * sideWidth), monoViewport.y, sideWidth, monoViewport.w); // Combine the side projection with the side View offset (the view matrix is same for all side)