• 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
spacerat

GPU Skinned Skeletal Animation Tutorial

4 posts in this topic


Today I completed a skinned skeletal animation tutorial, which is very helpful if you are just about to start with game development.

If you just started with game dev you should avoid skeletal animation for a looonnng time smile.png

Nvm, I really appreciate that someone took the time to write an article about this horrible topic wub.png . I just want to point out some stuff, you could consider if you want to update your tutorial in the future.

 

 

 


vec3 weights= gl_Color.xyz;
vec3 boneid = gl_Vertex.w * vec3( 1.0/128.0 , 1.0 , 128.0 );
boneid = (boneid - floor(boneid))*128.0;

mat4 mskin = bones[int(boneid.x)]*weights.x+
bones[int(boneid.y)]*weights.y+
bones[int(boneid.z)]*weights.z;

Some thoughts:

1. I would use custom attributes in times of shaders, no need to reuse all this fixed pipeline stuff, atleast to transport the bone weights. It would be much clearer.

2. Encoding the bone ids in the vertex.w coord is a little bit hacky smile.png A float component has 32bit, so why not use a standard 4x8bit channel. This way it is by far more robust, no magic needed, you get access to 255 bones and it uses the same bandwidth.

3. The same for the weights. Test is out with a 4x8bit channel. You have 4 channels and precision down to 0.5% for skinning, which is enough for me. If you still have issues with the precision, take 4x16bit channel, which is still less bandwidth and supports 4 channels instead of just 3.

 

Advanced:

4. If you have space for 128 bones, using matrix uniforms, then  you could use a combination of a quaternion (4 component) + position (3 component). This way you can use up to 256 bones for the same uniform param space. Btw. you dont need to tranform the quanterion into matrix in the vertex shader, you can rotate the incoming vertex directly by the quaternion.

Edited by Ashaman73
1

Share this post


Link to post
Share on other sites

Ashaman, thank you very much for your detailed reply! 

 

 


If you just started with game dev you should avoid skeletal animation for a looonnng time smile.png

 

Well, thats true from the difficulty point of view happy.png  

On the other hand, character animation is the most crucial thing that you need right at the beginning to get your game started.

Considering just having character animation and a flat plane with a few boxes (no offense to minecraft here smile.png ) already makes you having a game.

 

For making the class easy to use also for ppl just getting started with GDev, I have modified the tutorial description on top.

It also includes sample code for drawing a character, getting a bone matrix and setting a bone matrix.

 

 

 


Some thoughts:
1. I would use custom attributes in times of shaders, no need to reuse all this fixed pipeline stuff, atleast to transport the bone weights. It would be much clearer.

 

Hm.. that would require a major re-write from display-list based to VBO based.

I am not sure it would reduce the number of code-lines, but could be clearer indeed.

I cannot promise to do it anytime soon, but I certainly will post an update in case its done.

 

 


2. Encoding the bone ids in the vertex.w coord is a little bit hacky A float component has 32bit, so why not use a standard 4x8bit channel. This way it is by far more robust, no magic needed, you get access to 255 bones and it uses the same bandwidth.

 

When changing to custom attributes, this will also be done.

 

 


3. The same for the weights. Test is out with a 4x8bit channel. You have 4 channels and precision down to 0.5% for skinning, which is enough for me. If you still have issues with the precision, take 4x16bit channel, which is still less bandwidth and supports 4 channels instead of just 3.

 

Ah, in case somebody would like to change this, thats an easy one:

 

replace line 180 in mesh.h from

 

glColor3f(ps.weight[0],ps.weight[1],ps.weight[2]);
 
to
 
int w1=ps.weight[0]*255;
int w2=ps.weight[1]*255;
glColor3ub(w1,w2,255-(w1+w2));
 

Advanced:
4. If you have space for 128 bones, using matrix uniforms, then  you could use a combination of a quaternion (4 component) + position (3 component). This way you can use up to 256 bones for the same uniform param space. Btw. you dont need to tranform the quanterion into matrix in the vertex shader, you can rotate the incoming vertex directly by the quaternion.

 

That sounds advanced indeed. Might not suit for beginners in game development, but sounds like a good improvement when using the class in a commercial project.

 

Another optimization would be to preprocess the animation tracks. Rrightnow, the entire skeleton is traversed each time. Simply storing the final bone matrices in the animation tracks would already speed up the entire animation.

 

Further, you could upload the animation tracks as RGBA 16 bit float textures ( in the current version it would be one matrix = 4 pixels). Then,when sampling the texture with linear filtering, you already get the linear interpolated matrix. This would offload the entire animation from cpu to gpu.

Edited by spacerat
0

Share this post


Link to post
Share on other sites

you already get the linear interpolated matrix

This is a bad idea, because the matrix interpolation would be unkind to the rotation of bones. Therefor bone rotation is done with slerps (using quaternions). Just keep an eye on the quality of the animation, the vertex shader (where most of the gpu animation stuff is done) isn't the bottleneck in modern game engines ( fragment/pixel shader is often the bottleneck). Btw. using multi-threading to do the bone interpolation plus advanced stuff like blending,overlaying or IK on CPU really works great. Offloading whole animation sequences to the GPU might be useful only in some special case, like massive instancing of animated models etc., but if animation quality is more important, than doing most of the complex stuff on the CPU might be the better and easier solution.

Edited by Ashaman73
0

Share this post


Link to post
Share on other sites

This is a bad idea, because the matrix interpolation would be unkind to the rotation of bones. Therefor bone rotation is done with slerps (using quaternions). Just keep an eye on the quality of the animation, the vertex shader (where most of the gpu animation stuff is done) isn't the bottleneck in modern game engines ( fragment/pixel shader is often the bottleneck). Btw. using multi-threading to do the bone interpolation plus advanced stuff like blending,overlaying or IK on CPU really works great. Offloading whole animation sequences to the GPU might be useful only in some special case, like massive instancing of animated models etc., but if animation quality is more important, than doing most of the complex stuff on the CPU might be the better and easier solution.

 

Yes, in case of large angles and long interpolation times between two keyframes you might certainly figure out a difference between slerp and linear. 

In the tutorial here, the animation is resampled to 20 keyframes per second at the beginning. It takes a bit more memory, but I havent figured out an issue yet when interpolating linearly, since the keyframes are very close to each other.

 

In case you add complex stuff like rag doll physics etc, CPU is much more flexible of course and shader programming would be a pain in that case.

 

When benchmarking the current implementation, I found that about half the time from rendering and animation was used for the bone computation on my PC. Maybe pre-calculating the positions/rotations (as written previously) could help, switching to quaternions or also optimizing the math for SSE.

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