summaryrefslogtreecommitdiff
path: root/src/renderergl2/glsl
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderergl2/glsl')
-rw-r--r--src/renderergl2/glsl/depthblur_fp.glsl17
-rw-r--r--src/renderergl2/glsl/depthblur_vp.glsl3
2 files changed, 14 insertions, 6 deletions
diff --git a/src/renderergl2/glsl/depthblur_fp.glsl b/src/renderergl2/glsl/depthblur_fp.glsl
index 9685f6d7..d71b3487 100644
--- a/src/renderergl2/glsl/depthblur_fp.glsl
+++ b/src/renderergl2/glsl/depthblur_fp.glsl
@@ -9,7 +9,10 @@ varying vec2 var_ScreenTex;
float gauss[4] = float[4](0.40, 0.24, 0.054, 0.0044);
//float gauss[3] = float[3](0.60, 0.19, 0.0066);
#define BLUR_SIZE 4
+
+#if !defined(USE_DEPTH)
//#define USE_GAUSS
+#endif
float getLinearDepth(sampler2D depthMap, const vec2 tex, const float zFarDivZNear)
{
@@ -19,21 +22,21 @@ float getLinearDepth(sampler2D depthMap, const vec2 tex, const float zFarDivZNea
vec4 depthGaussian1D(sampler2D imageMap, sampler2D depthMap, vec2 tex, float zFarDivZNear, float zFar, vec2 scale)
{
- float depthCenter = getLinearDepth(depthMap, tex, zFarDivZNear);
- // enable for less blurring for farther objects
+#if defined(USE_DEPTH)
+ float depthCenter = getLinearDepth(depthMap, tex, zFarDivZNear);
+ vec2 slope = vec2(dFdx(depthCenter), dFdy(depthCenter)) / vec2(dFdx(tex.x), dFdy(tex.y));
scale /= clamp(zFarDivZNear * depthCenter / 32.0, 1.0, 2.0);
+#endif
#if defined(USE_HORIZONTAL_BLUR)
vec2 direction = vec2(scale.x * 2.0, 0.0);
vec2 nudge = vec2(0.0, scale.y * 0.5);
#else // if defined(USE_VERTICAL_BLUR)
vec2 direction = vec2(0.0, scale.y * 2.0);
- vec2 nudge = vec2(scale.x * 0.5, 0.0);
+ vec2 nudge = vec2(-scale.x * 0.5, 0.0);
#endif
- 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];
float total = gauss[0];
@@ -49,9 +52,13 @@ vec4 depthGaussian1D(sampler2D imageMap, sampler2D depthMap, vec2 tex, float zFa
for (j = 1; j < BLUR_SIZE; j++)
{
vec2 offset = direction * (float(j) - 0.25) + nudge;
+#if defined(USE_DEPTH)
float depthSample = getLinearDepth(depthMap, tex + offset, zFarDivZNear);
float depthExpected = depthCenter + dot(slope, offset);
float useSample = float(abs(depthSample - depthExpected) < zLimit);
+#else
+ float useSample = 1.0;
+#endif
#if defined(USE_GAUSS)
result += texture2D(imageMap, tex + offset) * (gauss[j] * useSample);
total += gauss[j] * useSample;
diff --git a/src/renderergl2/glsl/depthblur_vp.glsl b/src/renderergl2/glsl/depthblur_vp.glsl
index ba0b6c56..9c47660c 100644
--- a/src/renderergl2/glsl/depthblur_vp.glsl
+++ b/src/renderergl2/glsl/depthblur_vp.glsl
@@ -8,7 +8,8 @@ varying vec2 var_ScreenTex;
void main()
{
gl_Position = attr_Position;
- var_ScreenTex = (floor(attr_TexCoord0.xy * (1.0 / u_ViewInfo.zw - vec2(1.0))) + vec2(0.5)) * u_ViewInfo.zw;
+ vec2 wh = vec2(1.0) / u_ViewInfo.zw - vec2(1.0);
+ var_ScreenTex = (floor(attr_TexCoord0.xy * wh) + vec2(0.5)) * u_ViewInfo.zw;
//vec2 screenCoords = gl_Position.xy / gl_Position.w;
//var_ScreenTex = screenCoords * 0.5 + 0.5;