DirectX Terrain Tiled Texture

Started by
2 comments, last by Medo Mex 11 years, 5 months ago
I'm trying to make the texture tiled for the terrain, so I'm using the following:
device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
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?
Advertisement
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.
I'm not using vertex shader yet, how do I set the texture coordinates?

(I made the terrain in 3Ds Max and exported it as .x file)
Thanks, I had to set the UVW values in 3Ds Max, the problem is now resolved.

This topic is closed to new replies.

Advertisement