demo: Add usage examples for meshopt_optimizeMeshlet

Mention this in README as a recommended post-processing step and add to
meshlet processing pipeline for coverage.
This commit is contained in:
Arseny Kapoulkine
2024-03-30 19:07:20 -07:00
parent bd95292154
commit 6f367bd1d0
2 changed files with 9 additions and 0 deletions
+6
View File
@@ -330,6 +330,12 @@ meshlets.resize(meshlet_count);
However depending on the application other strategies of storing the data can be useful; for example, `meshlet_vertices` serves as indices into the original vertex buffer but it might be worthwhile to generate a mini vertex buffer for each meshlet to remove the extra indirection when accessing vertex data, or it might be desirable to compress vertex data as vertices in each meshlet are likely to be very spatially coherent.
For optimal performance, it is recommended to further optimize each meshlet in isolation for better triangle and vertex locality by calling `meshopt_optimizeMeshlet` on vertex and index data like so:
```c++
meshopt_optimizeMeshlet(&meshlet_vertices[m.vertex_offset], &meshlet_triangles[m.triangle_offset], m.triangle_count, m.vertex_count);
```
After generating the meshlet data, it's also possible to generate extra data for each meshlet that can be saved and used at runtime to perform cluster culling, where each meshlet can be discarded if it's guaranteed to be invisible. To generate the data, `meshlet_computeMeshletBounds` can be used:
```c++
+3
View File
@@ -866,6 +866,9 @@ void meshlets(const Mesh& mesh, bool scan)
else
meshlets.resize(meshopt_buildMeshlets(&meshlets[0], &meshlet_vertices[0], &meshlet_triangles[0], &mesh.indices[0], mesh.indices.size(), &mesh.vertices[0].px, mesh.vertices.size(), sizeof(Vertex), max_vertices, max_triangles, cone_weight));
for (size_t i = 0; i < meshlets.size(); ++i)
meshopt_optimizeMeshlet(&meshlet_vertices[meshlets[i].vertex_offset], &meshlet_triangles[meshlets[i].triangle_offset], meshlets[i].triangle_count, meshlets[i].vertex_count);
if (meshlets.size())
{
const meshopt_Meshlet& last = meshlets.back();