mirror of
https://github.com/openharmony/third_party_meshoptimizer.git
synced 2026-07-19 12:03:07 -04:00
simplify: Share quadric evaluation between position & attribute quadrics
The math for evaluating the error is the same up until normalization / gradient accumulation differences, and since this code is sensitive wrt performance / precision, it's nice to share it. This should not have any observable performance impact if the compiler makes reasonable inlining decisions.
This commit is contained in:
+8
-21
@@ -598,7 +598,7 @@ static void quadricAdd(QuadricGrad* G, const QuadricGrad* R, size_t attribute_co
|
||||
}
|
||||
}
|
||||
|
||||
static float quadricError(const Quadric& Q, const Vector3& v)
|
||||
static float quadricEval(const Quadric& Q, const Vector3& v)
|
||||
{
|
||||
float rx = Q.b0;
|
||||
float ry = Q.b1;
|
||||
@@ -621,6 +621,12 @@ static float quadricError(const Quadric& Q, const Vector3& v)
|
||||
r += ry * v.y;
|
||||
r += rz * v.z;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static float quadricError(const Quadric& Q, const Vector3& v)
|
||||
{
|
||||
float r = quadricEval(Q, v);
|
||||
float s = Q.w == 0.f ? 0.f : 1.f / Q.w;
|
||||
|
||||
return fabsf(r) * s;
|
||||
@@ -628,26 +634,7 @@ static float quadricError(const Quadric& Q, const Vector3& v)
|
||||
|
||||
static float quadricError(const Quadric& Q, const QuadricGrad* G, size_t attribute_count, const Vector3& v, const float* va)
|
||||
{
|
||||
float rx = Q.b0;
|
||||
float ry = Q.b1;
|
||||
float rz = Q.b2;
|
||||
|
||||
rx += Q.a10 * v.y;
|
||||
ry += Q.a21 * v.z;
|
||||
rz += Q.a20 * v.x;
|
||||
|
||||
rx *= 2;
|
||||
ry *= 2;
|
||||
rz *= 2;
|
||||
|
||||
rx += Q.a00 * v.x;
|
||||
ry += Q.a11 * v.y;
|
||||
rz += Q.a22 * v.z;
|
||||
|
||||
float r = Q.c;
|
||||
r += rx * v.x;
|
||||
r += ry * v.y;
|
||||
r += rz * v.z;
|
||||
float r = quadricEval(Q, v);
|
||||
|
||||
// see quadricFromAttributes for general derivation; here we need to add the parts of (eval(pos) - attr)^2 that depend on attr
|
||||
for (size_t k = 0; k < attribute_count; ++k)
|
||||
|
||||
Reference in New Issue
Block a user