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.
This commit is contained in:
Vincent Lejeune 2014-04-14 01:01:36 +02:00
parent 4c37cadd5f
commit 123a192963
4 changed files with 10 additions and 14 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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);
}
}

View File

@ -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);