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 4 of 4

Thread: glsl bilinear and artifact on same scale

  1. #1
    Junior Member Newbie
    Join Date
    May 2011
    Posts
    18

    glsl bilinear and artifact on same scale

    I need to implement a glsl bilinear filter (I can't use GL_LINEAR because i am doing YUY2 ->RGB convert, so I have set this to GL_NEAREST). I have a classic bilinear filtering like this :


    voidmain(void)
    {
    vec2f=fract(texcoord.st*vec2(width,height));
    vec4t00=yuv2rgb(texcoord.st);
    vec4t10=yuv2rgb(texcoord.st+vec2(1.0/width,0.0));
    vec4tA=mix(t00,t10,f.x);
    vec4t01=yuv2rgb(texcoord.st+vec2(0.0,1.0/height));
    vec4t11=yuv2rgb(texcoord.st+vec2(1.0/width,1.0/height));
    vec4tB=mix(t01,t11,f.x);
    gl_FragColor=mix(tA,tB,f.y);
    }where width and height are the size of the texture. I am trying to do that on Windows with Amd graphic card.If I move the textured quad, scale the textured scale .. I see at the some changing location an artifact (horizontal or vertical lines).it seems my shader is very classical .. I don't know what I can do to avoid theses artifacts.

  2. #2
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,269
    Try
    vec2f=fract(texcoord.st*vec2(width,height) - 0.5f);

    Pixel center is {0,0} , so {-0.5,-0.5} is its bottom-left coord.

  3. #3
    Junior Member Newbie
    Join Date
    May 2011
    Posts
    18
    I have test this and it's not working ... same artifact and more ... And I don't understand why I need shift from -0.5

  4. #4
    Intern Contributor
    Join Date
    Jul 2006
    Posts
    72
    Quote Originally Posted by qnext View Post
    I need to implement a glsl bilinear filter (I can't use GL_LINEAR because i am doing YUY2 ->RGB convert, so I have set this to GL_NEAREST). I have a classic bilinear filtering like this :

    vec2f=fract(texcoord.st*vec2(width,height));
    vec4t00=yuv2rgb(texcoord.st);
    vec4t10=yuv2rgb(texcoord.st+vec2(1.0/width,0.0));
    That is incorrect. It should be something like:

    // (0,0) is bottom left corner of texel. As we use nearest filtering - we want to sample at the relevant texel centers.
    vec2 tc_tmp = texcoord * vec2(width, height);
    vec2 tc_center = floor(tc_tmp - 0.5) + 0.5;
    vec2 f = fract(tc_tmp - tc_center);
    texcoord = tc_center / vec2(width, height);
    vec4 t00 = texture(some_tex, texcoord);
    vec4 t01 = texture(some_tex, texcoord + vec2(1.0/width,0.0));
    etc.

    Quote Originally Posted by Ilian Dinev View Post
    Try
    vec2f=fract(texcoord.st*vec2(width,height) - 0.5f);

    Pixel center is {0,0} , so {-0.5,-0.5} is its bottom-left coord.
    No it is not. AFAIK Direct3D has that - perhaps you are confusing the two.

Posting Permissions

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