DirectX 11 Rigging in Shader

Started by
4 comments, last by MJP 11 years ago

Hello,

I am a hobbyist game developer and am new to gamedev.net. I have been trying to make a game engine for the last few months using DirectX 11 and c++. I followed tutorials on braynzarsoft.net and I am currently working on animation with the md5 format. I currently do skinning on the cpu which is quite expensive and I hope to do it in the vertex shader or compute shader instead. The problem is that hlsl does not allow dynamic arrays. I need to pass a list of weights and joints for the model to be skinned on the gpu but am unsure how to do it. A joint structure would just be a float3 and a float4 (position and rotation) and a weight structure would be a two float3s and a float (position, normal and bias). I know how to bind resources using constant buffers but I don't know how to bind a resource that is a data structure with a dynamic size. I read that a texture could be used but I can't seem to figure out how to fill a ShaderResourceView with my own data and then read it in the shader. Does anyone have any idea how to do this? I would greatly appreciate any help?

Advertisement

i'm not sure this will help you, but i think this may be what you are looking for:

http://msdn.microsoft.com/en-us/library/windows/desktop/ff476523%28v=vs.85%29.aspx

i personally have a fixed maximum number of bones and use the constant buffer, and send the updated matrices by mapping that buffer. calculation of those matrices from quaternions is done on cpu, only the skinning itself (vertex transformations) is done on gpu, and stored in a dx buffer using stream output.

I calculate the quaternions of the bones on the cpu. I want to pass a list of them as a resource to the shader and a list of the weights (as they are in the bind pose position). The weights would then be put in to model space in the shader and then used to calculate the vertex position and normal in model space. Then the vertex position and normal are multiplied by the model's world matrix, view matrix and projection matrix. How do you pass the weights to the shader? I could have a fixed size array of weights in a cbuffer in the .fx file. Though this might be inefficient if the number of weight varies a lot between models.

You can use a structured buffer if you want instead of an array in a constant buffer. The shader doesn't need to know how many elements are in a structured buffer (although it can ask for the size if it cares), so you can just make it however big it needs to be to fit the bones for a particular mesh.

Thanks for your reply. A structured buffer is what I need to use and I have created one but I'm not sure how to bind one to the pipeline. Should I use Unordered_Access_View or ShaderResourceView?

You'll want to use a shader resource view (SRV). SRV's are read-only views of a resource, so you would use it in a case like this where the shader only reads to it and doesn't write to it. Unorderd access views (UAV) provide read and write access, so you only use those when you need to write to a resource.

This topic is closed to new replies.

Advertisement