Saturday, June 23, 2012

Animations using Instancing and Compute Shaders

The concept of Instancing was brought about in DX9, where using the same mesh you could render it again. Compute shaders was brought about when DX11 was introduced as a way to use the GPU to process non-graphics computations.

I decided that I wanted to use these features for animating my meshes. Instancing was useful because I wanted to render the same mesh in different places without using different draw calls for each mesh. And Compute shaders was very useful for computing the positions of the bones. In this case, I wanted to perform the bone computations for all the meshes in the same scene at the same time.

The use of unordered access buffers in the compute shaders made it possible for me to define a structure for the update of bones. I used this to update the bones of all the meshes.

And the use of structured buffers in the pixel shaders made it possible to read the data in anyway we wanted it to be.

In this case, I used the instance ID of the mesh to index into the bones buffer. And with GPU Skinning, the meshes are all animated

So with the combination of compute shaders for the update of skeletons, and instancing to render all the meshes alongwith their animations, I was able to animate and render 101 meshes with just one update and one draw call.

Following is a video of the result.

One major drawback for this method is that we have to load all the keyframes into the GPU when performing the Update for the skeleton.

Basic Animations

I started off constructing my basic engine. This involved setting up of the keyboard, camera handling, creation of various buffers, rendertargets etc. This was like the standard way of creating the engine.

I wanted to learn about how animations are done in graphics. So I started looking at various examples that involved animation a model based on some clip and keyframe animation and I came across the simple format from Microsoft - X Format.


http://paulbourke.net/dataformats/directx/ is a good reference for the .X Format.

Step 1: Load and render the mesh from .X file:
This step will help us see what the mesh will look like in a T-Pose.

Step 2: Load the skeleton from the .X file:
This step will load the skeleton the from the file which will be used to skin the skeleton

Step 3: Perform GPU Skinning and use weights from .X file:
A shader performs this step.

Step 4: Load the animation clips and apply movement data to the skeleton
Once this step is done, then the skeleton will be animated, which in turns animates the model. The principles of Articulated figures is used in this step.

Here is a snapshot of what the model and the skeleton looks like:
 I should give credit to Microsoft for providing this model from their DirectX SDK.

Step 5: Now I use the keyboard input to identify what animation clip to play. For Eg: if i press "Up" it plays the walk animation. If no  key is pressed, it plays the idle animation.

Only issue here is that the skeleton would suddenly start the next animation which results in a "pop" in the movement.

One way to get rid of this pop is to perform a Linear Interpolation (lerp) for some time between both the animations, during the transition. This results in a much smoother change, and looks much better. Below is a video of that demonstration.

This was my first step :). More to come soon.

Friday, June 22, 2012

So far...

I had already started working on my DX11 engine a while back (starting a year ago) and I have made some advancements in my engine. It's still very much the beginning stage, but I will try my best to make it look like what you folks have seen on Unreal Engine 4, Square Enix's new engine, etc.

My focus is actually not on the engine, but just trying to learn how to implement various techniques. I will be posting up various topics on parts of my engine, and a recap of what I've done so far.

Thursday, June 21, 2012

Launch Blog

Hey everyone,

I have decided to start my own blog about my experiments and journey with real time graphics. I want to share my experience with everyone on such interesting topics. Please provide any feedback on my experiments, or my writing about them :)