varying vec4 vColor; varying vec2 vTexCoord; uniform sampler2D u_texture; uniform vec2 resolution; uniform float radius; uniform int pass; void main() { //this will be our RGBA sum vec4 sum = vec4(0.0); //our original texcoord for this fragment vec2 tc = vTexCoord; //the amount to blur, i.e. how far off center to sample from //1.0 -> blur by one pixel //2.0 -> blur by two pixels, etc. float blur = radius/resolution.y; //the direction of our blur //(1.0, 0.0) -> x-axis blur //(0.0, 1.0) -> y-axis blur float hstep = 1.0; float vstep = 0.0; if (pass == 1) { hstep = 0.0; vstep = 1.0; } sum += texture2D(u_texture, vec2(tc.x - 5.0*blur*hstep, tc.y - 5.0*blur*vstep)) * 0.014374; sum += texture2D(u_texture, vec2(tc.x - 4.0*blur*hstep, tc.y - 4.0*blur*vstep)) * 0.035855; sum += texture2D(u_texture, vec2(tc.x - 3.0*blur*hstep, tc.y - 3.0*blur*vstep)) * 0.072994; sum += texture2D(u_texture, vec2(tc.x - 2.0*blur*hstep, tc.y - 2.0*blur*vstep)) * 0.121281; sum += texture2D(u_texture, vec2(tc.x - 1.0*blur*hstep, tc.y - 1.0*blur*vstep)) * 0.164472; sum += texture2D(u_texture, vec2(tc.x, tc.y)) * 0.182049; sum += texture2D(u_texture, vec2(tc.x + 1.0*blur*hstep, tc.y + 1.0*blur*vstep)) * 0.164472; sum += texture2D(u_texture, vec2(tc.x + 2.0*blur*hstep, tc.y + 2.0*blur*vstep)) * 0.121281; sum += texture2D(u_texture, vec2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.072994; sum += texture2D(u_texture, vec2(tc.x + 4.0*blur*hstep, tc.y + 4.0*blur*vstep)) * 0.035855; sum += texture2D(u_texture, vec2(tc.x + 5.0*blur*hstep, tc.y + 5.0*blur*vstep)) * 0.014374; gl_FragColor = vColor * vec4(sum.rgb, 1.0); }