Jump to content
  • entries
  • comments
  • views

RH to LH, texture coord oddities, and instancing

Sign in to follow this  


MS3D model geometry is now loaded correctly. One problem I did encounter was that the models are stored in a right-handed coordinate system, but the game uses a left-handed coordinate system. This means that the x coordinate is pointing in the wrong direction, basically. I initially tried to solve this by inverting the x coordinate of all vertices in the model. I was a bit surprised to find that the model appeared to have turned itself inside-out! After a bit of discussion in the #gamedev IRC channel, I figured out what the problem was: The triangles were wound in the wrong direction. This was fixed easily enough by reversing the order of the vertices of each triangle, and the model was no longer inside-out.

While adding in texture support, I discovered some rather odd things. First off, the U and V texture coordinates are named "s" and "t". After doing some poking around, I think this is an OpenGL thing. Trying to find the texture coordinates was a bit confusing at first though.

The second odd thing is that texture coordinates for each vertex are stored per triangle, not per vertex. This means that a single vertex can have multiple texture coordinates. I suppose this makes sense, since you may want two triangles which share a vertex to have completely unrelated textures. It did goof up my usual way of doing things though, and I had to scrap my indexed drawing code since each vertex of each triangle needs to be stored. There may be a way for me to split up the geometry data and the material data using stream frequencies, but further investigation along those lines will have to wait for the moment.

Texturing isn't completely working yet. Coordinates are stored fine, but the same texture is used for every model. Also, no other material properties are currently in use. I will probably get these things working correctly after skinning is in.

The method of instancing which I am using involves separating the model data and per-instance data into different vertex buffers. The model data is stuff like vertex position, texture coordinates, etc. and per-instance data is the world transformation matrix and anything else which differentiates instances of the same model. Stream frequencies are then setup so that one "vertex" of instance data is applied to the entire model.

This was my first time working with multiple streams, so I suppose it's not surprising that I made a newbie blunder. After the instancing code was all finished, the model wouldn't appear. I spent some time trying to figure out what went wrong, but everything checked out... I eventually found the culprit though: When creating the vertex declaration, I didn't start the offset over at 0 when I started specifying stream 1 elements. This caused all of the "vertices" in stream 1 to have a chunk of padding at their beginning equal in size to the stream 0 vertex size.

[size="1"]Reposted from http://invisiblegdev.blogspot.com/
Sign in to follow this  


Recommended Comments

There are no comments to display.

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
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!