Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #if defined(__GNUC__)
- #define forceinline __attribute__((always_inline))
- #else
- #define forceinline __forceinline
- #endif
- struct Vec3f
- {
- float vec[3];
- };
- struct Vec4f
- {
- float vec[4];
- };
- struct Matrix44f
- {
- float mat[4][4];
- };
- struct Vec4uc
- {
- unsigned char vec[4];
- };
- struct PN4f
- {
- Vec4f pn[2];
- };
- struct PN
- {
- Vec3f p;
- Vec3f n;
- };
- forceinline
- void transformPointNormal4x3Weight_NoW(const Matrix44f& mat,const Vec4f* pVerticiesNormals, PN& outPN)
- {
- outPN.p.vec[0] = (pVerticiesNormals[0].vec[0]*mat.mat[0][0] + pVerticiesNormals[0].vec[1]*mat.mat[1][0] + pVerticiesNormals[0].vec[2]*mat.mat[2][0] + mat.mat[3][0]);
- outPN.n.vec[0] = (pVerticiesNormals[1].vec[0]*mat.mat[0][0] + pVerticiesNormals[1].vec[1]*mat.mat[1][0] + pVerticiesNormals[1].vec[2]*mat.mat[2][0]);
- outPN.p.vec[1] = (pVerticiesNormals[0].vec[0]*mat.mat[0][1] + pVerticiesNormals[0].vec[1]*mat.mat[1][1] + pVerticiesNormals[0].vec[2]*mat.mat[2][1] + mat.mat[3][1]);
- outPN.n.vec[1] = (pVerticiesNormals[1].vec[0]*mat.mat[0][1] + pVerticiesNormals[1].vec[1]*mat.mat[1][1] + pVerticiesNormals[1].vec[2]*mat.mat[2][1]);
- outPN.p.vec[2] = (pVerticiesNormals[0].vec[0]*mat.mat[0][2] + pVerticiesNormals[0].vec[1]*mat.mat[1][2] + pVerticiesNormals[0].vec[2]*mat.mat[2][2] + mat.mat[3][2]);
- outPN.n.vec[2] = (pVerticiesNormals[1].vec[0]*mat.mat[0][2] + pVerticiesNormals[1].vec[1]*mat.mat[1][2] + pVerticiesNormals[1].vec[2]*mat.mat[2][2]);
- }
- forceinline
- void transformPointNormal4x3Weight(const Matrix44f& mat,const Vec4f* pVerticiesNormals, PN& outPN,float w )
- {
- outPN.p.vec[0] = (pVerticiesNormals[0].vec[0]*mat.mat[0][0] + pVerticiesNormals[0].vec[1]*mat.mat[1][0] + pVerticiesNormals[0].vec[2]*mat.mat[2][0] + mat.mat[3][0])*w;
- outPN.n.vec[0] = (pVerticiesNormals[1].vec[0]*mat.mat[0][0] + pVerticiesNormals[1].vec[1]*mat.mat[1][0] + pVerticiesNormals[1].vec[2]*mat.mat[2][0])*w;
- outPN.p.vec[1] = (pVerticiesNormals[0].vec[0]*mat.mat[0][1] + pVerticiesNormals[0].vec[1]*mat.mat[1][1] + pVerticiesNormals[0].vec[2]*mat.mat[2][1] + mat.mat[3][1])*w;
- outPN.n.vec[1] = (pVerticiesNormals[1].vec[0]*mat.mat[0][1] + pVerticiesNormals[1].vec[1]*mat.mat[1][1] + pVerticiesNormals[1].vec[2]*mat.mat[2][1])*w;
- outPN.p.vec[2] = (pVerticiesNormals[0].vec[0]*mat.mat[0][2] + pVerticiesNormals[0].vec[1]*mat.mat[1][2] + pVerticiesNormals[0].vec[2]*mat.mat[2][2] + mat.mat[3][2])*w;
- outPN.n.vec[2] = (pVerticiesNormals[1].vec[0]*mat.mat[0][2] + pVerticiesNormals[1].vec[1]*mat.mat[1][2] + pVerticiesNormals[1].vec[2]*mat.mat[2][2])*w;
- }
- forceinline
- void transformPointNormal4x3AddWeighted(const Matrix44f& mat,const Vec4f* pVerticiesNormals, PN& outPN,float w )
- {
- outPN.p.vec[0] += (pVerticiesNormals[0].vec[0]*mat.mat[0][0] + pVerticiesNormals[0].vec[1]*mat.mat[1][0] + pVerticiesNormals[0].vec[2]*mat.mat[2][0] + mat.mat[3][0])*w;
- outPN.n.vec[0] += (pVerticiesNormals[1].vec[0]*mat.mat[0][0] + pVerticiesNormals[1].vec[1]*mat.mat[1][0] + pVerticiesNormals[1].vec[2]*mat.mat[2][0])*w;
- outPN.p.vec[1] += (pVerticiesNormals[0].vec[0]*mat.mat[0][1] + pVerticiesNormals[0].vec[1]*mat.mat[1][1] + pVerticiesNormals[0].vec[2]*mat.mat[2][1] + mat.mat[3][1])*w;
- outPN.n.vec[1] += (pVerticiesNormals[1].vec[0]*mat.mat[0][1] + pVerticiesNormals[1].vec[1]*mat.mat[1][1] + pVerticiesNormals[1].vec[2]*mat.mat[2][1])*w;
- outPN.p.vec[2] += (pVerticiesNormals[0].vec[0]*mat.mat[0][2] + pVerticiesNormals[0].vec[1]*mat.mat[1][2] + pVerticiesNormals[0].vec[2]*mat.mat[2][2] + mat.mat[3][2])*w;
- outPN.n.vec[2] += (pVerticiesNormals[1].vec[0]*mat.mat[0][2] + pVerticiesNormals[1].vec[1]*mat.mat[1][2] + pVerticiesNormals[1].vec[2]*mat.mat[2][2])*w;
- }
- forceinline
- void ProcessVertex(
- size_t v,
- const PN4f* pVerticiesNormals,
- const Vec4f* pVertexWeight,
- const Vec4uc* pVertexBones,
- const Matrix44f* pBoneTMList,
- PN* skinTempPN,
- size_t wCount)
- {
- float w = pVertexWeight[v].vec[0];
- int boneIndex = pVertexBones[v].vec[0];
- const Matrix44f& boneTM = pBoneTMList[boneIndex];
- if( wCount==1 )
- {
- transformPointNormal4x3Weight_NoW(boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v]);
- }
- else
- {
- // 1st vertex without add
- transformPointNormal4x3Weight(boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v],w);
- if( wCount==2 )
- {
- // other verticies
- w = pVertexWeight[v].vec[1];
- boneIndex = pVertexBones[v].vec[1];
- const Matrix44f& boneTM = pBoneTMList[boneIndex];
- transformPointNormal4x3AddWeighted(boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v],w);
- }
- else if( wCount==3 )
- {
- // other verticies
- w = pVertexWeight[v].vec[1];
- boneIndex = pVertexBones[v].vec[1];
- const Matrix44f* boneTM = &pBoneTMList[boneIndex];
- transformPointNormal4x3AddWeighted(*boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v],w);
- // other verticies
- w = pVertexWeight[v].vec[2];
- boneIndex = pVertexBones[v].vec[2];
- boneTM = &pBoneTMList[boneIndex];
- transformPointNormal4x3AddWeighted(*boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v],w);
- }
- else if( wCount==4 )
- {
- // other verticies
- w = pVertexWeight[v].vec[1];
- boneIndex = pVertexBones[v].vec[1];
- const Matrix44f* boneTM = &pBoneTMList[boneIndex];
- transformPointNormal4x3AddWeighted(*boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v],w);
- // other verticies
- w = pVertexWeight[v].vec[2];
- boneIndex = pVertexBones[v].vec[2];
- boneTM = &pBoneTMList[boneIndex];
- transformPointNormal4x3AddWeighted(*boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v],w);
- // other verticies
- w = pVertexWeight[v].vec[3];
- boneIndex = pVertexBones[v].vec[3];
- boneTM = &pBoneTMList[boneIndex];
- transformPointNormal4x3AddWeighted(*boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v],w);
- }
- /*
- for(size_t i=1;i<wCount;i++)
- {
- // other verticies
- w = pVertexWeight[v].vec[i];
- boneIndex = &pVertexBones[v].vec[i];
- const Matrix44f& boneTM = pBoneTMList[boneIndex];
- transformPointNormal4x3AddWeighted(*boneTM,&pVerticiesNormals[v].pn[0],skinTempPN[v],w);
- }
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement