Jump to content
  • Advertisement

Archived

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

Raloth

vertex compression

This topic is 5329 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I understand how to compress the data but I don't know how to decompress it. I'm a little new to this vertex shader thing . When I was looking through the available instructions on the MSDN I didn't see anything that would be useful. Mostly I want to take a loss of precision and put 2 numbers into 4 bytes, but with texture coordinates I want to put 4 numbers into 4 bytes. Can anyone guide me to the proper instructions? [edited by - Raloth on January 13, 2004 6:21:20 PM]

Share this post


Link to post
Share on other sites
Advertisement
Say you want to compress a float in the range [-1,1] into a byte. You add 1 to the value, scale by 128 and store the result in a byte in your vertex struct. In the shader you simply can simply declare a float to hold the byte value. The conversion from byte to float is handled for you, nothing extra there. Then you just reverse the scale and bias to get your float [-1,1]. There is room for optimisation here though, because the decompression can be done as part of another process. E.g, if you compress the vertex position it can be decompressed in a matrix multiply. So you have your decompression matrix, if you concatenate your world-view-projection matrix with this then you can get the decompression during the position transformation for free.

AFAIK there are no specific instructions for decompression.

Share this post


Link to post
Share on other sites
I know there are no instructions designed for it. Since all of the x/z positions of these vertices lie on even numbers I wanted to store them as shorts packed together in groups of 4. I just don''t know how to put them back into two floats.

"In the shader you simply can simply declare a float to hold the byte value."

Uhhh? How do you tell the shader that it''s bytes it''s looking for and not floats? Is there another thing for the vertex shader declaration?

Share this post


Link to post
Share on other sites
Alright... I understand what you were talking about now. My one question is this: How does DirectX know you are only using bytes? Won''t the registers assume floats, so anything you do with them will also be manipulating who knows what data?

Share this post


Link to post
Share on other sites
I think you can assume that D3D will do the right thing with the conversion. I dont know exactly where it does the conversion though. D3D knows what data types the input registers are using because of the vertex declaration.

Share this post


Link to post
Share on other sites
I experimented with changing FLOAT4 to SHORT4 and changing my vertex structure appropriately, but nothing showed up afterwards. Does DirectX not do the cast to float?

Share this post


Link to post
Share on other sites
If you look here (http://geocities.com/treething/temp.htm) I uploaded a small sample that compresses the vertex position into a 4D short. Hope it helps.

Share this post


Link to post
Share on other sites

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