• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            戰魂小筑

            討論群:309800774 知乎關注:http://zhihu.com/people/sunicdavy 開源項目:https://github.com/davyxu

               :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              257 隨筆 :: 0 文章 :: 506 評論 :: 0 Trackbacks

            傳統的蒙皮骨骼動畫混合方法易于理解,但是在SM 2.0的256常量限制下,骨骼數保守計算最多50根骨頭,因此對美術的工作流程以及模型渲染方法造成了很大的障礙

            float4x4 matBoneArray[40]; //  這是傳輸的瓶頸
             
            VS_OUTPUT vs_main( SkinnedVS_INPUT In )
            {
             
                VS_OUTPUT Out = (VS_OUTPUT)0;
             
                float4x4 skinTransform = 0;
             
                skinTransform += matBoneArray[In.BoneIndices.x] * In.BoneWeights.x;
                skinTransform += matBoneArray[In.BoneIndices.y] * In.BoneWeights.y;
                skinTransform += matBoneArray[In.BoneIndices.z] * In.BoneWeights.z;
                skinTransform += matBoneArray[In.BoneIndices.w] * In.BoneWeights.w;
                float4 localpos = mul(In.Position, skinTransform);
                
                Out.Position = mul( localpos, matViewProj ); 
                Out.TexCoord = In.TexCoord;
              
                return Out;
            }

            matBoneArray這個數組是骨骼的LocalRot和LocalTranslation 通過以下函數build出來

                Matrix4& Matrix4::FromTranslationRotation( const Vector3& translation, const Quaternion& rotation )
                {
                    float xx = rotation.x * rotation.x * 2.0f, yy = rotation.y * rotation.y * 2.0f, zz = rotation.z * rotation.z * 2.0f;
                    float xy = rotation.x * rotation.y * 2.0f, zw = rotation.z * rotation.w * 2.0f, xz = rotation.x * rotation.z * 2.0f;
                    float yw = rotation.y * rotation.w * 2.0f, yz = rotation.y * rotation.z * 2.0f, xw = rotation.x * rotation.w * 2.0f;
             
                    m[0][0] = 1.0f - yy - zz; m[0][1] =        xy + zw; m[0][2] =        xz - yw; m[0][3] = 0.0f;
                    m[1][0] =        xy - zw; m[1][1] = 1.0f - xx - zz; m[1][2] =        yz + xw; m[1][3] = 0.0f;
                    m[2][0] =        xz + yw; m[2][1] =        yz - xw; m[2][2] = 1.0f - xx - yy; m[2][3] = 0.0f;
                    m[3][0] =  translation.x; m[3][1] =  translation.y; m[3][2] =  translation.z; m[3][3] = 1.0f;
             
                    return *this;
                }

            從這里你可以發現, 本來每根骨頭只需要2個float4 傳遞變換信息的,現在卻需要4個float4,也就是一個矩陣來傳遞,矩陣中還有很多不使用的變量也被傳輸到GPU中,這里就是優化的點.

            重新調整后的Shader代碼:

            float4x4 BuildFromTransRot( float4 translation, float4 rot )
            {
                float4 rotation = rot;
                
                float xx = rotation.x * rotation.x * 2.0f, yy = rotation.y * rotation.y * 2.0f, zz = rotation.z * rotation.z * 2.0f;
                float xy = rotation.x * rotation.y * 2.0f, zw = rotation.z * rotation.w * 2.0f, xz = rotation.x * rotation.z * 2.0f;
                float yw = rotation.y * rotation.w * 2.0f, yz = rotation.y * rotation.z * 2.0f, xw = rotation.x * rotation.w * 2.0f;
                float4x4 m = { 
                {1.0f - yy - zz,             xy + zw,             xz - yw,         0},
                {xy - zw,              1.0f - xx - zz,             yz + xw,         0},
                {xz + yw,                      yz - xw,     1.0f - xx - yy,         0},
                {translation.x,       translation.y,       translation.z,         1}
                
                };
                
                return m;
            }
             
            float4x4 GetBoneElement( float index )
            {
                return BuildFromTransRot( vecBoneLocalTrans[index], vecBoneLocalRot[index] );
            }

            VS_OUTPUT vs_main( SkinnedVS_INPUT In )
            {
             
                VS_OUTPUT Out = (VS_OUTPUT)0;
             
                float4x4 skinTransform = 0;
             
                skinTransform += GetBoneElement(In.BoneIndices.x) * In.BoneWeights.x;
                skinTransform += GetBoneElement(In.BoneIndices.y) * In.BoneWeights.y;
                skinTransform += GetBoneElement(In.BoneIndices.z) * In.BoneWeights.z;
                skinTransform += GetBoneElement(In.BoneIndices.w) * In.BoneWeights.w;
                float4 localpos = mul(In.Position, skinTransform);
                
                Out.Position = mul( localpos, matViewProj ); 
                Out.TexCoord = In.TexCoord;
              
                return Out;
            }

            我們將骨頭的local旋轉及偏移傳遞至GPU,然后在GPU內重組,雖然對GPU性能計算有部分損耗,但是骨骼數量就能保守提高到100個.

            posted on 2010-04-26 13:31 戰魂小筑 閱讀(3653) 評論(7)  編輯 收藏 引用 所屬分類: 游戲開發技術渲染 Shader 引擎

            評論

            # re: [原創]提高Shader Model 2.0 蒙皮骨骼動畫的骨骼限制 2010-04-26 18:17 Bill Hsu
            謝謝分享,好文

            可是我看到某個shader代碼里有這樣一句:
            uniform mat4 boneMat[96];

            那個最大50個骨骼的限制是怎么算出來的呢?

            還有這種方法沒有考慮scale,所以需要3個float4才可以。。。  回復  更多評論
              

            # re: [原創]提高Shader Model 2.0 蒙皮骨骼動畫的骨骼限制 2010-04-26 19:50 Davy.xu
            這里是在SM2.0的256個常量限制下計算的
            1個矩陣占用4個常量,那么最多可以傳入256/4=64個矩陣,由于轉換矩陣及其他的數據還需要占用常量,保守就是用50作為限制
            可以縮放的骨骼非常少見,為了這個很小的特性而提高工作流復雜度,不值得  回復  更多評論
              

            # re: [原創]提高Shader Model 2.0 蒙皮骨骼動畫的骨骼限制 2010-04-27 22:08 陳昱(CY)
            位移只有float3,應該能又節約一些吧?
            uniform vec4 g_allBonesQuaRot[50];
            uniform vec3 g_allBonesTran[50];  回復  更多評論
              

            # re: [原創]提高Shader Model 2.0 蒙皮骨骼動畫的骨骼限制 2010-04-28 09:03 Davy.xu
            在D3D下無論如何都是float4對齊吧  回復  更多評論
              

            # re: [原創]提高Shader Model 2.0 蒙皮骨骼動畫的骨骼限制 2010-04-28 11:37 Bill Hsu
            @陳昱(CY)
            好像float3也會被轉換成float4  回復  更多評論
              

            # re: [原創]提高Shader Model 2.0 蒙皮骨骼動畫的骨骼限制 2010-04-28 15:29 Davy.xu
            GLSL里默認不是float4  回復  更多評論
              

            # re: [原創]提高Shader Model 2.0 蒙皮骨骼動畫的骨骼限制 2010-05-14 16:26 Bill Hsu
            我試了樓主的代碼,
            會報錯:error X4004: Program too complex..
            為什們呢?


            我的完整shader:

            matrix WVPMatrix;
            float4 quat[100];
            float3 tran[100];

            struct VS_INPUT
            {
            float3 Position : POSITION;
            float3 Normal : NORMAL0;
            float2 TexCoord0 : TEXCOORD0;
            float4 Weights:TEXCOORD1;
            float4 Indices:TEXCOORD2;
            };


            struct VS_OUTPUT
            {
            float4 Pos : POSITION;
            float3 Diffuse : COLOR;
            float2 Tex0 : TEXCOORD0;
            };

            float4x4 BuildFromTransRot( float3 translation, float4 rot )

            {

            float4 rotation = rot;



            float xx = rotation.x * rotation.x * 2.0f, yy = rotation.y * rotation.y * 2.0f, zz = rotation.z * rotation.z * 2.0f;

            float xy = rotation.x * rotation.y * 2.0f, zw = rotation.z * rotation.w * 2.0f, xz = rotation.x * rotation.z * 2.0f;

            float yw = rotation.y * rotation.w * 2.0f, yz = rotation.y * rotation.z * 2.0f, xw = rotation.x * rotation.w * 2.0f;

            float4x4 m = {

            {1.0f - yy - zz, xy + zw, xz - yw, 0},

            {xy - zw, 1.0f - xx - zz, yz + xw, 0},

            {xz + yw, yz - xw, 1.0f - xx - yy, 0},

            {translation.x, translation.y, translation.z, 1}



            };



            return m;

            }



            float4x4 GetBoneElement( float index )

            {
            return BuildFromTransRot(tran[index], quat[index] );

            }


            VS_OUTPUT main(VS_INPUT input)
            {

            VS_OUTPUT Out = (VS_OUTPUT)0;



            float4x4 skinTransform = 0;



            skinTransform += GetBoneElement(input.Indices.x) * input.Weights.x;

            skinTransform += GetBoneElement(input.Indices.y) * input.Weights.y;

            skinTransform += GetBoneElement(input.Indices.z) * input.Weights.z;

            skinTransform += GetBoneElement(input.Indices.w) * input.Weights.w;

            float4 localpos = mul(input.Position, skinTransform);



            Out.Pos = mul( localpos, WVPMatrix );

            Out.Tex0 = input.TexCoord0;



            return Out;

            }
              回復  更多評論
              

            超级97碰碰碰碰久久久久最新| 色悠久久久久久久综合网| 色综合久久中文字幕无码| 久久久久久国产精品美女 | 九九精品99久久久香蕉| 久久棈精品久久久久久噜噜| 99久久人人爽亚洲精品美女| 久久精品国产色蜜蜜麻豆| 国产精品久久自在自线观看| 色婷婷久久综合中文久久一本| 久久久久99精品成人片试看| 久久久久免费视频| 97久久精品无码一区二区| 一本大道久久香蕉成人网| 亚洲精品高清国产一久久| 久久精品国产亚洲AV影院 | 久久天天躁夜夜躁狠狠躁2022| 久久狠狠高潮亚洲精品| 亚洲Av无码国产情品久久| 久久久久国产一级毛片高清版| 久久人人添人人爽添人人片牛牛 | 国产高潮国产高潮久久久91| 亚洲中文字幕无码久久综合网| 国产女人aaa级久久久级| 99久久精品毛片免费播放| 亚洲国产精品无码久久久不卡| 无码乱码观看精品久久| 国产激情久久久久影院老熟女| 国产精品一区二区久久不卡| 久久人人爽爽爽人久久久| 久久这里只精品99re66| 青青热久久国产久精品| 精品国产一区二区三区久久蜜臀| 国产精品99精品久久免费| 囯产精品久久久久久久久蜜桃| 亚洲性久久久影院| 久久亚洲中文字幕精品一区| 亚洲精品成人网久久久久久| 久久夜色精品国产噜噜亚洲a | 久久亚洲AV成人出白浆无码国产| 亚洲婷婷国产精品电影人久久 |