From f3ddf37d074f80bf40b42995e91db98b4d599534 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Sat, 8 Nov 2014 14:31:26 +0100 Subject: [PATCH] VideoCommon: Switch to Nvidia stereoscopy offset formula. --- Source/Core/DolphinWX/VideoConfigDiag.cpp | 2 +- Source/Core/VideoCommon/ConstantManager.h | 2 +- Source/Core/VideoCommon/GeometryShaderGen.cpp | 4 ++-- Source/Core/VideoCommon/ShaderGenCommon.h | 4 ++-- Source/Core/VideoCommon/VertexShaderManager.cpp | 9 +++++---- Source/Core/VideoCommon/VideoConfig.cpp | 4 ++-- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Source/Core/DolphinWX/VideoConfigDiag.cpp b/Source/Core/DolphinWX/VideoConfigDiag.cpp index 6d91447ace..dae92a728a 100644 --- a/Source/Core/DolphinWX/VideoConfigDiag.cpp +++ b/Source/Core/DolphinWX/VideoConfigDiag.cpp @@ -457,7 +457,7 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con szr_stereo->Add(new wxStaticText(page_enh, -1, _("Stereoscopic 3D Mode:")), 1, wxALIGN_CENTER_VERTICAL, 0); szr_stereo->Add(CreateChoice(page_enh, vconfig.iStereoMode, wxGetTranslation(stereo_3d_desc), 4, stereo_choices)); - wxSlider* const sep_slider = new wxSlider(page_enh, wxID_ANY, vconfig.iStereoSeparation, 30, 90, wxDefaultPosition, wxDefaultSize, wxSL_VALUE_LABEL); + wxSlider* const sep_slider = new wxSlider(page_enh, wxID_ANY, vconfig.iStereoSeparation, 10, 100, wxDefaultPosition, wxDefaultSize, wxSL_VALUE_LABEL); sep_slider->Bind(wxEVT_SLIDER, &VideoConfigDiag::Event_StereoSep, this); RegisterControl(sep_slider, wxGetTranslation(stereo_separation_desc)); diff --git a/Source/Core/VideoCommon/ConstantManager.h b/Source/Core/VideoCommon/ConstantManager.h index e31806bbd1..116088d76e 100644 --- a/Source/Core/VideoCommon/ConstantManager.h +++ b/Source/Core/VideoCommon/ConstantManager.h @@ -43,6 +43,6 @@ struct VertexShaderConstants float4 normalmatrices[32]; float4 posttransformmatrices[64]; float4 depthparams; - float4 stereooffset; + float4 stereoparams; }; diff --git a/Source/Core/VideoCommon/GeometryShaderGen.cpp b/Source/Core/VideoCommon/GeometryShaderGen.cpp index bac3823747..ff7632da05 100644 --- a/Source/Core/VideoCommon/GeometryShaderGen.cpp +++ b/Source/Core/VideoCommon/GeometryShaderGen.cpp @@ -83,8 +83,8 @@ static inline void GenerateGeometryShader(T& out, u32 components, API_TYPE ApiTy if (g_ActiveConfig.iStereoMode > 0) { - out.Write("\t\tf.clipPos.x += f.clipPos.w * " I_STEREOOFFSET"[layer] * " I_PROJECTION"[0][0];\n"); - out.Write("\t\tf.pos.x += f.pos.w * " I_STEREOOFFSET"[layer] * " I_PROJECTION"[0][0];\n"); + out.Write("\t\tf.clipPos.x += " I_STEREOPARAMS"[layer] * (f.clipPos.w - " I_STEREOPARAMS"[2]);\n"); + out.Write("\t\tf.pos.x += " I_STEREOPARAMS"[layer] * (f.pos.w - " I_STEREOPARAMS"[2]);\n"); } out.Write("\t\tgl_Position = f.pos;\n"); diff --git a/Source/Core/VideoCommon/ShaderGenCommon.h b/Source/Core/VideoCommon/ShaderGenCommon.h index 5e9e24e7fa..330b9f8ced 100644 --- a/Source/Core/VideoCommon/ShaderGenCommon.h +++ b/Source/Core/VideoCommon/ShaderGenCommon.h @@ -239,7 +239,7 @@ private: #define I_NORMALMATRICES "cnmtx" #define I_POSTTRANSFORMMATRICES "cpostmtx" #define I_DEPTHPARAMS "cDepth" // farZ, zRange -#define I_STEREOOFFSET "csoffset" +#define I_STEREOPARAMS "cstereo" static const char s_shader_uniforms[] = "\tfloat4 " I_POSNORMALMATRIX"[6];\n" @@ -251,4 +251,4 @@ static const char s_shader_uniforms[] = "\tfloat4 " I_NORMALMATRICES"[32];\n" "\tfloat4 " I_POSTTRANSFORMMATRICES"[64];\n" "\tfloat4 " I_DEPTHPARAMS";\n" - "\tfloat4 " I_STEREOOFFSET";\n"; + "\tfloat4 " I_STEREOPARAMS";\n"; 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; diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp index 18f10b0fd2..d97a5a9377 100644 --- a/Source/Core/VideoCommon/VideoConfig.cpp +++ b/Source/Core/VideoCommon/VideoConfig.cpp @@ -67,8 +67,8 @@ void VideoConfig::Load(const std::string& ini_file) settings->Get("FreeLook", &bFreeLook, 0); settings->Get("UseFFV1", &bUseFFV1, 0); settings->Get("StereoMode", &iStereoMode, 0); - settings->Get("StereoSeparation", &iStereoSeparation, 65); - settings->Get("StereoFocalLength", &iStereoFocalLength, 50); + settings->Get("StereoSeparation", &iStereoSeparation, 50); + settings->Get("StereoFocalLength", &iStereoFocalLength, 30); settings->Get("StereoSwapEyes", &bStereoSwapEyes, false); settings->Get("EnablePixelLighting", &bEnablePixelLighting, 0); settings->Get("FastDepthCalc", &bFastDepthCalc, true);