cronholio

Hi,

I'd like to do some simple vertex animation on a model using a vertex shader, but I'm having an extremely difficult and frustrating time figuring this out. I've been looking at the content pipeline documentation, I've found the tutorial about the BBox processor and done that a couple times, I've written a C# converter for a custom mesh format I have to X and still I can't work out how to accomplish this. I guess conceptually I understand how the content pipeline works.

I ran the X processor DLL that ships with XNA through reflector and just about had a nervous breakdown looking at all the classes in there. I write geometry exporters, importers, and deformers for Maya at my day job, so I like to think I should be able to do this, but I gotta be honest, a lot of the terminology I'm finding in the documentation and on the net is greek to me.

What I've gathered so far is that, I have to get my mesh and my per frame vertex positions and normals into a single ModelMeshPart so I can pass them to the vertex shader, I just can't work out how to do this. Can anyone help Do I have to write a whole new importer/processor/loader, is there a way I can augment the current X processor Is there anyway someone could provide a simple clear example of how this is done Anything at all would be greatly appreciated.



Re: XNA Game Studio Express Vertex Animation help

Bill Reiss

This blog post from Shawn Hargreaves of the XNA team might help.

http://blogs.msdn.com/shawnhar/archive/2006/12/07/rendering-a-model-with-a-custom-effect.aspx

There are (at least) two main ways to apply a custom effect in XNA, one is as outlined in Shawn's post, and another is to add the fx file for the effect to the project and then associate the effect with all of the ModelMeshParts in your Model.Meshes collection using code similar to this:

Model bubbleModel = content.Load<Model>("ball");
Effect bubble = content.Load<Effect>("bubble2");
bubble.CurrentTechnique = bubble.Techniques[
"Basic"];
Texture2D tex = content.Load<Texture2D>("soap");
bubble.Parameters[
"baseTexture"].SetValue(tex);
bubble.Parameters[
"cubeTexture"].SetValue(content.Load<TextureCube>("room-dxt5"));
foreach (ModelMesh m in bubbleModel.Meshes)
{
foreach (ModelMeshPart mp in m.MeshParts)
{
mp.Effect = bubble;
}
}

Then when looping through the meshes when updating and drawing the model, it might look something like this:

foreach (ModelMesh mesh in Model.Meshes)
{
foreach (Effect effect in mesh.Effects)
{
effect.Parameters["World"].SetValue(mesh.ParentBone.Transform);
effect.Parameters["View"].SetValue(view);
effect.Parameters[
"Projection"].SetValue(projection);
}
mesh.Draw();
}






Re: XNA Game Studio Express Vertex Animation help

crondog

Thanks for the reply to my late night rambling, Bill, but maybe I need to explain the issue better.

I have a mesh that I can load and display and apply effects to in an XNA project. I also have lists of point positions and normals that are stored in an ascii file that I can read into the project. These positions and normals represent per frame vertex animation data for the mesh.

My understanding is that a vertex shader operates on a single vertex at a time, and that I need to pack this animation (point and normal) data into the mesh somehow so that I can pass it to the vertex shader. The shader would be really simple. It would read in a mesh vertex and the corresponding animation point position and animation normal and then swap the point position and normal of the mesh for the current animation frame. I've found an example of this online done in Open GL and GLSL, but that doesn't help me when dealing with the content pipeline.

The issue in all this is how do I pack all this data up and get it into the shader My understanding is that the X format does not support vertex animation, so I can't pack it all up into an X file before running it through the content pipeline. If I have to write my own processor, or worse importer/processor/serialization/writer/etc; how exactly do I represent the data so that a vertex shader can access it And, more broadly, how does one write a custom mesh processor

Like I said before, I think I have a good grasp of how the content pipeline works conceptually, but the devil is in the details, right I am not a software engineer, but I like to think I am reasonably intelligent, and I'm hoping someone will be able to give me enough information to help me get this rolling :)




Re: XNA Game Studio Express Vertex Animation help

Shawn Hargreaves - MSFT

A custom processor will be the easiest way of doing this.
  • Derive from ModelProcessor
  • Override the Process method
  • Before you chain to base.Process, scan down the tree of NodeContent objects
  • Check each node to see if it is a MeshContent
  • If so, loop over its GeometryContent children (in the Geometry property)
  • Add new information to the Vertices.Channels collection of each GeometryContent
  • You'll probably want to use VertexChannelNames.TextureCoordinate(n) to look up a good name for each new channel you add (increment n for each one) - that way the data will be available to your vertex shader using TexCoord1, TexCoord2, etc, as the input semantics
  • When you chain to the base ModelProcessor, it will pack all the vertex channels from the source format into a D3D vertex buffer, and set up a vertex declaration all ready to pass them into your shader





Re: XNA Game Studio Express Vertex Animation help

crondog

Hmm, so you are suggesting stuffing the info into additional texture coords... Do you think I can avoid writing a processor by modifying my Houdini->.X convertor to stuff the information into addtional UV sets in an .X file Does the current .X processor proces multiple UV sets Is there a limit to the number of UV sets you can have on a model in .X or XNA I mean, if I wanted to do something ridiculous like having 1000 frames of vertex animation would I be able to have 2000 sets of UVs for the positions and normals

Thanks a ton, this really helps. I can't wait to get home and give it a shot.




Re: XNA Game Studio Express Vertex Animation help

Shawn Hargreaves - MSFT

The standard processor will pass through whatever vertex channels it finds in the input, so that would work fine if you can somehow get the data into your X file.

Vertex shaders can only have at most 16 input values, which includes position and normal as well as texture coordinates. So you won't be able to do many frames using this technique. This is in fact one of the reasons most modern games use skinned animation around a skeleton, rather than this kind of vertex animation tweening.

If you have shader model 3.0, there are various crazy tricks you can use to get more than 16 values into a vertex shader via encoding them into a texture, but that requires high end hardware and still isn't usually all that fast.





Re: XNA Game Studio Express Vertex Animation help

crondog

That's awesome. I really only need like 10 input values to do the tweening, I'll just be loading the mesh and at most 2 frames of animation.

I am well aquainted with the pros and cons of vertex vs skinned mesh animation, I'm just particularly interested in vertex animation for the game I want to make. Hopefully it will look different in a good way.

I really appreciate the info.




Re: XNA Game Studio Express Vertex Animation help

rusty_bone

<noob>

I didn't know there were multiple ways to animate a mesh.

Shawn,

When your animation sample gets released, will it help folks such as myself who just want to build a model in something like milkshape, add a skeleton to it, and then animate the skeleton

Or have I been barking up the wrong tree trying my hand at model creation and bone animation in milkshape

</noob>





Re: XNA Game Studio Express Vertex Animation help

Shawn Hargreaves - MSFT

Yes, our sample will play back skeletal animation, which is the most common technique used in both games and modelling/animation tools.





Re: XNA Game Studio Express Vertex Animation help

cronholio

rusty_bone wrote:

<noob>

I didn't know there were multiple ways to animate a mesh.

</noob>

Vertex animation or as some call it "tweening" is really the simplest form of animation in 3D. It's what early games that had closed character meshes like Quake used. The cool thing is it is possible to actually augment skeletal animation with vertex animation, so you can do things like complex facial expressions and what not. You can also do things like pose space deformers where you blend shapes in over a skeletal animation based on bone angles to fix bad deformations or simulate musculature. Shawn's right though, almost no one uses pure vertex animation in games anymore in part because it can be really resource intensive (a dense character with a reatively small animation set can be dozens of megs of data) and the other thing is vertex animation is pretty inflexible. Your animation is what it is. You can't blend nicely between different animations or subsets of animations as nicely as you can with bones, and you can't do procedural animation or things like rag doll physics. The one nice thing about vertex animation is that you get really low level control over the animation, so you can get really crazy with it, doing things like morphing from one character into a completely different character fairly easily.





Re: XNA Game Studio Express Vertex Animation help

rusty_bone

@Shawn

Thanks. I'll really appreciate the sample. I'm like a kid the night before Christmas waiting for it. Do you think we'll be seeing it sometime in the next 30 days or so ...or is it always going to be sometime soon

@Cron

That is some good info. Thanks.





Re: XNA Game Studio Express Vertex Animation help

cronholio

I think I found the clearest solution here....

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=890956&SiteID=1

Using this method and and possibly Multi-Streaming to the vertex shader seems to be the best way to go. You can find info on multi-streaming in the Direct X SDK help and through google, but the concept is simple, you use elements of multiple vertex streams to create a new vertex stream to feed to the vertex shader.