Problem with displaying objects' textures at high angles


I am writing my own 3D rendering engine using OpenGL in C++. I have encountered a problem with displaying textures, which is only visible at high angles. I thought the problem might be solved by enabling anisotropic filtering but nothing has changed when I enabled it (possibly I did it the wrong way).

Here is the part of Texture.cpp file that is responsible for enabling anisotropic filtering:
line 43: GLfloat maxAnisotropy;
line 44: glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
line 45: glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy); //target - GL_TEXTURE_2D

Link to google drive folder that contains screenshots and Texture.cpp file:

What did I wrong? What should I do if anisotropic filtering isn’t a solution to such problem?

Thanks in advance.


Some people might answer you quickly, but I’ll try to figure it out with you. This looks interesting to me…

To my opinion this has nothing to do with anisotropy.

In the first picture I am interested on how the polygons are. Are the triangles the same than these artifacts ? How do you get the image to texture ? I mean do you use separate image or use a single one with getting which part to use (like an atlas). Also, do the texture have seems ? Try to use a seamless texture and see if that changes.

Finally, this might also be some z-fighting. Are there any two coincident geometries at this place ?

Thank you for your response.

I have added wireframe for first image and texture that was used for rendering (it’s a single texture for all types of cubes).
I don’t know whether the texture has seems or not but I think it’s seamless.
In my opinion, it cannot be z-fighting (look at wireframe with back-face culling disabled).

Yes, this is not a z-fighting issue. This is neither an issue with the triangles since they are all belonging to well structured squares. I would go for just a texturing issue.

What you can try to do is to clamp your texture (if not already done). Then try to disable mipmapping and if that solves your issue, then provide all the mipmap levels of your texture image to GL. One cause to this is explained here.

If this is not that, we’ll have to look for something else.

ORLEON, assuming you’re texturing your entire world from a single 2D GPU texture populated with used_texture.png (+ mipmaps), then that’s likely your problem. You’ve probably got cross-texture filtering going on. That effect gets worse the more your texture is minified (i.e. in the distance and/or higher tilt angles). If so, what you should probably explore using is texture arrays.

The page you linked to by Steve Baker has some good background info, but it was written before Texture Arrays were added to OpenGL 8 years ago. Since then, they’ve been the better (and simple) solution to this “cross-texture” filtering problem.

ORLEON, try taking a surface you see the problem on and instead of texturing it from your atlas, texture it from a single 18x18 2D texture containing only the single texture that’s displayed on that surface. Set your TEXTURE_WRAP_S/_T to REPEAT, your MIN_FILTER to LINEAR_MIPMAP_LINEAR and your MAG_FILTER to LINEAR. Also generate MIPmaps for the texture, and verify that the texture tiles seamlessly. See if this gets rid of your artifact. If so, then you should explore using texture arrays for your texturing instead.

I indeed have to have a look at these Texture Arrays. Thanks for pointing this.

I did everything that you mentioned and all artifacts have gone. Actually replacing atlas to single texture solved it. I have attached new image to google drive folder. I will try to implement texturing with Texture Arrays.