From 26d48cdad099efc061db5a223b98c056aadf15bf Mon Sep 17 00:00:00 2001 From: vlj Date: Mon, 12 May 2014 23:59:17 +0200 Subject: [PATCH] SSAO: Stronger blur + tweak param Use another algorithm to have gaussian blur that lets us customise radius more easily. --- data/shaders/gaussian17taph.frag | 35 +++++++++++++------------------ data/shaders/gaussian17tapv.frag | 36 +++++++++++++------------------- data/shaders/ssao.frag | 4 ++-- src/graphics/render.cpp | 2 +- 4 files changed, 32 insertions(+), 45 deletions(-) diff --git a/data/shaders/gaussian17taph.frag b/data/shaders/gaussian17taph.frag index 874d22a7f..f02a49dfc 100644 --- a/data/shaders/gaussian17taph.frag +++ b/data/shaders/gaussian17taph.frag @@ -1,37 +1,30 @@ -// From http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/ +// From http://http.developer.nvidia.com/GPUGems3/gpugems3_ch40.html uniform sampler2D tex; uniform vec2 pixel; - +uniform float sigma = 5.; in vec2 uv; out vec4 FragColor; void main() { - float X = uv.x; float Y = uv.y; - float offset[5] = { - 0., - 1.41176470588235, - 3.29411764705882, - 5.17647058823529, - 7.05882352941176 - }; - float weight[5] = { - 0.196380615234375, - 0.1888427734375, - 0.03631591796875, - 0.0020751953125, - 0.000015258789062 - }; - vec4 sum = texture(tex, vec2(X, Y)) * weight[0]; - for (int i = 1; i < 5; i++) { - sum += texture(tex, vec2(X - offset[i] * pixel.x, Y)) * weight[i]; - sum += texture(tex, vec2(X + offset[i] * pixel.x, Y)) * weight[i]; + float g0, g1, g2; + g0 = 1.0 / (sqrt(2.0 * 3.14) * sigma); + g1 = exp(-0.5 / (sigma * sigma)); + g2 = g1 * g1; + vec4 sum = texture(tex, vec2(X, Y)) * g0; + g0 *= g1; + g1 *= g2; + for (int i = 1; i < 9; i++) { + sum += texture(tex, vec2(X - i * pixel.x, Y)) * g0; + sum += texture(tex, vec2(X + i * pixel.x, Y)) * g0; + g0 *= g1; + g1 *= g2; } FragColor = sum; diff --git a/data/shaders/gaussian17tapv.frag b/data/shaders/gaussian17tapv.frag index 00de4c4aa..01e54a8a9 100644 --- a/data/shaders/gaussian17tapv.frag +++ b/data/shaders/gaussian17tapv.frag @@ -1,38 +1,32 @@ -// From http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/ +// From http://http.developer.nvidia.com/GPUGems3/gpugems3_ch40.html uniform sampler2D tex; uniform vec2 pixel; - +uniform float sigma = 5.; in vec2 uv; out vec4 FragColor; void main() { - float X = uv.x; float Y = uv.y; - float offset[5] = { - 0., - 1.41176470588235, - 3.29411764705882, - 5.17647058823529, - 7.05882352941176 - }; - float weight[5] = { - 0.196380615234375, - 0.1888427734375, - 0.03631591796875, - 0.0020751953125, - 0.000015258789062 - }; - vec4 sum = texture(tex, vec2(X, Y)) * weight[0]; - for (int i = 1; i < 5; i++) { - sum += texture(tex, vec2(X, Y - offset[i] * pixel.y)) * weight[i]; - sum += texture(tex, vec2(X, Y + offset[i] * pixel.y)) * weight[i]; + float g0, g1, g2; + g0 = 1.0 / (sqrt(2.0 * 3.14) * sigma); + g1 = exp(-0.5 / (sigma * sigma)); + g2 = g1 * g1; + vec4 sum = texture(tex, vec2(X, Y)) * g0; + g0 *= g1; + g1 *= g2; + for (int i = 1; i < 9; i++) { + sum += texture(tex, vec2(X, Y - i * pixel.y)) * g0; + sum += texture(tex, vec2(X, Y + i * pixel.y)) * g0; + g0 *= g1; + g1 *= g2; } FragColor = sum; } + diff --git a/data/shaders/ssao.frag b/data/shaders/ssao.frag index 7693590e9..5c0080ead 100644 --- a/data/shaders/ssao.frag +++ b/data/shaders/ssao.frag @@ -27,10 +27,10 @@ in vec2 uv; out float AO; const float sigma = 1.; -const float tau = 2.; +const float tau = 7.; const float beta = 0.0001; const float epsilon = .00001; -const float radius = 1.; +const float radius = 1.5; const float k = 1.; #define SAMPLES 16 diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 154be4eb9..42e7628c8 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -899,7 +899,7 @@ void IrrDriver::renderSSAO() m_post_processing->renderSSAO(); // Blur it to reduce noise. m_post_processing->renderGaussian17TapBlur(irr_driver->getFBO(FBO_SSAO), irr_driver->getRenderTargetTexture(RTT_SSAO), - irr_driver->getFBO(FBO_TMP4), irr_driver->getRenderTargetTexture(RTT_TMP4), UserConfigParams::m_width, UserConfigParams::m_height); + irr_driver->getFBO(FBO_TMP4), irr_driver->getRenderTargetTexture(RTT_TMP4), UserConfigParams::m_width, UserConfigParams::m_height ); glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height); }