Jump to content
  • Advertisement
Sign in to follow this  
LevyDee

Shader Animation

This topic is 2534 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

Apparently the cool thing to do with skeletal animation systems is to unload them from the CPU over to the GPU. This being done using a vertex shader.

So I have been working on my own skeletal system for a while now, and am to the point where all I need to do is fill my shader with the bone transforms.

Each vertex is associated with a specific bone/s.

My question is, how would one go about removing an arbitrary bone limit on a vertex using shaders to animate? Right now, all I can think of is to pass my bone association in using multiple TEXTURECOORD semantic variables, but that is limited to 8(i think).

A related question as well, how many matrices can you fit into a vertex shader? I think there are limits to how many variables you can have in a shader right?

Thanks!

Share this post


Link to post
Share on other sites
Advertisement
You can probably find the limits using glGet* with something like [color=#000000][font=monospace]

GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS,

[/font][color=#000000][font=monospace]

GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS,

[/font][color=#000000][font=monospace]

GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, or

[/font][color=#000000][font=monospace]

GL_MAX_VERTEX_UNIFORM_COMPONENTS

[/font]

Share this post


Link to post
Share on other sites
I am assuming the gl prefix means your are using openGL? Sorry, I should have clarified in my original post, I am using Directx9 and HLSL.

Share this post


Link to post
Share on other sites
Usually when doing GPU skinning, you dictate a maximum number of bone associations per vertex. The most common value I've seen for this is 4, which only requires one 4D texcoord to hold the bone indices and one 4D texcoord to hold the weights.

IIRC DirectX9 cards must support a minimum of 256 float4 constants (though specific cards may provide more, which you can see with D3DCAPS9.MaxVertexShaderConst).

If you represent your bones as mat4x4's, then you can only fit 64 (and no other data). Usually, you'll "compress" them into mat4x3's instead, so you can fit up to ~80 bones. There are also more advanced compressions like dual-quaternions, that get up to 128 bones if your math is up to the job ;)

Usually if bone-limits become a problem, then you simply split the mesh into two parts and draw it in two draw-calls, each with a section of the skeleton.

Share this post


Link to post
Share on other sites

Usually when doing GPU skinning, you dictate a maximum number of bone associations per vertex. The most common value I've seen for this is 4, which only requires one 4D texcoord to hold the bone indices and one 4D texcoord to hold the weights.

IIRC DirectX9 cards must support a minimum of 256 float4 constants (though specific cards may provide more, which you can see with D3DCAPS9.MaxVertexShaderConst).

If you represent your bones as mat4x4's, then you can only fit 64 (and no other data). Usually, you'll "compress" them into mat4x3's instead, so you can fit up to ~80 bones. There are also more advanced compressions like dual-quaternions, that get up to 128 bones if your math is up to the job ;)

Usually if bone-limits become a problem, then you simply split the mesh into two parts and draw it in two draw-calls, each with a section of the skeleton.


Thank you for the response, you answered my question exactly as I was concerned. Thanks =)

Share this post


Link to post
Share on other sites
Another option is to store your bone matrices in a texture. On DX9-era GPU's it's either slow or not possible to sample a texture in a vertex shader, but DX10-era GPU's can do it just fine.

Share this post


Link to post
Share on other sites
Or you can use texture buffers. They are basically constant buffers but the memory access is done via the texture fetching pipeline (so you need a view). This prevents constant waterfalling (serialization of memory accesses if threads fetch different constants at the same time). The Skinning10 Sample of the DxSDK shows how it is used. (The texture approach is shown there, too.) However, you still have the same memory limit as with constant buffers.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!