heightfield processAllTriangles: Skip triangle processing if the triangle is out-of-AABB

Skips triangle processing if the triangle is out-of-AABB on the up axis.

This massively improves OpenMW performance on my test machine.

Co-authored-by: Andrew Shulaev <ash.drone@gmail.com>
This commit is contained in:
Gleb Mazovetskiy 2021-02-28 15:39:36 +00:00
parent 782f14caa1
commit e7e28bebf8

View File

@ -352,7 +352,13 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
getVertex(x, j, vertices[indices[0]]);
getVertex(x, j + 1, vertices[indices[1]]);
getVertex(x + 1, j + 1, vertices[indices[2]]);
callback->processTriangle(vertices, 2 * x, j);
// Skip triangle processing if the triangle is out-of-AABB.
btScalar minUp = btMin(vertices[0][m_upAxis], btMin(vertices[1][m_upAxis], vertices[2][m_upAxis]));
btScalar maxUp = btMax(vertices[0][m_upAxis], btMax(vertices[1][m_upAxis], vertices[2][m_upAxis]));
if (!(minUp > aabbMax[m_upAxis] || maxUp < aabbMin[m_upAxis]))
callback->processTriangle(vertices, 2 * x, j);
// already set: getVertex(x, j, vertices[indices[0]])
@ -360,15 +366,24 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
vertices[indices[1]] = vertices[indices[2]];
getVertex(x + 1, j, vertices[indices[2]]);
callback->processTriangle(vertices, 2 * x+1, j);
minUp = btMin(minUp, vertices[indices[2]][m_upAxis]);
maxUp = btMax(maxUp, vertices[indices[2]][m_upAxis]);
if (!(minUp > aabbMax[m_upAxis] || maxUp < aabbMin[m_upAxis]))
callback->processTriangle(vertices, 2 * x+1, j);
}
else
{
getVertex(x, j, vertices[indices[0]]);
getVertex(x, j + 1, vertices[indices[1]]);
getVertex(x + 1, j, vertices[indices[2]]);
callback->processTriangle(vertices, 2 * x, j);
// Skip triangle processing if the triangle is out-of-AABB.
btScalar minUp = btMin(vertices[0][m_upAxis], btMin(vertices[1][m_upAxis], vertices[2][m_upAxis]));
btScalar maxUp = btMax(vertices[0][m_upAxis], btMax(vertices[1][m_upAxis], vertices[2][m_upAxis]));
if (!(minUp > aabbMax[m_upAxis] || maxUp < aabbMin[m_upAxis]))
callback->processTriangle(vertices, 2 * x, j);
// already set: getVertex(x, j + 1, vertices[indices[1]]);
@ -376,7 +391,11 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
vertices[indices[0]] = vertices[indices[2]];
getVertex(x + 1, j + 1, vertices[indices[2]]);
callback->processTriangle(vertices, 2 * x+1, j);
minUp = btMin(minUp, vertices[indices[2]][m_upAxis]);
maxUp = btMax(maxUp, vertices[indices[2]][m_upAxis]);
if (!(minUp > aabbMax[m_upAxis] || maxUp < aabbMin[m_upAxis]))
callback->processTriangle(vertices, 2 * x+1, j);
}
}
}