2014-04-23 16:08:37 -04:00
|
|
|
uniform sampler2D tex;
|
|
|
|
uniform sampler2D dtex;
|
2014-05-16 21:09:21 -04:00
|
|
|
|
2014-04-23 16:08:37 -04:00
|
|
|
out vec4 FragColor;
|
|
|
|
|
|
|
|
float focalDepth = 10.;
|
|
|
|
float maxblur = 1.;
|
|
|
|
float range = 100.;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2014-06-03 13:56:59 -04:00
|
|
|
vec2 uv = gl_FragCoord.xy / screen;
|
2014-04-23 16:08:37 -04:00
|
|
|
float curdepth = texture(dtex, uv).x;
|
2016-06-28 15:55:51 -04:00
|
|
|
vec4 FragPos = InverseProjectionMatrix * (2.0 * vec4(uv, curdepth, 1.0) - 1.0);
|
2014-04-23 16:08:37 -04:00
|
|
|
FragPos /= FragPos.w;
|
|
|
|
|
|
|
|
float depth = FragPos.z;
|
|
|
|
float blur = clamp(abs(depth - focalDepth) / range, -maxblur, maxblur);
|
|
|
|
|
|
|
|
vec2 offset = 10. / screen;
|
|
|
|
|
2014-05-13 18:59:51 -04:00
|
|
|
vec4 col = texture(tex, uv);
|
2014-04-23 20:44:34 -04:00
|
|
|
vec4 colOriginal = col;
|
2014-04-23 16:08:37 -04:00
|
|
|
// Weight from here http://artmartinsh.blogspot.fr/2010/02/glsl-lens-blur-filter-with-bokeh.html
|
|
|
|
|
2014-05-13 18:59:51 -04:00
|
|
|
col += texture(tex, uv + (vec2(0.0, 0.4) * offset) * blur);
|
|
|
|
col += texture(tex, uv + (vec2(0.15, 0.37) * offset) * blur);
|
|
|
|
col += texture(tex, uv + (vec2(0.29,0.29) * offset) * blur);
|
|
|
|
col += texture(tex, uv + (vec2(-0.37,0.15) * offset) * blur);
|
|
|
|
col += texture(tex, uv + (vec2(0.4, 0.0) * offset) * blur);
|
|
|
|
col += texture(tex, uv + (vec2(0.37, -0.15) * offset) * blur);
|
|
|
|
col += texture(tex, uv + (vec2(0.29, -0.29) * offset) * blur);
|
|
|
|
col += texture(tex, uv + (vec2(-0.15, -0.37) * offset) * blur);
|
|
|
|
col += texture(tex, uv + (vec2(0.0, -0.4) * offset) * blur);
|
|
|
|
col += texture(tex, uv + (vec2(-0.15, 0.37) * offset) * blur);
|
|
|
|
col += texture(tex, uv + (vec2(-0.29, 0.29) * offset) * blur);
|
|
|
|
col += texture(tex, uv + (vec2(0.37, 0.15) * offset) * blur);
|
|
|
|
col += texture(tex, uv + (vec2(-0.4, 0.0) * offset) * blur);
|
|
|
|
col += texture(tex, uv + (vec2(-0.37, -0.15) * offset) * blur);
|
|
|
|
col += texture(tex, uv + (vec2(-0.29, -0.29) * offset) * blur);
|
|
|
|
col += texture(tex, uv + (vec2(0.15, -0.37) * offset) * blur);
|
2014-04-23 16:08:37 -04:00
|
|
|
|
2014-05-13 18:59:51 -04:00
|
|
|
col += texture(tex, uv + (vec2(0.15, 0.37) * offset) * blur * 0.9);
|
|
|
|
col += texture(tex, uv + (vec2(-0.37, 0.15) * offset) * blur * 0.9);
|
|
|
|
col += texture(tex, uv + (vec2(0.37, -0.15) * offset) * blur * 0.9);
|
|
|
|
col += texture(tex, uv + (vec2(-0.15, -0.37) * offset) * blur * 0.9);
|
|
|
|
col += texture(tex, uv + (vec2(-0.15, 0.37) * offset) * blur * 0.9);
|
|
|
|
col += texture(tex, uv + (vec2(0.37, 0.15) * offset) * blur * 0.9);
|
|
|
|
col += texture(tex, uv + (vec2(-0.37, -0.15) * offset) * blur * 0.9);
|
|
|
|
col += texture(tex, uv + (vec2(0.15, -0.37) * offset) * blur * 0.9);
|
2014-04-23 16:08:37 -04:00
|
|
|
|
2014-05-13 18:59:51 -04:00
|
|
|
col += texture(tex, uv + (vec2(0.29, 0.29) * offset) * blur * 0.7);
|
|
|
|
col += texture(tex, uv + (vec2(0.4, 0.0) * offset) * blur * 0.7);
|
|
|
|
col += texture(tex, uv + (vec2(0.29, -0.29) * offset) * blur * 0.7);
|
|
|
|
col += texture(tex, uv + (vec2(0.0, -0.4) * offset) * blur * 0.7);
|
|
|
|
col += texture(tex, uv + (vec2(-0.29, 0.29) * offset) * blur * 0.7);
|
|
|
|
col += texture(tex, uv + (vec2(-0.4, 0.0) * offset) * blur * 0.7);
|
|
|
|
col += texture(tex, uv + (vec2(-0.29, -0.29) * offset) * blur * 0.7);
|
|
|
|
col += texture(tex, uv + (vec2(0.0, 0.4) * offset) * blur *0.7);
|
2014-04-23 16:08:37 -04:00
|
|
|
|
2014-05-13 18:59:51 -04:00
|
|
|
col += texture(tex, uv + (vec2(0.29, 0.29) * offset) * blur * 0.4);
|
|
|
|
col += texture(tex, uv + (vec2(0.4, 0.0) * offset) * blur * 0.4);
|
|
|
|
col += texture(tex, uv + (vec2(0.29, -0.29) * offset) * blur * 0.4);
|
|
|
|
col += texture(tex, uv + (vec2(0.0, -0.4) * offset) * blur * 0.4);
|
|
|
|
col += texture(tex, uv + (vec2(-0.29, 0.29) * offset) * blur * 0.4);
|
|
|
|
col += texture(tex, uv + (vec2(-0.4, 0.0) * offset) * blur * 0.4);
|
|
|
|
col += texture(tex, uv + (vec2(-0.29, -0.29) * offset) * blur * 0.4);
|
|
|
|
col += texture(tex, uv + (vec2(0.0, 0.4) * offset) * blur * 0.4);
|
2014-04-23 20:44:34 -04:00
|
|
|
|
2014-05-05 09:59:20 -04:00
|
|
|
col = vec4(col.rgb / 41.0, col.a);
|
2014-07-08 19:21:31 -04:00
|
|
|
depth = clamp(max(1.1666 - (FragPos.z/240.0), FragPos.z - 2000.0), 0., 1.);
|
|
|
|
|
2016-06-28 15:55:51 -04:00
|
|
|
vec3 final = colOriginal.rgb * depth + col.rgb * (1. - depth);
|
2014-04-23 16:08:37 -04:00
|
|
|
|
2014-05-29 20:32:01 -04:00
|
|
|
FragColor = vec4(final, colOriginal.a);
|
2014-04-23 20:44:34 -04:00
|
|
|
}
|