From 29afd22b68889c0edca6f3098c2c86b6eaa75440 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Tue, 18 Nov 2014 03:13:39 +0100 Subject: [PATCH] Smoothen shadow split --- src/graphics/post_processing.cpp | 68 +++++++++++++++----------------- src/graphics/post_processing.hpp | 2 +- src/graphics/render_geometry.cpp | 9 ++++- 3 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index cbeb8b095..277ada3a0 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -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(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(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(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(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) diff --git a/src/graphics/post_processing.hpp b/src/graphics/post_processing.hpp index 430623036..796114f22 100644 --- a/src/graphics/post_processing.hpp +++ b/src/graphics/post_processing.hpp @@ -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 */ diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 0966b8526..d94c2e176 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -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); }