diff --git a/data/shaders/gaussian6h.comp b/data/shaders/gaussian6h.comp index c1909b9ab..f2df38fe0 100644 --- a/data/shaders/gaussian6h.comp +++ b/data/shaders/gaussian6h.comp @@ -1,7 +1,7 @@ uniform sampler2D source; uniform layout(rgba16f) restrict writeonly image2D dest; uniform vec2 pixel; -uniform float sigma; +uniform float weights[7]; // Gaussian separated blur with radius 6. @@ -23,18 +23,10 @@ void main() barrier(); - float g0, g1, g2; - g0 = 1.0 / (sqrt(2.0 * 3.14) * sigma); - g1 = exp(-0.5 / (sigma * sigma)); - g2 = g1 * g1; - vec4 sum = local_src[x + 6][y] * g0; - g0 *= g1; - g1 *= g2; + vec4 sum = local_src[x + 6][y] * weights[0]; for (int i = 1; i < 6; i++) { - sum += local_src[6 + x - i][y] * g0; - sum += local_src[6 + x + i][y] * g0; - g0 *= g1; - g1 *= g2; + sum += local_src[6 + x - i][y] * weights[i]; + sum += local_src[6 + x + i][y] * weights[i]; } imageStore(dest, iuv, sum); diff --git a/data/shaders/gaussian6v.comp b/data/shaders/gaussian6v.comp index dfd71c920..7c3a0979a 100644 --- a/data/shaders/gaussian6v.comp +++ b/data/shaders/gaussian6v.comp @@ -1,7 +1,7 @@ uniform sampler2D source; uniform layout(rgba16f) restrict writeonly image2D dest; uniform vec2 pixel; -uniform float sigma; +uniform float weights[7]; // Gaussian separated blur with radius 6. @@ -23,18 +23,10 @@ void main() barrier(); - float g0, g1, g2; - g0 = 1.0 / (sqrt(2.0 * 3.14) * sigma); - g1 = exp(-0.5 / (sigma * sigma)); - g2 = g1 * g1; - vec4 sum = local_src[x][y + 6] * g0; - g0 *= g1; - g1 *= g2; + vec4 sum = local_src[x][y + 6] * weights[0]; for (int i = 1; i < 6; i++) { - sum += local_src[x][6 + y - i] * g0; - sum += local_src[x][6 + y + i] * g0; - g0 *= g1; - g1 *= g2; + sum += local_src[x][6 + y - i] * weights[i]; + sum += local_src[x][6 + y + i] * weights[i]; } imageStore(dest, iuv, sum); diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 9d8dcf0b0..cb6db3a25 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -353,45 +353,63 @@ void PostProcessing::renderGaussian6Blur(FrameBuffer &in_fbo, FrameBuffer &auxil { assert(in_fbo.getWidth() == auxiliary.getWidth() && in_fbo.getHeight() == auxiliary.getHeight()); float inv_width = 1.0f / in_fbo.getWidth(), inv_height = 1.0f / in_fbo.getHeight(); - { - if (!irr_driver->hasARBComputeShaders()) - { - auxiliary.Bind(); - FullScreenShader::Gaussian6VBlurShader::getInstance()->SetTextureUnits(in_fbo.getRTT()[0]); - DrawFullScreenEffect(core::vector2df(inv_width, inv_height), sigmaV); - } - else - { - glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT); - glUseProgram(FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->Program); - FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->SetTextureUnits(in_fbo.getRTT()[0]); - glBindSampler(FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->TU_dest, 0); - glBindImageTexture(FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->TU_dest, auxiliary.getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_RGBA16F); - FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->setUniforms(core::vector2df(inv_width, inv_height), sigmaV); - glDispatchCompute((int)in_fbo.getWidth() / 8 + 1, (int)in_fbo.getHeight() / 8 + 1, 1); - } - } + if (!irr_driver->hasARBComputeShaders()) { - if (!irr_driver->hasARBComputeShaders()) - { - in_fbo.Bind(); + auxiliary.Bind(); - FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(auxiliary.getRTT()[0]); - DrawFullScreenEffect(core::vector2df(inv_width, inv_height), sigmaH); - } - else - { - glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); - glUseProgram(FullScreenShader::ComputeGaussian6HBlurShader::getInstance()->Program); - FullScreenShader::ComputeGaussian6HBlurShader::getInstance()->SetTextureUnits(auxiliary.getRTT()[0]); - glBindSampler(FullScreenShader::ComputeGaussian6HBlurShader::getInstance()->TU_dest, 0); - glBindImageTexture(FullScreenShader::ComputeGaussian6HBlurShader::getInstance()->TU_dest, in_fbo.getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_RGBA16F); - FullScreenShader::ComputeGaussian6HBlurShader::getInstance()->setUniforms(core::vector2df(inv_width, inv_height), sigmaH); - glDispatchCompute((int)in_fbo.getWidth() / 8 + 1, (int)in_fbo.getHeight() / 8 + 1, 1); - glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); - } + FullScreenShader::Gaussian6VBlurShader::getInstance()->SetTextureUnits(in_fbo.getRTT()[0]); + DrawFullScreenEffect(core::vector2df(inv_width, inv_height), sigmaV); + + in_fbo.Bind(); + + FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(auxiliary.getRTT()[0]); + DrawFullScreenEffect(core::vector2df(inv_width, inv_height), sigmaH); } + else + { + float g0, g1, g2; + + std::vector weightsV; + g0 = 1.f / (sqrtf(2.f * 3.14f) * sigmaV); + g1 = exp(-.5f / (sigmaV * sigmaV)); + g2 = g1 * g1; + for (unsigned i = 0; i < 7; i++) + { + weightsV.push_back(g0); + g0 *= g1; + g1 *= g2; + } + + glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT); + glUseProgram(FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->Program); + FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->SetTextureUnits(in_fbo.getRTT()[0]); + glBindSampler(FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->TU_dest, 0); + glBindImageTexture(FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->TU_dest, auxiliary.getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_RGBA16F); + FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->setUniforms(core::vector2df(inv_width, inv_height), weightsV); + glDispatchCompute((int)in_fbo.getWidth() / 8 + 1, (int)in_fbo.getHeight() / 8 + 1, 1); + + std::vector weightsH; + g0 = 1.f / (sqrtf(2.f * 3.14f) * sigmaH); + g1 = exp(-.5f / (sigmaH * sigmaH)); + g2 = g1 * g1; + for (unsigned i = 0; i < 7; i++) + { + weightsH.push_back(g0); + g0 *= g1; + g1 *= g2; + } + + glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); + glUseProgram(FullScreenShader::ComputeGaussian6HBlurShader::getInstance()->Program); + FullScreenShader::ComputeGaussian6HBlurShader::getInstance()->SetTextureUnits(auxiliary.getRTT()[0]); + glBindSampler(FullScreenShader::ComputeGaussian6HBlurShader::getInstance()->TU_dest, 0); + glBindImageTexture(FullScreenShader::ComputeGaussian6HBlurShader::getInstance()->TU_dest, in_fbo.getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_RGBA16F); + FullScreenShader::ComputeGaussian6HBlurShader::getInstance()->setUniforms(core::vector2df(inv_width, inv_height), weightsH); + glDispatchCompute((int)in_fbo.getWidth() / 8 + 1, (int)in_fbo.getHeight() / 8 + 1, 1); + glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); + } + } void PostProcessing::renderHorizontalBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary) diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 9b4bf7cc9..3634ef3da 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -1752,7 +1752,7 @@ namespace FullScreenShader Program = LoadProgram(OBJECT, GL_COMPUTE_SHADER, file_manager->getAsset("shaders/gaussian6h.comp").c_str()); TU_dest = 1; - AssignUniforms("pixel", "sigma"); + AssignUniforms("pixel", "weights"); AssignSamplerNames(Program, 0, "source"); AssignTextureUnit(Program, TexUnit(TU_dest, "dest")); } @@ -1822,7 +1822,7 @@ namespace FullScreenShader Program = LoadProgram(OBJECT, GL_COMPUTE_SHADER, file_manager->getAsset("shaders/gaussian6v.comp").c_str()); TU_dest = 1; - AssignUniforms("pixel", "sigma"); + AssignUniforms("pixel", "weights"); AssignSamplerNames(Program, 0, "source"); AssignTextureUnit(Program, TexUnit(TU_dest, "dest")); } diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index a8be956d0..24f1c616f 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -471,7 +471,7 @@ public: ComputeGaussian17TapHShader(); }; -class ComputeGaussian6HBlurShader : public ShaderHelperSingleton, public TextureRead +class ComputeGaussian6HBlurShader : public ShaderHelperSingleton >, public TextureRead { public: GLuint TU_dest; @@ -517,7 +517,7 @@ public: ComputeGaussian17TapVShader(); }; -class ComputeGaussian6VBlurShader : public ShaderHelperSingleton, public TextureRead +class ComputeGaussian6VBlurShader : public ShaderHelperSingleton >, public TextureRead { public: GLuint TU_dest;