cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

sergik128
Journeyman III

sampler2D produces artefacts with GL_REPEAT and GL_NEAREST

Hi,

In openGL 2.0 when using sampler2D in fragment shader in conjuction with GL_REPEAT wrapping mode and GL_NEAREST filter a hairline artefacts appear near the edges where texture coordinates approach 1.0, the edges where texture coordinates approach 0.0 are fine.

In the example below a simple quad is rendered parallel to the screen plane rotated 20 degrees around Z axis. Texture is being interpolated between four vertices (0, 0;  1, 0;  1, 1;  0, 1). On the two edges where one of the coordinates approach 1.0 sampler2D overflows and starts sampling "outside" of the texture which leads to a hairline artefacts.

The problem is reproducible on both Windows 7 (64-bit) and Ubuntu 10.10 Linux with Catalyst 11.2 driver running on Radeon HD 5850.

I have a complete source code for both platforms and can provide it on request. The same code works fine with SGX 530/540 and Nvidia drivers.

 

 

const char *vertShader = 

    "precision highp float;                                 \n"

    "attribute vec4 vVxPos;                                 \n"

    "attribute vec2 vTexCoord;                              \n"

    "uniform mat4 myPMVMatrix;                              \n"

    "varying   vec2 tex_coord;                              \n"

    "void main()                                            \n"

    "{                                                      \n"

    "   gl_Position = myPMVMatrix * vVxPos;                 \n"

    "   tex_coord = vTexCoord;                              \n"

    "}                                                      \n";

 

const char *fragShader = 

    "precision highp float;                                 \n"

    "varying vec2      tex_coord;                           \n"

    "uniform sampler2D tx;                                  \n"

    "void main()                                            \n"

    "{                                                      \n"

    "  gl_FragColor = texture2D (tx, tex_coord);            \n"

    "}                                                      \n";

 



 

    GLuint texture_id;

    glEnable(GL_TEXTURE_2D);

    glGenTextures (1, &texture_id);

    glBindTexture (GL_TEXTURE_2D, texture_id);

    unsigned tex[] =

    {

        0xFF000000, 0xFFFFFFFF, 0xFF000000, 0xFFFFFFFF,

        0xFFFFFFFF, 0xFF00FFFF, 0xFF00FF00, 0xFF000000,

        0xFF000000, 0xFFFF0000, 0xFF0000FF, 0xFFFFFFFF,

        0xFFFFFFFF, 0xFF000000, 0xFFFFFFFF, 0xFF000000,

    };

    glTexImage2D(GL_TEXTURE_2D,

                 0,

                 GL_RGBA,

                 4,

                 4,

                 0,

                 GL_RGBA,

                 GL_UNSIGNED_BYTE,

                 tex);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);



0 Likes
8 Replies
frali
Staff

Could you please send the source codes to me for reproduction? My email address is frank.li@amd.com. Thanks.

0 Likes

The source code has been sent.

Best regards, Sergey

0 Likes

No matter what the edge color will be. It seems wrong that half of the color is the same as the texture coordinate being 1.0, another half is the same as the texture coordinate being 0.0. It should be a driver bug. We will take a look at soon. Thanks.

0 Likes

I think the correct behavior would be to sample within original texture area when texture coordinates approach or equal to 1.0. Only when coordinates exceed 1.0 then sampler should start repeating the texture.

Regarding half of the colors, I guess the black dots on the gray background are not visible very well, but I had an impression that all colors on those two edges are sampled from the wrong place. In case of black tiles there are white dots and they are visible, in case of white tiles there are black dots and they are barely visible.

Thanks, Sergey

 

0 Likes

There is a workaround for your case. You could use GL_CLAMP to replace GL_REPEAT to change the wrap mode to explicitly clamp since there is no "repeat" in your demo right now.

0 Likes

Thanks, but the demo is just the simplified use-case. I need to use REPEAT so that I could use smaller textures. In the demo we could change interpolation range from [0-1] to [0-3] for example, this will make REPEAT mode relevant.

0 Likes

hi, sergik

Still there? Very sorry that we did not reply in time.

This issue looks like some corner case when GL_REPEAT wrapping mode is enabled.  I will continue to check whether this issue still exists on current AMD chips with latest driver, if you can provide the complete source code again.

0 Likes

hi, sergik

We have proved that this is a known issue on our chips which we do not have plan to fix.

When using GL_REPEAT addressing mode, please avoid the case of sampling a very small texture and then rendering it to a large render target . Or please choose other addressing mode to avoid this issue.

Very sorry for the inconvenience brought to you due to this issue.

And at the same time, thank you very much for reporting the issue and providing a very good test sample for us.

0 Likes