Sign in to follow this  
Medo Mex

DirectX Terrain Tiled Texture

Recommended Posts

I'm trying to make the texture tiled for the terrain, so I'm using the following:
device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
device->SetSamplerState(0, D3DSAMP_ADDRESSW, D3DTADDRESS_WRAP);

// Code to render terrain here...

After using the above code, the texture is still not tiled, how do I make it tiled?

Share this post

Link to post
Share on other sites
It depends on the texture coordinates of the terrain vertices. Wrapping mode will repeat the texture every integer junction. So if the texture coordinates of the vertices only go from 0.0f to 1.0f (or they are continuous along the terrain) it wont tile the texture.

So you're left with two options:
-You can manually change the texture coordinates of your terrain vertices which will give you the best results and most freedom;
-In the vertex shader before outputting the texture coordinates multiply them by the number of tiles you want, so if you multiply by 2 in both axis, if you had a plane with texture coordinates from 0.0 to 1.0 you would end up with 4 tiles of the texture.

I'm guessing you terrain is a big plane made of rows/columns of triangles, if so you're probably setting the texture coordinates of one of the corners (0.0f, 0.0f) and the opposite corner (1.0f, 1.0f) and interpolating the coordinates of the other vertices, if so you just have to change the coordinates of the last corner to (2.0f, 2.0f) and you will end of with 4 tiles. Edited by TiagoCosta

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