summaryrefslogtreecommitdiff
path: root/src/renderergl2/glsl/depthblur_fp.glsl
diff options
context:
space:
mode:
authorSmileTheory <SmileTheory@gmail.com>2016-03-08 18:30:51 -0800
committerTim Angus <tim@ngus.net>2016-04-07 11:54:14 +0100
commitc1ec25db8442cacf87df39d1e8e54b819b83a047 (patch)
tree2cf21e9807ba7bb7e384c787023bc34f2edc6e8e /src/renderergl2/glsl/depthblur_fp.glsl
parent7c858dafb7941be2ea6522a2a267252abf2d4fe7 (diff)
OpenGL2: Speedup for SSAO & blur shaders, fix sunlight normals in lightall.
Diffstat (limited to 'src/renderergl2/glsl/depthblur_fp.glsl')
-rw-r--r--src/renderergl2/glsl/depthblur_fp.glsl46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/renderergl2/glsl/depthblur_fp.glsl b/src/renderergl2/glsl/depthblur_fp.glsl
index 15f7be27..60a261c5 100644
--- a/src/renderergl2/glsl/depthblur_fp.glsl
+++ b/src/renderergl2/glsl/depthblur_fp.glsl
@@ -11,22 +11,23 @@ float gauss[4] = float[4](0.40, 0.24, 0.054, 0.0044);
float getLinearDepth(sampler2D depthMap, const vec2 tex, const float zFarDivZNear)
{
- float sampleZDivW = texture2D(depthMap, tex).r;
- return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW);
+ float sampleZDivW = texture2D(depthMap, tex).r;
+ return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW);
}
-vec4 depthGaussian1D(sampler2D imageMap, sampler2D depthMap, vec2 tex, float zFarDivZNear, float zFar)
+vec4 depthGaussian1D(sampler2D imageMap, sampler2D depthMap, vec2 tex, float zFarDivZNear, float zFar, vec2 scale)
{
- vec2 scale = u_ViewInfo.zw;
+ float depthCenter = getLinearDepth(depthMap, tex, zFarDivZNear);
+ //scale /= zFarDivZNear * depthCenter;
+ //int blurSteps = int(float(BLUR_SIZE) / (zFarDivZNear * depthCenter));
#if defined(USE_HORIZONTAL_BLUR)
- vec2 direction = vec2(1.0, 0.0) * scale;
+ vec2 direction = vec2(scale.x, 0.0);
#else // if defined(USE_VERTICAL_BLUR)
- vec2 direction = vec2(0.0, 1.0) * scale;
+ vec2 direction = vec2(0.0, scale.y);
#endif
-
- float depthCenter = zFar * getLinearDepth(depthMap, tex, zFarDivZNear);
- vec2 centerSlope = vec2(dFdx(depthCenter), dFdy(depthCenter)) / vec2(dFdx(tex.x), dFdy(tex.y));
+
+ vec2 slope = vec2(dFdx(depthCenter), dFdy(depthCenter)) / vec2(dFdx(tex.x), dFdy(tex.y));
#if defined(USE_GAUSS)
vec4 result = texture2D(imageMap, tex) * gauss[0];
@@ -36,33 +37,32 @@ vec4 depthGaussian1D(sampler2D imageMap, sampler2D depthMap, vec2 tex, float zFa
float total = 1.0;
#endif
+ float zLimit = 5.0 / zFar;
int i, j;
for (i = 0; i < 2; i++)
{
for (j = 1; j < BLUR_SIZE; j++)
{
vec2 offset = direction * j;
- float depthSample = zFar * getLinearDepth(depthMap, tex + offset, zFarDivZNear);
- float depthExpected = depthCenter + dot(centerSlope, offset);
- if(abs(depthSample - depthExpected) < 5.0)
- {
+ float depthSample = getLinearDepth(depthMap, tex + offset, zFarDivZNear);
+ float depthExpected = depthCenter + dot(slope, offset);
+ float useSample = float(abs(depthSample - depthExpected) < zLimit);
#if defined(USE_GAUSS)
- result += texture2D(imageMap, tex + offset) * gauss[j];
- total += gauss[j];
+ result += texture2D(imageMap, tex + offset) * (gauss[j] * useSample);
+ total += gauss[j] * useSample;
#else
- result += texture2D(imageMap, tex + offset);
- total += 1.0;
+ result += texture2D(imageMap, tex + offset) * useSample;
+ total += useSample;
#endif
- }
}
-
+
direction = -direction;
- }
-
+ }
+
return result / total;
}
void main()
-{
- gl_FragColor = depthGaussian1D(u_ScreenImageMap, u_ScreenDepthMap, var_ScreenTex, u_ViewInfo.x, u_ViewInfo.y);
+{
+ gl_FragColor = depthGaussian1D(u_ScreenImageMap, u_ScreenDepthMap, var_ScreenTex, u_ViewInfo.x, u_ViewInfo.y, u_ViewInfo.zw);
}