Skip to content
This repository has been archived by the owner on Jul 19, 2018. It is now read-only.

Commit

Permalink
Software vertex blend optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
sinbad committed Mar 2, 2004
1 parent 29c600a commit 6c14200
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions OgreMain/src/OgreMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,6 @@ namespace Ogre {
Vector3 sourceVec, sourceNorm;
// Accumulation vectors
Vector3 accumVecPos, accumVecNorm;
Matrix3 rot3x3;

Real *pSrcPos, *pSrcNorm, *pDestPos, *pDestNorm, *pBlendWeight;
unsigned char* pBlendIdx;
Expand Down Expand Up @@ -1176,7 +1175,6 @@ namespace Ogre {
}

// Loop per vertex
Vector3 tempVec;
for (size_t vertIdx = 0; vertIdx < targetVertexData->vertexCount; ++vertIdx)
{
// Load source vertex elements
Expand Down Expand Up @@ -1212,21 +1210,48 @@ namespace Ogre {
// NB weights must be normalised!!
if (*pBlendWeight != 0.0)
{
// Blend position
tempVec = pMatrices[*pBlendIdx] * sourceVec;
tempVec *= *pBlendWeight;
accumVecPos += tempVec;
// Blend position, use 3x4 matrix
const Matrix4& mat = pMatrices[*pBlendIdx];
accumVecPos.x +=
(mat[0][0] * sourceVec.x +
mat[0][1] * sourceVec.y +
mat[0][2] * sourceVec.z +
mat[0][3])
* (*pBlendWeight);
accumVecPos.y +=
(mat[1][0] * sourceVec.x +
mat[1][1] * sourceVec.y +
mat[1][2] * sourceVec.z +
mat[1][3])
* (*pBlendWeight);
accumVecPos.z +=
(mat[2][0] * sourceVec.x +
mat[2][1] * sourceVec.y +
mat[2][2] * sourceVec.z +
mat[2][3])
* (*pBlendWeight);
if (includeNormals)
{
// Blend normal
// We should blend by inverse transpose here, but because we're assuming the 3x3
// aspect of the matrix is orthogonal (no non-uniform scaling), the inverse transpose
// is equal to the main 3x3 matrix
// Note because it's a normal we just extract the rotational part, saves us renormalising here
pMatrices[*pBlendIdx].extract3x3Matrix(rot3x3);
tempVec = rot3x3 * sourceNorm;
tempVec *= *pBlendWeight;
accumVecNorm += tempVec;
accumVecNorm.x +=
(mat[0][0] * sourceNorm.x +
mat[0][1] * sourceNorm.y +
mat[0][2] * sourceNorm.z)
* (*pBlendWeight);
accumVecNorm.y +=
(mat[1][0] * sourceNorm.x +
mat[1][1] * sourceNorm.y +
mat[1][2] * sourceNorm.z)
* (*pBlendWeight);
accumVecNorm.z +=
(mat[2][0] * sourceNorm.x +
mat[2][1] * sourceNorm.y +
mat[2][2] * sourceNorm.z)
* (*pBlendWeight);
}

}
Expand Down

0 comments on commit 6c14200

Please sign in to comment.