Adding AABB to meshlets

This commit is contained in:
Dynamitos
2023-12-11 14:45:37 +01:00
parent eceb0f6bcc
commit 3feb331927
17 changed files with 63 additions and 51 deletions
+1 -1
View File
@@ -268,7 +268,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
Array<Meshlet> meshlets;
meshlets.reserve(indices.size() / (3ull * Gfx::numPrimitivesPerMeshlet));
Meshlet::buildFromIndexBuffer(indices, meshlets);
Meshlet::build(positions, indices, meshlets);
vertexData->loadMesh(id, indices, meshlets);
collider.physicsMesh.addCollider(positions, indices, Matrix4(1.0f));
+1 -1
View File
@@ -229,7 +229,7 @@ int main()
sceneViewInfo.dimensions.size.y = 1080;
sceneViewInfo.dimensions.offset.x = 0;
sceneViewInfo.dimensions.offset.y = 0;
sceneViewInfo.numSamples = Gfx::SE_SAMPLE_COUNT_1_BIT;
sceneViewInfo.numSamples = Gfx::SE_SAMPLE_COUNT_4_BIT;
OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string());
//ViewportCreateInfo inspectorViewInfo;
-2
View File
@@ -1,6 +1,5 @@
target_sources(Engine
PRIVATE
AABB.h
BoxCollider.h
Camera.h
Camera.cpp
@@ -24,7 +23,6 @@ target_sources(Engine
target_sources(Engine
PUBLIC FILE_SET HEADERS
FILES
AABB.h
BoxCollider.h
Camera.h
Collider.h
+1 -1
View File
@@ -1,5 +1,5 @@
#pragma once
#include "AABB.h"
#include "Math/AABB.h"
#include "ShapeBase.h"
namespace Seele
+1 -1
View File
@@ -1,5 +1,5 @@
#pragma once
#include "AABB.h"
#include "Math/AABB.h"
namespace Seele
{
+1 -1
View File
@@ -1,5 +1,5 @@
#include "ShapeBase.h"
#include "AABB.h"
#include "Math/AABB.h"
using namespace Seele;
using namespace Seele::Component;
+11 -4
View File
@@ -456,9 +456,12 @@ public:
{
return;
}
for(size_type i = 0; i < arraySize; ++i)
if constexpr (!std::is_trivially_destructible_v<T>)
{
std::allocator_traits<allocator_type>::destroy(allocator, &_data[i]);
for (size_type i = 0; i < arraySize; ++i)
{
std::allocator_traits<allocator_type>::destroy(allocator, &_data[i]);
}
}
deallocateArray(_data, allocated);
_data = nullptr;
@@ -596,9 +599,13 @@ private:
if(newSize < arraySize)
{
// But since we are sizing down we destruct some of them
for(size_type i = newSize; i < arraySize; ++i)
if constexpr (!std::is_trivially_destructible_v<T>)
{
std::allocator_traits<allocator_type>::destroy(allocator, &_data[i]);
for (size_type i = newSize; i < arraySize; ++i)
{
std::allocator_traits<allocator_type>::destroy(allocator, &_data[i]);
}
}
}
else
+15 -15
View File
@@ -70,21 +70,21 @@ struct TextureCreateInfo
struct SamplerCreateInfo
{
Gfx::SeSamplerCreateFlags flags;
Gfx::SeFilter magFilter;
Gfx::SeFilter minFilter;
Gfx::SeSamplerMipmapMode mipmapMode;
Gfx::SeSamplerAddressMode addressModeU;
Gfx::SeSamplerAddressMode addressModeV;
Gfx::SeSamplerAddressMode addressModeW;
float mipLodBias;
uint32 anisotropyEnable;
float maxAnisotropy;
uint32 compareEnable;
Gfx::SeCompareOp compareOp;
float minLod;
float maxLod;
Gfx::SeBorderColor borderColor;
uint32 unnormalizedCoordinates;
Gfx::SeFilter magFilter = Gfx::SE_FILTER_LINEAR;
Gfx::SeFilter minFilter = Gfx::SE_FILTER_LINEAR;
Gfx::SeSamplerMipmapMode mipmapMode = Gfx::SE_SAMPLER_MIPMAP_MODE_LINEAR;
Gfx::SeSamplerAddressMode addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT;
Gfx::SeSamplerAddressMode addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT;
Gfx::SeSamplerAddressMode addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT;
float mipLodBias = 0.0f;
uint32 anisotropyEnable = 0;
float maxAnisotropy = 0.0f;
uint32 compareEnable = 0;
Gfx::SeCompareOp compareOp = Gfx::SE_COMPARE_OP_NEVER;
float minLod = 0.0f;
float maxLod = 0.0f;
Gfx::SeBorderColor borderColor = Gfx::SE_BORDER_COLOR_FLOAT_OPAQUE_BLACK;
uint32 unnormalizedCoordinates = 0;
};
struct VertexBufferCreateInfo
{
+7 -3
View File
@@ -97,9 +97,11 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
{
uint32 numMeshlets = std::min<uint32>(512, loadedMeshlets.size() - currentMesh);
uint32 meshletOffset = meshlets.size();
AABB meshAABB;
for (uint32 i = 0; i < numMeshlets; ++i)
{
Meshlet& m = loadedMeshlets[currentMesh + i];
meshAABB = meshAABB.combine(m.boundingBox);
uint32 vertexOffset = vertexIndices.size();
vertexIndices.resize(vertexOffset + m.numVertices);
std::memcpy(vertexIndices.data() + vertexOffset, m.uniqueVertices, m.numVertices * sizeof(uint32));
@@ -107,7 +109,7 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
primitiveIndices.resize(primitiveOffset + (m.numPrimitives * 3));
std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout, m.numPrimitives * 3 * sizeof(uint8));
meshlets.add(MeshletDescription{
.boundingBox = MeshletAABB(),
.boundingBox = m.boundingBox,
.vertexCount = m.numVertices,
.primitiveCount = m.numPrimitives,
.vertexOffset = vertexOffset,
@@ -115,6 +117,7 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
});
}
meshData[id].add(MeshData{
.boundingBox = meshAABB,
.numMeshlets = numMeshlets,
.meshletOffset = meshletOffset,
.indicesOffset = static_cast<uint32>(meshOffsets[id]),
@@ -230,14 +233,14 @@ VertexData::VertexData()
{
}
void Seele::Meshlet::buildFromIndexBuffer(const Array<uint32>& indices, Array<Meshlet>& meshlets)
void Meshlet::build(const Array<Vector>& positions, const Array<uint32>& indices, Array<Meshlet>& meshlets)
{
std::set<uint32> uniqueVertices;
Meshlet current = {
.numVertices = 0,
.numPrimitives = 0,
};
auto insertAndGetIndex = [&uniqueVertices, &current](uint32 index) -> int8_t
auto insertAndGetIndex = [&positions, &uniqueVertices, &current](uint32 index) -> int8_t
{
auto [it, inserted] = uniqueVertices.insert(index);
if (inserted)
@@ -247,6 +250,7 @@ void Seele::Meshlet::buildFromIndexBuffer(const Array<uint32>& indices, Array<Me
return -1;
}
current.uniqueVertices[current.numVertices] = index;
current.boundingBox.adjust(positions[index]);
return current.numVertices++;
}
else
+5 -9
View File
@@ -6,6 +6,7 @@
#include "Graphics/Command.h"
#include "Graphics/Descriptor.h"
#include "Graphics/Buffer.h"
#include "Math/AABB.h"
namespace Seele
{
@@ -24,11 +25,12 @@ struct MeshId
};
struct Meshlet
{
AABB boundingBox;
uint32 uniqueVertices[Gfx::numVerticesPerMeshlet]; // unique vertiex indices in the vertex data
uint8 primitiveLayout[Gfx::numPrimitivesPerMeshlet * 3]; // indices into the uniqueVertices array, only uint8 needed
uint32 numVertices;
uint32 numPrimitives;
static void buildFromIndexBuffer(const Array<uint32>& indices, Array<Meshlet>& meshlets);
static void build(const Array<Vector>& positions, const Array<uint32>& indices, Array<Meshlet>& meshlets);
};
class VertexData
{
@@ -39,6 +41,7 @@ public:
};
struct MeshData
{
AABB boundingBox;
uint32 numMeshlets = 0;
uint32 meshletOffset = 0;
uint32 firstIndex = 0;
@@ -87,16 +90,9 @@ protected:
virtual void resizeBuffers() = 0;
virtual void updateBuffers() = 0;
VertexData();
struct MeshletAABB
{
Vector min;
float pad0;
Vector max;
float pad1;
};
struct MeshletDescription
{
MeshletAABB boundingBox;
AABB boundingBox;
uint32_t vertexCount;
uint32_t primitiveCount;
uint32_t vertexOffset;
@@ -1,6 +1,6 @@
#pragma once
#include "Math/Vector.h"
#include "Math/Matrix.h"
#include "Vector.h"
#include "Matrix.h"
#include "Containers/Array.h"
#include "Graphics/DebugVertex.h"
namespace Seele
@@ -8,7 +8,9 @@ namespace Seele
struct AABB
{
Vector min = Vector(std::numeric_limits<float>::max());
float pad0; // So that it can be used directly in shaders
Vector max = Vector(std::numeric_limits<float>::lowest());// cause of reasons
float pad1;
void visualize(Array<DebugVertex>& vertices) const
{
StaticArray<DebugVertex, 8> corners;
+2
View File
@@ -1,5 +1,6 @@
target_sources(Engine
PRIVATE
AABB.h
Math.h
Matrix.h
Transform.h
@@ -10,6 +11,7 @@ target_sources(Engine
target_sources(Engine
PUBLIC FILE_SET HEADERS
FILES
AABB.h
Math.h
Matrix.h
Transform.h
+1 -1
View File
@@ -1,7 +1,7 @@
#pragma once
#include <entt/entt.hpp>
#include "Containers/Array.h"
#include "Component/AABB.h"
#include "Math/AABB.h"
#include "Component/Collider.h"
#include "Containers/Pair.h"