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

            牽著老婆滿街逛

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

            計算三角形網格的tangent space

            轉載自:http://absolute.javaeye.com/blog/213872

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

             

             

             

             

             算法:

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

            Tangent space是一個三維空間。對3D空間中的一個頂點來說,切空間的三條座標軸分別對應該點的法線N,切線T,和副法線(binormalB,顯然,對不同的頂點來說,切空間是不同的。那么在已知三角形三個頂點及其紋理坐標的時候,如何計算出NTB呢?

            目前已知的數據有三角形的三個頂點在世界坐標中的位置: P0, P1,P2, 以及相應的紋理坐標在紋理空間中的位置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在世界坐標中的方向和C10在紋理空間中的方向是一致的(這一點確實比較抽象,偶畫圖研究了好久才弄明白-_-),同樣,20C20也是如此,發現這一點很重要,可以說是整個計算的基石。進一步來說,TB分別和紋理坐標軸UV是平行的。因此我們有:

             

            P10 = U10T + V10B

            P­20 = U20T + V20B

            把矢量展開得到:

             

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

             

            法線N = T x B

            這樣我們就得到了坐標從切空間轉變到世界坐標下的變換矩陣M = [ T B N ],當然,更加常用的是M的逆矩陣。注意,這里計算得出的只是面法線,如果需要計算每個頂點的法線,則應該對共享該頂點的多個面的法線取均值,求出結果。

             

            實現:

             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 楊粼波 閱讀(778) 評論(0)  編輯 收藏 引用

            俺来也俺去啦久久综合网| 男女久久久国产一区二区三区| 久久亚洲精品成人AV| 久久久久久人妻无码| 伊人久久大香线蕉AV色婷婷色| 久久精品国产AV一区二区三区 | 久久精品国产一区二区三区不卡| 亚洲国产精品人久久| 久久久精品久久久久久| 亚洲精品乱码久久久久久久久久久久 | 综合人妻久久一区二区精品| 久久精品中文无码资源站| 91精品国产高清久久久久久国产嫩草 | 亚洲欧美国产精品专区久久| 午夜精品久久久久久99热| Xx性欧美肥妇精品久久久久久| 久久精品国产亚洲AV忘忧草18| 丰满少妇人妻久久久久久| 亚洲国产精品综合久久一线 | 99久久夜色精品国产网站| 久久综合欧美成人| 久久天天躁狠狠躁夜夜网站| 久久er国产精品免费观看8| 久久人妻少妇嫩草AV无码专区| 国产综合成人久久大片91| 99re这里只有精品热久久| 久久妇女高潮几次MBA| 久久午夜综合久久| 久久久九九有精品国产| 亚洲精品午夜国产VA久久成人| 一极黄色视频久久网站| 蜜桃麻豆www久久| 精品久久久噜噜噜久久久| 国产69精品久久久久久人妻精品| 久久久久国产一区二区| 国内精品久久久久久久涩爱| 久久精品国产秦先生| 狠狠精品久久久无码中文字幕| 色天使久久综合网天天| 亚洲伊人久久综合影院| 四虎亚洲国产成人久久精品|