• <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>

            牽著老婆滿街逛

            嚴(yán)以律己,寬以待人. 三思而后行.
            GMail/GTalk: yanglinbo#google.com;
            MSN/Email: tx7do#yahoo.com.cn;
            QQ: 3 0 3 3 9 6 9 2 0 .

            計(jì)算三角形網(wǎng)格的tangent space

            轉(zhuǎn)載自:http://absolute.javaeye.com/blog/213872

                 又一篇學(xué)習(xí)筆記,參考Mathematics for 3D Game Programming and Computer Graphics和ShaderX4上一篇關(guān)于tangent space計(jì)算的文章寫的東西。對于計(jì)算時(shí)需要分裂頂點(diǎn)的內(nèi)容看的還不是太清楚-_-b。另外,目前的算法還不能完美處理鏡像或者在紋理不連續(xù)處可能出現(xiàn)的問題,就算在Farcry中,很多問題也是通過美工來“隱藏”的,再一次應(yīng)證了之前對美工重要性的結(jié)論^^。

             

             

             

             

             算法:

                  Tangent spaceBump Map中有著重要作用,通常需要把燈光轉(zhuǎn)換到tangent space進(jìn)行計(jì)算。對由參數(shù)方程計(jì)算出的規(guī)則曲面(比如,球體,圓環(huán))來說,很容易通過方程計(jì)算出tangent space,但對任意的三角形網(wǎng)格來說,則沒有那么簡單。

            Tangent space是一個(gè)三維空間。對3D空間中的一個(gè)頂點(diǎn)來說,切空間的三條座標(biāo)軸分別對應(yīng)該點(diǎn)的法線N,切線T,和副法線(binormalB,顯然,對不同的頂點(diǎn)來說,切空間是不同的。那么在已知三角形三個(gè)頂點(diǎn)及其紋理坐標(biāo)的時(shí)候,如何計(jì)算出NTB呢?

            目前已知的數(shù)據(jù)有三角形的三個(gè)頂點(diǎn)在世界坐標(biāo)中的位置: P0, P1,P2, 以及相應(yīng)的紋理坐標(biāo)在紋理空間中的位置C0 (U0,V0)C1C2,則有:

             

            P10 = P1 – P0

            P­20 = P2 - P1 ,

            C10 = C1 – C0 = (U1-U0, V1-V0) = ( U10 ,V10)

            C20 = C2 – C0.= (U2-U0, V2-V0) = ( U20 ,V20)

             

            注意,P10在世界坐標(biāo)中的方向和C10在紋理空間中的方向是一致的(這一點(diǎn)確實(shí)比較抽象,偶畫圖研究了好久才弄明白-_-),同樣,20C20也是如此,發(fā)現(xiàn)這一點(diǎn)很重要,可以說是整個(gè)計(jì)算的基石。進(jìn)一步來說,TB分別和紋理坐標(biāo)軸UV是平行的。因此我們有:

             

            P10 = U10T + V10B

            P­20 = U20T + V20B

            把矢量展開得到:

             

            兩邊乘以[C10 C20]的逆矩陣,最后得到

             

            法線N = T x B

            這樣我們就得到了坐標(biāo)從切空間轉(zhuǎn)變到世界坐標(biāo)下的變換矩陣M = [ T B N ],當(dāng)然,更加常用的是M的逆矩陣。注意,這里計(jì)算得出的只是面法線,如果需要計(jì)算每個(gè)頂點(diǎn)的法線,則應(yīng)該對共享該頂點(diǎn)的多個(gè)面的法線取均值,求出結(jié)果。

             

            實(shí)現(xiàn):

             ogre calculate tangent:

            Vector3 Math::calculateTangentSpaceVector(
             
            const Vector3& position1, const Vector3& position2, const Vector3& position3,
             Real u1, Real v1, Real u2, Real v2, Real u3, Real v3)
             
            {
               
            //side0 is the vector along one side of the triangle of vertices passed in, 
               
            //and side1 is the vector along another side. Taking the cross product of these returns the normal.
               Vector3 side0 = position1 - position2;
               Vector3 side1 
            = position3 - position1;
               
            //Calculate face normal
               Vector3 normal = side1.crossProduct(side0);
               normal.normalise();
               
            //Now we use a formula to calculate the tangent. 
               Real deltaV0 = v1 - v2;
               Real deltaV1 
            = v3 - v1;
               Vector3 tangent 
            = deltaV1 * side0 - deltaV0 * side1;
               tangent.normalise();
               
            //Calculate binormal
               Real deltaU0 = u1 - u2;
               Real deltaU1 
            = u3 - u1;
               Vector3 binormal 
            = deltaU1 * side0 - deltaU0 * side1;
               binormal.normalise();
               
            //Now, we take the cross product of the tangents to get a vector which 
               
            //should point in the same direction as our normal calculated above. 
               
            //If it points in the opposite direction (the dot product between the normals is less than zero), 
               
            //then we need to reverse the s and t tangents. 
               
            //This is because the triangle has been mirrored when going from tangent space to object space.
               
            //reverse tangents if necessary
               Vector3 tangentCross = tangent.crossProduct(binormal);
               
            if (tangentCross.dotProduct(normal) < 0.0f)
               
            {
                 tangent 
            = -tangent;
                 binormal 
            = -binormal;
               }


             
            return tangent;

             }

            posted on 2008-12-09 04:37 楊粼波 閱讀(777) 評論(0)  編輯 收藏 引用

            久久久久久久91精品免费观看| 久久丫忘忧草产品| 久久久久人妻精品一区二区三区| 久久久久久久亚洲精品| 狠狠综合久久综合中文88| 97久久天天综合色天天综合色hd| 亚洲人成伊人成综合网久久久 | 亚洲狠狠婷婷综合久久蜜芽| 午夜精品久久久内射近拍高清 | 国产麻豆精品久久一二三| 亚洲国产精品无码久久一区二区| 漂亮人妻被中出中文字幕久久| 一本色综合久久| 亚洲欧美国产精品专区久久| 欧美麻豆久久久久久中文| 婷婷久久综合九色综合九七| 超级碰碰碰碰97久久久久| 久久福利资源国产精品999| 久久精品国产久精国产果冻传媒| 亚洲一区精品伊人久久伊人 | 久久精品一区二区三区AV| 国色天香久久久久久久小说| 亚洲AV成人无码久久精品老人 | 九九99精品久久久久久| 日本精品久久久久中文字幕8 | 久久精品国产亚洲77777| 69久久夜色精品国产69| A级毛片无码久久精品免费| 久久精品无码一区二区app| 久久免费视频1| 国产91久久精品一区二区| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 | 精品无码久久久久久久动漫| 亚洲欧美一区二区三区久久| 欧美精品久久久久久久自慰| 国产精品免费看久久久香蕉| 久久综合伊人77777| 久久香综合精品久久伊人| 国产精品九九久久免费视频 | 亚洲伊人久久成综合人影院| 久久综合亚洲鲁鲁五月天|