PDA

View Full Version : Problem with displaying objects' textures at high angles



ORLEON
08-31-2016, 02:47 AM
Hello!

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:
https://drive.google.com/folderview?id=0BwinoxM7BwFqTkVReGVWdFphYU0&usp=sharing

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

Thanks in advance.

Liubomyr

Silence
08-31-2016, 05:49 AM
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 ?

ORLEON
08-31-2016, 07:15 AM
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).

Silence
08-31-2016, 07:38 AM
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 (https://www.sjbaker.org/steve/omniv/tiling_textures.html).

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

Dark Photon
08-31-2016, 06:23 PM
...texture that was used for rendering (it's a single texture for all types of cubes).

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.


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 (https://www.sjbaker.org/steve/omniv/tiling_textures.html).

The page you linked to by Steve Baker has some good background info, but it was written before Texture Arrays (https://www.opengl.org/wiki/Array_Texture) 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.

Silence
09-01-2016, 01:29 AM
The page you linked to by Steve Baker has some good background info, but it was written before Texture Arrays (https://www.opengl.org/wiki/Array_Texture) were added to OpenGL 8 years ago. Since then, they've been the better (and simple) solution to this "cross-texture" filtering problem.

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

ORLEON
09-02-2016, 10:24 AM
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.
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.
Thanks!