MLAA: Use srgb for auxiliary buffer.

This commit is contained in:
vlj 2014-06-08 03:28:24 +02:00
parent 9bc89e0f40
commit e959d6c857
4 changed files with 20 additions and 9 deletions

View File

@ -3,7 +3,7 @@ uniform sampler2D colorMapG;
in vec4 offset[2]; in vec4 offset[2];
in vec2 uv; in vec2 uv;
const float threshold = 0.006; const float threshold = 0.1;
out vec4 FragColor; out vec4 FragColor;

View File

@ -83,6 +83,8 @@ enum TypeFBO
FBO_COLORS, FBO_COLORS,
FBO_LOG_LUMINANCE, FBO_LOG_LUMINANCE,
FBO_MLAA_COLORS, FBO_MLAA_COLORS,
FBO_MLAA_BLEND,
FBO_MLAA_TMP,
FBO_TMP1_WITH_DS, FBO_TMP1_WITH_DS,
FBO_TMP2_WITH_DS, FBO_TMP2_WITH_DS,
FBO_TMP4, FBO_TMP4,
@ -171,6 +173,8 @@ enum TypeRTT
RTT_DISPLACE, RTT_DISPLACE,
RTT_MLAA_COLORS, RTT_MLAA_COLORS,
RTT_MLAA_BLEND,
RTT_MLAA_TMP,
RTT_BLOOM_1024, RTT_BLOOM_1024,
RTT_BLOOM_512, RTT_BLOOM_512,

View File

@ -648,7 +648,7 @@ void PostProcessing::applyMLAA()
{ {
const core::vector2df &PIXEL_SIZE = core::vector2df(1.0f / UserConfigParams::m_width, 1.0f / UserConfigParams::m_height); const core::vector2df &PIXEL_SIZE = core::vector2df(1.0f / UserConfigParams::m_width, 1.0f / UserConfigParams::m_height);
IVideoDriver *const drv = irr_driver->getVideoDriver(); IVideoDriver *const drv = irr_driver->getVideoDriver();
irr_driver->getFBO(FBO_TMP1_WITH_DS).Bind(); irr_driver->getFBO(FBO_MLAA_TMP).Bind();
glEnable(GL_STENCIL_TEST); glEnable(GL_STENCIL_TEST);
glClearColor(0.0, 0.0, 0.0, 1.0); glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
@ -667,11 +667,11 @@ void PostProcessing::applyMLAA()
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
// Pass 2: blend weights // Pass 2: blend weights
irr_driver->getFBO(FBO_TMP2_WITH_DS).Bind(); irr_driver->getFBO(FBO_MLAA_BLEND).Bind();
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(FullScreenShader::MLAABlendWeightSHader::Program); glUseProgram(FullScreenShader::MLAABlendWeightSHader::Program);
setTexture(0, irr_driver->getRenderTargetTexture(RTT_TMP1), GL_LINEAR, GL_LINEAR); setTexture(0, irr_driver->getRenderTargetTexture(RTT_MLAA_TMP), GL_LINEAR, GL_LINEAR);
setTexture(1, getTextureGLuint(m_areamap), GL_NEAREST, GL_NEAREST); setTexture(1, getTextureGLuint(m_areamap), GL_NEAREST, GL_NEAREST);
FullScreenShader::MLAABlendWeightSHader::setUniforms(PIXEL_SIZE, 0, 1); FullScreenShader::MLAABlendWeightSHader::setUniforms(PIXEL_SIZE, 0, 1);
@ -679,14 +679,14 @@ void PostProcessing::applyMLAA()
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
// Blit in to tmp1 // Blit in to tmp1
FrameBuffer::Blit(irr_driver->getFBO(FBO_MLAA_COLORS), irr_driver->getFBO(FBO_TMP1_WITH_DS)); FrameBuffer::Blit(irr_driver->getFBO(FBO_MLAA_COLORS), irr_driver->getFBO(FBO_MLAA_TMP));
// Pass 3: gather // Pass 3: gather
irr_driver->getFBO(FBO_MLAA_COLORS).Bind(); irr_driver->getFBO(FBO_MLAA_COLORS).Bind();
glUseProgram(FullScreenShader::MLAAGatherSHader::Program); glUseProgram(FullScreenShader::MLAAGatherSHader::Program);
setTexture(0, irr_driver->getRenderTargetTexture(RTT_TMP1), GL_NEAREST, GL_NEAREST); setTexture(0, irr_driver->getRenderTargetTexture(RTT_MLAA_TMP), GL_NEAREST, GL_NEAREST);
setTexture(1, irr_driver->getRenderTargetTexture(RTT_TMP2), GL_NEAREST, GL_NEAREST); setTexture(1, irr_driver->getRenderTargetTexture(RTT_MLAA_BLEND), GL_NEAREST, GL_NEAREST);
FullScreenShader::MLAAGatherSHader::setUniforms(PIXEL_SIZE, 0, 1); FullScreenShader::MLAAGatherSHader::setUniforms(PIXEL_SIZE, 0, 1);
glBindVertexArray(FullScreenShader::MLAAGatherSHader::vao); glBindVertexArray(FullScreenShader::MLAAGatherSHader::vao);
@ -694,7 +694,6 @@ void PostProcessing::applyMLAA()
// Done. // Done.
glDisable(GL_STENCIL_TEST); glDisable(GL_STENCIL_TEST);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -862,7 +861,6 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode)
glEnable(GL_FRAMEBUFFER_SRGB); glEnable(GL_FRAMEBUFFER_SRGB);
irr_driver->getFBO(FBO_MLAA_COLORS).Bind(); irr_driver->getFBO(FBO_MLAA_COLORS).Bind();
renderPassThrough(in_fbo->getRTT()[0]); renderPassThrough(in_fbo->getRTT()[0]);
glDisable(GL_FRAMEBUFFER_SRGB);
out_fbo = &irr_driver->getFBO(FBO_MLAA_COLORS); out_fbo = &irr_driver->getFBO(FBO_MLAA_COLORS);
if (UserConfigParams::m_mlaa) // MLAA. Must be the last pp filter. if (UserConfigParams::m_mlaa) // MLAA. Must be the last pp filter.
@ -872,6 +870,7 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode)
applyMLAA(); applyMLAA();
PROFILER_POP_CPU_MARKER(); PROFILER_POP_CPU_MARKER();
} }
glDisable(GL_FRAMEBUFFER_SRGB);
return out_fbo; return out_fbo;
} // render } // render

View File

@ -117,6 +117,8 @@ RTT::RTT(size_t width, size_t height)
RenderTargetTextures[RTT_NORMAL_AND_DEPTH] = generateRTT(res, GL_RGBA16F, GL_RGBA, GL_FLOAT); RenderTargetTextures[RTT_NORMAL_AND_DEPTH] = generateRTT(res, GL_RGBA16F, GL_RGBA, GL_FLOAT);
RenderTargetTextures[RTT_COLOR] = generateRTT(res, GL_RGBA16F, GL_BGRA, GL_FLOAT); RenderTargetTextures[RTT_COLOR] = generateRTT(res, GL_RGBA16F, GL_BGRA, GL_FLOAT);
RenderTargetTextures[RTT_MLAA_COLORS] = generateRTT(res, GL_SRGB8_ALPHA8, GL_BGR, GL_UNSIGNED_BYTE); RenderTargetTextures[RTT_MLAA_COLORS] = generateRTT(res, GL_SRGB8_ALPHA8, GL_BGR, GL_UNSIGNED_BYTE);
RenderTargetTextures[RTT_MLAA_TMP] = generateRTT(res, GL_SRGB8_ALPHA8, GL_BGR, GL_UNSIGNED_BYTE);
RenderTargetTextures[RTT_MLAA_BLEND] = generateRTT(res, GL_SRGB8_ALPHA8, GL_BGR, GL_UNSIGNED_BYTE);
RenderTargetTextures[RTT_SSAO] = generateRTT(res, GL_R16F, GL_RED, GL_FLOAT); RenderTargetTextures[RTT_SSAO] = generateRTT(res, GL_R16F, GL_RED, GL_FLOAT);
RenderTargetTextures[RTT_DISPLACE] = generateRTT(res, GL_RGBA16F, GL_BGRA, GL_FLOAT); RenderTargetTextures[RTT_DISPLACE] = generateRTT(res, GL_RGBA16F, GL_BGRA, GL_FLOAT);
@ -164,6 +166,12 @@ RTT::RTT(size_t width, size_t height)
somevector.push_back(RenderTargetTextures[RTT_MLAA_COLORS]); somevector.push_back(RenderTargetTextures[RTT_MLAA_COLORS]);
FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height));
somevector.clear(); somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_MLAA_BLEND]);
FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height));
somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_MLAA_TMP]);
FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height));
somevector.clear();
somevector.push_back(RenderTargetTextures[RTT_TMP1]); somevector.push_back(RenderTargetTextures[RTT_TMP1]);
FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height)); FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height));
somevector.clear(); somevector.clear();