• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Aardvajk

Matrix palettes in vertex shader

11 posts in this topic

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.

1

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

 

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.

0

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.

2

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.

0

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.

1

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.

0

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.

1

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.

0

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

0

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

 

 

vec4	orientation	= u_quaternionArray[index];

float invS  = 2.0 / dot(orientation, orientation);
vec3 s = orientation.xyz * invS;
vec3 w = orientation.w   * s;
vec3 x = orientation.x   * s;
vec3 y = orientation.yyz * s.yzz;
			
vec4	posAndScale	= u_positionAndScaleArray[index];//xyz = translation, w = scale

mat4	objectToWorld = mat4(
        posAndScale.w * vec4(1.0 - (y.x + y.z), x.y - w.z, x.z + w.y, 0.0),
	posAndScale.w * vec4(x.y + w.z, 1.0 - (x.x + y.z), y.y - w.x, 0.0),
	posAndScale.w * vec4(x.z - w.y, y.y + w.x, 1.0 - (x.x + y.x), 0.0),
	vec4(posAndScale.xyz, 1.0));

Additional cost per vertex is not that big after all. Didn't even notice performance drop with iphone4s.  It's quite gpu friendly ALU code after all.

1

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

 

 

vec4	orientation	= u_quaternionArray[index];

float invS  = 2.0 / dot(orientation, orientation);
vec3 s = orientation.xyz * invS;
vec3 w = orientation.w   * s;
vec3 x = orientation.x   * s;
vec3 y = orientation.yyz * s.yzz;
			
vec4	posAndScale	= u_positionAndScaleArray[index];//xyz = translation, w = scale

mat4	objectToWorld = mat4(
        posAndScale.w * vec4(1.0 - (y.x + y.z), x.y - w.z, x.z + w.y, 0.0),
	posAndScale.w * vec4(x.y + w.z, 1.0 - (x.x + y.z), y.y - w.x, 0.0),
	posAndScale.w * vec4(x.z - w.y, y.y + w.x, 1.0 - (x.x + y.x), 0.0),
	vec4(posAndScale.xyz, 1.0));

Additional cost per vertex is not that big after all. Didn't even notice performance drop with iphone4s.  It's quite gpu friendly ALU code after all.

Yes I'm aware its a tradeoff. Pretty cool that kalle_h profiled it on iphone4s and was happy with the tradeoff. Honestly re-reading the OP, I shouldn't even have suggested this since they are writing a 3D modeler, not a skinned character animation/rendering engine. So really all that one would expect from a modeler program is to break the character up into skin partitions based on constraints such as matrix palette array size and texture, as well as limiting per-vertex bone weights/indices to 4 or less, as well as possibly some sort of texture map description per vertex (normal, bump, refraction, etc). How an engine consumes that data is of little interest, provided the engine does not need to do costly processing on it (such as breaking it into skin partitions to meet Vertex Shader register limitations).

Edited by Steve_Segreto
0

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0