Skip to content

Commit

Permalink
Merge pull request #1805 from Armada651/dubois
Browse files Browse the repository at this point in the history
PostProcessing: Use Dubois algorithm for anaglyph shader.
  • Loading branch information
dolphin-emu-bot committed Jan 2, 2015
2 parents 9c6795c + 582a15d commit 7dc6484
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
13 changes: 12 additions & 1 deletion Source/Core/VideoBackends/D3D/PixelShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ const char color_copy_program_code[] = {
"}\n"
};

// Anaglyph Red-Cyan shader based on Dubois algorithm
// Constants taken from the paper:
// "Conversion of a Stereo Pair to Anaglyph with
// the Least-Squares Projection Method"
// Eric Dubois, March 2009
const char anaglyph_program_code[] = {
"sampler samp0 : register(s0);\n"
"Texture2DArray Tex0 : register(t0);\n"
Expand All @@ -70,7 +75,13 @@ const char anaglyph_program_code[] = {
"in float3 uv0 : TEXCOORD0){\n"
"float4 c0 = Tex0.Sample(samp0, float3(uv0.xy, 0.0));\n"
"float4 c1 = Tex0.Sample(samp0, float3(uv0.xy, 1.0));\n"
"ocol0 = float4(pow(0.7 * c0.g + 0.3 * c0.b, 1.5), c1.gba);"
"float3x3 l = float3x3( 0.437, 0.449, 0.164,\n"
" -0.062,-0.062,-0.024,\n"
" -0.048,-0.050,-0.017);\n"
"float3x3 r = float3x3(-0.011,-0.032,-0.007,\n"
" 0.377, 0.761, 0.009,\n"
" -0.026,-0.093, 1.234);\n"
"ocol0 = float4(mul(l, c0.rgb) + mul(r, c1.rgb), c0.a);\n"
"}\n"
};

Expand Down
32 changes: 25 additions & 7 deletions Source/Core/VideoBackends/OGL/PostProcessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace OGL
{

static char s_vertex_workaround_shader[] =
static const char s_vertex_workaround_shader[] =
"in vec4 rawpos;\n"
"out vec2 uv0;\n"
"uniform vec4 src_rect;\n"
Expand All @@ -27,7 +27,7 @@ static char s_vertex_workaround_shader[] =
" uv0 = rawpos.zw * src_rect.zw + src_rect.xy;\n"
"}\n";

static char s_vertex_shader[] =
static const char s_vertex_shader[] =
"out vec2 uv0;\n"
"uniform vec4 src_rect;\n"
"void main(void) {\n"
Expand All @@ -36,6 +36,26 @@ static char s_vertex_shader[] =
" uv0 = rawpos * src_rect.zw + src_rect.xy;\n"
"}\n";

// Anaglyph Red-Cyan shader based on Dubois algorithm
// Constants taken from the paper:
// "Conversion of a Stereo Pair to Anaglyph with
// the Least-Squares Projection Method"
// Eric Dubois, March 2009
static const char s_anaglyph_shader[] =
"void main() {\n"
" vec4 c0 = SampleLayer(0);\n"
" vec4 c1 = SampleLayer(1);\n"
" mat3 l = mat3( 0.437, 0.449, 0.164,\n"
" -0.062,-0.062,-0.024,\n"
" -0.048,-0.050,-0.017);\n"
" mat3 r = mat3(-0.011,-0.032,-0.007,\n"
" 0.377, 0.761, 0.009,\n"
" -0.026,-0.093, 1.234);\n"
" SetOutput(vec4(c0.rgb * l + c1.rgb * r, c0.a));\n"
"}\n";

static const char s_default_shader[] = "void main() { SetOutput(Sample()); }\n";

OpenGLPostProcessing::OpenGLPostProcessing()
: m_initialized(false)
, m_anaglyph(false)
Expand Down Expand Up @@ -172,15 +192,13 @@ void OpenGLPostProcessing::ApplyShader()

// load shader code
std::string code = "";
std::string default_shader = "void main() { SetOutput(Sample()); }\n";

if (g_ActiveConfig.iStereoMode == STEREO_ANAGLYPH)
code = "void main() { SetOutput(float4(pow(0.7 * SampleLayer(0).g + 0.3 * SampleLayer(0).b, 1.5), SampleLayer(1).gba)); }\n";
code = s_anaglyph_shader;
else if (g_ActiveConfig.sPostProcessingShader != "")
code = m_config.LoadShader();

if (code == "")
code = default_shader;
code = s_default_shader;

code = LoadShaderOptions(code);

Expand All @@ -194,7 +212,7 @@ void OpenGLPostProcessing::ApplyShader()
{
ERROR_LOG(VIDEO, "Failed to compile post-processing shader %s", m_config.GetShader().c_str());

code = LoadShaderOptions(default_shader);
code = LoadShaderOptions(s_default_shader);
ProgramShaderCache::CompileShader(m_shader, vertex_shader, code.c_str());
}

Expand Down

0 comments on commit 7dc6484

Please sign in to comment.