Jump to content
  • Advertisement
Sign in to follow this  
Aardvajk

Matrix palettes in vertex shader

This topic is 1865 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'm writing a 3D modeller at the moment so am trying to find a way to support as many joints as possible in a model since I can't just restrict to a domain-specific sensible number like you could in a game.

 

This is DirectX 9.0 by the way, should probably stress that.

 

The only way I've ever known how to get this data into a shader is an array of matrices as a global in the shader that is written to prior to the render. However, seems (obviously) there is a fairly strict limit on how much you can allocate for global data in a shader and I also don't know if this will vary from hardware to hardware so hard to know what I can rely upon here. On my laptop I can't get more than about 40 matrices in an array before it bombs out.

 

Just wondering what other approaches people are aware of to get this matrix data into the shader. I know I can reduce things by just inputting a quaternion and a translation vector, but that is still going to take half as many (registers?) as a matrix so will still have a hard limit.

 

I'm toying with the idea of using a floating point texture to store a list of pairs of quaternion and translation vectors, using 8 texels per joint, but just wanted to see if there were more obvious solutions I'm missing? I'd rather avoid software processing of the model for animation since I can't predict the model size/complexity so need it as performant as possible.

 

Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement

As far as I'm aware, on D3D9 hardware, vs_3_0 texture fetches are your only option.

 

3.0 vertex texture look-ups aren't the fastest, so you'll have to try and see if performance becomes an issue.

 

ftp://download.nvidia.com/developer/Papers/2004/Vertex_Textures/Vertex_Textures.pdf

 

Thanks eppo, nice to have some confirmation that I'm on the right track. Appreciate it won't be as fast but hopefully a good compromise. Can maybe combine the existing system with a texture fetch if the branching doesn't make the performance even worse.

Share this post


Link to post
Share on other sites

Another option may be to live with the VS constants limit and split the model into multiple draw calls instead.  Of course, then you get extra draw call overhead so there's a balancing act involved, but on DX10+ class hardware draw calls are cheaper, even if using D3D9 so you may come out on the right side of it.

Share this post


Link to post
Share on other sites

Another option may be to live with the VS constants limit and split the model into multiple draw calls instead.  Of course, then you get extra draw call overhead so there's a balancing act involved, but on DX10+ class hardware draw calls are cheaper, even if using D3D9 so you may come out on the right side of it.

 

Yes, I'm leaning towards this now. If I sort the model based on joint number, I should then be able to divide it up into a set of renders that keep the number of matrices in the array down to a reasonable number. Seems better than some exotic system using floating point textures and lookups.

 

This will actually be fine - the overhead I want to avoid per-frame is reconstructing the vertex buffers. Splitting a model into a few draw calls should be negligable.

 

Thanks.

Share this post


Link to post
Share on other sites

On my laptop I can't get more than about 40 matrices in an array before it bombs out.

 

DX9 hardware supports 256 vertex shader constants.

 

Assuming a 4x3 matrix for each bone transform, that should get you at best 256/3 = 85 matrices with one constant left unused.

 

That's not very realistic though. At a minimum you want 4 constants for the World-View-Projection transform, and probably a few more than that for other stuff.

 

Based on that, 80 matrices is a reasonable goal, and 70 should fit easily.

Share this post


Link to post
Share on other sites

On my laptop I can't get more than about 40 matrices in an array before it bombs out.

 

DX9 hardware supports 256 vertex shader constants.

 

Assuming a 4x3 matrix for each bone transform, that should get you at best 256/3 = 85 matrices with one constant left unused.

 

That's not very realistic though. At a minimum you want 4 constants for the World-View-Projection transform, and probably a few more than that for other stuff.

 

Based on that, 80 matrices is a reasonable goal, and 70 should fit easily.

Thanks for the info.

Share this post


Link to post
Share on other sites

As far as I'm aware, on D3D9 hardware, vs_3_0 texture fetches are your only option.

 

3.0 vertex texture look-ups aren't the fastest, so you'll have to try and see if performance becomes an issue.

 

ftp://download.nvidia.com/developer/Papers/2004/Vertex_Textures/Vertex_Textures.pdf

 

It's not that vertex texture lookups are slow if you use vs_3_0, it's that the earliest SM3.0 hardware that supported vertex texture fetch was really slow at it (Nvidia 6000 and 7000 series). Any DX10 or higher GPU will have no problem with sampling textures in a vertex shader.

Share this post


Link to post
Share on other sites

As said before you should consider having your modeler split the model into different "skin partitions" where the vertices of each skin partition use at most say 60 bone transforms, also I think you should consider encoding the matrix palette transforms as a quat rotation + translation to take up half as many registers.

Share this post


Link to post
Share on other sites

also I think you should consider encoding the matrix palette transforms as a quat rotation + translation to take up half as many registers.

 

That's a tradeoff as you're going to need to convert it to a matrix for each bone in your vertex shader, so you could end up with less storage but at a cost of a high additional per-vertex computational overhead (if hardware supported quaternion transforms it would be different, of course).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!