From c3ad6e78207bc0f64a9687fd8f27fbe0f7606bc7 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Fri, 31 Oct 2014 15:53:08 +0100 Subject: [PATCH] PostProcessing: Add support for anaglyph stereoscopy mode. --- Source/Core/DolphinWX/VideoConfigDiag.cpp | 11 ++++++++--- Source/Core/DolphinWX/VideoConfigDiag.h | 8 ++++++++ Source/Core/VideoBackends/OGL/PostProcessing.cpp | 16 ++++++++++++---- Source/Core/VideoCommon/VideoConfig.h | 3 ++- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Source/Core/DolphinWX/VideoConfigDiag.cpp b/Source/Core/DolphinWX/VideoConfigDiag.cpp index 93c7e83734..9b8b70b5d5 100644 --- a/Source/Core/DolphinWX/VideoConfigDiag.cpp +++ b/Source/Core/DolphinWX/VideoConfigDiag.cpp @@ -399,7 +399,7 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con if (vconfig.backend_info.PPShaders.size()) { wxFlexGridSizer* const szr_pp = new wxFlexGridSizer(3, 5, 5); - wxChoice *const choice_ppshader = new wxChoice(page_enh, -1); + choice_ppshader = new wxChoice(page_enh, -1); RegisterControl(choice_ppshader, wxGetTranslation(ppshader_desc)); choice_ppshader->AppendString(_("(off)")); @@ -428,6 +428,11 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con szr_pp->Add(button_config_pp); szr_enh->Add(szr_pp); } + else + { + choice_ppshader = nullptr; + button_config_pp = nullptr; + } // Scaled copy, PL, Bilinear filter szr_enh->Add(CreateCheckBox(page_enh, _("Scaled EFB Copy"), wxGetTranslation(scaled_efb_copy_desc), vconfig.bCopyEFBScaled)); @@ -447,9 +452,9 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con { wxGridSizer* const szr_stereo = new wxGridSizer(2, 5, 5); - const wxString stereo_choices[] = { "Off", "Side-by-Side" }; + const wxString stereo_choices[] = { "Off", "Side-by-Side", "Anaglyph" }; 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)); + szr_stereo->Add(CreateChoice(page_enh, vconfig.iStereoMode, wxGetTranslation(stereo_3d_desc), 3, 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); diff --git a/Source/Core/DolphinWX/VideoConfigDiag.h b/Source/Core/DolphinWX/VideoConfigDiag.h index 2d21912c1c..7900039bea 100644 --- a/Source/Core/DolphinWX/VideoConfigDiag.h +++ b/Source/Core/DolphinWX/VideoConfigDiag.h @@ -198,6 +198,12 @@ protected: virtual_xfb->Enable(vconfig.bUseXFB); real_xfb->Enable(vconfig.bUseXFB); + // PP Shaders + if (choice_ppshader) + choice_ppshader->Enable(vconfig.iStereoMode != STEREO_ANAGLYPH); + if (button_config_pp) + button_config_pp->Enable(vconfig.iStereoMode != STEREO_ANAGLYPH); + // Things which shouldn't be changed during emulation if (Core::IsRunning()) { @@ -262,6 +268,8 @@ protected: wxCheckBox* progressive_scan_checkbox; + wxChoice* choice_ppshader; + std::map ctrl_descs; // maps setting controls to their descriptions std::map desc_texts; // maps dialog tabs (which are the parents of the setting controls) to their description text objects diff --git a/Source/Core/VideoBackends/OGL/PostProcessing.cpp b/Source/Core/VideoBackends/OGL/PostProcessing.cpp index 7cd99a05d7..905531226c 100644 --- a/Source/Core/VideoBackends/OGL/PostProcessing.cpp +++ b/Source/Core/VideoBackends/OGL/PostProcessing.cpp @@ -166,10 +166,13 @@ void OpenGLPostProcessing::ApplyShader() m_shader.Destroy(); m_uniform_bindings.clear(); - // load shader from disk - std::string default_shader = "void main() { SetOutput(Sample()); }\n"; + // load shader code std::string code = ""; - if (g_ActiveConfig.sPostProcessingShader != "") + std::string default_shader = "void main() { SetOutput(Sample()); }\n"; + + if (g_ActiveConfig.iStereoMode == STEREO_ANAGLYPH) + code = "void main() { SetOutput(float4(SampleLayer(1).r, SampleLayer(0).gba)); }\n"; + else if (g_ActiveConfig.sPostProcessingShader != "") code = m_config.LoadShader(); if (code == "") @@ -253,7 +256,12 @@ void OpenGLPostProcessing::CreateHeader() "\treturn texture(samp9, float3(location, layer));\n" "}\n" - "#define SampleOffset(offset) textureOffset(samp9, uv0, offset)\n" + "float4 SampleLayer(int layer)\n" + "{\n" + "\treturn texture(samp9, float3(uv0, layer));\n" + "}\n" + + "#define SampleOffset(offset) textureOffset(samp9, float3(uv0, layer), offset)\n" "float4 SampleFontLocation(float2 location)\n" "{\n" diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h index 2cd83e64c5..2eec352021 100644 --- a/Source/Core/VideoCommon/VideoConfig.h +++ b/Source/Core/VideoCommon/VideoConfig.h @@ -47,7 +47,8 @@ enum EFBScale enum StereoMode { STEREO_OFF = 0, - STEREO_SBS + STEREO_SBS, + STEREO_ANAGLYPH }; // NEVER inherit from this class.