Creating blur filter with a shader - access adjacent pixels from fragment shader?

Viewed 9481

I want to create a blur effect using a fragment shader in OpenGL ES 2.0. The algorithm I am interested in is simply an averaging blur - add all adjacent pixels to myself and divide by 9 to normalize.

However I have 2 issues:

1) does this require me to first render to a framebuffer, then switch rendering targets? Or is there an easier way

2) assume I bind my "source" image to blur as texture 0, and I'm outputting my blurred texture. How do I access the pixels that aren't the one I'm current dealing with. The vert shader has invoked me for pixel i, but I need to access the pixels around me. How? And how do I know if I'm an edge case (literally at edge of screen)

(3: is there a more suitable algorithm to get a fuzzy frosted glass looking blur)

2 Answers
Related