1uniform sampler2D u_Tex0;
2varying vec2 v_TexCoord;
3
4// some const, tweak for best look
5const float sampleDist = 1.0;
6const float sampleStrength = 1.5;
7
8void main(void)
9{
10 // 0.5,0.5 is the center of the screen
11 // so substracting v_TexCoord from it will result in
12 // a vector pointing to the middle of the screen
13 vec2 dir = 0.5 - v_TexCoord;
14
15 // calculate the distance to the center of the screen
16 float dist = sqrt(dir.x*dir.x + dir.y*dir.y);
17
18 // normalize the direction (reuse the distance)
19 dir = dir/dist;
20
21 // this is the original colour of this fragment
22 // using only this would result in a nonblurred version
23 vec4 color = texture2D(u_Tex0,v_TexCoord);
24
25 vec4 sum = color;
26
27 // take 10 additional blur samples in the direction towards
28 // the center of the screen
29 sum += texture2D(u_Tex0, v_TexCoord - 0.08 * dir * sampleDist);
30 sum += texture2D(u_Tex0, v_TexCoord - 0.05 * dir * sampleDist);
31 sum += texture2D(u_Tex0, v_TexCoord - 0.03 * dir * sampleDist);
32 sum += texture2D(u_Tex0, v_TexCoord - 0.02 * dir * sampleDist);
33 sum += texture2D(u_Tex0, v_TexCoord - 0.01 * dir * sampleDist);
34 sum += texture2D(u_Tex0, v_TexCoord + 0.01 * dir * sampleDist);
35 sum += texture2D(u_Tex0, v_TexCoord + 0.02 * dir * sampleDist);
36 sum += texture2D(u_Tex0, v_TexCoord + 0.03 * dir * sampleDist);
37 sum += texture2D(u_Tex0, v_TexCoord + 0.05 * dir * sampleDist);
38 sum += texture2D(u_Tex0, v_TexCoord + 0.08 * dir * sampleDist);
39
40 // we have taken eleven samples
41 sum *= 1.0/11.0;
42
43 // weighten the blur effect with the distance to the
44 // center of the screen ( further out is blurred more)
45 float t = dist * sampleStrength;
46 t = clamp(t ,0.0,1.0); //0 <= t <= 1
47
48 //Blend the original color with the averaged pixels
49 gl_FragColor = mix(color, sum, t);
50}
51