Meshlet gen

This commit is contained in:
Dynamitos
2024-04-07 22:55:17 +02:00
parent cde48f0d15
commit d6381a03c5
3 changed files with 63 additions and 24 deletions
-5
View File
@@ -121,11 +121,6 @@ if(WIN32)
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:Engine> $<TARGET_FILE_DIR:Editor>
COMMAND_EXPAND_LISTS
DEPENDS Editor)
elseif(APPLE)
add_custom_target(dll_copy ALL
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_ROOT}/libslang.dylib $<TARGET_FILE_DIR:Editor>
COMMAND_EXPAND_LISTS
DEPENDS Editor)
else()
add_custom_target(dll_copy ALL
COMMAND ${CMAKE_COMMAND} -E true)
+5 -5
View File
@@ -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
+58 -14
View File
@@ -8,9 +8,12 @@ using namespace Seele;
struct Triangle
{
StaticArray<uint32, 3> indices;
Array<uint32> twoAdjacent;
Array<uint32> oneAdjacent;
int32 meshletId = -1;
};
int findIndex(Meshlet& current, uint32 index)
int findIndex(Meshlet &current, 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<Meshlet>& meshlets, Meshlet& current)
void completeMeshlet(Array<Meshlet> &meshlets, Meshlet &current)
{
meshlets.add(current);
current = {
@@ -38,7 +41,7 @@ void completeMeshlet(Array<Meshlet>& meshlets, Meshlet& current)
};
}
void addTriangle(Array<Meshlet>& meshlets, Meshlet& current, Triangle tri)
bool addTriangle(const Array<Vector>& positions, Array<Meshlet> &meshlets, Meshlet &current, Triangle tri)
{
int f1 = findIndex(current, tri.indices[0]);
int f2 = findIndex(current, tri.indices[1]);
@@ -46,22 +49,19 @@ void addTriangle(Array<Meshlet>& 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<Vector>& positions, const Array<uint32>& indices, Array<Meshlet>& meshlets)
void Meshlet::build(const Array<Vector> &positions, const Array<uint32> &indices, Array<Meshlet> &meshlets)
{
Meshlet current = {
.numVertices = 0,
@@ -70,14 +70,58 @@ void Meshlet::build(const Array<Vector>& positions, const Array<uint32>& indices
Array<Triangle> 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)
{