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

前端 未结 2 749
灰色年华
灰色年华 2021-02-06 00:25

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 di

2条回答
  •  甜味超标
    2021-02-06 01:09

    1) Yes, using a FBO is the way to go.

    2) With math, if you are at pixel (x, y), then the neighbors are (x+1, y), (x, y+1), (x+1, y+1), (x-1, y), etc. Edge cases are handled with the wrap modes of the texture. Notice that since GL_TEXTURE_2D uses normalized coordinates, the offsets aren't 1, but 1 / width and 1 / height of the texture.

提交回复
热议问题