Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Texture/UV Transforms

Started by matthughson 1 reply 750+ views
Original Post
matthughson
matthughson
Hey Guys, I'm working on a tile engine in Managed DX and C#. I would like to use a sprite sheet for the tile map, but I would also like to avoid locking and unlock the vertex buffer every time I switch UVs (in order to access a different tile image). I came across something called texture transforms, and it seems to be what I need; a transformation applied to the UVs in the fixed pipeline. I can't seem to get it to work though, or find much documentation on the topic. Here is what I am doing:

ManD3D.m_device.Transform.Texture0 = Matrix.Translation(new Vector3(UOffSet, VOffSet, 0.0f));

// ...render mesh
This call doesn't seem to be affecting the texture coordinates at all. Am I on the right track, or completely off here? Is there a renderstate or something I need to set? Any example code would be fantastic! Thanks! Matt Hughson [Edited by - matthughson on October 15, 2005 4:47:27 PM]
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
Namethatnobodyelsetook
Namethatnobodyelsetook
Matrices for 2D vectors are slightly different. See here where I describe how to make it work.

Having said that, draw calls have a huge overhead, so setting a texture transform and world transform for each tile is going to be slow. For things like tile engines and particle systems you're better off making a dynamic vertex buffer, which is optimized for sending new vertices to the card without stalling. I briefly describe how to use a dynamic VB here. Using this technique and sprite sheets is the optimal way to do a tile engine. Mix in alphatesting to get shaped sprites with accurate Z buffering, and you're all set.
MasterWorks
MasterWorks
Dynamic VBs are definitely the way to go, as Namethatnobodyelsetook said. I don't think the texture transform matrices are going to help you here. With a dynamic VB, you'll be recreating all the vertices for all the sprites every frame so you can use whatever TU/TVs you would like. This makes animation with a sprite sheet very easy also.

Eventually you could use a dynamic index buffer in combination so that you can render 2 triangles with 4 vertices instead of 6.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.