vertex compression

Started by
6 comments, last by Raloth 20 years, 3 months ago
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]
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
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.
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?
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
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?
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
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.
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?
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
I just tried the same thing and it worked fine. I''ll try and upload the code a little later.
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.

This topic is closed to new replies.

Advertisement