Texture tiling

Started by
5 comments, last by xytor 13 years, 1 month ago
Hi, my normal directX 9.0/HLSL graphics engine has objects which, when scaled, the texture simply stretches.
Is there any obvious way to make the texture tile instead of stretching? I tried modifying the texture coordinates based on the object scale, but, since there are only two texture coordinate components and three scale components, I could not come up with a perfect solution. Am I missing something?
Advertisement
you need to change your sampler texture addressing mode to wrap, this will tile it if texture coords are greater that [1,1], so you'll need to adjust your UV to the size of the tile

you need to change your sampler texture addressing mode to wrap, this will tile it if texture coords are greater that [1,1], so you'll need to adjust your UV to the size of the tile


Right, but is there a technique to adjusting the UV coords? I can't seem to find a really good way to do it.


Edit: What I mean is, I want an arbitrary object to have a texture which is tiled (not stretched) over it, where the number of tiles depends on the object's scale. The size of each tile stays the same regardless of how big the object gets. There must be a way to use surface normals to achieve this, but I have not yet found a solution. Is there a standard way or algorithm that I just don't know about?
Use the world space position as the UV coordinate and divide by the grid size. It might even be faster than loading UV from a vertex structure. You might need to upgrade your engine if you are using fixed functions.

Use the world space position as the UV coordinate and divide by the grid size. It might even be faster than loading UV from a vertex structure. You might need to upgrade your engine if you are using fixed functions.


But world space position has 3 components (x,y,z) while texture coordinates only have u and v...
It's not something that can really be done automatically for anything but the simplest of 3D models and when the texture has no obvious recognisable details. Even then I think it would look strange.

Consider for example a sphere textured with a map of the world. If you simply repeat the texture by scaling up the UV coordinates as it gets closer to the camera, the countries will get repeated across the sphere and it will look completely wrong. Even a square textured with that map of the world will look odd if you change the texture coordinates as it gets closer.

If you just want to make the object look more detailed consider using detail textures.

It's not something that can really be done automatically for anything but the simplest of 3D models and when the texture has no obvious recognisable details. Even then I think it would look strange.

Consider for example a sphere textured with a map of the world. If you simply repeat the texture by scaling up the UV coordinates as it gets closer to the camera, the countries will get repeated across the sphere and it will look completely wrong. Even a square textured with that map of the world will look odd if you change the texture coordinates as it gets closer.

If you just want to make the object look more detailed consider using detail textures.


This is not for detail. I'm not scaling UV coords as it gets closer to the camera, but as it gets scaled in world space. Think of wrapping a present with pretty wrapping paper. The bigger the present, the more wrapping paper you use (the wrapping paper doesn't stretch and the pattern repeats).

This topic is closed to new replies.

Advertisement