PostProcessing: Add support for user-supplied anaglyph shaders.

There are lots of different anaglyph glasses out there and there may be even more creative uses for stereoscopic post-processing shaders.
This commit is contained in:
Jules Blok
2015-01-03 01:33:30 +01:00
parent a93433a860
commit 262c3b19ec
14 changed files with 110 additions and 58 deletions

View File

@ -36,29 +36,10 @@ static const 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)
{
CreateHeader();
@ -183,8 +164,7 @@ void OpenGLPostProcessing::BlitFromTexture(TargetRectangle src, TargetRectangle
void OpenGLPostProcessing::ApplyShader()
{
// shader didn't changed
if (m_initialized && m_config.GetShader() == g_ActiveConfig.sPostProcessingShader &&
((g_ActiveConfig.iStereoMode == STEREO_ANAGLYPH) == m_anaglyph))
if (m_initialized && m_config.GetShader() == g_ActiveConfig.sPostProcessingShader)
return;
m_shader.Destroy();
@ -192,9 +172,7 @@ void OpenGLPostProcessing::ApplyShader()
// load shader code
std::string code = "";
if (g_ActiveConfig.iStereoMode == STEREO_ANAGLYPH)
code = s_anaglyph_shader;
else if (g_ActiveConfig.sPostProcessingShader != "")
if (g_ActiveConfig.sPostProcessingShader != "")
code = m_config.LoadShader();
if (code == "")
@ -244,7 +222,6 @@ void OpenGLPostProcessing::ApplyShader()
std::string glsl_name = "option_" + it.first;
m_uniform_bindings[it.first] = glGetUniformLocation(m_shader.glprogid, glsl_name.c_str());
}
m_anaglyph = g_ActiveConfig.iStereoMode == STEREO_ANAGLYPH;
m_initialized = true;
}

View File

@ -28,7 +28,6 @@ public:
private:
bool m_initialized;
bool m_anaglyph;
SHADER m_shader;
GLuint m_uniform_resolution;
GLuint m_uniform_src_rect;

View File

@ -95,14 +95,14 @@ std::string VideoBackend::GetDisplayName() const
return "OpenGL";
}
static void GetShaders(std::vector<std::string> &shaders)
static void GetShaders(std::vector<std::string> &shaders, const std::string &sub_dir = "")
{
std::set<std::string> already_found;
shaders.clear();
static const std::string directories[] = {
File::GetUserPath(D_SHADERS_IDX),
File::GetSysDirectory() + SHADERS_DIR DIR_SEP,
const std::string directories[] = {
File::GetUserPath(D_SHADERS_IDX) + sub_dir,
File::GetSysDirectory() + SHADERS_DIR DIR_SEP + sub_dir,
};
for (auto& directory : directories)
{
@ -139,6 +139,7 @@ static void InitBackendInfo()
g_Config.backend_info.bSupportsOversizedViewports = true;
g_Config.backend_info.bSupportsGeometryShaders = true;
g_Config.backend_info.bSupports3DVision = false;
g_Config.backend_info.bSupportsPostProcessing = true;
g_Config.backend_info.Adapters.clear();
@ -148,6 +149,7 @@ static void InitBackendInfo()
// pp shaders
GetShaders(g_Config.backend_info.PPShaders);
GetShaders(g_Config.backend_info.AnaglyphShaders, std::string(ANAGLYPH_DIR DIR_SEP));
}
void VideoBackend::ShowConfig(void *_hParent)