Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Tutorial - FastBone Shader GPU Animation

Author
Message
MMM
15
Years of Service
User Offline
Joined: 21st Jan 2009
Location: NSW, Australia
Posted: 18th Apr 2012 08:58 Edited at: 30th Apr 2012 15:26
I finally wrote one! Find PDF attached.

Similar discussion here.

My production cycles are getting longer and more complex so I figured I better record what I've done as I go - to help remember it when something breaks. This particular issue was a major pain for almost two weeks and the documentation on it is scattered to the wind. So I wrote this 5-min refresher-tutorial for myself. Suddenly I realised almost none of the work therein is mine... So, on giants' shoulders, I figured I'd share here.

I'm hoping someone will proof-read this for me and bring to attention any major mistakes or misconceptions I've made. Otherwise, use it however you like; this stuff should really be common knowledge.

Cheers.



EDIT: added extra note on setup; thanks GG!

Attachments

Login to view attachments
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 18th Apr 2012 09:44
Excellent tutorial!
Btw, have you got a tutorial on how to mix two animations? Like look up while running?
MMM
15
Years of Service
User Offline
Joined: 21st Jan 2009
Location: NSW, Australia
Posted: 18th Apr 2012 17:49
Thanks Handy! Use Enhanced Animations for ripping and mixing animations based on limbs. I can confirm EA is compatible with vertex shaders like these. It comes with good examples. If you want to mix animations in the shader without EA... Well that's an issue all of its own and probably one best discussed elsewhere with more knowledgeable people than I. For now, I can only imagine the main hurdle would be gathering the two different mesh sets from each animation for importing into the shader. Surely such information cannot be stored during the graphics-rendering process? Though I only say that without an operational understanding of how EA works.
Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 18th Apr 2012 19:42
Nicely put together doc with justification. I'll definitely try out fastbone when I get back into animation and look back at this tute for ideas on integration. Thanks for your efforts.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Apr 2012 01:22
A good place to start is VanB's demo posted a few years back - attached.

DBPro now supports a larger BonePalette by the way - I think you can increase the 32 to something like 60.

If you have FPSC have a look in

C:\Program Files (x86)\The Game Creators\FPS Creator\Files\effectbank\bumpbone

or wherever it is on your system.

Attachments

Login to view attachments
MMM
15
Years of Service
User Offline
Joined: 21st Jan 2009
Location: NSW, Australia
Posted: 19th Apr 2012 03:52
Cheers Fallout, if this helps with Carnage it'll all be worth it.

GG - knew I forgot something! Have updated the file in first post with a setup note for BonePalette. But I'll admit I've had problems when messing with BonePalette. Is the hard-number (32, 60, etc) compatible with any bone structure? Or is it specific to the bone structure of the target object? If the latter, how would one determine which number to specify? For that matter, what are the pros and cons of the various available values? The operational workings of BonePalette elude me.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Apr 2012 14:32 Edited at: 19th Apr 2012 14:48
Quote: "The operational workings of BonePalette elude me."


Me too.

I believe the number relates either to the maximum length of any given bone heirarchy in your model or to the total number of bones in the model - or perhaps something else entirely. It's an upper limit of some sort so if 32 works for your model then leave it at 32 - but more complicated models might need 60 (and I believe that is the maximum value which DBPro supports). You could just experiment with different vales and see what happens.

Edit You could have a look at the MS DX9 docs. Here's an extract from my copy of the SDK:

Quote: "Rendering with Fixed-Function Non-Indexed Skinning

When this skinning technique is active, the device can load up to four world matrices at a time and transform the vertices influenced by those four matrices. After these vertices are rendered, a different set of matrices can be loaded, and vertices influenced by the second set of matrices can be rendered. This rendering process continues until all faces of the mesh are rendered. GenerateSkinnedMesh calls ID3DXSkinInfo::ConvertToBlendedMesh which divides a mesh's faces into attribute groups. Each attribute group identifies geometry influenced by a particular set of four matrices. At render time, each attribute group can be rendered with a single IDirect3DDevice9:rawIndexedPrimitive.

For non-indexed skinning, DrawMeshContainer loops through each attribute group in the mesh and renders one attribute group at a time. The mesh is set up so that each attribute group is influenced by up to four matrices. Before the vertices can be sent to the device, the influencing matrices first need to be sent to the device. To set the matrices, IDirect3DDevice9::SetTransform is called with the transformation type D3DTS_WORLDMATRIX(i), where i ranges from a minimum of 0 to a maximum of 3. The matrices that the function sends to the device for a particular attribute group are obtained from pBoneCombinationBuf of the mesh container. This member points to a buffer containing an array of type D3DXBONECOMBINATION. Each D3DXBONECOMBINATION identifies the bone matrices influencing this attribute group. With this information, the sample knows which four matrices to load on the device to properly render an attribute group. Before actually setting the matrices, however, the matrices need to have the bone offset matrices applied to them. Recall that bone offset matrices transform the vertices from the mesh's default pose on the disk to the parent bone's frame of reference. Therefore, a matrix that gets sent to the device is the product of the bone matrix and the frame's combined transformation matrix. After loading the matrices, the faces of the attribute group can be rendered by calling ID3DXBaseMesh:rawSubset.

Rendering with Fixed-Function Indexed Skinning

With the fixed-function indexed skinning, the device has a matrix palette. The size of the palette can be obtained from the device capability information. The application can load as many matrices as the palette could hold. Each vertex in the mesh has up to four indices to identify the matrices in the palette that influence the vertex. In the sample, the code uses a maximum 12-matrix palette. Using a larger palette is more efficient, but using a smaller palette makes the code compatible with more devices. To obtain a mesh suitable for indexed skinning, GenerateSkinnedMesh calls ID3DXSkinInfo::ConvertToIndexedBlendedMesh (which is similar to ID3DXSkinInfo::ConvertToBlendedMesh) but it takes a palette size and divides the mesh vertices into attribute groups to work with the matrix palette. Each attribute group is influenced by one specific set of matrices that can fit in the palette, and can be drawn with a single IDirect3DDevice9:rawIndexedPrimitive.

The render code for indexed skinning looks extremely similar to the non-indexed case. GenerateSkinnedMesh loops through the attribute groups and sets up the matrices to send to the device, just as it would for non-indexed skinning. Here, each attribute group identifies the vertices influenced by a particular set of matrices in the palette. In the D3DXBONECOMBINATION array, each element identifies the bone matrices with which to load the palette when rendering this attribute group. After the matrices are set, this attribute group's faces are rendered with a call to ID3DXBaseMesh:rawSubset."


Edit2 I see the forum engine has replaced ": D" (with no space ) with this "". Can't have everything I suppose.
MMM
15
Years of Service
User Offline
Joined: 21st Jan 2009
Location: NSW, Australia
Posted: 21st Apr 2012 13:18
(no issue here - always running with smilies turned off)


That info makes it sound like in-shader animation blending is possible after all. No idea how, though.

All I can add at this stage is that I'm running objects through shaders with vertex animation of bone-counts up to 66 with a palette definition of 32. So it's not based on bone-count. None of the heirarchies reach 32 bones, sure, but using a number higher than 32 breaks the shader - which, as the documentation above suggests, should make it a hardware issue. I'm using a dual Nvidia GTX 260m. So, a laptop. But whatever; like you say, jab the numbers until they work. Or better yet... Just stick with 32 until it breaks.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Apr 2012 13:25
Try 60 - that's what DBPro uses now. For example this is what the builtin stencilshadowbone.fx shader uses:

MMM
15
Years of Service
User Offline
Joined: 21st Jan 2009
Location: NSW, Australia
Posted: 24th Apr 2012 12:27
Okay then, the "60" value appears to work. Caveat; the "60" value will not work properly with a shader that has been set up to use the "32" value - it will compile and run, but with unexpected results. In my test case, this means the code as per GPU animation returning odd normals.

Considering the problems I'm having in my other thread, I don't think I can afford to get bogged down testing this right now except to say anyone modding their shaders with GPU animation code should be mindful of the BonePalette type their original shader uses and observe the results they get when using the code in the tutorial.
Zwarteziel
13
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 24th Apr 2012 12:45 Edited at: 24th Apr 2012 16:08
Hello,

thank you for this tutorial. I've recenly added the fastbone-shader to my project and it has sped up animation quite well. As I'm both relatively new to DBPro and shaders I'd like to ask a question that is related:

Although objects that are rendered by the shader animate well, it seems they're not affected by the DBPro's native lighting-functions any longer. Thus, objects that (in my case) used to fade nicely into the distance etc, suddenly can be seen from extremely far away, while other (non-shaded, static) objects still fade like they should.

What would be my best course of action?
- Add the static objects to the shader?
- Remove the current lightning-system and switch to one that is built solely using shaders? And if so... do I need to integrate these functions with the fastbone.fx-file?
MMM
15
Years of Service
User Offline
Joined: 21st Jan 2009
Location: NSW, Australia
Posted: 27th Apr 2012 06:12 Edited at: 27th Apr 2012 06:15
Sorry its taken me so long to reply, Zerotown - engaged elsewhere. Your problem is common to many (if not all) shaders that don't compute lighting internally. There are heaps of ways you can overcome the problem and achieve the results you want but I don't know of any fix-all solutions that will work with every shader. It depends on your individual circumstances - try searching, based on your specific shader or your specific lighting needs.

One thing I can say: if you start integrating extra techniques into your shader (maybe depth-mapping for shadows or something) then, yes, you'll usually have to implement the shader-animation code into each technique. This is where you have to be careful with your WorldVP declaration (I've made a note in the tutorial) because that projection matrix has to be set to the current camera used for the individual technique - not just the generic "WorldViewProjection" camera. It's not an issue with every shader though, just keep it in mind.
Zwarteziel
13
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 27th Apr 2012 09:17
Hi MMM,

thank you very much for your reply. I do intend to take an extensive 'survey' of our forum and read up on all that has been writtten about the subject. Your tutorial has provided a good start and is much appreciated. I have good hope I'll have something working soon, since my initial shading-needs are very basic: I'd like to use the fastbone-shader to gain a little extra speed and add some simple lighting.

Login to post a reply

Server time is: 2024-04-18 15:31:53
Your offset time is: 2024-04-18 15:31:53