Web Toolbar by Wibiya

Animations don't work on Xna


A place to ask questions or discuss issues relating to implementing applications with Axiom. If you are unsure of where to post, post here.

Team Member
Team Member

Posts: 213

Joined: Tue Nov 17, 2009 1:56 pm

Post Tue Nov 09, 2010 6:13 pm

Animations don't work on Xna

Alright, I really need to get this fixed. If anybody targets Xbox, you may want to pay attention to this thread.
I've created a ticket here, but to sum it up:

Animation done without the help of shaders (software animation), plays on both x86 and Xbox. The problem is the entity shrinks and is offset of it's position.

Animation done with shaders (hardware animation) works on x86 perfectly, but on Xbox any animated entity "bounces" up and down in place.

Ideas:
The math for Software animation is the same regardless of Render System, so it has to be something Xna specific. We were thinking it had something to do with Right-Hand coordinate system vs. Left-Hand. D3D uses a left-hand system, but both OpenGL and Xna use a Right-hand system.
Perhaps a Matrix is being Inverted when it shouldn't be, or vice versa, a Matrix should be getting inverted, but isn't.
Another method perhaps is to find out how offset it is, and reverse it. i.e. if we found out the scale was 5/5/5 less than it should be, then we could multiply the scale by 5/5/5. This would be a kludge, and a temporary fix, but I'm getting desperate here :)

On the hardware animation side of things, it's interesting that it works on x86. My guess is that the shader profile from Xbox is slightly different enough. So either a compatible shader would have to be created, or is has something to do with how Axiom compiles the shader-language.
This shader's taken from an XNA demo demonstrating hardware animation:
http://axiom.pastebin.com/zZBaeJhq Perhaps someone could create a test app using this shader?

In any case, this is a discussion thread. If you have any ideas/leads post them here so that this issue can be solved.
I don't believe there's a lot of people that target Xbox, but any help would be appreciated.

Team Member
Team Member

Posts: 213

Joined: Tue Nov 17, 2009 1:56 pm

Post Wed Nov 17, 2010 5:50 pm

Re: Animations don't work on Xna

Alright, I tried the XNA shader above, and it stretched the entities vertices all along the z axis :?
so, that's one lead down.

I've been looking into this SkinnedEffect c lass for XNA 4.0, so it would have to wait until Axiom is brought up to 4.0, but it looks promising.
The idea is instead of a shader, a code-behind class is filled with the needed values and that can be set on the GraphicsDevice instead of a shader.

In the meantime, or if this doesn't work (I'm sure borrillis can shoot it down, along with the rest of my hopes and dreams :P ), I'm still seeing about getting working with the current implementation of the XNA renderer.
User avatar

Team Member
Team Member

Posts: 1588

Joined: Thu Mar 02, 2006 11:29 pm

Location: Boston, MA, USA

Post Wed Nov 17, 2010 6:22 pm

Re: Animations don't work on Xna

The SkinnedEffect class you are refering too is still an Effect. It just has a .Net wrapper around the Parameters that are used to pass into the shader itself. In fact all of the built in Xna effects work that way. They have a compiled effect part as well as a .Net class wrapper. You can find the Source for all the Xna Shaders on http://create.msdn.com under the downloads.
Borrillis
The Steward of Axiom

Team Member
Team Member

Posts: 213

Joined: Tue Nov 17, 2009 1:56 pm

Post Wed Nov 17, 2010 6:42 pm

Re: Animations don't work on Xna

Well, there you go borrillis. Destroying Dreams, once again :P
I am glad to see where all the Effect's are coming from though.
User avatar

Team Member
Team Member

Posts: 1588

Joined: Thu Mar 02, 2006 11:29 pm

Location: Boston, MA, USA

Post Wed Nov 17, 2010 11:19 pm

Re: Animations don't work on Xna

My pleasure, let me know when I can be of any more assistance.
Borrillis
The Steward of Axiom

Team Member
Team Member

Posts: 213

Joined: Tue Nov 17, 2009 1:56 pm

Post Thu Nov 18, 2010 7:11 pm

Re: Animations don't work on Xna

Alright, I'm getting pissed at this. Why doesn't software animation work, that doesn't make a lick of sense. I've included a couple of screenshots where the only change made is removing the .skeleton file so as to see the difference.

Hardware animation, I've got a question. In each of the shaders I've seen the matrix used for holding bones has always been different.
In Robot Hardware skinning example: float3x4 worldMatrix3x4Array[24]
In XNA 3.1 SkinningSample: float4x4 Bones[MaxBones]
In XNA 4.0 SkinningEffect shader: float4x3 Bones[SKINNED_EFFECT_MAX_BONES]

why are every single one a different size?

Anway, those screenshots I was smoking about:

Skeleton Removed (correct scale/position)
http://img268.imageshack.us/i/skellynoskeleton.png

Skeleton Present (incorrect scale/position)
http://img442.imageshack.us/i/skellywithskeleton.png/
User avatar

Team Member
Team Member

Posts: 1588

Joined: Thu Mar 02, 2006 11:29 pm

Location: Boston, MA, USA

Post Thu Nov 18, 2010 10:57 pm

Re: Animations don't work on Xna

I think I can shed a little light on some of this:

DoubleA wrote:Alright, I'm getting pissed at this. Why doesn't software animation work, that doesn't make a lick of sense. I've included a couple of screenshots where the only change made is removing the .skeleton file so as to see the difference.

The Skeleton files makes the difference. It provides the scaling and positioning difference that you see. All the mesh verticies are offset by the bone they are attached to.
DoubleA wrote:Hardware animation, I've got a question. In each of the shaders I've seen the matrix used for holding bones has always been different.
In Robot Hardware skinning example: float3x4 worldMatrix3x4Array[24]
In XNA 3.1 SkinningSample: float4x4 Bones[MaxBones]
In XNA 4.0 SkinningEffect shader: float4x3 Bones[SKINNED_EFFECT_MAX_BONES]

why are every single one a different size?

Robot was originally a CG program that was written using the VS1_1 profile, the 24 is because that is the largest it could be under that profile.
The other major difference is the float4x3 vs float4x4, and if I'm not mistaken the w component is hardcoded to 1.0 in the float4x3 shader.
Borrillis
The Steward of Axiom

Team Member
Team Member

Posts: 213

Joined: Tue Nov 17, 2009 1:56 pm

Post Thu Nov 18, 2010 11:08 pm

Re: Animations don't work on Xna

Borrillis wrote:The Skeleton files makes the difference. It provides the scaling and positioning difference that you see. All the mesh verticies are offset by the bone they are attached to.

But using the exact same .skeleton renders the correct size/position on DX9/OpenGL.
Why only on XNA does it do this?
Borrillis wrote:Robot was originally a CG program that was written using the VS1_1 profile, the 24 is because that is the largest it could be under that profile.
The other major difference is the float4x3 vs float4x4, and if I'm not mistaken the w component is hardcoded to 1.0 in the float4x3 shader.


Right, I understand the max_bones thing. and the profile limit.
I've mentioned this before, but worldMatrix3x4Array is a really weird variable name for a variable meant to hold bones.
Anway, a new question:
  Code:

    float4x3 skinning = 0;

    [unroll]
    for (int i = 0; i < boneCount; i++)
    {
        skinning += Bones[vin.Indices[i]] * vin.Weights[i];
    }

    vin.Position.xyz = mul(vin.Position, skinning);
    vin.Normal = mul(vin.Normal, (float3x3)skinning);


this is from the SkinnedEffect.fx, I'm just curious why they typecasted skinning to float3x3

Team Member
Team Member

Posts: 213

Joined: Tue Nov 17, 2009 1:56 pm

Post Sun Nov 21, 2010 9:26 pm

Re: Animations don't work on Xna

Alright, so borrillis confirmed that, using hardware animation, Xbox bones load slightly differently than PC bones. The weird thing is that the variable is filled from the exact same source (SubEntity.cs line 725, if I'm correct; of course it does go back farther than that), however this is not part of a #if (XBOX) or anything similar, so the same value should be getting passed, again terribly weird.

Software animation, no progress. Some speculation, that applies to both hardware and software: the Xbox using the compact CLR, so it doesn't run code in the same way that the normal CLR/Mono does. I'm wondering if perhaps it's a bug, or a "feature" of Compact .Net that is causing skewed values.
I recall that events are particularly different on compact, behind the scenes. Skeletons are loaded via an event, if I'm reading the source correctly, so that may something to look into.

Team Member
Team Member

Posts: 213

Joined: Tue Nov 17, 2009 1:56 pm

Post Tue Nov 30, 2010 3:18 pm

Re: Animations don't work on Xna

We have a new lead, based off this article here: http://thomas.decroyere.be/post/BinaryR ... x-360.aspx

The short, non-technicality version, because Xbox uses a PowerPC processor, whereas Windows uses intel, bytes are arranged differently when using the class BinaryReader. Because the skeleton importer uses BinaryReader, it may be loading values incorrectly.

I changed the Encoding of the BinaryReader in OgreSkeletonImporter.ImportSkeleton() to System.Text.Encoding.BigEndianUnicode. It's having problem's reading strings because the new-line character doesn't match up, but I'm looking into it. If you know how to check the new-line character in unicode, let me know.

Return to General Q & A

Who is online

Users browsing this forum: No registered users and 1 guest

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.