• 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
Anand Baumunk

[Optimising] Bone based Animation

5 posts in this topic

Well met!

 

I recently started to optimise my Engine. Using VS2012 Performance analysing tool, I quickly found the biggest bottlenecks.

 

By far the biggest one are my animations. I already managed to go up from 100Fps with 1 simple animated model to 150Fps with 50. While that is not bad, I still need it to get better. 

I fixed everything I could, but I don't know how to continue. The major performance-eaters are 

 D3DXQuaternionInverse

and

 D3DXQuaternionMultiply

which are an essential part of the computation that bone-based animations need, right?

Is there a way to work around those or are there cheaper ways to compute bb animations?

 

Those two take around 50%, the other 50% are beeing lost to stuff like

tempVert->pos.x += ( tempJoint->pos.x + rotatedPoint.x ) * tempWeight->bias;
// or
tempVert->normal.x -= rotatedPoint2.x * tempWeight->bias;
// or
currentSubset->vertices[i]->normal = -tempVert->normal;

( All CPU % in %-of-the-full-time in an uncapped application )

With 5% of the complete CPU time each. I don't understand why those are so very expensive.

Stuff like sqrt, sin and maybe even / are concidered expensive, but why are the basic math operations also a problem?

I am adding the full code of the function in question below, adding the % of CPU to the end of each line which is over 0.1%.

I tried to make it as readable as possible, but the Copy-paste into this forum still screws it up, I'm sorry.

 

[spoiler]

uint numVCurrentSubset;
Vertex *tempVert;
Weight* tempWeight;
joint* tempJoint;
D3DXQUATERNION tempJointOrientation, tempWeightPos, tempJointOrientationConjugate, tempWeightNormal;
D3DXVECTOR3 rotatedPoint;
D3DXQUATERNION temp1, temp2;
D3DXVECTOR3 rotatedPoint2;
D3DXQUATERNION temp3, temp4;
ModelSubset *currentSubset;
 
for ( int k = 0; k < numSubsets; k++){
currentSubset = subsets[k];
numVCurrentSubset = currentSubset->vertices.size();
for ( uint i = 0; i < numVCurrentSubset; ++i ){
tempVert = currentSubset->vertices[i]; // ---- 0.3%
tempVert->pos.x = 0.0f; tempVert->pos.y = 0.0f; tempVert->pos.z = 0.0f;
tempVert->normal.x = 0.0f; tempVert->normal.y = 0.0f; tempVert->normal.z = 0.0f;
 
// Sum up the joints and weights information to get vertex's position and normal
for ( int j = 0; j < tempVert->WeightCount; ++j ){ // ---- 0.6% (only this line, not whole loop)
 
tempWeight = currentSubset->weights[tempVert->StartWeight + j]; // ---- 0.5%
tempJoint = interpolatedSkeleton[tempWeight->jointID]; // ---- 0.5%
 
 
 
// Convert joint orientation and weight pos to vectors for easier computation
tempJointOrientation.x = tempJoint->orientation.x;
tempJointOrientation.y = tempJoint->orientation.y;
tempJointOrientation.z = tempJoint->orientation.z;
tempJointOrientation.w = tempJoint->orientation.w;
 
tempWeightPos.x = tempWeight->pos.x;
tempWeightPos.y = tempWeight->pos.y;
tempWeightPos.z = tempWeight->pos.z;
tempWeightPos.w = 0.0f;
 
 
// We will need to use the conjugate of the joint orientation quaternion
D3DXQuaternionInverse(&tempJointOrientationConjugate, &tempJointOrientation); // ---- 20.0%
 
// Calculate vertex position (in joint space, eg. rotate the point around (0,0,0)) for this weight using the joint orientation quaternion and its conjugate
// We can rotate a point using a quaternion with the equation "rotatedPoint = quaternion * point * quaternionConjugate"
D3DXQuaternionMultiply(&temp1, &tempJointOrientation, &tempWeightPos); // ---- 3.5%
D3DXQuaternionMultiply(&temp2, &temp1, &tempJointOrientationConjugate); // ---- 3.5%
rotatedPoint.x = temp2.x;rotatedPoint.y = temp2.y;rotatedPoint.z = temp2.z;
 
// Now move the verices position from joint space (0,0,0) to the joints position in world space, taking the weights bias into account
tempVert->pos.x += ( tempJoint->pos.x + rotatedPoint.x ) * tempWeight->bias; // ---- 5.1 % (???)
tempVert->pos.y += ( tempJoint->pos.y + rotatedPoint.y ) * tempWeight->bias;
tempVert->pos.z += ( tempJoint->pos.z + rotatedPoint.z ) * tempWeight->bias;
 
// Compute the normals for this frames skeleton using the weight normals from before
// We can comput the normals the same way we compute the vertices position, only we don't have to translate them (just rotate)
tempWeightNormal.x = tempWeight->normal.x;
tempWeightNormal.y = tempWeight->normal.y;
tempWeightNormal.z = tempWeight->normal.z;
tempWeightNormal.w = 0.0f;
 
// Rotate the normal
D3DXQuaternionMultiply(&temp3, &tempJointOrientation, &tempWeightPos); // ---- 4.6 %
D3DXQuaternionMultiply(&temp4, &temp3, &tempJointOrientationConjugate); // ---- 6.2 %
rotatedPoint2.x = temp4.x; rotatedPoint2.y = temp4.y; rotatedPoint2.z = temp4.z;
 
// Add to vertices normal and ake weight bias into account
tempVert->normal.x -= rotatedPoint2.x * tempWeight->bias; // ---- 4.9 %
tempVert->normal.y -= rotatedPoint2.y * tempWeight->bias;
tempVert->normal.z -= rotatedPoint2.z * tempWeight->bias;
 
}
 
currentSubset->vertices[i]->pos = tempVert->pos; // -- 0.3%
currentSubset->vertices[i]->normal = -tempVert->normal; // --- 6.1 %
//D3DXVec3Normalize(&currentSubset->vertices[i]->normal, &-tempVert->normal); // can be done on GPU, otherwise ---- 15.0%
 
}
 
// Put the positions into the vertices for this subset
for(uint i = 0; i < numVCurrentSubset; i++){ // ---- alltogether 5%, but I can work around this one
currentSubset->verts[i].pos = currentSubset->vertices[i]->pos;
currentSubset->verts[i].normal = currentSubset->vertices[i]->normal;
currentSubset->verts[i].texcoord = currentSubset->vertices[i]->texCoord;
}
 
 
// Copy to the GPU
   D3D11_MAPPED_SUBRESOURCE mappedVertBuff;
   d3dev->devCon->Map(currentSubset->vertBuff, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedVertBuff);
VertexPosNormalTex *updatedV; updatedV = (VertexPosNormalTex *)mappedVertBuff.pData;
 
memcpy(updatedV, currentSubset->verts, numVCurrentSubset*sizeof(VertexPosNormalTex));
 
d3dev->devCon->Unmap(currentSubset->vertBuff, 0);
}
 

[/spoiler]

 

 

I am new to profiling and optimising, so any tips are welcome! 

Thanks for your time!

 

0

Share this post


Link to post
Share on other sites

I suppose that would be a good idea. I never did that because I somehow assumed that pushing "all that stuff" to the GPU would create as much traffic as this eats away CPU.

 

So, how do I go about it. I update only the bones on the CPU, then I push those to the GPU (per model in a constant buffer) and just add weight-information to each vertex.

Can I do the computation on the Vertex-Shader or should I use a computation shader? 

0

Share this post


Link to post
Share on other sites


I suppose that would be a good idea. I never did that because I somehow assumed that pushing "all that stuff" to the GPU would create as much traffic as this eats away CPU.

 

All you have to do is send the bone transformations to the GPU, which is going to be significantly less data than having to send an entire mesh worth of skinned verts each frame (assuming your meshes have more than a small handful of verts).

 


So, how do I go about it. I update only the bones on the CPU, then I push those to the GPU (per model in a constant buffer) and just add weight-information to each vertex.
Can I do the computation on the Vertex-Shader or should I use a computation shader? 

 

That's exactly right. Add weight/index info to each vert, then send bone information to the vertex shader via a constant buffer. It'll be FAR more natural to do this in the vertex shader, rather than a compute shader. Do your bone transformations on each vert, then do the regular model-view-projection transformation just like normal.

1

Share this post


Link to post
Share on other sites

Thanks a bunch Spiro, that is extremly helpfull! I'll rewrite everything using the model you mention in your other posts.

There is a good number of tutorials that use quaternions or suggest them.

That is not the first time something like that occurs. I have found a lot of tutorials that use the worst method possible. Really gotta be careful on who I listen to :/

Edited by gnomgrol
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