Skip to content

Commit

Permalink
demo: Implement locked boundary metrics
Browse files Browse the repository at this point in the history
When vertex locks are used, we can count the number of locked vertices
in each cluster which is a representation of the boundary that restricts
the simplifier. This is a little different from the regular meshlet
boundary, as the boundary is computed for groups of clusters, but
evaluated on a simplified subset to make the metrics match between other
metrics of the same LOD.

To reduce clutter we also now output stuck statistics only if any
clusters are stuck in a given LOD.
  • Loading branch information
zeux committed Jan 22, 2025
1 parent f38bd3b commit d909484
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions demo/nanite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ static int measureComponents(std::vector<int>& parents, const std::vector<unsign
return roots;
}

static int measureUnique(std::vector<int>& used, const std::vector<unsigned int>& indices)
static int measureUnique(std::vector<int>& used, const std::vector<unsigned int>& indices, const std::vector<unsigned char>* locks = NULL)
{
for (size_t i = 0; i < indices.size(); ++i)
{
Expand All @@ -481,7 +481,7 @@ static int measureUnique(std::vector<int>& used, const std::vector<unsigned int>
for (size_t i = 0; i < indices.size(); ++i)
{
unsigned int v = indices[i];
vertices += used[v];
vertices += used[v] && (!locks || !(*locks)[v]);
used[v] = 0;
}

Expand Down Expand Up @@ -575,6 +575,7 @@ void nanite(const std::vector<Vertex>& vertices, const std::vector<unsigned int>
int full_clusters = 0;
size_t components_lod = 0;
size_t xformed_lod = 0;
size_t boundary_lod = 0;

if (dump && depth == atoi(dump))
dumpObj(vertices, std::vector<unsigned int>());
Expand Down Expand Up @@ -666,16 +667,20 @@ void nanite(const std::vector<Vertex>& vertices, const std::vector<unsigned int>
full_clusters += split[j].indices.size() == kClusterSize * 3;
components_lod += measureComponents(parents, split[j].indices, remap);
xformed_lod += measureUnique(parents, split[j].indices);
boundary_lod += kUseLocks ? measureUnique(parents, split[j].indices, &locks) : 0;
}
}

double inv_clusters = pending.empty() ? 0 : 1.0 / double(pending.size());

depth++;
printf("lod %d: simplified %d clusters (%.1f%% full, %.1f tri/cl, %.1f vtx/cl, %.2f connected), %d triangles; stuck %d clusters (%d single), %d triangles\n",
printf("lod %d: %d clusters (%.1f%% full, %.1f tri/cl, %.1f vtx/cl, %.2f connected, %.1f boundary), %d triangles",
depth, int(pending.size()),
double(full_clusters) * inv_clusters * 100, double(triangles) * inv_clusters, double(xformed_lod) * inv_clusters, double(components_lod) * inv_clusters,
int(triangles), stuck_clusters, single_clusters, int(stuck_triangles));
double(full_clusters) * inv_clusters * 100, double(triangles) * inv_clusters, double(xformed_lod) * inv_clusters, double(components_lod) * inv_clusters, double(boundary_lod) * inv_clusters,
int(triangles));
if (stuck_clusters)
printf("; stuck %d clusters (%d single, %d triangles)", stuck_clusters, single_clusters, int(stuck_triangles));
printf("\n");

if (kUseRetry)
{
Expand Down

0 comments on commit d909484

Please sign in to comment.