how to remove those ugly seams between patch boundaries from the texture atlas?

788 views Asked by At

When I try to render a textured 3D model with a GLSL shader with OpenTK, I get very ugly seams between texture patches. Does anyone know how to remove them?

This picture is my rendering result

This picture is the texture atlas

the 3D model comes from the sketchfab.com,

1

There are 1 answers

1
Josh Parnell On

It is very difficult to tell from this screenshot whether the issue is mipmapping or a lack of mesh segmentation, so I'll respond to both.

Possibility 1: Mipmapping

Ensure that mipmapping is turned off on the atlas. In GL that means your minification filter should be linear or nearest, but not the mipmapped variants.

glBindTexture(GL_TEXTURE_2D, texAtlas);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);

That atlas is packed incredibly tightly and standard mip generation is going to blur across the patch boundaries, resulting in seams.

Possibility 2: Lack of Mesh Segmentation

It could also be that the model is being loaded (incorrectly) as one contiguous mesh, whereas the texture atlas makes it clear that the mesh should be broken up into many pieces.

The ugly seams are a result of the fact that OpenGL is interpolating texture coordinates (UVs) across boundaries where the mesh is intended to be discontinuous. Each of the little 'pieces' in the texture atlas should correspond to one distinct patch on the mesh, and the vertices that correspond to the edges of that patch must not be shared with others, because the texture coordinates are discontinuous.

Some mesh formats, like the common .obj, can specify vertices in bizarre ways that must be handled carefully in order to work correctly in, e.g., OpenGL. For example, a vertex can be associated with two distinct texture coordinates. To render the model correctly, we must duplicate such a vertex, creating one unique vertex for each set of texture coordinates. Check the documentation for whatever API you're using to load the model, and see if it mentions vertex duplication, texture coordinates, etc.