Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Texturing error on a Sphere

I have a number of spherical longitude/latitude coordinates for points on a sphere that I need to visualize. For that purpose, I transformed the points to cartesian coordinates and built a mesh of triangles that I can render with VTK. Works so far.

Now I want to use a texture for the sphere model. Therefore I transformed the spherical coordinates to texture coordinates and assigned these to each point. This works for the majority of the sphere's surface triangles and the result looks acceptable.

But, for the triangles on the opposite side of the prime meridian, where the texture wraps, the triangles are textured incorrectly: Instead of repeating the texture and mapping “over the texture boundary”, the whole texture gets squeezed onto the single triangle.

Here is a picture of how it looks like:

sphere-texture

The zick-zack line is obviously wrong, the blue line should be visible instead. The whole texture is mapped on the triangles, resulting in red and white stripes. This makes sense since, for the triangles in question, the texture coordinates span the whole texture space.

To illustrate this problem, which is not specific to spheres but all closed objects, I have created the following figure:

texture-seam

In the upper rectangle, we see a triangle that spans over the texture boundaries with computed texture coordinates A, B and C. Since the texture can be tiled, this is how I would like the triangle to be rendered.

The lower triangle shows how the texture coordinates are interpreted currently. The coordinates of the edges A, B and C are the same, but this time, the majority of the texture is used for the triangle, instead of tiling the texture at the borders.

I am sure there is quite a common mistake I made but I didn't find anything to help me yet. Have any hints for me?

like image 332
Ferdinand Beyer Avatar asked Jan 23 '23 03:01

Ferdinand Beyer


1 Answers

The answer is very simple you need to map your texture coordinates over the edge. The implementation depends on your data set but here is a stab at the problem.

In computer graphics texture coordinates are stored on the faces and not on the vertices and your problem shows the reason. When you map a texture around a sphere, let us say in 10 steps you start with 0.0 then continue in 0.1 increments. If you go with texture coordinates along the prime meridian you get faces with the texture coordinate 0.9 and 0.0. The graphic hardware does what it is told and interpolates the texture between 0.0 and 0.9.

To solve your problem you need to map the texture from 0.9 to 1.0.

If you can, create the polygons that way or duplicate the offending vertices with other texture coordinates.

like image 97
rioki Avatar answered Jan 31 '23 08:01

rioki