normalize texture coordinates to [0,1] range

Started by
6 comments, last by Buckeye 9 years, 1 month ago

hiho

my question is simple.

SHORT QUESTION:

Can I normalize somehow (if yes, how?) 3D model texture coordinates to [0,1] range?

LONG QUESTION:

I mean, it looks like coordinates are sometimes out of [0,1] range but it's okay for GPU since it's using GL_REPEAT for image or equivalement for DX, but let's imagine that I have to store texcoords only in [0,1], would it affect model texture mapping or still look the same?

thank you for any ansawers!

Advertisement

If coords are correct that looks the same, the flag GL_REPEAT is just there to say what behavior you want if outside the [0,1] range.

would it affect model texture mapping or still look the same?

It would not look the same. Extra vertices and degenerate triangles would be required to get the same result.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Really, I was sure if coord was correct it looked the same.

EDIT : The interpolation of coords will not give the same result that's true like a lerp from 0.75 to 0.5 and 0.75 to 1.5 for example.

As L. Spiro says, it wouldn't look the same. Consider the situation below. The thin gray box with the red sine wave is a tiling texture. That is, using wrapped (repeat) tex coords, quads could be rendered side-by-side and the sine wave would appear continuous (the pink continuation of the curve on the right side).

Say you have a quad (the green box) with tex coords along the u axis, say from 0.4 to 0.8, and you put a quad next to it (the blue box), with the intent of wrapping the texture so that the red curve continues to the right in that second quad. With tex coord wrapping (repeating), you could set the u value of the tex coords for the blue box to something like 0.8 and 1.4 to achieve that. With tex coord wrapping (repeating), the effect will be that the blue box tex coords from left to right will be rendered as if they were 0.8 on the left, 1.0 at about one-fourth the way from the left, one pixel to the right of that will be equivalent to 0, and the right edge (with an actual value of 1.4) will appear as if it were 0.4.

If you restrict tex coords to the range [ 0, 1 ], there is no value that you can set the blue box tex coord to (at the position ??) to have the same texturing.

[attachment=26370:wrapped tex coords.png]

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Okay, so when I want to merge two textures (two index buffers) into single batch, how can I do that? I have two meshes with 512x512 texture, and I wanted to create one mesh with 1024x512 texture. It "worked" so far but the texcoords are disturbed, so you are right.

Any workarounds?

If they have repeating texture coordinates then you are kind of out of luck.

But say if they only repeat in one axis then you can combine them into either 1024x512 or 512x1024 and just repeat on the 512 axis. Like buckeys picture in the x/u direction you cant wrap, but you could in the y/v direction.

If they don't repeat you just need to divide the texture coordinates of the long axis each by 0.5 so now both textures go from 0-.5. Then whichever you place not at 0 in the texture you would add 0.5 to that axis. so you would get one that is 0-.5 and one that is .5-1 in say u and then in v both would go from 0 - 1 still.

If you really need to wrap things then you could look at using a texture array of 512 x 512 x 2.

This can be one of the down sides of atlasing. If you need something to wrap you generally have to add in a new poly that repeats the same 0-1 range.

It's usually better to fix this in the art side so that combining them is the trivial case of shifting uv coordinates and merging textures.


I wanted to create one mesh with 1024x512 texture.

As Eklipse mentions: can't be done if any tex coords for any vertex in either mesh is not in the range [0,1].


If you really need to wrap things then you could look at using a texture array of 512 x 512 x 2.

^^^ This.

That means you have to provide info at render-time to select the texture in the array.

Alternatively, load the textures separately, and, for the combined (re-indexed) mesh, render the first range of indices with the first texture, and the second range of indices with the second texture.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement