Meshlet gen
This commit is contained in:
@@ -121,11 +121,6 @@ if(WIN32)
|
|||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:Engine> $<TARGET_FILE_DIR:Editor>
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:Engine> $<TARGET_FILE_DIR:Editor>
|
||||||
COMMAND_EXPAND_LISTS
|
COMMAND_EXPAND_LISTS
|
||||||
DEPENDS Editor)
|
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()
|
else()
|
||||||
add_custom_target(dll_copy ALL
|
add_custom_target(dll_copy ALL
|
||||||
COMMAND ${CMAKE_COMMAND} -E true)
|
COMMAND ${CMAKE_COMMAND} -E true)
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ if(WIN32)
|
|||||||
${SLANG_ROOT}/lib/slang.lib
|
${SLANG_ROOT}/lib/slang.lib
|
||||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
|
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
|
||||||
elseif(APPLE)
|
elseif(APPLE)
|
||||||
set(SLANG_ROOT ${EXTERNAL_ROOT}/vcpkg/packages/shader-slang_${CMAKE_PLATFORM}-macos/)
|
set(SLANG_ROOT ${EXTERNAL_ROOT}/vcpkg/packages/shader-slang_${CMAKE_PLATFORM}-osx)
|
||||||
set_target_properties(shader-slang-glslang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}/libslang-glslang.dylib)
|
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}/libslang.dylib)
|
set_target_properties(shader-slang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}/bin/libslang.dylib)
|
||||||
target_link_libraries(shader-slang INTERFACE shader-slang-glslang)
|
target_link_libraries(shader-slang INTERFACE shader-slang-glslang)
|
||||||
install(FILES
|
install(FILES
|
||||||
${SLANG_ROOT}/libslang.dylib
|
${SLANG_ROOT}/bin/libslang.dylib
|
||||||
${SLANG_ROOT}/libslang-glslang.dylib
|
${SLANG_ROOT}/bin/libslang-glslang.dylib
|
||||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||||
endif()
|
endif()
|
||||||
target_include_directories(shader-slang INTERFACE
|
target_include_directories(shader-slang INTERFACE
|
||||||
|
|||||||
@@ -8,9 +8,12 @@ using namespace Seele;
|
|||||||
struct Triangle
|
struct Triangle
|
||||||
{
|
{
|
||||||
StaticArray<uint32, 3> indices;
|
StaticArray<uint32, 3> indices;
|
||||||
|
Array<uint32> twoAdjacent;
|
||||||
|
Array<uint32> oneAdjacent;
|
||||||
|
int32 meshletId = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
int findIndex(Meshlet& current, uint32 index)
|
int findIndex(Meshlet ¤t, uint32 index)
|
||||||
{
|
{
|
||||||
for (uint32 i = 0; i < current.numVertices; ++i)
|
for (uint32 i = 0; i < current.numVertices; ++i)
|
||||||
{
|
{
|
||||||
@@ -28,7 +31,7 @@ int findIndex(Meshlet& current, uint32 index)
|
|||||||
return current.numVertices++;
|
return current.numVertices++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void completeMeshlet(Array<Meshlet>& meshlets, Meshlet& current)
|
void completeMeshlet(Array<Meshlet> &meshlets, Meshlet ¤t)
|
||||||
{
|
{
|
||||||
meshlets.add(current);
|
meshlets.add(current);
|
||||||
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 ¤t, Triangle tri)
|
||||||
{
|
{
|
||||||
int f1 = findIndex(current, tri.indices[0]);
|
int f1 = findIndex(current, tri.indices[0]);
|
||||||
int f2 = findIndex(current, tri.indices[1]);
|
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)
|
if (f1 == -1 || f2 == -1 || f3 == -1)
|
||||||
{
|
{
|
||||||
completeMeshlet(meshlets, current);
|
return false;
|
||||||
f1 = findIndex(current, tri.indices[0]);
|
|
||||||
f2 = findIndex(current, tri.indices[1]);
|
|
||||||
f3 = findIndex(current, tri.indices[2]);
|
|
||||||
}
|
}
|
||||||
|
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 + 0] = uint8(f1);
|
||||||
current.primitiveLayout[current.numPrimitives * 3 + 1] = uint8(f2);
|
current.primitiveLayout[current.numPrimitives * 3 + 1] = uint8(f2);
|
||||||
current.primitiveLayout[current.numPrimitives * 3 + 2] = uint8(f3);
|
current.primitiveLayout[current.numPrimitives * 3 + 2] = uint8(f3);
|
||||||
current.numPrimitives++;
|
current.numPrimitives++;
|
||||||
if (current.numPrimitives == Gfx::numPrimitivesPerMeshlet)
|
return true;
|
||||||
{
|
|
||||||
completeMeshlet(meshlets, current);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = {
|
Meshlet current = {
|
||||||
.numVertices = 0,
|
.numVertices = 0,
|
||||||
@@ -70,13 +70,57 @@ void Meshlet::build(const Array<Vector>& positions, const Array<uint32>& indices
|
|||||||
Array<Triangle> triangles(indices.size() / 3);
|
Array<Triangle> triangles(indices.size() / 3);
|
||||||
for (size_t i = 0; i < triangles.size(); ++i)
|
for (size_t i = 0; i < triangles.size(); ++i)
|
||||||
{
|
{
|
||||||
triangles.add(Triangle{
|
triangles[i] = Triangle{
|
||||||
.indices = {
|
.indices = {
|
||||||
indices[i * 3 + 0],
|
indices[i * 3 + 0],
|
||||||
indices[i * 3 + 1],
|
indices[i * 3 + 1],
|
||||||
indices[i * 3 + 2],
|
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)
|
if (current.numVertices > 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user