XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

shaders and skinned animation

Last post 3/6/2009 9:11 PM by HerrUppoHoppa. 5 replies.
  • 3/6/2009 8:35 AM

    shaders and skinned animation

    Hy , i read this article on skin animation:
    http://exdream.no-ip.info/blog/2007/02/25/SkeletalBoneAnimationAndSkinningWithColladaModelsInXNA.aspx

    The article explain how do the skin animation with a shader approach.
    The vertex shader have a list of matrix for the transform that are updated by the skinned mesh on a new pose(animation).

    My problem is that i'm not understand how i do it with more than one type mesh or with different poses of the mesh!
    The shader must be updated with the render matrix for each bone at each frame.
    But if i have different mesh with different skeleton or different bone poses how i resolve?

    this is the render code:

    public void Render(Matrix renderMatrix)
    		{
    			// Make sure we use the correct vertex declaration for our shader.
    			BaseGame.Device.VertexDeclaration =
    				SkinnedTangentVertex.VertexDeclaration;
    			// Set the world matrix for this object (often Identity).
    			// The renderMatrix is directly applied to the matrices we use
    			// as bone matrices for the shader (has to be done this way because
    			// the bone matrices are transmitted transposed and we could lose
    			// important render matrix translation data if we do not apply it there).
    			BaseGame.WorldMatrix = objectMatrix;
    			// And set all bone matrices (Goblin has 40, but we support up to 80).
    			ShaderEffect.skinnedNormalMapping.SetBoneMatrices(
    				GetBoneMatrices(renderMatrix));
    
    			// Rendering is pretty straight forward (if you know how anyway).
    			ShaderEffect.skinnedNormalMapping.Render(
    				material, "DiffuseSpecular20",
    				RenderVertices);
    		} // 
    
    

    and this is the render vertex:

    private void RenderVertices()
    {
    BaseGame.Device.Vertices[0].SetSource(vertexBuffer, 0,
    SkinnedTangentVertex.SizeInBytes);
    BaseGame.Device.Indices = indexBuffer;
    BaseGame.Device.DrawIndexedPrimitives(
    PrimitiveType.TriangleList,
    0, 0, numOfVertices,
    0, numOfIndices / 3);
    } // RenderVertices()


    is possible to
    1)update the matrix
    2)draw the mesh 1
    3)do the transform work with the shader

    4)reupdate the matrix whit a different mesh (also skinned)
    5)draw the mesh n
    6)redo the transform work with the shader and the changed matrix

    and so one....????
    how???
    Thanks
  • 3/6/2009 9:17 AM In reply to

    Re: shaders and skinned animation

    I'm exactly sure what your question is but I'll give it a try anyway. The way it's handled in our engine is that for each instance of a model we keep a reference to the mesh and animation library but it has its own instance of the skinned shader effect as well as the current pose for itself. Each frame before render time, the world matrix as well as the bone transforms for the pose of each model gets calculated and set on the effect for that model.

    Because each model has it's own effect, you don't have to worry about one model overwriting the bone transforms of another model. It also means that each model can have any skeleton and animation data you'd want it to have (as long as the skinning data supports it).

    Not sure this answers your question, if not then feel free to ask again:)

    Regards
  • 3/6/2009 10:27 AM In reply to

    Re: shaders and skinned animation

    very thanks HerrUppoHoppa.
    Is the same also in directx 9?
    I don't know really what is a "Model"
    How rapresent a "model" in directdraw and is possible to apply a shader transformation only to a "model" also in directx9?

    By.
  • 3/6/2009 11:43 AM In reply to

    Re: shaders and skinned animation

    giugio:
    Is the same also in directx 9?
    I'm talking about a general purpose 3D model system that supports skinned animations. It can be implemented using direct 3d 9....I use xna myself...which is built upon directx 9. As for direct draw I cannot say since I haven't used it but I think it's deprecated and only allows you to render 2D surfaces anyway.

    giugio:
    I don't know really what is a "Model"
    Think of it like the renderable part of something in your game. If it's your player then it keeps all the vertices of your player in a vertex buffer, along with normals for all the triangles, texture coordinates, skinning data etc. If the object happens to be animated it must keep skinning data as well as animations.

    Ofcourse you can translate this behavior into 2D but I haven't tried it so I'm not sure it's a good idea anyway. Also I don't think you can do skinned animations using direct draw (huge disclaimer !!!I don't know direct draw, don't take my word for it!!!).

    giugio:
    How rapresent a "model" in directdraw and is possible to apply a shader transformation only to a "model" also in directx9?

    What?
  • 3/6/2009 2:05 PM In reply to

    Re: shaders and skinned animation

    giugio:
    How rapresent a "model" in directdraw and is possible to apply a shader transformation only to a "model" also in directx9?

    excuse for my english.

    Is possible to apply shader vertex transform to a vertexbuffer and only to a vertexbuffer and not to a scene?
    I'm don't understand this section of the shaders : They transform the entire scene or only a set of vertex and it's attribute?
    Thanks.
  • 3/6/2009 9:11 PM In reply to

    Re: shaders and skinned animation

    giugio:
    giugio:
    How rapresent a "model" in directdraw and is possible to apply a shader transformation only to a "model" also in directx9?

    excuse for my english.

    Is possible to apply shader vertex transform to a vertexbuffer and only to a vertexbuffer and not to a scene?
    I'm don't understand this section of the shaders : They transform the entire scene or only a set of vertex and it's attribute?
    Thanks.
    Yes you're exactly right!! I guess you already know that there are (in direct3d 9 ie including xna) two kinds of shaders, vertex shaders and pixel shaders. The vertex shader gets executed for each vertex that gets rendered using that particular shader programe and the pixel shader gets executed for each pixel that gets rendered using that same shader programme.

    A shader programme in XNA application space is represented by the Effect class. Each render call made to the graphics device requires that an effect is in use. This is enforced when you as a programmer calls effect.begin() and effect.end() before and after each render call respecively.

    If you should happen to use the same effect for each object in the scene then sure the same vertex tranform will get applied to the entire scene, otherwise you can and should do it individually.

    Regards
Page 1 of 1 (6 items) Previous Next