Skip to content

Commit 1523126

Browse files
committed
demo: Use flexible clusterization for hierarchical simplification
Instead of optimizing all clusters for the target size, use the newly added splitting functionality; some output clusters may be smaller than the max if the alternative is a disconnected cluster that is far away. This improves the DAG quality at fairly little cost to the cluster fill.
1 parent 64aa6f8 commit 1523126

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

demo/nanite.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <string.h>
1919

2020
#include <algorithm>
21-
#include <map>
21+
#include <map> // only for METIS
2222
#include <vector>
2323

2424
#ifndef _WIN32
@@ -145,14 +145,16 @@ static std::vector<Cluster> clusterize(const std::vector<Vertex>& vertices, cons
145145

146146
const size_t max_vertices = 192; // TODO: depends on kClusterSize, also may want to dial down for mesh shaders
147147
const size_t max_triangles = kClusterSize;
148+
const size_t min_triangles = (kClusterSize / 3) & ~3;
149+
const float split_factor = 2.0f;
148150

149-
size_t max_meshlets = meshopt_buildMeshletsBound(indices.size(), max_vertices, max_triangles);
151+
size_t max_meshlets = meshopt_buildMeshletsBound(indices.size(), max_vertices, min_triangles);
150152

151153
std::vector<meshopt_Meshlet> meshlets(max_meshlets);
152154
std::vector<unsigned int> meshlet_vertices(max_meshlets * max_vertices);
153155
std::vector<unsigned char> meshlet_triangles(max_meshlets * max_triangles * 3);
154156

155-
meshlets.resize(meshopt_buildMeshlets(&meshlets[0], &meshlet_vertices[0], &meshlet_triangles[0], &indices[0], indices.size(), &vertices[0].px, vertices.size(), sizeof(Vertex), max_vertices, max_triangles, 0.f));
157+
meshlets.resize(meshopt_buildMeshletsFlex(&meshlets[0], &meshlet_vertices[0], &meshlet_triangles[0], &indices[0], indices.size(), &vertices[0].px, vertices.size(), sizeof(Vertex), max_vertices, min_triangles, max_triangles, 0.f, split_factor));
156158

157159
std::vector<Cluster> clusters(meshlets.size());
158160

0 commit comments

Comments
 (0)