Skip to content

Commit 60e0677

Browse files
authored
Merge pull request #1041 from zeux/ml-optrot
meshletutils: Restrict triangle rotation to optimizeMeshletLevel 1+
2 parents afb074f + 3aa731d commit 60e0677

File tree

5 files changed

+48
-37
lines changed

5 files changed

+48
-37
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ Decoder is heavily optimized and can directly target write-combined memory; you
429429

430430
> Applications that do most of the streaming decompression on the GPU can also decode meshlet data on the GPU if CPU decoding is inconvenient; an example [meshletdec.slang](./demo/meshletdec.slang) shader is provided for 32-bit output format, and can be easily adapted to other formats, including custom ones.
431431
432-
Note that meshlet encoding assumes that the meshlet data was optimized; meshlets should be processed using `meshopt_optimizeMeshlet` before encoding. Additionally, vertex references should have a high degree of reference locality; this can be achieved by building meshlets from meshes optimized for vertex cache/fetch, or linearizing the vertex reference data and reordering the vertex buffer using `meshopt_optimizeVertexFetch`. For maximum compression, consider also using `meshopt_optimizeMeshletLevel` with level 3. Feeding unoptimized data into the encoder will result in poor compression ratios. Codec preserves the order of triangles, however it can rotate each triangle to improve compression ratio (which means the provoking vertex may change).
432+
Note that meshlet encoding assumes that the meshlet data was optimized; meshlets should be processed using `meshopt_optimizeMeshletLevel` with level 1 or higher (3 recommended for improved compression) before encoding. Additionally, vertex references should have a high degree of reference locality; this can be achieved by building meshlets from meshes optimized for vertex cache/fetch, or linearizing the vertex reference data and reordering the vertex buffer using `meshopt_optimizeVertexFetch`. Feeding unoptimized data into the encoder will result in poor compression ratios. Codec preserves the order of triangles, however it can rotate each triangle to improve compression ratio (which means the provoking vertex may change).
433433

434434
Meshlets without vertex references are supported; passing `NULL` vertices and `0` vertex count during encoding and decoding will produce encoded meshlets with just triangle data. Note that parameters supplied during decoding must match those used during encoding; if a meshlet was encoded with vertex references, it must be decoded with the same number of vertex references.
435435

demo/clusterlod.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct clodConfig
6060

6161
// should clodCluster::indices be optimized for locality; helps with rasterization performance and ray tracing performance in fast-build modes
6262
bool optimize_clusters;
63+
int optimize_clusters_level;
6364
};
6465

6566
struct clodMesh
@@ -259,8 +260,13 @@ static std::vector<Cluster> clusterize(const clodConfig& config, const clodMesh&
259260
{
260261
const meshopt_Meshlet& meshlet = meshlets[i];
261262

263+
#if MESHOPTIMIZER_VERSION < 1010
262264
if (config.optimize_clusters)
263265
meshopt_optimizeMeshlet(&meshlet_vertices[meshlet.vertex_offset], &meshlet_triangles[meshlet.triangle_offset], meshlet.triangle_count, meshlet.vertex_count);
266+
#else
267+
if (config.optimize_clusters)
268+
meshopt_optimizeMeshletLevel(&meshlet_vertices[meshlet.vertex_offset], meshlet.vertex_count, &meshlet_triangles[meshlet.triangle_offset], meshlet.triangle_count, config.optimize_clusters_level);
269+
#endif
264270

265271
clusters[i].vertices = meshlet.vertex_count;
266272

@@ -522,6 +528,7 @@ clodConfig clodDefaultConfig(size_t max_triangles)
522528
config.cluster_split_factor = 2.0f;
523529

524530
config.optimize_clusters = true;
531+
config.optimize_clusters_level = 1;
525532

526533
config.simplify_ratio = 0.5f;
527534
config.simplify_threshold = 0.85f;

0 commit comments

Comments
 (0)