From 123a192963fb22f3ad5296aa15f53a37ddd8f0b3 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 14 Apr 2014 01:01:36 +0200 Subject: [PATCH] Use half res FBO for SSAO SSAO is a medium frequency effect, using half res fbo is fine and improve performance and look by doing an additionnal bilinear filtering. Also tune up some values. --- data/shaders/ssao.frag | 8 ++++---- src/graphics/post_processing.cpp | 8 ++------ src/graphics/render.cpp | 4 +++- src/graphics/rtts.cpp | 4 +--- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/data/shaders/ssao.frag b/data/shaders/ssao.frag index e38e75067..e31464efa 100644 --- a/data/shaders/ssao.frag +++ b/data/shaders/ssao.frag @@ -13,8 +13,8 @@ varying vec2 uv; #define AO gl_FragColor.x #endif -const float strengh = 4.; -const float radius = .4f; +const float strengh = 3.; +const float radius = 1.f; #define SAMPLES 16 @@ -22,7 +22,7 @@ const float invSamples = strengh / SAMPLES; vec3 rand(vec2 co) { - return texture(noise_texture, co*20.16).xyz; + return texture(noise_texture, co * pow(3.14159265359, 2.)).xyz; } vec3 DecodeNormal(vec2 n); @@ -61,7 +61,7 @@ void main(void) occluderPos /= occluderPos.w; bool isOccluded = isInsideTexture && (sampleProj.z > (2. * occluderFragmentDepth - 1.0)) && (distance(FragPos, occluderPos) < radius); - bl += isOccluded ? smoothstep(radius, 0, distance(samplePos, FragPos)) : 0.; + bl += isOccluded ? samplePoints[i].z * smoothstep(5 * radius, 0, distance(samplePos, FragPos)) : 0.; } AO = 1.0 - bl * invSamples; diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 603e8fef9..4efeccbde 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -413,17 +413,13 @@ void PostProcessing::renderSSAO(const core::matrix4 &invprojm, const core::matri glUseProgram(FullScreenShader::SSAOShader::Program); glBindVertexArray(FullScreenShader::SSAOShader::vao); - setTexture(0, irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), GL_NEAREST, GL_NEAREST); + setTexture(0, irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), GL_LINEAR, GL_LINEAR); setTexture(1, irr_driver->getDepthStencilTexture(), GL_LINEAR, GL_LINEAR); - setTexture(2, getTextureGLuint(noise_tex), GL_NEAREST, GL_NEAREST); + setTexture(2, getTextureGLuint(noise_tex), GL_LINEAR, GL_LINEAR); FullScreenShader::SSAOShader::setUniforms(projm, invprojm, 0, 1, 2); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - glBindVertexArray(0); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - glEnable(GL_DEPTH_TEST); } void PostProcessing::renderFog(const core::matrix4 &ipvmat) diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index fa3524975..0ca86da50 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -935,10 +935,12 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox, glBindFramebuffer(GL_FRAMEBUFFER, m_rtts->getFBO(FBO_SSAO)); glClearColor(1., 1., 1., 1.); glClear(GL_COLOR_BUFFER_BIT); + glViewport(0, 0, UserConfigParams::m_width / 2, UserConfigParams::m_height / 2); m_post_processing->renderSSAO(irr_driver->getInvProjMatrix(), irr_driver->getProjMatrix()); // Blur it to reduce noise. m_post_processing->renderGaussian6Blur(irr_driver->getFBO(FBO_SSAO), irr_driver->getRenderTargetTexture(RTT_SSAO), - irr_driver->getFBO(FBO_TMP4), irr_driver->getRenderTargetTexture(RTT_TMP4), UserConfigParams::m_width, UserConfigParams::m_height); + irr_driver->getFBO(FBO_HALF1), irr_driver->getRenderTargetTexture(RTT_HALF1), UserConfigParams::m_width / 2, UserConfigParams::m_height / 2); + glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height); } } diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 2a3e3359b..598d178e7 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -64,8 +64,6 @@ RTT::RTT() const dimension2du eighth = res/8; const dimension2du sixteenth = res/16; - const dimension2du ssaosize = UserConfigParams::m_ssao == 2 ? res : quarter; - const u16 shadowside = 1024; const dimension2du shadowsize0(shadowside, shadowside); const dimension2du shadowsize1(shadowside / 2, shadowside / 2); @@ -88,7 +86,7 @@ RTT::RTT() RenderTargetTextures[RTT_COLOR] = generateRTT(res, GL_RGBA16F, GL_BGRA, GL_FLOAT); RenderTargetTextures[RTT_MLAA_COLORS] = generateRTT(res, GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE); RenderTargetTextures[RTT_LOG_LUMINANCE] = generateRTT(res, GL_R16F, GL_RED, GL_FLOAT); - RenderTargetTextures[RTT_SSAO] = generateRTT(res, GL_R16F, GL_RED, GL_FLOAT); + RenderTargetTextures[RTT_SSAO] = generateRTT(half, GL_R16F, GL_RED, GL_FLOAT); RenderTargetTextures[RTT_DISPLACE] = generateRTT(res, GL_RGBA16F, GL_BGRA, GL_FLOAT); RenderTargetTextures[RTT_HALF1] = generateRTT(half, GL_RGBA16F, GL_BGRA, GL_FLOAT);