Port MLAA Shaders

This commit is contained in:
Vincent Lejeune 2014-08-13 00:51:32 +02:00
parent b0d63ab399
commit 0dd1fd605c
3 changed files with 40 additions and 85 deletions

View File

@ -636,11 +636,11 @@ void PostProcessing::applyMLAA()
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
// Pass 1: color edge detection
setTexture(0, irr_driver->getRenderTargetTexture(RTT_MLAA_COLORS), GL_NEAREST, GL_NEAREST);
glUseProgram(FullScreenShader::MLAAColorEdgeDetectionSHader::Program);
FullScreenShader::MLAAColorEdgeDetectionSHader::setUniforms(PIXEL_SIZE, 0);
setTexture(FullScreenShader::MLAAColorEdgeDetectionSHader::getInstance()->TU_colorMapG, irr_driver->getRenderTargetTexture(RTT_MLAA_COLORS), GL_NEAREST, GL_NEAREST);
glUseProgram(FullScreenShader::MLAAColorEdgeDetectionSHader::getInstance()->Program);
FullScreenShader::MLAAColorEdgeDetectionSHader::getInstance()->setUniforms(PIXEL_SIZE);
glBindVertexArray(FullScreenShader::MLAAColorEdgeDetectionSHader::vao);
glBindVertexArray(FullScreenShader::MLAAColorEdgeDetectionSHader::getInstance()->vao);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glStencilFunc(GL_EQUAL, 1, ~0);
@ -650,12 +650,12 @@ void PostProcessing::applyMLAA()
irr_driver->getFBO(FBO_MLAA_BLEND).Bind();
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(FullScreenShader::MLAABlendWeightSHader::Program);
setTexture(0, irr_driver->getRenderTargetTexture(RTT_MLAA_TMP), GL_LINEAR, GL_LINEAR);
setTexture(1, getTextureGLuint(m_areamap), GL_NEAREST, GL_NEAREST);
FullScreenShader::MLAABlendWeightSHader::setUniforms(PIXEL_SIZE, 0, 1);
glUseProgram(FullScreenShader::MLAABlendWeightSHader::getInstance()->Program);
setTexture(FullScreenShader::MLAABlendWeightSHader::getInstance()->TU_edgesMap, irr_driver->getRenderTargetTexture(RTT_MLAA_TMP), GL_LINEAR, GL_LINEAR);
setTexture(FullScreenShader::MLAABlendWeightSHader::getInstance()->TU_areaMap, getTextureGLuint(m_areamap), GL_NEAREST, GL_NEAREST);
FullScreenShader::MLAABlendWeightSHader::getInstance()->setUniforms(PIXEL_SIZE);
glBindVertexArray(FullScreenShader::MLAABlendWeightSHader::vao);
glBindVertexArray(FullScreenShader::MLAABlendWeightSHader::getInstance()->vao);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
// Blit in to tmp1
@ -664,12 +664,12 @@ void PostProcessing::applyMLAA()
// Pass 3: gather
irr_driver->getFBO(FBO_MLAA_COLORS).Bind();
glUseProgram(FullScreenShader::MLAAGatherSHader::Program);
setTexture(0, irr_driver->getRenderTargetTexture(RTT_MLAA_TMP), GL_NEAREST, GL_NEAREST);
setTexture(1, irr_driver->getRenderTargetTexture(RTT_MLAA_BLEND), GL_NEAREST, GL_NEAREST);
FullScreenShader::MLAAGatherSHader::setUniforms(PIXEL_SIZE, 0, 1);
glUseProgram(FullScreenShader::MLAAGatherSHader::getInstance()->Program);
setTexture(FullScreenShader::MLAAGatherSHader::getInstance()->TU_colorMap, irr_driver->getRenderTargetTexture(RTT_MLAA_TMP), GL_NEAREST, GL_NEAREST);
setTexture(FullScreenShader::MLAAGatherSHader::getInstance()->TU_blendMap, irr_driver->getRenderTargetTexture(RTT_MLAA_BLEND), GL_NEAREST, GL_NEAREST);
FullScreenShader::MLAAGatherSHader::getInstance()->setUniforms(PIXEL_SIZE);
glBindVertexArray(FullScreenShader::MLAAGatherSHader::vao);
glBindVertexArray(FullScreenShader::MLAAGatherSHader::getInstance()->vao);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
// Done.

View File

@ -376,9 +376,6 @@ void Shaders::loadShaders()
FullScreenShader::LayerPassThroughShader::init();
FullScreenShader::DiffuseEnvMapShader::init();
FullScreenShader::RHDebug::init();
FullScreenShader::MLAAColorEdgeDetectionSHader::init();
FullScreenShader::MLAABlendWeightSHader::init();
FullScreenShader::MLAAGatherSHader::init();
MeshShader::BubbleShader::init();
LightShader::PointLightShader::init();
MeshShader::SkyboxShader::init();
@ -1951,74 +1948,40 @@ namespace FullScreenShader
vao = createVAO(Program);
}
GLuint MLAAColorEdgeDetectionSHader::Program;
GLuint MLAAColorEdgeDetectionSHader::uniform_colorMapG;
GLuint MLAAColorEdgeDetectionSHader::uniform_PIXEL_SIZE;
GLuint MLAAColorEdgeDetectionSHader::vao;
void MLAAColorEdgeDetectionSHader::init()
MLAAColorEdgeDetectionSHader::MLAAColorEdgeDetectionSHader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/mlaa_offset.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/mlaa_color1.frag").c_str());
uniform_colorMapG = glGetUniformLocation(Program, "colorMapG");
uniform_PIXEL_SIZE = glGetUniformLocation(Program, "PIXEL_SIZE");
AssignUniforms("PIXEL_SIZE");
TU_colorMapG = 0;
AssignTextureUnit(Program, TexUnit(TU_colorMapG, "colorMapG"));
vao = createVAO(Program);
}
void MLAAColorEdgeDetectionSHader::setUniforms(const core::vector2df &PIXEL_SIZE, unsigned TU_colorMapG)
{
glUniform1i(uniform_colorMapG, TU_colorMapG);
glUniform2f(uniform_PIXEL_SIZE, PIXEL_SIZE.X, PIXEL_SIZE.Y);
}
GLuint MLAABlendWeightSHader::Program;
GLuint MLAABlendWeightSHader::uniform_edgesMap;
GLuint MLAABlendWeightSHader::uniform_areaMap;
GLuint MLAABlendWeightSHader::uniform_PIXEL_SIZE;
GLuint MLAABlendWeightSHader::vao;
void MLAABlendWeightSHader::init()
MLAABlendWeightSHader::MLAABlendWeightSHader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/mlaa_blend2.frag").c_str());
uniform_edgesMap = glGetUniformLocation(Program, "edgesMap");
uniform_areaMap = glGetUniformLocation(Program, "areaMap");
uniform_PIXEL_SIZE = glGetUniformLocation(Program, "PIXEL_SIZE");
AssignUniforms("PIXEL_SIZE");
TU_edgesMap = 0;
TU_areaMap = 1;
AssignTextureUnit(Program, TexUnit(TU_edgesMap, "edgesMap"), TexUnit(TU_areaMap, "areaMap"));
vao = createVAO(Program);
}
void MLAABlendWeightSHader::setUniforms(const core::vector2df &PIXEL_SIZE, unsigned TU_edgesMap, unsigned TU_areaMap)
{
glUniform1i(uniform_edgesMap, TU_edgesMap);
glUniform1i(uniform_areaMap, TU_areaMap);
glUniform2f(uniform_PIXEL_SIZE, PIXEL_SIZE.X, PIXEL_SIZE.Y);
}
GLuint MLAAGatherSHader::Program;
GLuint MLAAGatherSHader::uniform_colorMap;
GLuint MLAAGatherSHader::uniform_blendMap;
GLuint MLAAGatherSHader::uniform_PIXEL_SIZE;
GLuint MLAAGatherSHader::vao;
void MLAAGatherSHader::init()
MLAAGatherSHader::MLAAGatherSHader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/mlaa_offset.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/mlaa_neigh3.frag").c_str());
uniform_colorMap = glGetUniformLocation(Program, "colorMap");
uniform_blendMap = glGetUniformLocation(Program, "blendMap");
uniform_PIXEL_SIZE = glGetUniformLocation(Program, "PIXEL_SIZE");
AssignUniforms("PIXEL_SIZE");
TU_blendMap = 0;
TU_colorMap = 1;
AssignTextureUnit(Program, TexUnit(TU_blendMap, "blendMap"), TexUnit(TU_colorMap, "colorMap"));
vao = createVAO(Program);
}
void MLAAGatherSHader::setUniforms(const core::vector2df &PIXEL_SIZE, unsigned TU_colormap, unsigned TU_blendmap)
{
glUniform1i(uniform_colorMap, TU_colormap);
glUniform1i(uniform_blendMap, TU_blendmap);
glUniform2f(uniform_PIXEL_SIZE, PIXEL_SIZE.X, PIXEL_SIZE.Y);
}
}
namespace UIShader

View File

@ -764,39 +764,31 @@ public:
GodRayShader();
};
class MLAAColorEdgeDetectionSHader
class MLAAColorEdgeDetectionSHader : public ShaderHelperSingleton<MLAAColorEdgeDetectionSHader, core::vector2df>
{
public:
static GLuint Program;
static GLuint uniform_colorMapG, uniform_PIXEL_SIZE;
static GLuint vao;
GLuint TU_colorMapG;
GLuint vao;
static void init();
static void setUniforms(const core::vector2df &PIXEL_SIZE, unsigned TU_colorMapG);
MLAAColorEdgeDetectionSHader();
};
class MLAABlendWeightSHader
class MLAABlendWeightSHader : public ShaderHelperSingleton<MLAABlendWeightSHader, core::vector2df>
{
public:
static GLuint Program;
static GLuint uniform_PIXEL_SIZE, uniform_edgesMap, uniform_areaMap;
static GLuint vao;
static void init();
static void setUniforms(const core::vector2df &PIXEL_SIZE, unsigned TU_edgesMap, unsigned TU_areaMap);
GLuint TU_edgesMap, TU_areaMap;
GLuint vao;
MLAABlendWeightSHader();
};
class MLAAGatherSHader
class MLAAGatherSHader : public ShaderHelperSingleton<MLAAGatherSHader, core::vector2df>
{
public:
static GLuint Program;
static GLuint uniform_PIXEL_SIZE, uniform_colorMap, uniform_blendMap;
static GLuint vao;
GLuint TU_colorMap, TU_blendMap;
GLuint vao;
static void init();
static void setUniforms(const core::vector2df &PIXEL_SIZE, unsigned TU_colormap, unsigned TU_blendmap);
MLAAGatherSHader();
};
}