Archived

This topic is now archived and is closed to further replies.

perallen

Rotating Texture on a Terrain

Recommended Posts

perallen    122
I am trying to render different textures on a terrain using DrawIndexedPrimitive for speed. The problem is that because the vertices are shared, the texture has to flip in order to be draw correctly. See this for an example, a 2 by 2 terrain: http://www.mobilesolutions.com/home/Image2.jpg How can I get the textures the keep orientation with a draw indexed primitive call without loading 4 of each texture? Sorry if this question is basic, I am just starting on the road to frustration. Thanks!

Share this post


Link to post
Share on other sites
Supernat02    604
The way I handled this is to just use 6 vertices and pass in all 6 to the index buffer. You could just use 4 if you have culling turned off and use triangle_strips...because I think half of the quad will get culled if you have culling on for triangle_strips. I don''t know for sure. I think it''s less memory intensive to copy an index buffer with 6 DWORDs per quad than copy 6 vertex structures per quad to recreate a vertex buffer. I couldn''t swear to that, but it seems like it would be.

You can''t save vertices when you tile like this, because like you said each vertex will have a different texture coordinate.

The only savings that you gain from index buffers will come with something like a mesh with a single texture applied to it (a terrain). There could be a lot of shared vertices, but the tex coord is the same for all of the shared vertices in a given spot, so it works okay.

Hope that helps,
Chris

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Thanks for the Reply Supernat02, I am starting to change my index buffer and vertex buffer routine to accomodate the changes, my normals are all crazy now so I have some bizzare shading I have to work with.

Raloth, My texture wraps fine, the problem is that the texture is being mirrored and flipped instead of wrapping.

Feeding DirectX approx 2x the number of vertices per terrain seems intensive, but at least I can get it working =)

Share this post


Link to post
Share on other sites
Raloth    379
Ummm...?

If you have vertices like this:

. . . . .
. . . . .
. . . . .
. . . . .
. . . . .


You can give them texture coordinates like this:

0,0 1,0 2,0 3,0 4,0 5,0
0,1 1,1 2,1 3,1 4,1 5,1
0,2 1,2 2,2 3,2 4,2 5,2
0,3 1,3 2,3 3,3 4,3 5,3
0,4 1,4 2,4 3,4 4,4 5,4
0,5 1,5 2,5 3,5 4,5 5,5
Assuming you haven''t changed any of the wrapping settings, that should take care of everything for you without you having to duplicate vertices.

Share this post


Link to post
Share on other sites
hplus0603    11356
Artists know how to create textures that tile correctly (left edge matches up with right edge; top with bottom). Thus, you don''t need to duplicate vertices; just keep going on the tiling.

Beware that some graphics cards start having poor precision after about 32x tiling, so don''t go overboard; you gotta restart from 0 (or -32) at some point.

Share this post


Link to post
Share on other sites