# Cylindrical texture coordinates

This topic is 1956 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello,

In my application I want to handle textures in a same way, even if they are applied in a different manner (projection, cylindrical, spherical, box). So this means I don't want to use automatic texture coord. generation, but I want to calculate them myself, when the object is created.

Usually, people calculate one texture coordinate (u,v) for each vertex (x,y,z). So each vertex will always have assigned the same texture coordinate.

But in my understanding, this cannot work when using cylindrical/spherical texture mapping:

suppose that one of the triangle (with vertices A, B, C) closing the cylinder has following angular coordinates (in polar coordinates, in degrees): 340, 350, 10

So those 3 vertices will be mapped following 3 u-texture coordinates: 0.9, 0.95, 0.05 (approximately!)

But that is not correct: the texture fragment would be spanning across almost the whole texture!

we should rather have following u-texture coordinates: 0.9, 0.95, 1.05

I could assign the vertex C the u-texture coordinate "1.05" to make that triangle look ok, but the problem is that the same vertex C is also part of other triangles, which might rather require the u-texture coordinate "0.05".

I hope I explained myself clearly enough ;)

So the only solution to this would be to have 3 texture coordinates for each triangle, rather than to have one texture coordinate for each vertex. Do people usually do that?

Is there another option?

##### Share on other sites
So the only solution to this would be to have 3 texture coordinates for each triangle, rather than to have one texture coordinate for each vertex. Do people usually do that?[/quote]
the texture fragment would be spanning across almost the whole texture![/quote]
What the hell are you talking about. How does a texture fragment which has a single pixel from a texture have a whole texture mapped to it? That's impossible. And to unwrap a cylinder to a texture you only need 2 uv's. You have to have a seam obviously. Take a soup can without top/bottom, cut the label from top to bottom and unfold. It is 2d applied to a cylinder.

##### Share on other sites

I didn't use the right word I guess. With "texture fragment" I meant "one textured triangle part of the cylinder".
I attached a picture to this reply, it should clarify my problem.

Thanks

##### Share on other sites
Right so don't build a triangle that goes over that seam. That's how it has to be obviously. You can either cut up your triangles along the seam or/but for any model done by an artist they will have seams anyway. You don't make seams and then model them, you make the seams cut through existing vertices based on your models shape.

##### Share on other sites
Thanks again.

Obviously that's one way to do. But it is very troublesome if you are not directly in control of what geometry is being used (i.e. the user can edit and manipulate the geometry)
The way I am doing it now (see my "funny" explanation above) works, but instead of calculating the texture coordinates on a vertex basis, I am calculating the texture coordinates on a triangle basis:

Basically, instead of one pair of texture coordinate per vertex, I use 3 pair of texture coordinate per triangle

I just wanted to confirm that this method is also being used sometimes, since I will have to be able to export the whole thing at some point, and provide something "standard" ;)

##### Share on other sites
No it is never used because there is no reason to not open it up in a 3d application and edit it. Not to mention a perfect cydlinder that had the triangle as you have shown it should have never ever been built that way.

##### Share on other sites
Well, then here is a stupid question maybe:

With the specially prepared cylinder (with correct seam) you will still need special handling at the seam points: indeed every seam point is part of a triangle "opening" the cylinder, and a triangle "closing" the cylinder, thus every seam point will need 2 differentiated texture coordinates... unless you create the cylinder open (i.e. two overlapping seams, each seam point is present twice).

Please refer to the picture: points B & C in the upper part, will require different texture coordinates!

##### Share on other sites
The second form, the "open" cylinder, is the common solution used in almost every model exporter available. The reason is exactly as you have mentioned.
Texture coordinates are not the only attribute that can differ per vertex on the model. Multiple normals are also commonly available, forcing even more splitting into multiple "single attribute" vertices.

##### Share on other sites
Thank you Ignifex!

That makes sense.

Cheers