Matrix palettes in vertex shader

Started by
10 comments, last by Steve_Segreto 10 years, 11 months ago

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.

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

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.

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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

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.

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.

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.

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.

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.

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).

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement