From 0f63186371c4f0bcc784fa8506d18b9514075d29 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Sat, 8 Nov 2014 16:19:15 +0100 Subject: [PATCH] TextureCache: Add "Mono EFB Depth Copy" stereoscopy option. --- Source/Core/DolphinWX/VideoConfigDiag.cpp | 3 ++ .../Core/VideoBackends/OGL/TextureCache.cpp | 28 ++++++++----------- Source/Core/VideoCommon/TextureCacheBase.cpp | 4 ++- Source/Core/VideoCommon/TextureCacheBase.h | 1 + Source/Core/VideoCommon/VideoConfig.cpp | 3 ++ Source/Core/VideoCommon/VideoConfig.h | 1 + 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Source/Core/DolphinWX/VideoConfigDiag.cpp b/Source/Core/DolphinWX/VideoConfigDiag.cpp index dae92a728a..3ec8010f1a 100644 --- a/Source/Core/DolphinWX/VideoConfigDiag.cpp +++ b/Source/Core/DolphinWX/VideoConfigDiag.cpp @@ -153,6 +153,7 @@ static wxString stereo_3d_desc = wxTRANSLATE("Select the stereoscopic 3D mode, static wxString stereo_separation_desc = wxTRANSLATE("Control the interpupillary distance, this is the distance between the virtual eyes."); static wxString stereo_convergence_desc = wxTRANSLATE("Control the convergence distance, this controls the apparant distance of virtual objects.\nA lower value creates a stronger feeling of depth while a higher value is generally more comfortable."); static wxString stereo_swap_desc = wxTRANSLATE("Swap the left and right eye, mostly useful if you want to view side-by-side cross-eyed.\n\nIf unsure, leave this unchecked."); +static wxString stereo_mono_depth_desc = wxTRANSLATE("Use the same depth buffer for both eyes in an EFB copy.\nThis is needed for games which use the depth buffer to calculate shadows.\n\nIf unsure, leave this unchecked."); #if !defined(__APPLE__) @@ -473,6 +474,8 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con szr_stereo->Add(CreateCheckBox(page_enh, _("Swap eyes"), wxGetTranslation(stereo_swap_desc), vconfig.bStereoSwapEyes)); + szr_stereo->Add(CreateCheckBox(page_enh, _("Mono EFB Depth Copy"), wxGetTranslation(stereo_mono_depth_desc), vconfig.bStereoMonoEFBDepth)); + 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); diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp index a84da5dbb6..f635cb5fe6 100644 --- a/Source/Core/VideoBackends/OGL/TextureCache.cpp +++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp @@ -361,7 +361,7 @@ void TextureCache::CompileShaders() "out vec4 ocol0;\n" "\n" "void main(){\n" - " vec4 texcol = texture(samp9, vec3(f_uv0.xy, 0));\n" + " vec4 texcol = texture(samp9, vec3(f_uv0.xy, %s));\n" // 255.99998474121 = 16777215/16777216*256 " float workspace = texcol.x * 255.99998474121;\n" @@ -387,30 +387,21 @@ void TextureCache::CompileShaders() " ocol0 = texcol * mat4(colmat[0], colmat[1], colmat[2], colmat[3]) + colmat[4];\n" "}\n"; - const char *VProgram = (g_ActiveConfig.iStereoMode > 0) ? - "out vec2 v_uv0;\n" + const char *VProgram = + "out vec3 %s_uv0;\n" "SAMPLER_BINDING(9) uniform sampler2DArray samp9;\n" "uniform vec4 copy_position;\n" // left, top, right, bottom "void main()\n" "{\n" " vec2 rawpos = vec2(gl_VertexID&1, gl_VertexID&2);\n" - " v_uv0 = mix(copy_position.xy, copy_position.zw, rawpos) / vec2(textureSize(samp9, 0).xy);\n" - " gl_Position = vec4(rawpos*2.0-1.0, 0.0, 1.0);\n" - "}\n" : - "out vec3 f_uv0;\n" - "SAMPLER_BINDING(9) uniform sampler2DArray samp9;\n" - "uniform vec4 copy_position;\n" // left, top, right, bottom - "void main()\n" - "{\n" - " vec2 rawpos = vec2(gl_VertexID&1, gl_VertexID&2);\n" - " f_uv0 = vec3(mix(copy_position.xy, copy_position.zw, rawpos) / vec2(textureSize(samp9, 0).xy), 0.0);\n" + " %s_uv0 = vec3(mix(copy_position.xy, copy_position.zw, rawpos) / vec2(textureSize(samp9, 0).xy), 0.0);\n" " gl_Position = vec4(rawpos*2.0-1.0, 0.0, 1.0);\n" "}\n"; const char *GProgram = (g_ActiveConfig.iStereoMode > 0) ? "layout(triangles) in;\n" "layout(triangle_strip, max_vertices = 6) out;\n" - "in vec2 v_uv0[];\n" + "in vec3 v_uv0[];\n" "out vec3 f_uv0;\n" "SAMPLER_BINDING(9) uniform sampler2DArray samp9;\n" "void main()\n" @@ -418,7 +409,7 @@ void TextureCache::CompileShaders() " int layers = textureSize(samp9, 0).z;\n" " for (int layer = 0; layer < layers; ++layer) {\n" " for (int i = 0; i < gl_in.length(); ++i) {\n" - " f_uv0 = vec3(v_uv0[i], layer);\n" + " f_uv0 = vec3(v_uv0[i].xy, layer);\n" " gl_Position = gl_in[i].gl_Position;\n" " gl_Layer = layer;\n" " EmitVertex();\n" @@ -427,8 +418,11 @@ void TextureCache::CompileShaders() " }\n" "}\n" : nullptr; - ProgramShaderCache::CompileShader(s_ColorMatrixProgram, VProgram, pColorMatrixProg, GProgram); - ProgramShaderCache::CompileShader(s_DepthMatrixProgram, VProgram, pDepthMatrixProg, GProgram); + const char* prefix = (GProgram == nullptr) ? "f" : "v"; + const char* depth_layer = (g_ActiveConfig.bStereoMonoEFBDepth) ? "0" : "f_uv0.z"; + + ProgramShaderCache::CompileShader(s_ColorMatrixProgram, StringFromFormat(VProgram, prefix, prefix).c_str(), pColorMatrixProg, GProgram); + ProgramShaderCache::CompileShader(s_DepthMatrixProgram, StringFromFormat(VProgram, prefix, prefix).c_str(), StringFromFormat(pDepthMatrixProg, depth_layer).c_str(), GProgram); s_ColorMatrixUniform = glGetUniformLocation(s_ColorMatrixProgram.glprogid, "colmat"); s_DepthMatrixUniform = glGetUniformLocation(s_DepthMatrixProgram.glprogid, "colmat"); diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index e057b379ad..7fa540022d 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -116,7 +116,8 @@ void TextureCache::OnConfigChanged(VideoConfig& config) g_texture_cache->ClearRenderTargets(); } - if ((config.iStereoMode > 0) != backup_config.s_stereo_3d) + if ((config.iStereoMode > 0) != backup_config.s_stereo_3d || + config.bStereoMonoEFBDepth != backup_config.s_mono_efb_depth) { g_texture_cache->DeleteShaders(); g_texture_cache->CompileShaders(); @@ -133,6 +134,7 @@ void TextureCache::OnConfigChanged(VideoConfig& config) backup_config.s_hires_textures = config.bHiresTextures; backup_config.s_copy_cache_enable = config.bEFBCopyCacheEnable; backup_config.s_stereo_3d = config.iStereoMode > 0; + backup_config.s_mono_efb_depth = config.bStereoMonoEFBDepth; } void TextureCache::Cleanup() diff --git a/Source/Core/VideoCommon/TextureCacheBase.h b/Source/Core/VideoCommon/TextureCacheBase.h index 64bc41f19d..d9cd2b8c16 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.h +++ b/Source/Core/VideoCommon/TextureCacheBase.h @@ -146,6 +146,7 @@ private: bool s_hires_textures; bool s_copy_cache_enable; bool s_stereo_3d; + bool s_mono_efb_depth; } backup_config; }; diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp index d97a5a9377..de2891fa74 100644 --- a/Source/Core/VideoCommon/VideoConfig.cpp +++ b/Source/Core/VideoCommon/VideoConfig.cpp @@ -70,6 +70,7 @@ void VideoConfig::Load(const std::string& ini_file) settings->Get("StereoSeparation", &iStereoSeparation, 50); settings->Get("StereoFocalLength", &iStereoFocalLength, 30); settings->Get("StereoSwapEyes", &bStereoSwapEyes, false); + settings->Get("StereoMonoEFBDepth", &bStereoMonoEFBDepth, false); settings->Get("EnablePixelLighting", &bEnablePixelLighting, 0); settings->Get("FastDepthCalc", &bFastDepthCalc, true); settings->Get("MSAA", &iMultisampleMode, 0); @@ -145,6 +146,7 @@ void VideoConfig::GameIniLoad() CHECK_SETTING("Video_Settings", "StereoSeparation", iStereoSeparation); CHECK_SETTING("Video_Settings", "StereoFocalLength", iStereoFocalLength); CHECK_SETTING("Video_Settings", "StereoSwapEyes", bStereoSwapEyes); + CHECK_SETTING("Video_Settings", "StereoMonoEFBDepth", bStereoMonoEFBDepth); CHECK_SETTING("Video_Settings", "EnablePixelLighting", bEnablePixelLighting); CHECK_SETTING("Video_Settings", "FastDepthCalc", bFastDepthCalc); CHECK_SETTING("Video_Settings", "MSAA", iMultisampleMode); @@ -237,6 +239,7 @@ void VideoConfig::Save(const std::string& ini_file) settings->Set("StereoSeparation", iStereoSeparation); settings->Set("StereoFocalLength", iStereoFocalLength); settings->Set("StereoSwapEyes", bStereoSwapEyes); + settings->Set("StereoMonoEFBDepth", bStereoMonoEFBDepth); settings->Set("EnablePixelLighting", bEnablePixelLighting); settings->Set("FastDepthCalc", bFastDepthCalc); settings->Set("ShowEFBCopyRegions", bShowEFBCopyRegions); diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h index 994264e58e..9d926a879b 100644 --- a/Source/Core/VideoCommon/VideoConfig.h +++ b/Source/Core/VideoCommon/VideoConfig.h @@ -83,6 +83,7 @@ struct VideoConfig final int iStereoSeparation; int iStereoFocalLength; bool bStereoSwapEyes; + bool bStereoMonoEFBDepth; // Information bool bShowFPS;