Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Results of Gaussian Blur are white.

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    5

    Results of Gaussian Blur are white.

    I've been attempting to code a normal Gaussian Blur shader which scales the image down to half the size in the vertex shader. The scaling works, but when I attempted to code the gaussian blur my results are coming out white and sadly I don't have enough knowledge to figure out why this is the case. Here is how I'm doing things at the moment:

    Code :
            float offset[5] = { 0.0, 1.0, 2.0, 3.0, 4.0 };
            float weight[5] = { 0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162 };
     
            anchors.fill: parent
     
            vertexShader: "
                uniform mat4 matrix;
                uniform float scale;
                attribute vec4 gl_Vertex;
                attribute vec2 gl_MultiTexCoord0;
                varying vec2 coord;
                void main() {
                    coord = gl_MultiTexCoord0;
                    coord.x /= scale;
                    lowp vec4 vertex = gl_Vertex;
                    vertex.x *= scale;
                    gl_Position = matrix * vertex;
                }"
            fragmentShader: "
                varying vec2 coord;
                uniform sampler2D src;
                uniform float qt_Opacity;
                uniform float textureWidth;
                uniform float offset[5];
                uniform float weight[5];
                void main() {
                    vec4 acc = texture2D(src, coord / textureWidth) * weight[0];
                    for (int i = 1; i < 5; i++)
                    {
                       acc += texture2D(src, coord + vec2(offset[i] / textureWidth, 0.0)) * weight[i];
                       acc += texture2D(src, coord - vec2(offset[i] / textureWidth, 0.0)) * weight[i];
                    }
                    gl_FragColor = acc;
                }"
        }

    Any comments are tips would be much appreciated!

  2. #2
    Intern Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    98
    hi,

    i guess almost everybody makes this mistake at least once in the fragment shader .. :-)

    you are adding 5*2 values that you took from the texture, that leads to the fact taht you properbly get a value greater than 1 for RGB .. and 1 is withe..
    vals: 0.3 + 0.4 + 0.2 + 0.35 + 0.26 = 1,51 << very withe

    try to devide the result by 5*2 ore to use a mix() function from GLSL.. than you get a propper result

    Quote Originally Posted by UraniumSlug View Post
    for (int i = 1; i < 5; i++)
    {
    acc += texture2D(src, coord + vec2(offset[i] / textureWidth, 0.0)) * weight[i];
    acc += texture2D(src, coord - vec2(offset[i] / textureWidth, 0.0)) * weight[i];
    }
    gl_FragColor = acc;
    maybe try:

    Code :
                    for (int i = 1; i < 5; i++)
                    {
                       acc += texture2D(src, coord + vec2(offset[i] / textureWidth, 0.0)) * weight[i];
                       acc += texture2D(src, coord - vec2(offset[i] / textureWidth, 0.0)) * weight[i];
                    }
                    gl_FragColor = acc / 10.0 ;

    cu
    uwi
    uwi2k2 - OpenGL Trainer: www.opengl-trainer.com
    ---------------------------------------------------------
    Free Programming Helpline: www.programming-hotline.com
    ---------------------------------------------------------
    A Friday Night Programmer: www.uwiworld.net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •