diff --git a/Source/Core/DolphinWX/VideoConfigDiag.cpp b/Source/Core/DolphinWX/VideoConfigDiag.cpp index dfa4055fa1..93c7e83734 100644 --- a/Source/Core/DolphinWX/VideoConfigDiag.cpp +++ b/Source/Core/DolphinWX/VideoConfigDiag.cpp @@ -150,6 +150,8 @@ static wxString ppshader_desc = wxTRANSLATE("Apply a post-processing effect afte static wxString cache_efb_copies_desc = wxTRANSLATE("Slightly speeds up EFB to RAM copies by sacrificing emulation accuracy.\nSometimes also increases visual quality.\nIf you're experiencing any issues, try raising texture cache accuracy or disable this option.\n\nIf unsure, leave this unchecked."); static wxString shader_errors_desc = wxTRANSLATE("Usually if shader compilation fails, an error message is displayed.\nHowever, one may skip the popups to allow interruption free gameplay by checking this option.\n\nIf unsure, leave this unchecked."); static wxString stereo_3d_desc = wxTRANSLATE("Side-by-side stereoscopic 3D."); +static wxString stereo_separation_desc = wxTRANSLATE("Control the Interpupillary distance."); +static wxString stereo_focal_desc = wxTRANSLATE("Control the distance at which objects appear to be at screen depth."); #if !defined(__APPLE__) @@ -434,14 +436,39 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con szr_enh->Add(CreateCheckBox(page_enh, _("Widescreen Hack"), wxGetTranslation(ws_hack_desc), vconfig.bWidescreenHack)); szr_enh->Add(CreateCheckBox(page_enh, _("Disable Fog"), wxGetTranslation(disable_fog_desc), vconfig.bDisableFog)); - - if (vconfig.backend_info.bSupportsStereoscopy) - szr_enh->Add(CreateCheckBox(page_enh, _("Stereo 3D"), wxGetTranslation(stereo_3d_desc), vconfig.bStereo)); wxStaticBoxSizer* const group_enh = new wxStaticBoxSizer(wxVERTICAL, page_enh, _("Enhancements")); group_enh->Add(szr_enh, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5); szr_enh_main->Add(group_enh, 0, wxEXPAND | wxALL, 5); + // - stereoscopy + + if (vconfig.backend_info.bSupportsStereoscopy) + { + wxGridSizer* const szr_stereo = new wxGridSizer(2, 5, 5); + + const wxString stereo_choices[] = { "Off", "Side-by-Side" }; + szr_stereo->Add(new wxStaticText(page_enh, -1, _("Stereo 3D Mode:")), 1, wxALIGN_CENTER_VERTICAL, 0); + szr_stereo->Add(CreateChoice(page_enh, vconfig.iStereoMode, wxGetTranslation(stereo_3d_desc), 2, stereo_choices)); + + wxSlider* const sep_slider = new wxSlider(page_enh, wxID_ANY, vconfig.iStereoSeparation, 30, 90, wxDefaultPosition, wxDefaultSize, wxSL_VALUE_LABEL); + sep_slider->Bind(wxEVT_SLIDER, &VideoConfigDiag::Event_StereoSep, this); + RegisterControl(sep_slider, wxGetTranslation(stereo_separation_desc)); + + szr_stereo->Add(new wxStaticText(page_enh, wxID_ANY, _("Interpupillary distance:")), 1, wxALIGN_CENTER_VERTICAL, 0); + szr_stereo->Add(sep_slider, 1, wxEXPAND | wxRIGHT); + + wxSlider* const foc_slider = new wxSlider(page_enh, wxID_ANY, vconfig.iStereoFocalLength, 10, 200, wxDefaultPosition, wxDefaultSize, wxSL_VALUE_LABEL); + foc_slider->Bind(wxEVT_SLIDER, &VideoConfigDiag::Event_StereoFoc, this); + RegisterControl(foc_slider, wxGetTranslation(stereo_focal_desc)); + + szr_stereo->Add(new wxStaticText(page_enh, wxID_ANY, _("Focal Length:")), 1, wxALIGN_CENTER_VERTICAL, 0); + szr_stereo->Add(foc_slider, 1, wxEXPAND | wxRIGHT); + + wxStaticBoxSizer* const group_stereo = new wxStaticBoxSizer(wxVERTICAL, page_enh, _("Stereoscopy")); + group_stereo->Add(szr_stereo, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5); + szr_enh_main->Add(group_stereo, 0, wxEXPAND | wxALL, 5); + } szr_enh_main->AddStretchSpacer(); CreateDescriptionArea(page_enh, szr_enh_main); diff --git a/Source/Core/DolphinWX/VideoConfigDiag.h b/Source/Core/DolphinWX/VideoConfigDiag.h index bd242d3a99..2d21912c1c 100644 --- a/Source/Core/DolphinWX/VideoConfigDiag.h +++ b/Source/Core/DolphinWX/VideoConfigDiag.h @@ -165,6 +165,20 @@ protected: ev.Skip(); } + void Event_StereoSep(wxCommandEvent &ev) + { + vconfig.iStereoSeparation = ev.GetInt(); + + ev.Skip(); + } + + void Event_StereoFoc(wxCommandEvent &ev) + { + vconfig.iStereoFocalLength = ev.GetInt(); + + ev.Skip(); + } + void Event_ClickClose(wxCommandEvent&); void Event_Close(wxCloseEvent&); diff --git a/Source/Core/VideoBackends/OGL/FramebufferManager.cpp b/Source/Core/VideoBackends/OGL/FramebufferManager.cpp index 8603c3b030..dcc5791dfc 100644 --- a/Source/Core/VideoBackends/OGL/FramebufferManager.cpp +++ b/Source/Core/VideoBackends/OGL/FramebufferManager.cpp @@ -73,7 +73,7 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms m_efbDepth = glObj[1]; m_efbColorSwap = glObj[2]; - m_EFBLayers = (g_ActiveConfig.bStereo) ? 2 : 1; + m_EFBLayers = (g_ActiveConfig.iStereoMode > 0) ? 2 : 1; // OpenGL MSAA textures are a different kind of texture type and must be allocated // with a different function, so we create them separately. diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp index f32fa7edca..69dbbac063 100644 --- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp +++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp @@ -200,7 +200,7 @@ SHADER* ProgramShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components ShaderCode gcode; GenerateVertexShaderCode(vcode, components, API_OPENGL); GeneratePixelShaderCode(pcode, dstAlphaMode, API_OPENGL, components); - if (g_ActiveConfig.bStereo) + if (g_ActiveConfig.iStereoMode > 0) GenerateGeometryShaderCode(gcode, components, API_OPENGL); if (g_ActiveConfig.bEnableShaderDebugging) diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 9ef13ddba9..58d3fd0ee3 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -599,7 +599,7 @@ Renderer::Renderer() s_LastMultisampleMode = g_ActiveConfig.iMultisampleMode; s_MSAASamples = GetNumMSAASamples(s_LastMultisampleMode); ApplySSAASettings(); - s_LastStereo = g_ActiveConfig.bStereo; + s_LastStereo = g_ActiveConfig.iStereoMode > 0; // Decide framebuffer size s_backbuffer_width = (int)GLInterface->GetBackBufferWidth(); @@ -1514,7 +1514,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co sourceRc.right -= fbStride - fbWidth; - if (g_ActiveConfig.bStereo) + if (g_ActiveConfig.iStereoMode == 1) { TargetRectangle leftRc = drawRc, rightRc = drawRc; int width = drawRc.right - drawRc.left; @@ -1537,7 +1537,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co // for msaa mode, we must resolve the efb content to non-msaa GLuint tex = FramebufferManager::ResolveAndGetRenderTarget(rc); - if (g_ActiveConfig.bStereo) + if (g_ActiveConfig.iStereoMode == 1) { TargetRectangle leftRc = flipped_trc, rightRc = flipped_trc; int width = flipped_trc.right - flipped_trc.left; @@ -1699,16 +1699,16 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co s_LastEFBScale = g_ActiveConfig.iEFBScale; } - if (xfbchanged || WindowResized || (s_LastMultisampleMode != g_ActiveConfig.iMultisampleMode) || (s_LastStereo != g_ActiveConfig.bStereo)) + if (xfbchanged || WindowResized || (s_LastMultisampleMode != g_ActiveConfig.iMultisampleMode) || (s_LastStereo != (g_ActiveConfig.iStereoMode > 0))) { UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height); - if (CalculateTargetSize(s_backbuffer_width, s_backbuffer_height) || s_LastMultisampleMode != g_ActiveConfig.iMultisampleMode || s_LastStereo != g_ActiveConfig.bStereo) + if (CalculateTargetSize(s_backbuffer_width, s_backbuffer_height) || s_LastMultisampleMode != g_ActiveConfig.iMultisampleMode || s_LastStereo != (g_ActiveConfig.iStereoMode > 0)) { s_LastMultisampleMode = g_ActiveConfig.iMultisampleMode; s_MSAASamples = GetNumMSAASamples(s_LastMultisampleMode); ApplySSAASettings(); - s_LastStereo = g_ActiveConfig.bStereo; + s_LastStereo = g_ActiveConfig.iStereoMode > 0; delete g_framebuffer_manager; g_framebuffer_manager = new FramebufferManager(s_target_width, s_target_height, diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp index 89de707280..f58a71fc92 100644 --- a/Source/Core/VideoBackends/OGL/TextureCache.cpp +++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp @@ -364,7 +364,7 @@ TextureCache::TextureCache() " ocol0 = texcol * mat4(colmat[0], colmat[1], colmat[2], colmat[3]) + colmat[4];\n" "}\n"; - const char *VProgram = (g_ActiveConfig.bStereo) ? + const char *VProgram = (g_ActiveConfig.iStereoMode > 0) ? "out vec2 v_uv0;\n" "SAMPLER_BINDING(9) uniform sampler2DArray samp9;\n" "uniform vec4 copy_position;\n" // left, top, right, bottom @@ -385,7 +385,7 @@ TextureCache::TextureCache() " gl_Position = vec4(rawpos*2.0-1.0, 0.0, 1.0);\n" "}\n"; - const char *GProgram = (g_ActiveConfig.bStereo) ? + const char *GProgram = (g_ActiveConfig.iStereoMode > 0) ? "layout(triangles) in;\n" "layout(triangle_strip, max_vertices = 6) out;\n" "in vec2 v_uv0[];\n" diff --git a/Source/Core/VideoCommon/GeometryShaderGen.cpp b/Source/Core/VideoCommon/GeometryShaderGen.cpp index 88be1d4098..cded3bdea1 100644 --- a/Source/Core/VideoCommon/GeometryShaderGen.cpp +++ b/Source/Core/VideoCommon/GeometryShaderGen.cpp @@ -41,12 +41,12 @@ static inline void GenerateGeometryShader(T& out, u32 components, API_TYPE ApiTy out.Write("//Geometry Shader for 3D stereoscopy\n"); - uid_data->stereo = g_ActiveConfig.bStereo; + uid_data->stereo = g_ActiveConfig.iStereoMode > 0; if (ApiType == API_OPENGL) { // Insert layout parameters if (g_ActiveConfig.backend_info.bSupportsGSInstancing) - out.Write("layout(triangles, invocations = %d) in;\n", g_ActiveConfig.bStereo ? 2 : 1); + out.Write("layout(triangles, invocations = %d) in;\n", g_ActiveConfig.iStereoMode > 0 ? 2 : 1); else out.Write("layout(triangles) in;\n"); out.Write("layout(triangle_strip, max_vertices = %d) out;\n", g_ActiveConfig.backend_info.bSupportsGSInstancing ? 3 : 6); @@ -74,7 +74,7 @@ static inline void GenerateGeometryShader(T& out, u32 components, API_TYPE ApiTy if (g_ActiveConfig.backend_info.bSupportsGSInstancing) out.Write("\tlayer = gl_InvocationID;\n"); else - out.Write("\tfor (layer = 0; layer < %d; ++layer) {\n", g_ActiveConfig.bStereo ? 2 : 1); + out.Write("\tfor (layer = 0; layer < %d; ++layer) {\n", g_ActiveConfig.iStereoMode > 0 ? 2 : 1); out.Write("\tgl_Layer = layer;\n"); out.Write("\tvec4 stereoproj = "I_PROJECTION"[0];\n"); @@ -83,7 +83,7 @@ static inline void GenerateGeometryShader(T& out, u32 components, API_TYPE ApiTy out.Write("\tfor (int i = 0; i < gl_in.length(); ++i) {\n"); out.Write("\t\to = v[i];\n"); - if (g_ActiveConfig.bStereo) + if (g_ActiveConfig.iStereoMode > 0) out.Write("\t\to.pos = float4(dot(stereoproj, v[i].rawpos), dot(" I_PROJECTION"[1], v[i].rawpos), dot(" I_PROJECTION"[2], v[i].rawpos), dot(" I_PROJECTION"[3], v[i].rawpos)); \n"); out.Write("\t\tgl_Position = o.pos;\n"); diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index 4f0c7ea5e1..11c9679ca9 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -321,8 +321,8 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T // Without MSAA, this flag is defined to have no effect. out.Write("centroid in VS_OUTPUT o;\n"); - uid_data->stereo = g_ActiveConfig.bStereo; - if (g_ActiveConfig.bStereo) + uid_data->stereo = g_ActiveConfig.iStereoMode > 0; + if (g_ActiveConfig.iStereoMode > 0) out.Write("flat in int layer;\n"); out.Write("void main()\n{\n"); @@ -926,7 +926,7 @@ static inline void SampleTexture(T& out, const char *texcoords, const char *texs if (ApiType == API_D3D) out.Write("iround(255.0 * Tex%d.Sample(samp%d,%s.xy * " I_TEXDIMS"[%d].xy)).%s;\n", texmap,texmap, texcoords, texmap, texswap); else - out.Write("iround(255.0 * texture(samp%d, float3(%s.xy * " I_TEXDIMS"[%d].xy, %s))).%s;\n", texmap, texcoords, texmap, g_ActiveConfig.bStereo ? "layer" : "0.0", texswap); + out.Write("iround(255.0 * texture(samp%d, float3(%s.xy * " I_TEXDIMS"[%d].xy, %s))).%s;\n", texmap, texcoords, texmap, g_ActiveConfig.iStereoMode > 0 ? "layer" : "0.0", texswap); } static const char *tevAlphaFuncsTable[] = diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index 7c5ca62464..fd2ee7f3e6 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -52,7 +52,7 @@ static inline void GenerateVSOutputStruct(T& object, API_TYPE api_type) if (g_ActiveConfig.bEnablePixelLighting) DefineVSOutputStructMember(object, api_type, "float4", "Normal", -1, "TEXCOORD", xfmem.numTexGen.numTexGens + 1); - if (g_ActiveConfig.bStereo) + if (g_ActiveConfig.iStereoMode > 0) DefineVSOutputStructMember(object, api_type, "float4", "rawpos", -1, "POSITION"); object.Write("};\n"); @@ -125,11 +125,11 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ out.Write("in float%d tex%d; // ATTR%d,\n", hastexmtx ? 3 : 2, i, SHADER_TEXTURE0_ATTRIB + i); } - out.Write("centroid out VS_OUTPUT %s;\n", (g_ActiveConfig.bStereo) ? "v" : "o"); + out.Write("centroid out VS_OUTPUT %s;\n", (g_ActiveConfig.iStereoMode > 0) ? "v" : "o"); out.Write("void main()\n{\n"); - if (g_ActiveConfig.bStereo) + if (g_ActiveConfig.iStereoMode > 0) out.Write("VS_OUTPUT o;\n"); } else // D3D @@ -205,8 +205,8 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ out.Write("o.pos = float4(dot(" I_PROJECTION"[0], pos), dot(" I_PROJECTION"[1], pos), dot(" I_PROJECTION"[2], pos), dot(" I_PROJECTION"[3], pos));\n"); - uid_data->stereo = g_ActiveConfig.bStereo; - if (g_ActiveConfig.bStereo) + uid_data->stereo = g_ActiveConfig.iStereoMode > 0; + if (g_ActiveConfig.iStereoMode > 0) out.Write("o.rawpos = pos;\n"); out.Write("int4 lacc;\n" @@ -420,7 +420,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ if (api_type == API_OPENGL) { - if (g_ActiveConfig.bStereo) + if (g_ActiveConfig.iStereoMode > 0) out.Write("v = o;\n"); out.Write("gl_Position = o.pos;\n"); 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; diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp index af073fab5e..18e098652d 100644 --- a/Source/Core/VideoCommon/VideoConfig.cpp +++ b/Source/Core/VideoCommon/VideoConfig.cpp @@ -66,7 +66,7 @@ void VideoConfig::Load(const std::string& ini_file) settings->Get("DumpEFBTarget", &bDumpEFBTarget, 0); settings->Get("FreeLook", &bFreeLook, 0); settings->Get("UseFFV1", &bUseFFV1, 0); - settings->Get("Stereo", &bStereo, false); + settings->Get("StereoMode", &iStereoMode, 0); settings->Get("StereoSeparation", &iStereoSeparation, 65); settings->Get("StereoFocalLength", &iStereoFocalLength, 100); settings->Get("EnablePixelLighting", &bEnablePixelLighting, 0); @@ -140,7 +140,7 @@ void VideoConfig::GameIniLoad() CHECK_SETTING("Video_Settings", "UseRealXFB", bUseRealXFB); CHECK_SETTING("Video_Settings", "SafeTextureCacheColorSamples", iSafeTextureCache_ColorSamples); CHECK_SETTING("Video_Settings", "HiresTextures", bHiresTextures); - CHECK_SETTING("Video_Settings", "Stereo", bStereo); + CHECK_SETTING("Video_Settings", "StereoMode", iStereoMode); CHECK_SETTING("Video_Settings", "StereoSeparation", iStereoSeparation); CHECK_SETTING("Video_Settings", "StereoFocalLength", iStereoFocalLength); CHECK_SETTING("Video_Settings", "EnablePixelLighting", bEnablePixelLighting); @@ -203,7 +203,7 @@ void VideoConfig::VerifyValidity() // TODO: Check iMaxAnisotropy value if (iAdapter < 0 || iAdapter > ((int)backend_info.Adapters.size() - 1)) iAdapter = 0; if (iMultisampleMode < 0 || iMultisampleMode >= (int)backend_info.AAModes.size()) iMultisampleMode = 0; - if (!backend_info.bSupportsStereoscopy) bStereo = false; + if (!backend_info.bSupportsStereoscopy) iStereoMode = 0; } void VideoConfig::Save(const std::string& ini_file) @@ -231,7 +231,7 @@ void VideoConfig::Save(const std::string& ini_file) settings->Set("DumpEFBTarget", bDumpEFBTarget); settings->Set("FreeLook", bFreeLook); settings->Set("UseFFV1", bUseFFV1); - settings->Set("Stereo", bStereo); + settings->Set("StereoMode", iStereoMode); settings->Set("StereoSeparation", iStereoSeparation); settings->Set("StereoFocalLength", iStereoFocalLength); settings->Set("EnablePixelLighting", bEnablePixelLighting); diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h index b1682bab58..a44b0a78a2 100644 --- a/Source/Core/VideoCommon/VideoConfig.h +++ b/Source/Core/VideoCommon/VideoConfig.h @@ -71,6 +71,9 @@ struct VideoConfig final bool bForceFiltering; int iMaxAnisotropy; std::string sPostProcessingShader; + int iStereoMode; + int iStereoSeparation; + int iStereoFocalLength; // Information bool bShowFPS; @@ -92,9 +95,6 @@ struct VideoConfig final bool bDumpEFBTarget; bool bUseFFV1; bool bFreeLook; - bool bStereo; - int iStereoSeparation; - int iStereoFocalLength; bool bBorderlessFullscreen; // Hacks