Skinning sample Translation

Source: Internet
Author: User

I have studied d3d skeleton animation over the past few days. By the way, I have translated the skeleton animation examples in DirectX. please correct me if they are inappropriate ..

 

How the sample works

 

This example describes four ways to index the Skeleton Through the skeleton index number. The skeleton index number is provided in the vertex stream of the model. This example does not contain bone animation and hierarchical transformation.

 

This example describes four different index skeleton transformation matrices suitable for GPU skin. In addition, it also describes how to stream out without using geometry shader. When the skin model requires multi-channel rendering, it can be used to reduce the time of vertex processing.

 

Constant buffer skinning

In the four methods described here, constant buffer Skinning is very similar to the traditional direct3d 9 GPU-based skin. Transform Matrices are loaded to Shader constants, vertex shader indexes, which are based on the skeleton indexes in the vertex stream. Just like most direct3d 9 implementations, each vertex's skeleton index is limited to 4. unlike direct3d 9, the skin method in this example does not create a matrix palette, nor is it divided into different parts based on the vertex of similar indexes. This is because direct3d 10 allows a buffer greater than direct3d 9. Only models with hundreds of bones need to divide the Skeleton Matrix into different tuning boards. The code for indexing the skeleton in the shader is as follows:

Mret = g_mconstboneworld [ibone];

Texture buffer skinning

 

Texture buffer skinning looks the same as constant buffer skinning. In fact, the same method is used for indexing a skeleton in HLSL:

Mret = g_mtexboneworld [ibone];

The only difference is that the buffer that saves the transformation matrix is declared as a Texture buffer rather than a conventional constant buffer. Defining a buffer as tbuffer can be accessed just like texture. This improves performance for programs that require more random access to texture.

 

Texture skinning

 

A logical extension based on tbuffer skin is to save the rotation matrix of the skeleton to a floating-point texture. Depending on the texture pickup (texture-Fetch) performance of the video card and whether the shader is ALU or texture-Fetch bound, this method can produce an amazing increase in the binding speed.

 

Ibone * = 4;
Float4 row1 = g_txtexboneworld.load (float2 (ibone, 0 ));
Float4 row2 = g_txtexboneworld.load (float2 (ibone + 1, 0 ));
Float4 row3 = g_txtexboneworld.load (float2 (ibone + 2, 0 ));
Float4 row4 = g_txtexboneworld.load (float2 (ibone + 3, 0 ));

Mret = float4x4 (row1, row2, row3, row4 );

Here we can see that the method of obtaining the transformation matrix through four texture fetches may be faster than that of the constent buffer, depending on the hardware.

 

Buffer skinning

 

The last method of the index matrix is through buffer skinning. in buffer skinning, the matrix is loaded into an id3d10buffer object. This object is bound to a shader resource. the data of the matrix is obtained from the buffer using the load command.

 

Ibone * = 4;
Float4 row1 = g_bufferboneworld.load (ibone );
Float4 row2 = g_bufferboneworld.load (ibone + 1 );
Float4 row3 = g_bufferboneworld.load (ibone + 2 );
Float4 row4 = g_bufferboneworld.load (ibone + 3 );

Mret = float4x4 (row1, row2, row3, row4 );

 

Speed up multiple passes with stream out

 

A problem with the traditional GPU skin is that if an object needs to be rendered in multiple channels, the object needs to be skin once in each channel. For example, in a scenario where there are three Shadow light sources and skin roles, in order to calculate the shadows produced by each light source, this role needs to be rendered three times-the angle of each light source once. This requires that vertex shader bind the role three times. Unfortunately, there are too many chances to come out twice. In fact, you only need to bind the role once and store the changed role. In this way, if a scenario requires 10 channels for rendering, the role does not need to be bound for 10 times.

 

Fortunately, stream out allows us to do this. Direct3d can be bound once with up to 10 characters, and then the information is stored in the cache of the video card. Then, for the next rendering channel, you only need to use the previously bound vertex. For a role that requires 10-channel rendering, this will save 90% of the vertex processing time.

 

In this example, multi-channel rendering is not performed, but multiple role instances are rendered. This is actually the same problem, but the expressions are different. When stream out is disabled, the role is bound every time the program renders. However, when stream out is enabled, the role only needs to be bound once, save the result in stream out, and use the pre-Bound Model when rendering other role instances.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.