Square distortion texture

I have GL_QUAD_STRIP that I am mapping textures. The square strip folds back onto itself, forming a UV sphere. Essentially, a four-lane strip usually does not consist of rectangles - instead, a trapezoid.

I get texture distortion issues. The texture coordinates are correct (for example, they align well where they should). The problem lies in the trapezoidal faces themselves.

I expect the texels to the larger end of the trapezoidal surface to even out a large area, but the face seems to be split into two triangles. It looks like an affine texture mapping (but I don't think so, it still seems promising correctly, and I would not expect it to be used anyway).

I know that graphics cards usually cut the quadrants inside the triangles inside, but I did not expect this to affect texturing.,.

So, I do not know what is going on here. Any thoughts?

Here is an example of unwanted behavior. Low resolution globe texture, closest filtering, no mipmaps or anisotropy: enter image description here

+3
source share
2 answers

This is a classic problem when texturing a simple quadrant. This is due to the fact that (you guessed it right) that the square is divided into separate triangles. These triangles, in turn, are textured independently.

The problem is that the texture coordinates inside the triangle are interpolated linearly from the vertices (although the perspective is correct, but this does not help here). You can portray him as a rasterizer, without knowing the fourth vertex of this trapezoid, he sees only individual triangles. Thus, it is assumed that the transformation of triangles into texture space should be completely affine, and therefore the triangle should be part of a parallelogram.

What you need to do to solve this is to switch from a simple 2D affine texture space to a projective texture space using the full 4-dimensional texture coordinates instead of simple 2D-tex cocoons, as described here . You basically do what GL already does with perspective correct interpolation, but using your own perspective projection for texture coordinates (in addition to perspective projection already done for vertex positions).

+4
source

Is each section displayed correctly when it is rendered in reverse order (to be completely square)?

You can try the following command before rendering:

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); 

GL_PERSPECTIVE_CORRECTION_HINT Indicates the quality of the color, texture coordinates, and fog coordinate interpolation. If, from a perspective point of view, parameter interpolation is not supported by the GL implementation, a hint of GL_DONT_CARE or GL_FASTEST may result in a simple linear interpolation of the colors and / or texture coordinates.

-1
source

Source: https://habr.com/ru/post/917127/


All Articles