From b005f61a2e8e34e9de10183d1fe6f873f7dd9133 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Thu, 16 Oct 2014 18:52:32 +0200 Subject: Add geometry shader generator for stereo 3D. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 93f969b0b5..b62e2f93e3 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -489,7 +489,7 @@ void VertexShaderManager::SetConstants() PRIM_LOG("Projection: %f %f %f %f %f %f\n", rawProjection[0], rawProjection[1], rawProjection[2], rawProjection[3], rawProjection[4], rawProjection[5]); - if ((g_ActiveConfig.bFreeLook || g_ActiveConfig.bAnaglyphStereo ) && xfmem.projection.type == GX_PERSPECTIVE) + if (g_ActiveConfig.bFreeLook && xfmem.projection.type == GX_PERSPECTIVE) { Matrix44 mtxA; Matrix44 mtxB; -- cgit v1.2.3 From f6ea293027e553cf89f780ec2a1b716cc026a4b5 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Sun, 26 Oct 2014 19:17:00 +0100 Subject: VertexShaderManager: Compute stereoscopy projection matrices. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index b62e2f93e3..e40eb92152 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -512,6 +512,30 @@ void VertexShaderManager::SetConstants() Matrix44::Multiply(s_viewportCorrection, projMtx, correctedMtx); memcpy(constants.projection, correctedMtx.data, 4*16); } + + if (g_ActiveConfig.bStereo && xfmem.projection.type == GX_PERSPECTIVE) + { + Matrix44 projMtx; + Matrix44::Set(projMtx, g_fProjectionMatrix); + + Matrix44 leftShearMtx, rightShearMtx; + Matrix44::Shear(leftShearMtx, g_ActiveConfig.iStereoSeparation / (200.0f * g_ActiveConfig.iStereoFocalLength)); + Matrix44::Shear(rightShearMtx, -g_ActiveConfig.iStereoSeparation / (200.0f * g_ActiveConfig.iStereoFocalLength)); + + Matrix44 leftProjMtx, rightProjMtx, leftCorrectedMtx, rightCorrectedMtx; + Matrix44::Multiply(projMtx, leftShearMtx, leftProjMtx); + Matrix44::Multiply(s_viewportCorrection, leftProjMtx, leftCorrectedMtx); + Matrix44::Multiply(projMtx, rightShearMtx, rightProjMtx); + Matrix44::Multiply(s_viewportCorrection, rightProjMtx, rightCorrectedMtx); + memcpy(constants.stereoprojection, leftCorrectedMtx.data, 4*16); + memcpy(constants.stereoprojection + 4, rightCorrectedMtx.data, 4*16); + } + else + { + memcpy(constants.stereoprojection, constants.projection, 4 * 16); + memcpy(constants.stereoprojection + 4, constants.projection, 4 * 16); + } + dirty = true; } } -- cgit v1.2.3 From 6cacfad010b05cd9d79056a81c4dc7d19ca57273 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Thu, 30 Oct 2014 02:08:15 +0100 Subject: GeometryShader: Transform the projection within the geometry shader. Reduces the amount of data transferred through uniforms. The shearing transformation is reduced to a single multiplication/addition for optimization. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index e40eb92152..5d65a49186 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -515,25 +515,13 @@ void VertexShaderManager::SetConstants() if (g_ActiveConfig.bStereo && xfmem.projection.type == GX_PERSPECTIVE) { - Matrix44 projMtx; - Matrix44::Set(projMtx, g_fProjectionMatrix); - - Matrix44 leftShearMtx, rightShearMtx; - Matrix44::Shear(leftShearMtx, g_ActiveConfig.iStereoSeparation / (200.0f * g_ActiveConfig.iStereoFocalLength)); - Matrix44::Shear(rightShearMtx, -g_ActiveConfig.iStereoSeparation / (200.0f * g_ActiveConfig.iStereoFocalLength)); - - Matrix44 leftProjMtx, rightProjMtx, leftCorrectedMtx, rightCorrectedMtx; - Matrix44::Multiply(projMtx, leftShearMtx, leftProjMtx); - Matrix44::Multiply(s_viewportCorrection, leftProjMtx, leftCorrectedMtx); - Matrix44::Multiply(projMtx, rightShearMtx, rightProjMtx); - Matrix44::Multiply(s_viewportCorrection, rightProjMtx, rightCorrectedMtx); - memcpy(constants.stereoprojection, leftCorrectedMtx.data, 4*16); - memcpy(constants.stereoprojection + 4, rightCorrectedMtx.data, 4*16); + float offset = g_ActiveConfig.iStereoSeparation / (200.0f * g_ActiveConfig.iStereoFocalLength); + constants.stereooffset[0] = offset; + constants.stereooffset[1] = -offset; } else { - memcpy(constants.stereoprojection, constants.projection, 4 * 16); - memcpy(constants.stereoprojection + 4, constants.projection, 4 * 16); + constants.stereooffset[0] = constants.stereooffset[1] = 0; } dirty = true; -- cgit v1.2.3 From 9b22e151803ccfb757eb9319f1b32e3d1999f42e Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Thu, 30 Oct 2014 23:29:56 +0100 Subject: VideoConfigDiag: Add stereoscopy options group. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 5d65a49186..ad69ba4362 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -513,7 +513,7 @@ void VertexShaderManager::SetConstants() memcpy(constants.projection, correctedMtx.data, 4*16); } - if (g_ActiveConfig.bStereo && xfmem.projection.type == GX_PERSPECTIVE) + if (g_ActiveConfig.iStereoMode > 0 && xfmem.projection.type == GX_PERSPECTIVE) { float offset = g_ActiveConfig.iStereoSeparation / (200.0f * g_ActiveConfig.iStereoFocalLength); constants.stereooffset[0] = offset; -- cgit v1.2.3 From 1261bd02caa0ca2503bdd52e7b37c22f8e0bcde5 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Fri, 31 Oct 2014 16:05:44 +0100 Subject: VertexShaderManager: Add stereoscopy options to swap the left and right eye. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index ad69ba4362..150bd783a8 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -516,8 +516,8 @@ void VertexShaderManager::SetConstants() if (g_ActiveConfig.iStereoMode > 0 && xfmem.projection.type == GX_PERSPECTIVE) { float offset = g_ActiveConfig.iStereoSeparation / (200.0f * g_ActiveConfig.iStereoFocalLength); - constants.stereooffset[0] = offset; - constants.stereooffset[1] = -offset; + constants.stereooffset[0] = (g_ActiveConfig.bStereoSwapEyes) ? -offset : offset; + constants.stereooffset[1] = (g_ActiveConfig.bStereoSwapEyes) ? offset : -offset; } else { -- cgit v1.2.3 From 51a4d6a4bef09e7b270ee26e5b2889379819da45 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Tue, 4 Nov 2014 01:12:00 +0100 Subject: GeometryShader: Adjust positions after projection. By adjusting the positions in clip space we can avoid the re-projection. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 150bd783a8..f6d285cffd 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -516,8 +516,8 @@ void VertexShaderManager::SetConstants() if (g_ActiveConfig.iStereoMode > 0 && xfmem.projection.type == GX_PERSPECTIVE) { float offset = g_ActiveConfig.iStereoSeparation / (200.0f * g_ActiveConfig.iStereoFocalLength); - constants.stereooffset[0] = (g_ActiveConfig.bStereoSwapEyes) ? -offset : offset; - constants.stereooffset[1] = (g_ActiveConfig.bStereoSwapEyes) ? offset : -offset; + constants.stereooffset[0] = (g_ActiveConfig.bStereoSwapEyes) ? offset : -offset; + constants.stereooffset[1] = (g_ActiveConfig.bStereoSwapEyes) ? -offset : offset; } else { -- cgit v1.2.3 From f3ddf37d074f80bf40b42995e91db98b4d599534 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Sat, 8 Nov 2014 14:31:26 +0100 Subject: VideoCommon: Switch to Nvidia stereoscopy offset formula. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index f6d285cffd..7237ee41f1 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -515,13 +515,14 @@ void VertexShaderManager::SetConstants() if (g_ActiveConfig.iStereoMode > 0 && xfmem.projection.type == GX_PERSPECTIVE) { - float offset = g_ActiveConfig.iStereoSeparation / (200.0f * g_ActiveConfig.iStereoFocalLength); - constants.stereooffset[0] = (g_ActiveConfig.bStereoSwapEyes) ? offset : -offset; - constants.stereooffset[1] = (g_ActiveConfig.bStereoSwapEyes) ? -offset : offset; + float offset = g_ActiveConfig.iStereoSeparation / 10000.0f; + constants.stereoparams[0] = (g_ActiveConfig.bStereoSwapEyes) ? offset : -offset; + constants.stereoparams[1] = (g_ActiveConfig.bStereoSwapEyes) ? -offset : offset; + constants.stereoparams[2] = (float)g_ActiveConfig.iStereoFocalLength; } else { - constants.stereooffset[0] = constants.stereooffset[1] = 0; + constants.stereoparams[0] = constants.stereoparams[1] = 0; } dirty = true; -- cgit v1.2.3 From 0f4d59f61207af19f4977c1a11afc8cac1acdd91 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Mon, 24 Nov 2014 11:50:35 +0100 Subject: VideoConfig: Rename StereoFocalLength to StereoConvergence. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 7237ee41f1..f71dd6514b 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -518,7 +518,7 @@ void VertexShaderManager::SetConstants() float offset = g_ActiveConfig.iStereoSeparation / 10000.0f; constants.stereoparams[0] = (g_ActiveConfig.bStereoSwapEyes) ? offset : -offset; constants.stereoparams[1] = (g_ActiveConfig.bStereoSwapEyes) ? -offset : offset; - constants.stereoparams[2] = (float)g_ActiveConfig.iStereoFocalLength; + constants.stereoparams[2] = (float)g_ActiveConfig.iStereoConvergence; } else { -- cgit v1.2.3 From a04edbcb9a5ffe9351c75446982e3832b6d3e5a4 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Mon, 24 Nov 2014 12:19:25 +0100 Subject: VideoConfig: Add separation and convergence modifiers to the game ini. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index f71dd6514b..8c9791f276 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -515,10 +515,10 @@ void VertexShaderManager::SetConstants() if (g_ActiveConfig.iStereoMode > 0 && xfmem.projection.type == GX_PERSPECTIVE) { - float offset = g_ActiveConfig.iStereoSeparation / 10000.0f; + float offset = (g_ActiveConfig.iStereoSeparation / 10000.0f) * (g_ActiveConfig.iStereoSeparationPercent / 100.0f); constants.stereoparams[0] = (g_ActiveConfig.bStereoSwapEyes) ? offset : -offset; constants.stereoparams[1] = (g_ActiveConfig.bStereoSwapEyes) ? -offset : offset; - constants.stereoparams[2] = (float)g_ActiveConfig.iStereoConvergence; + constants.stereoparams[2] = g_ActiveConfig.iStereoConvergence * (g_ActiveConfig.iStereoConvergencePercent / 100.0f); } else { -- cgit v1.2.3 From 6d51455195e95a1bb97eb263fcd3423c757f59e7 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Thu, 27 Nov 2014 15:28:00 +0100 Subject: VideoConfig: Further optimize convergence and separation values and update their descriptions. Previous convergence distance was much too large. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 8c9791f276..8de50c5436 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -515,10 +515,10 @@ void VertexShaderManager::SetConstants() if (g_ActiveConfig.iStereoMode > 0 && xfmem.projection.type == GX_PERSPECTIVE) { - float offset = (g_ActiveConfig.iStereoSeparation / 10000.0f) * (g_ActiveConfig.iStereoSeparationPercent / 100.0f); + float offset = (g_ActiveConfig.iStereoSeparation / 1000.0f) * (g_ActiveConfig.iStereoSeparationPercent / 100.0f); constants.stereoparams[0] = (g_ActiveConfig.bStereoSwapEyes) ? offset : -offset; constants.stereoparams[1] = (g_ActiveConfig.bStereoSwapEyes) ? -offset : offset; - constants.stereoparams[2] = g_ActiveConfig.iStereoConvergence * (g_ActiveConfig.iStereoConvergencePercent / 100.0f); + constants.stereoparams[2] = (g_ActiveConfig.iStereoConvergence / 10.0f) * (g_ActiveConfig.iStereoConvergencePercent / 100.0f); } else { -- cgit v1.2.3