• Advertisement

Archived

This topic is now archived and is closed to further replies.

UV offsets and tiled textures

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am using a single texture to store multiple terrain tiles. To get this working, I am splitting the texture up into a 16x16 grid, and then just assigning different UV co-ordinates to the vertices to use different terrains. The problem is that the textures seem to be badly aligned, and get very confused at lower mipmap levels. For example, if I have bright green grass in tile and then brown mud in an adjacent tile, at lower mip levels, the grass appears to have a brown line running along one edge. The function I call to generate the UV co-ordinates uses an offset parameter. If I set the offset to 0.001 (for example), it subtracts the offset on top/left UV co-ordinates and adds it to right/bottom co-ordinates after dividing the co-ordinate by 16. Using that offset, I get the texture bleeding at distance. If I change the offset to 0.002, I get rid of the bleeding, but the actual texture area mapped to the quad seems very small and I lose a lot of detail. Is this the correct way to handle the UV co-ordinates (and I must just mess with the offset), or do have to use different offsets for tiles on the edge of the texture vs tiles in the middle of the texture? (btw. If anyone is interested in going down the tiles-within-a-big-texture route, I got a 30 fps increase in speed in scenes with a lot of different tiles, compared to using multiple textures and batching the primitives by texture. On the down-side, I''ve lost the ability to use texture co-ordinates outside the 0-1 range which makes large polys with tiled textures impossible. So, you have to use a lot more polys to retain correct texturing even if the scene can be geometrically reduced).

Share this post


Link to post
Share on other sites
Advertisement
quote:
The problem is that the textures seem to be badly aligned, and get very confused at lower mipmap levels. For example, if I have bright green grass in tile and then brown mud in an adjacent tile, at lower mip levels, the grass appears to have a brown line running along one edge.

With mip-maps, you''ll either have to create your own, or use some fancy thing like texture borders. I''ve not done texture borders before (haven''t got into that part yet), so I can''t go into detail. The borders prevent tiles from bleeding to each other.

quote:
The function I call to generate the UV co-ordinates uses an offset parameter. If I set the offset to 0.001 (for example), it subtracts the offset on top/left UV co-ordinates and adds it to right/bottom co-ordinates after dividing the co-ordinate by 16. Using that offset, I get the texture bleeding at distance. If I change the offset to 0.002, I get rid of the bleeding, but the actual texture area mapped to the quad seems very small and I lose a lot of detail.

- I don''t understand what you describe for UV coordinate generation. Would you clarify a bit?

- The bleeding is due to mip-mapping. If you disable mipmapping, it should go away. (If your UVs are correct - define the correct tile - then there should be no bleeding).

Peace,
Muhammad Haggag

Share this post


Link to post
Share on other sites
OK, I will put in a pixel border around each tile, thanks for the suggestion.

The UV co-ord thing...

You are supposed to specify an offset for your texture co-ords because there is a slight error in texel generation. That offset is supposed to be something like 0.01. So, a top-left co-ord won''t be 0,0, it''ll be -0.01,-0.01. As I understand it.

The thing is, because I am using a texture that contains 16x16 tiles, does that mean that I must divide the offset by 16 as well? And if so, does that division only apply to interior tiles - i.e. tiles that share no border with the edge of the texture - while those tiles on the left, top, right and bottom edges of the texture should still use the default offset?

Share this post


Link to post
Share on other sites
Pixel border will not help when the programm wants to use the very low resolution mip levels. So say to the programm, that the very low resolution mip levels should not be used!!!!!

Share this post


Link to post
Share on other sites
quote:
Original post by SoaringTortoise
The UV co-ord thing...

You are supposed to specify an offset for your texture co-ords because there is a slight error in texel generation. That offset is supposed to be something like 0.01. So, a top-left co-ord won''t be 0,0, it''ll be -0.01,-0.01. As I understand it.

The thing is, because I am using a texture that contains 16x16 tiles, does that mean that I must divide the offset by 16 as well? And if so, does that division only apply to interior tiles - i.e. tiles that share no border with the edge of the texture - while those tiles on the left, top, right and bottom edges of the texture should still use the default offset?

As far as I know, the tex coord bias is used with screenspace primitives only, to directly map texels to pixels. Check "Directly mapping texels to pixels" in the SDK docs.

Peace,
Muhammad Haggag

Share this post


Link to post
Share on other sites
Keep in mind that Direct3D uses inclusive-exclusive coords for UVs.

In other words, don''t modify the top or left coordinates. They should be 0, not -0.01.

Share this post


Link to post
Share on other sites

  • Advertisement