3

Is it possible to make Gaussian blur like in Photoshop via GLSL? I found just some examples of shaders which work the same. But none of them return same result as Photoshop, if half-transparent blur.

I do two-pass ping-pong Gaussian blur, where i use two framebuffers and change direction via uniform. Iterations and sigma on screenshot both are equal 2.

P.S. After two days of researching i didn't find real useful answers, i can't believe that nobody wanted to fix/make this shader.

varying vec2 uv;

uniform float iterations;
uniform float sigma;

uniform vec2 texelSize;
uniform vec2 direction;

void main() {

    vec4 color = texture2D(texture, uv);
    
    float weight = 0.0;
    float totalWeight = 1.0;

    for(float i = 1.0; i <= iterations; i++) {
        
        weight = exp(-(i * i) / (2.0 * sigma * sigma)); // gaussian 1D
        
        color += texture2D(texture, uv - i * direction * texelSize) * weight;
        color += texture2D(texture, uv + i * direction * texelSize) * weight;
        
        totalWeight += 2.0 * weight;
    
    }

    color.rgb /= totalWeight;

    /*=========================*/
    
    gl_FragColor = color;
    
    /*==========OR============*/
    
    gl_FragColor = vec4(color.rgb, 1.0);

}

enter image description here

2pha
  • 9,798
  • 2
  • 29
  • 43
dt_
  • 95
  • 1
  • 10
  • If i divide alpha too, then image will be smaller, but i want result where it becomes bigger and around image more and more half alpha pixels. It actually exists, but in color channel, not in alpha and because of that we can see black-shaped borders which should be just low-alpha green pixels. Blending is normal (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) – dt_ Aug 21 '20 at 21:13
  • @Rabbid76 I don't know how to explain it better, but first and second results look correct, but in first result, for example, if color after blur became nearly black 0, 5, 0 and alpha 1, in ideal it should be something like 0, 250, 0 with alpha ~0.01 and it will look totally correctly then, i think. Changing sigma without changing iterations doesn't change anything, it looks the same. Check this [link](https://i.imgur.com/LGx9kyX.png). You will see that left result becomes smaller and left result looks good excluding black borders, which i explained above. – dt_ Aug 22 '20 at 00:12
  • But image area becomes smaller and smaller, when i increse sigma and iterations. It never will be the same result as i want / Photoshop do, if i will divide alpha too. – dt_ Aug 22 '20 at 19:01

0 Answers0