Sign in to follow this  
xytor

Texture tiling

Recommended Posts

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?

Share this post


Link to post
Share on other sites
you need to change your sampler texture addressing mode to [url="http://msdn.microsoft.com/en-us/library/bb206366(v=vs.85).aspx"]wrap[/url], 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

Share this post


Link to post
Share on other sites
[quote name='Necrolis' timestamp='1298090120' post='4776206']
you need to change your sampler texture addressing mode to [url="http://msdn.microsoft.com/en-us/library/bb206366(v=vs.85).aspx"]wrap[/url], 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
[/quote]

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote name='Dawoodoz' timestamp='1298112877' post='4776275']
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.
[/quote]

But world space position has 3 components (x,y,z) while texture coordinates only have u and v...

Share this post


Link to post
Share on other sites
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 [url="http://blogs.msdn.com/b/shawnhar/archive/2008/11/03/detail-textures.aspx"]detail textures[/url].

Share this post


Link to post
Share on other sites
[quote name='Adam_42' timestamp='1298151620' post='4776435']
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 [url="http://blogs.msdn.com/b/shawnhar/archive/2008/11/03/detail-textures.aspx"]detail textures[/url].
[/quote]

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).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this