Smoothen shadow split

This commit is contained in:
Vincent Lejeune 2014-11-18 03:13:39 +01:00
parent b7fc539f57
commit 29afd22b68
3 changed files with 41 additions and 38 deletions

View File

@ -316,45 +316,41 @@ void PostProcessing::renderGaussian3Blur(FrameBuffer &in_fbo, FrameBuffer &auxil
}
}
void PostProcessing::renderGaussian6BlurLayer(FrameBuffer &in_fbo)
void PostProcessing::renderGaussian6BlurLayer(FrameBuffer &in_fbo, size_t layer, float sigmaH, float sigmaV)
{
for (unsigned i = 0; i < 4; i++)
GLuint LayerTex;
glGenTextures(1, &LayerTex);
glTextureView(LayerTex, GL_TEXTURE_2D, in_fbo.getRTT()[0], GL_R32F, 0, 1, layer, 1);
if (!irr_driver->hasARBComputeShaders())
{
GLuint LayerTex;
glGenTextures(1, &LayerTex);
glTextureView(LayerTex, GL_TEXTURE_2D, in_fbo.getRTT()[0], GL_R32F, 0, 1, i, 1);
if (!irr_driver->hasARBComputeShaders())
{
// Used as temp
irr_driver->getFBO(FBO_SCALAR_1024).Bind();
FullScreenShader::Gaussian6VBlurShader::getInstance()->SetTextureUnits(LayerTex);
DrawFullScreenEffect<FullScreenShader::Gaussian6VBlurShader>(core::vector2df(1.f / 1024.f, 1.f / 1024.f), 1.f);
in_fbo.BindLayer(i);
FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(irr_driver->getFBO(FBO_SCALAR_1024).getRTT()[0]);
DrawFullScreenEffect<FullScreenShader::Gaussian6HBlurShader>(core::vector2df(1.f / 1024.f, 1.f / 1024.f), 1.f);
}
else
{
glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT);
glUseProgram(FullScreenShader::ComputeShadowBlurVShader::getInstance()->Program);
FullScreenShader::ComputeShadowBlurVShader::getInstance()->SetTextureUnits(LayerTex);
glBindSampler(FullScreenShader::ComputeShadowBlurVShader::getInstance()->TU_dest, 0);
glBindImageTexture(FullScreenShader::ComputeShadowBlurVShader::getInstance()->TU_dest, irr_driver->getFBO(FBO_SCALAR_1024).getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_R32F);
FullScreenShader::ComputeShadowBlurVShader::getInstance()->setUniforms(core::vector2df(1.f / 1024.f, 1.f / 1024.f), 1.5f);
glDispatchCompute((int)1024 / 8 + 1, (int)1024 / 8 + 1, 1);
glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
glUseProgram(FullScreenShader::ComputeShadowBlurHShader::getInstance()->Program);
FullScreenShader::ComputeShadowBlurHShader::getInstance()->SetTextureUnits(irr_driver->getFBO(FBO_SCALAR_1024).getRTT()[0]);
glBindSampler(FullScreenShader::ComputeShadowBlurHShader::getInstance()->TU_dest, 0);
glBindImageTexture(FullScreenShader::ComputeShadowBlurHShader::getInstance()->TU_dest, LayerTex, 0, false, 0, GL_WRITE_ONLY, GL_R32F);
FullScreenShader::ComputeShadowBlurHShader::getInstance()->setUniforms(core::vector2df(1.f / 1024.f, 1.f / 1024.f), 1.5f);
glDispatchCompute((int)1024 / 8 + 1, (int)1024 / 8 + 1, 1);
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
}
glDeleteTextures(1, &LayerTex);
// Used as temp
irr_driver->getFBO(FBO_SCALAR_1024).Bind();
FullScreenShader::Gaussian6VBlurShader::getInstance()->SetTextureUnits(LayerTex);
DrawFullScreenEffect<FullScreenShader::Gaussian6VBlurShader>(core::vector2df(1.f / 1024.f, 1.f / 1024.f), sigmaV);
in_fbo.BindLayer(layer);
FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(irr_driver->getFBO(FBO_SCALAR_1024).getRTT()[0]);
DrawFullScreenEffect<FullScreenShader::Gaussian6HBlurShader>(core::vector2df(1.f / 1024.f, 1.f / 1024.f), sigmaH);
}
else
{
glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT);
glUseProgram(FullScreenShader::ComputeShadowBlurVShader::getInstance()->Program);
FullScreenShader::ComputeShadowBlurVShader::getInstance()->SetTextureUnits(LayerTex);
glBindSampler(FullScreenShader::ComputeShadowBlurVShader::getInstance()->TU_dest, 0);
glBindImageTexture(FullScreenShader::ComputeShadowBlurVShader::getInstance()->TU_dest, irr_driver->getFBO(FBO_SCALAR_1024).getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_R32F);
FullScreenShader::ComputeShadowBlurVShader::getInstance()->setUniforms(core::vector2df(1.f / 1024.f, 1.f / 1024.f), sigmaV);
glDispatchCompute((int)1024 / 8 + 1, (int)1024 / 8 + 1, 1);
glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
glUseProgram(FullScreenShader::ComputeShadowBlurHShader::getInstance()->Program);
FullScreenShader::ComputeShadowBlurHShader::getInstance()->SetTextureUnits(irr_driver->getFBO(FBO_SCALAR_1024).getRTT()[0]);
glBindSampler(FullScreenShader::ComputeShadowBlurHShader::getInstance()->TU_dest, 0);
glBindImageTexture(FullScreenShader::ComputeShadowBlurHShader::getInstance()->TU_dest, LayerTex, 0, false, 0, GL_WRITE_ONLY, GL_R32F);
FullScreenShader::ComputeShadowBlurHShader::getInstance()->setUniforms(core::vector2df(1.f / 1024.f, 1.f / 1024.f), sigmaH);
glDispatchCompute((int)1024 / 8 + 1, (int)1024 / 8 + 1, 1);
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
}
glDeleteTextures(1, &LayerTex);
}
void PostProcessing::renderGaussian6Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary, float sigmaV, float sigmaH)

View File

@ -91,7 +91,7 @@ public:
void renderGaussian6Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary, float sigmaV, float sigmaH);
void renderHorizontalBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary);
void renderGaussian6BlurLayer(FrameBuffer &in_fbo);
void renderGaussian6BlurLayer(FrameBuffer &in_fbo, size_t layer, float sigmaH, float sigmaV);
void renderGaussian17TapBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary);
/** Render tex. Used for blit/texture resize */

View File

@ -1030,7 +1030,14 @@ void IrrDriver::renderShadows()
glDisable(GL_POLYGON_OFFSET_FILL);
if (irr_driver->hasARBTextureView())
m_post_processing->renderGaussian6BlurLayer(m_rtts->getShadowFBO());
{
for (unsigned i = 0; i < 2; i++)
{
m_post_processing->renderGaussian6BlurLayer(m_rtts->getShadowFBO(), i,
1.5f * m_shadow_scales[0].first / m_shadow_scales[i].first,
1.5f * m_shadow_scales[0].second / m_shadow_scales[i].second);
}
}
glBindTexture(GL_TEXTURE_2D_ARRAY, m_rtts->getShadowFBO().getRTT()[0]);
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
}