From d6381a03c5acad5f36db4b7d5a9211fbc7e54244 Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Sun, 7 Apr 2024 22:55:17 +0200 Subject: [PATCH] Meshlet gen --- CMakeLists.txt | 5 --- cmake/SuperBuild.cmake | 10 ++--- src/Engine/Graphics/Meshlet.cpp | 72 ++++++++++++++++++++++++++------- 3 files changed, 63 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cbabe16..b681195 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,11 +121,6 @@ if(WIN32) COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ COMMAND_EXPAND_LISTS DEPENDS Editor) -elseif(APPLE) - add_custom_target(dll_copy ALL - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_ROOT}/libslang.dylib $ - COMMAND_EXPAND_LISTS - DEPENDS Editor) else() add_custom_target(dll_copy ALL COMMAND ${CMAKE_COMMAND} -E true) diff --git a/cmake/SuperBuild.cmake b/cmake/SuperBuild.cmake index 8f405c9..fda1c21 100644 --- a/cmake/SuperBuild.cmake +++ b/cmake/SuperBuild.cmake @@ -19,13 +19,13 @@ if(WIN32) ${SLANG_ROOT}/lib/slang.lib DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) elseif(APPLE) - set(SLANG_ROOT ${EXTERNAL_ROOT}/vcpkg/packages/shader-slang_${CMAKE_PLATFORM}-macos/) - set_target_properties(shader-slang-glslang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}/libslang-glslang.dylib) - set_target_properties(shader-slang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}/libslang.dylib) + set(SLANG_ROOT ${EXTERNAL_ROOT}/vcpkg/packages/shader-slang_${CMAKE_PLATFORM}-osx) + set_target_properties(shader-slang-glslang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}/bin/libslang-glslang.dylib) + set_target_properties(shader-slang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}/bin/libslang.dylib) target_link_libraries(shader-slang INTERFACE shader-slang-glslang) install(FILES - ${SLANG_ROOT}/libslang.dylib - ${SLANG_ROOT}/libslang-glslang.dylib + ${SLANG_ROOT}/bin/libslang.dylib + ${SLANG_ROOT}/bin/libslang-glslang.dylib DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) endif() target_include_directories(shader-slang INTERFACE diff --git a/src/Engine/Graphics/Meshlet.cpp b/src/Engine/Graphics/Meshlet.cpp index aad824a..23fc4b4 100644 --- a/src/Engine/Graphics/Meshlet.cpp +++ b/src/Engine/Graphics/Meshlet.cpp @@ -8,9 +8,12 @@ using namespace Seele; struct Triangle { StaticArray indices; + Array twoAdjacent; + Array oneAdjacent; + int32 meshletId = -1; }; -int findIndex(Meshlet& current, uint32 index) +int findIndex(Meshlet ¤t, uint32 index) { for (uint32 i = 0; i < current.numVertices; ++i) { @@ -28,7 +31,7 @@ int findIndex(Meshlet& current, uint32 index) return current.numVertices++; } -void completeMeshlet(Array& meshlets, Meshlet& current) +void completeMeshlet(Array &meshlets, Meshlet ¤t) { meshlets.add(current); current = { @@ -38,7 +41,7 @@ void completeMeshlet(Array& meshlets, Meshlet& current) }; } -void addTriangle(Array& meshlets, Meshlet& current, Triangle tri) +bool addTriangle(const Array& positions, Array &meshlets, Meshlet ¤t, Triangle tri) { int f1 = findIndex(current, tri.indices[0]); int f2 = findIndex(current, tri.indices[1]); @@ -46,22 +49,19 @@ void addTriangle(Array& meshlets, Meshlet& current, Triangle tri) if (f1 == -1 || f2 == -1 || f3 == -1) { - completeMeshlet(meshlets, current); - f1 = findIndex(current, tri.indices[0]); - f2 = findIndex(current, tri.indices[1]); - f3 = findIndex(current, tri.indices[2]); + return false; } + current.boundingBox.adjust(positions[tri.indices[0]]); + current.boundingBox.adjust(positions[tri.indices[1]]); + current.boundingBox.adjust(positions[tri.indices[2]]); current.primitiveLayout[current.numPrimitives * 3 + 0] = uint8(f1); current.primitiveLayout[current.numPrimitives * 3 + 1] = uint8(f2); current.primitiveLayout[current.numPrimitives * 3 + 2] = uint8(f3); current.numPrimitives++; - if (current.numPrimitives == Gfx::numPrimitivesPerMeshlet) - { - completeMeshlet(meshlets, current); - } + return true; } -void Meshlet::build(const Array& positions, const Array& indices, Array& meshlets) +void Meshlet::build(const Array &positions, const Array &indices, Array &meshlets) { Meshlet current = { .numVertices = 0, @@ -70,14 +70,58 @@ void Meshlet::build(const Array& positions, const Array& indices Array triangles(indices.size() / 3); for (size_t i = 0; i < triangles.size(); ++i) { - triangles.add(Triangle{ + triangles[i] = Triangle{ .indices = { indices[i * 3 + 0], indices[i * 3 + 1], indices[i * 3 + 2], }, - }); + }; + } + for (size_t i = 0; i < triangles.size(); i++) + { + for (size_t j = 0; j < triangles.size(); j++) + { + if (i == j) + continue; + uint32 adjacency = 0; + if (triangles[i].indices[0] == triangles[j].indices[0] + || triangles[i].indices[0] == triangles[j].indices[1] + || triangles[i].indices[0] == triangles[j].indices[2]) + { + adjacency++; + } + if (triangles[i].indices[1] == triangles[j].indices[0] + || triangles[i].indices[1] == triangles[j].indices[1] + || triangles[i].indices[1] == triangles[j].indices[2]) + { + adjacency++; + } + if (triangles[i].indices[1] == triangles[j].indices[0] + || triangles[i].indices[1] == triangles[j].indices[1] + || triangles[i].indices[1] == triangles[j].indices[2]) + { + adjacency++; + } + if(adjacency == 2) + { + triangles[i].twoAdjacent.add(j); + triangles[j].twoAdjacent.add(i); + } + if(adjacency == 1) + { + triangles[i].oneAdjacent.add(j); + triangles[j].oneAdjacent.add(i); + } + } + } + addTriangle(positions, meshlets, current, triangles.back()); + triangles.pop(); + while(!triangles.empty()) + { + AABB boundingBox; + } if (current.numVertices > 0) {