How to make tile texture

Started by
8 comments, last by BlackJoker 10 years, 4 months ago

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?

Advertisement

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.

Is this the only way to do this?

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.

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?

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.

Eric Richards

SlimDX tutorials - http://www.richardssoftware.net/

Twitter - @EricRichards22

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

OK, but what if I already have coordinates from 0 to 1? How I can tile texture in this case?

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.

Eric Richards

SlimDX tutorials - http://www.richardssoftware.net/

Twitter - @EricRichards22

Thank a lot for explanation.

This topic is closed to new replies.

Advertisement