From 448f254a2b62aefc9effe4069a0041bbf32d71e8 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 15 Nov 2014 21:02:24 +0100 Subject: [PATCH] Fixes --- data/shaders/blurshadowH.comp | 2 +- data/shaders/blurshadowV.comp | 4 ++-- src/graphics/irr_driver.hpp | 2 ++ src/graphics/post_processing.cpp | 36 +++++++++++++++++++++++++------- src/graphics/rtts.cpp | 4 ++++ 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/data/shaders/blurshadowH.comp b/data/shaders/blurshadowH.comp index e03ae6d77..21b176cbe 100644 --- a/data/shaders/blurshadowH.comp +++ b/data/shaders/blurshadowH.comp @@ -1,5 +1,5 @@ uniform sampler2D source; -uniform layout(rgba16f) restrict writeonly image2D dest; +uniform layout(r32f) restrict writeonly image2D dest; uniform vec2 pixel; uniform float sigma; diff --git a/data/shaders/blurshadowV.comp b/data/shaders/blurshadowV.comp index cbcc567c9..a6b439ce3 100644 --- a/data/shaders/blurshadowV.comp +++ b/data/shaders/blurshadowV.comp @@ -1,5 +1,5 @@ uniform sampler2D source; -uniform layout(rgba16f) restrict writeonly image2D dest; +uniform layout(r32f) restrict writeonly image2D dest; uniform vec2 pixel; uniform float sigma; @@ -27,7 +27,7 @@ void main() g0 = 1.0 / (sqrt(2.0 * 3.14) * sigma); g1 = exp(-0.5 / (sigma * sigma)); g2 = g1 * g1; - floar sum = local_src[x][y + 6] * g0; + float sum = local_src[x][y + 6] * g0; g0 *= g1; g1 *= g2; for (int i = 1; i < 6; i++) { diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index 9bffa86cc..e5358012b 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -99,6 +99,7 @@ enum TypeFBO FBO_EIGHTH2, FBO_DISPLACE, FBO_BLOOM_1024, + FBO_SCALAR_1024, FBO_BLOOM_512, FBO_TMP_512, FBO_LENS_512, @@ -160,6 +161,7 @@ enum TypeRTT RTT_MLAA_TMP, RTT_BLOOM_1024, + RTT_SCALAR_1024, RTT_BLOOM_512, RTT_TMP_512, RTT_LENS_512, diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 1488ba56c..2f557ecc6 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -321,16 +321,38 @@ void PostProcessing::renderGaussian6BlurLayer(FrameBuffer &in_fbo) for (unsigned i = 0; i < 4; i++) { - // Used as temp - irr_driver->getFBO(FBO_BLOOM_1024).Bind(); GLuint LayerTex; glGenTextures(1, &LayerTex); glTextureView(LayerTex, GL_TEXTURE_2D, in_fbo.getRTT()[0], GL_R32F, 0, 1, i, 1); - 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_BLOOM_1024).getRTT()[0]); - DrawFullScreenEffect(core::vector2df(1.f / 1024.f, 1.f / 1024.f), 1.f); + 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.f); + 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.f); + glDispatchCompute((int)1024 / 8 + 1, (int)1024 / 8 + 1, 1); + glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); + } glDeleteTextures(1, &LayerTex); } } diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 5dad9df4f..723dfdd80 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -123,6 +123,7 @@ RTT::RTT(size_t width, size_t height) RenderTargetTextures[RTT_HALF2_R] = generateRTT(half, GL_R16F, GL_RED, GL_FLOAT); RenderTargetTextures[RTT_BLOOM_1024] = generateRTT(shadowsize0, GL_RGBA16F, GL_BGR, GL_FLOAT); + RenderTargetTextures[RTT_SCALAR_1024] = generateRTT(shadowsize0, GL_R32F, GL_RED, GL_FLOAT); RenderTargetTextures[RTT_BLOOM_512] = generateRTT(shadowsize1, GL_RGBA16F, GL_BGR, GL_FLOAT); RenderTargetTextures[RTT_TMP_512] = generateRTT(shadowsize1, GL_RGBA16F, GL_BGR, GL_FLOAT); RenderTargetTextures[RTT_LENS_512] = generateRTT(shadowsize1, GL_RGBA16F, GL_BGR, GL_FLOAT); @@ -208,6 +209,9 @@ RTT::RTT(size_t width, size_t height) somevector.push_back(RenderTargetTextures[RTT_BLOOM_1024]); FrameBuffers.push_back(new FrameBuffer(somevector, 1024, 1024)); somevector.clear(); + somevector.push_back(RenderTargetTextures[RTT_SCALAR_1024]); + FrameBuffers.push_back(new FrameBuffer(somevector, 1024, 1024)); + somevector.clear(); somevector.push_back(RenderTargetTextures[RTT_BLOOM_512]); FrameBuffers.push_back(new FrameBuffer(somevector, 512, 512)); somevector.clear();