From c7358e6efc2ff241eb2c49b3a6d455ccfa27ea1a Mon Sep 17 00:00:00 2001 From: Faerbit Date: Thu, 5 Mar 2015 00:00:31 +0100 Subject: [PATCH] Changed blur of flames to gaussian blur. --- data/shader/flame_post.fsh | 31 ++++++++++++++++++++++++++----- graphics.cc | 3 +++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/data/shader/flame_post.fsh b/data/shader/flame_post.fsh index ea0bc2a..36c3c00 100644 --- a/data/shader/flame_post.fsh +++ b/data/shader/flame_post.fsh @@ -5,17 +5,38 @@ in vec2 vTexCoord; uniform sampler2D light_fbo; uniform int windowSizeX; uniform int windowSizeY; +uniform bool verticalPass; out vec4 oColor; -const float lookup_offset = 4.0; +//const float lookup_offset = 4.0; +const float stretching = 2.0; void main() { vec4 sum = vec4(0.0); - for(float i = -lookup_offset; i<=lookup_offset; i+=1.0) { - for(float j = -lookup_offset; j<=lookup_offset; j+=1.0) { - sum += texture(light_fbo, vec2(vTexCoord.x + i * 1.0/(windowSizeX/2.0), vTexCoord.y + j * 1.0/(windowSizeY/2.0)))/pow(lookup_offset*2+1, 2.0); - } + if (verticalPass){ + float blurSize = 1.0/(float(windowSizeY)/(stretching)); + sum += texture(light_fbo, vec2(vTexCoord.x - 4.0*blurSize, vTexCoord.y)) * 0.05; + sum += texture(light_fbo, vec2(vTexCoord.x - 3.0*blurSize, vTexCoord.y)) * 0.09; + sum += texture(light_fbo, vec2(vTexCoord.x - 2.0*blurSize, vTexCoord.y)) * 0.12; + sum += texture(light_fbo, vec2(vTexCoord.x - blurSize, vTexCoord.y)) * 0.15; + sum += texture(light_fbo, vec2(vTexCoord.x, vTexCoord.y)) * 0.16; + sum += texture(light_fbo, vec2(vTexCoord.x + blurSize, vTexCoord.y)) * 0.15; + sum += texture(light_fbo, vec2(vTexCoord.x + 2.0*blurSize, vTexCoord.y)) * 0.12; + sum += texture(light_fbo, vec2(vTexCoord.x + 3.0*blurSize, vTexCoord.y)) * 0.09; + sum += texture(light_fbo, vec2(vTexCoord.x + 4.0*blurSize, vTexCoord.y)) * 0.05; + } + else { + float blurSize = 1.0/(float(windowSizeX)/stretching); + sum += texture(light_fbo, vec2(vTexCoord.x, vTexCoord.y - 4.0*blurSize)) * 0.05; + sum += texture(light_fbo, vec2(vTexCoord.x, vTexCoord.y - 3.0*blurSize)) * 0.09; + sum += texture(light_fbo, vec2(vTexCoord.x, vTexCoord.y - 2.0*blurSize)) * 0.12; + sum += texture(light_fbo, vec2(vTexCoord.x, vTexCoord.y - blurSize)) * 0.15; + sum += texture(light_fbo, vec2(vTexCoord.x, vTexCoord.y)) * 0.16; + sum += texture(light_fbo, vec2(vTexCoord.x, vTexCoord.y + blurSize)) * 0.15; + sum += texture(light_fbo, vec2(vTexCoord.x, vTexCoord.y + 2.0*blurSize)) * 0.12; + sum += texture(light_fbo, vec2(vTexCoord.x, vTexCoord.y + 3.0*blurSize)) * 0.09; + sum += texture(light_fbo, vec2(vTexCoord.x, vTexCoord.y + 4.0*blurSize)) * 0.05; } oColor = sum; } diff --git a/graphics.cc b/graphics.cc index 65dcead..72e8afc 100644 --- a/graphics.cc +++ b/graphics.cc @@ -350,6 +350,9 @@ void Graphics::render(double time) glDisable(GL_CULL_FACE); flamePostShader->use(); + flamePostShader->setUniform("verticalPass", true); + fullscreen_quad->render(); + flamePostShader->setUniform("verticalPass", false); fullscreen_quad->render(); glDisable(GL_STENCIL_TEST);