Sign in to follow this  
BlackJoker

How to make tile texture

Recommended Posts

BlackJoker    1328

Hello,

 

I want to make some textures to be tile instead of stretches on whole mesh.

 

Could you please answer how to implement such feature in DirectX 11?

Edited by BlackJoker

Share this post


Link to post
Share on other sites
Necrolis    1464

You can do this using "wrap" for the texture addressing mode; it'll cause the texture unit to take texture u/v addresses mod 1.0, so essentially, 11.25 would map to 0.25 in the texture, see the example here.

Share this post


Link to post
Share on other sites
Tasaq    1530

Is this the only way to do this?

 

I believe so, this is the best way, unless you want to do something extra. If so tell us.

Share this post


Link to post
Share on other sites
BlackJoker    1328

OK, but what means in this situation variable: AddresU,V,W with value D3D11_TEXTURE_ADDRESS_WRAP in D3D11_SAMPLER_DESC structure?

 

Does this variables not intended for this?

Edited by BlackJoker

Share this post


Link to post
Share on other sites
ericrrichards22    2421

I can't quite understand what you're asking, but for 2D textures, you generally only use the U and V texture coordinates.  TEXTURE_ADDRESS_WRAP does mean that the texture coordinates on your vertices are modded with 1.0f, in order to tile the texture.

 

I think the W texture coordinate is usually only used for cubemaps, and sometimes texture arrays.

Share this post


Link to post
Share on other sites
unbird    8336

Is this the only way to do this?


You could wrap manually in the pixel shader. Not that it is simple (derivatives go bad at the border if you just mod and sample normally), or performant. But I think it has its use (texture atlas, say).

Share this post


Link to post
Share on other sites
ericrrichards22    2421

You can supply a texture coordinate transformation matrix to your shader, and use that to transform your vertex texture coordinates.

So, if you wanted to tile the texture 4x4 across a quad, and the vertex texture coordinates are setup to go [0,1], you'd use this matrix:

[[4, 0, 0, 0]
 [0, 4, 0, 0]
 [0, 0, 1, 0]
 [0, 0, 0, 1]]

You can also use this technique to apply other transformations, like rotating the texture or offsetting the starting point.

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