Fragment-shader blur ... how does it work?

uniform sampler2D sampler0;
uniform vec2 tc_offset[9];
void blur()
{
  vec4 sample[9];
  for(int i = 0; i < 9; ++i)
    sample[i] = texture2D(sampler0, gl_TexCoord[0].st + tc_offset[i]);

  gl_FragColor = (sample[0] + (2.0 * sample[1]) + sample[2] +
      (2.0 * sample[3]) + sample[4] + 2.0 * sample[5] +
      sample[6] + 2.0 * sample[7] + sample[8] ) / 13.0;
}

How does the string [i] = texture2D (sample0, ...) work?

It seems that the image is blurry, I have to generate the image first, but here I am somehow trying to fulfill the request to the iamge itself that I am creating. How it works?

+3
source share
3 answers

As you noticed, to make a blurry image, you first need to make an image, and then blur it. This shader takes the (simple) second step, capturing the image that was created earlier and blurring it. An additional code must be added to create the original non-blurry image.

+4
source

​​ . tc_offset , 3x3 :

0   0   0
0   x   0
0   0   0

(, x - ). -1/width,-1/height. ( --0,5). , ( ).

. :

for(int i = 0; i < NUM_SAMPLES; ++i) {
    result += texture2D(sampler,texcoord+offsetscaling[i].xy)*offsetscaling[i].z;
}
+6

- , . , , .

+5

Source: https://habr.com/ru/post/1736774/


All Articles