1
$\begingroup$

I am trying to map a texture on a UV sphere. I created an algorithm to generate the vertices of the sphere and the UV texture coordinates for each vertex. How I do fix the distortion or aliasing? The formulas I used to generate the vertices of the sphere are: x = rsinΦcosθ y = rcosΦ z = -rsinΦsinθ

The formulas used to generate the UV texture coordinates for each vertex are: θ = arctan(z / x) / 2π Φ = arcos(y) / π

I am using Direct3D 12 to render the sphere.

enter image description here

$\endgroup$
3
  • $\begingroup$ Some code might be beneficial here. Since only a single strip is affected by the distortion and you use a formula where you divide by the coordinate x, my first guess would be that you have a "division by zero" error. Turn on all compiler warnings and check the UV-values you are getting. $\endgroup$
    – wychmaster
    Apr 28, 2023 at 7:17
  • $\begingroup$ It looks like you are generating vertices and use an index buffer object to define the triangles (connection of the vertices). the last vertex column seems to be the problem, because they are connected to the first vertex column. so the texture inbetween is interpolated over the whole texture. The solution is to add an additional vertex column with position of vertex column 0 and texture coordinates x = 1 $\endgroup$
    – Thomas
    Apr 28, 2023 at 7:24
  • $\begingroup$ if you look closer to the distorted column, you can see, that the whole earth texture is rendered within this small range... This tells us, that the UV coordinates are wrong... maybe because of the reason you can see in my answer, or like wychmaster said, that you divide by 0 in equation: θ = arctan(z / x) / 2π $\endgroup$
    – Thomas
    Apr 28, 2023 at 7:31

1 Answer 1

1
$\begingroup$

This problem might occur, because the most left vertices and the most right vertices are connected while the UV coordinates (texture coordinates) are 1(right) and 0(left)... so the whole texture is interpolated within the small area. (See figure 1)

enter image description here

Figure 1: This is what you have right now. The green triangles are correct, the red triangles show the problem you have...

You can add an additional vertex column on the right, where the vertex positions are the same as the most left vertices. (see Figure 2)

enter image description here

Figure 2: This is what you need. The orange vertices have the same position as the blue vertices. So this column of vertices is duplicated. But the texture coordinates are different. The blue vertices have a texture coordinate (x) = 0 and the orange vertices have a texture coordinate (x) = 1.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.