diff --git a/modules/meshlet/include/vkcv/meshlet/Tipsify.hpp b/modules/meshlet/include/vkcv/meshlet/Tipsify.hpp index a5bcef76b518eb9629eeb5e90614dfd705edc6ed..70fbd39c76dc6c204ac8e84ba056ac99197a3b58 100644 --- a/modules/meshlet/include/vkcv/meshlet/Tipsify.hpp +++ b/modules/meshlet/include/vkcv/meshlet/Tipsify.hpp @@ -5,6 +5,19 @@ #include <iostream> namespace vkcv::meshlet { + struct tipsifyResult{ + /** + * + * @param indexBuffer new indexBuffer + * @param skippedIndices indices that have a spacial break + */ + tipsifyResult(const std::vector<uint32_t> indexBuffer, const std::vector<uint32_t> skippedIndices) + :indexBuffer(indexBuffer), skippedIndices(skippedIndices) {} + + std::vector<uint32_t> indexBuffer; + std::vector<uint32_t> skippedIndices; + }; + /** * reorders the IndexBuffer, so all usages of vertices to triangle are as close as possible * @param indexBuffer32Bit current IndexBuffer @@ -13,9 +26,12 @@ namespace vkcv::meshlet { * Recommended: 20. Keep the value between 5 and 50 <br> * low: more random and patchy<br> * high: closer vertices have higher chance -> leads to sinuous lines - * @return new IndexBuffer that replaces the input IndexBuffer + * @return new IndexBuffer that replaces the input IndexBuffer, and the indices that are skipped + * + * https://gfx.cs.princeton.edu/pubs/Sander_2007_%3ETR/tipsy.pdf + * https://www.martin.st/thesis/efficient_triangle_reordering.pdf */ - std::vector<uint32_t> tipsifyMesh( + tipsifyResult tipsifyMesh( const std::vector<uint32_t> &indexBuffer32Bit, const int vertexCount, const unsigned int cacheSize = 20); diff --git a/modules/meshlet/src/vkcv/meshlet/Tipsify.cpp b/modules/meshlet/src/vkcv/meshlet/Tipsify.cpp index a41d37c15d81d60c4152c58051ad362ba83c77a6..21c03645b3eae8c2edb3aefc2b257d036a8e1e84 100644 --- a/modules/meshlet/src/vkcv/meshlet/Tipsify.cpp +++ b/modules/meshlet/src/vkcv/meshlet/Tipsify.cpp @@ -3,10 +3,11 @@ #include "vkcv/meshlet/Tipsify.hpp" #include <iostream> -const int maxUsedVertices = 128; - namespace vkcv::meshlet { + const int maxUsedVertices = 128; + std::vector<uint32_t> skippedIndices; + /** * modulo operation with maxUsedVertices * @param number for modulo operation @@ -47,6 +48,7 @@ namespace vkcv::meshlet { while (lowestLivingVertexIndex + 1 < vertexCount) { lowestLivingVertexIndex++; if (livingTriangles[lowestLivingVertexIndex] > 0) { + skippedIndices.push_back(static_cast<uint32_t>(lowestLivingVertexIndex)); return lowestLivingVertexIndex; } } @@ -115,14 +117,14 @@ namespace vkcv::meshlet { return nextVertexIndex; } - std::vector<uint32_t> tipsifyMesh( + tipsifyResult tipsifyMesh( const std::vector<uint32_t> &indexBuffer32Bit, const int vertexCount, const unsigned int cacheSize) { if (indexBuffer32Bit.empty() || vertexCount <= 0) { vkcv_log(LogLevel::ERROR, "Invalid Input."); - return indexBuffer32Bit; + return tipsifyResult(indexBuffer32Bit ,skippedIndices ); } int triangleCount = indexBuffer32Bit.size() / 3; @@ -264,6 +266,6 @@ namespace vkcv::meshlet { } } - return reorderedIndexBuffer; + return tipsifyResult(reorderedIndexBuffer, skippedIndices); } } \ No newline at end of file diff --git a/projects/mesh_shader/src/main.cpp b/projects/mesh_shader/src/main.cpp index 7d3c785e1ace0c4bf866818744ab9417d0ab8cdd..bfbd595e79e1b9495757e046fe457b1fb91c49e8 100644 --- a/projects/mesh_shader/src/main.cpp +++ b/projects/mesh_shader/src/main.cpp @@ -140,10 +140,10 @@ int main(int argc, const char** argv) { // mesh shader buffers const auto& assetLoaderIndexBuffer = mesh.vertexGroups[0].indexBuffer; std::vector<uint32_t> indexBuffer32Bit = vkcv::meshlet::assetLoaderIndicesTo32BitIndices(assetLoaderIndexBuffer.data, assetLoaderIndexBuffer.type); - //std::vector<uint32_t> reorderedIndexBuffer32Bit = vkcv::meshlet::tipsifyMesh(indexBuffer32Bit, interleavedVertices.size()); - std::vector<uint32_t> reorderedIndexBuffer32Bit = vkcv::meshlet::forsythReorder(indexBuffer32Bit, interleavedVertices.size()); + vkcv::meshlet::tipsifyResult tipsifyResult = vkcv::meshlet::tipsifyMesh(indexBuffer32Bit, interleavedVertices.size()); + //std::vector<uint32_t> reorderedIndexBuffer32Bit = vkcv::meshlet::forsythReorder(indexBuffer32Bit, interleavedVertices.size()); - const auto meshShaderModelData = createMeshShaderModelData(interleavedVertices, reorderedIndexBuffer32Bit); + const auto meshShaderModelData = createMeshShaderModelData(interleavedVertices, tipsifyResult.indexBuffer); auto meshShaderVertexBuffer = core.createBuffer<vkcv::meshlet::Vertex>( vkcv::BufferType::STORAGE,