More tangent changes
This commit is contained in:
@@ -462,40 +462,44 @@ void MeshLoader::findMeshRoots(aiNode* node, List<aiNode*>& meshNodes) {
|
||||
}
|
||||
}
|
||||
|
||||
uint32 MeshLoader::encodeQTangent(Matrix3 m) {
|
||||
float r = (glm::determinant(m) ? -1.0 : 1.0);
|
||||
m[2] *= r;
|
||||
Vector4 MeshLoader::encodeQTangent(Matrix3 m) {
|
||||
float f = 1.0;
|
||||
if (((((((m[0][0] * m[1][1] * m[2][2]) + (m[0][1] * m[1][2] * m[2][0])) + (m[0][2] * m[1][0] * m[2][1])) -
|
||||
(m[0][2] * m[1][1] * m[2][0])) -
|
||||
(m[0][1] * m[1][0] * m[2][2])) -
|
||||
(m[0][0] * m[1][2] * m[2][1])) < 0.0) {
|
||||
f = -1.0;
|
||||
m[2] = -m[2];
|
||||
}
|
||||
float t = m[0][0] + (m[1][1] + m[2][2]);
|
||||
Vector4 q;
|
||||
Vector4 r;
|
||||
if (t > 2.9999999) {
|
||||
q = Vector4(0.0, 0.0, 0.0, 1.0);
|
||||
r = Vector4(0.0, 0.0, 0.0, 1.0);
|
||||
} else if (t > 0.0000001) {
|
||||
float s = sqrt(1.0 + t) * 2.0;
|
||||
q = Vector4(Vector(m[1][2] - m[2][1], m[2][0] - m[0][2], m[0][1] - m[1][0]) / s, s * 0.25);
|
||||
r = Vector4(Vector(m[1][2] - m[2][1], m[2][0] - m[0][2], m[0][1] - m[1][0]) / s, s * 0.25);
|
||||
} else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {
|
||||
float s = sqrt(1.0 + (m[0][0] - (m[1][1] + m[2][2]))) * 2.0;
|
||||
q = Vector4(s * 0.25, Vector(m[1][0] + m[0][1], m[2][0] + m[0][2], m[1][2] - m[2][1]) / s);
|
||||
r = Vector4(s * 0.25, Vector(m[1][0] - m[0][1], m[2][0] - m[0][2], m[0][2] - m[2][1]) / s);
|
||||
} else if (m[1][1] > m[2][2]) {
|
||||
float s = sqrt(1.0 + (m[1][1] - (m[0][0] + m[2][2]))) * 2.0;
|
||||
q = Vector4(Vector(m[1][0] + m[0][1], m[2][1] + m[1][2], m[2][0] - m[0][2]) / s, s * 0.25);
|
||||
q = Vector4(q.x, q.w, q.y, q.z);
|
||||
r = Vector4(Vector(m[1][0] + m[0][1], m[2][1] + m[1][2], m[2][0] - m[0][2]) / s, s * 0.25);
|
||||
r = Vector4(r.x, r.w, r.y, r.z);
|
||||
} else {
|
||||
float s = sqrt(1.0 + (m[2][2] - (m[0][0] + m[1][1]))) * 2.0;
|
||||
q = Vector4(Vector(m[2][0] + m[0][2], m[2][1] + m[1][2], m[0][1] - m[1][0]) / s, s * 0.25);
|
||||
q = Vector4(q.x, q.y, q.w, q.z);
|
||||
r = Vector4(Vector(m[2][0] + m[0][2], m[2][1] + m[1][2], m[0][1] - m[1][0]) / s, s * 0.25);
|
||||
r = Vector4(r.x, r.y, r.w, r.z);
|
||||
}
|
||||
Vector4 qAbs = abs(q = glm::normalize(q));
|
||||
int maxComponentIndex = (qAbs.x > qAbs.y) ? ((qAbs.x > qAbs.z) ? ((qAbs.x > qAbs.w) ? 0 : 3) : ((qAbs.z > qAbs.w) ? 2 : 3))
|
||||
: ((qAbs.y > qAbs.z) ? ((qAbs.y > qAbs.w) ? 1 : 3) : ((qAbs.z > qAbs.w) ? 2 : 3));
|
||||
Vector components[4] = {Vector(q.y, q.z, q.w), Vector(q.x, q.z, q.w), Vector(q.x, q.y, q.w), Vector(q.x, q.y, q.z)};
|
||||
|
||||
q = Vector4(components[maxComponentIndex] * float(((q[maxComponentIndex] < 0.0) ? -1.0 : 1.0) * 1.4142135623730951), q.w);
|
||||
return ((uint32(round(glm::clamp(q.x * 511.0, -511.0, 511.0) + 512.0)) & 0x3ffu) << 0u) |
|
||||
((uint32(round(glm::clamp(q.y * 511.0, -511.0, 511.0) + 512.0)) & 0x3ffu) << 10u) |
|
||||
((uint32(round(glm::clamp(q.z * 255.0, -255.0, 255.0) + 256.0)) & 0x1ffu) << 20u) |
|
||||
((uint32(((dot(cross(m[0], m[2]), m[1]) * r) < 0.0) ? 1u : 0u) & 0x1u) << 29u) | ((uint32(maxComponentIndex) & 0x3u) << 30u);
|
||||
r = normalize(r);
|
||||
const float threshold = 1.0 / 32767.0;
|
||||
if (r.w <= threshold) {
|
||||
r = Vector4(Vector(r) * (float)sqrt(1.0 - (threshold * threshold)), (r.w > 0.0) ? threshold : -threshold);
|
||||
}
|
||||
if (((f < 0.0) && (r.w >= 0.0)) || ((f >= 0.0) && (r.w < 0.0))) {
|
||||
r = -r;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialInstanceAsset>& materials, Array<OMesh>& globalMeshes,
|
||||
Component::Collider& collider) {
|
||||
List<std::function<void()>> work;
|
||||
@@ -512,13 +516,15 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
||||
collider.boundingbox.adjust(Vector(mesh->mAABB.mMax.x, mesh->mAABB.mMax.y, mesh->mAABB.mMax.z));
|
||||
work.add([=, this, &globalMeshes]() {
|
||||
// assume static mesh for now
|
||||
Array<Vector> positions(mesh->mNumVertices);
|
||||
StaticArray<Array<U16Vector2>, MAX_TEXCOORDS> texCoords;
|
||||
Array<StaticMeshVertexData::PositionType> positions(mesh->mNumVertices);
|
||||
StaticArray<Array<StaticMeshVertexData::TexCoordType>, MAX_TEXCOORDS> texCoords;
|
||||
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
|
||||
texCoords[i].resize(mesh->mNumVertices);
|
||||
}
|
||||
Array<uint32> normals(mesh->mNumVertices);
|
||||
Array<U16Vector> colors(mesh->mNumVertices);
|
||||
Array<StaticMeshVertexData::NormalType> normals(mesh->mNumVertices);
|
||||
Array<StaticMeshVertexData::TangentType> tangents(mesh->mNumVertices);
|
||||
Array<StaticMeshVertexData::BiTangentType> biTangents(mesh->mNumVertices);
|
||||
Array<StaticMeshVertexData::ColorType> colors(mesh->mNumVertices);
|
||||
|
||||
for (int32 i = 0; i < mesh->mNumVertices; ++i) {
|
||||
positions[i] = Vector(mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z);
|
||||
@@ -536,14 +542,14 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
||||
tangent = Vector(mesh->mTangents[i].x, mesh->mTangents[i].y, mesh->mTangents[i].z);
|
||||
biTangent = Vector(mesh->mBitangents[i].x, mesh->mBitangents[i].y, mesh->mBitangents[i].z);
|
||||
}
|
||||
Matrix3 tbn = {normal, biTangent, tangent};
|
||||
|
||||
normals[i] = encodeQTangent(tbn);
|
||||
normals[i] = normal;
|
||||
tangents[i] = tangent;
|
||||
biTangents[i] = biTangent;
|
||||
|
||||
if (mesh->HasVertexColors(0)) {
|
||||
colors[i] = U16Vector(mesh->mColors[0][i].r * 65535, mesh->mColors[0][i].g * 65535, mesh->mColors[0][i].b * 65535);
|
||||
colors[i] = StaticMeshVertexData::ColorType(mesh->mColors[0][i].r * 65535, mesh->mColors[0][i].g * 65535, mesh->mColors[0][i].b * 65535);
|
||||
} else {
|
||||
colors[i] = U16Vector(1, 1, 1);
|
||||
colors[i] = StaticMeshVertexData::ColorType(1, 1, 1);
|
||||
}
|
||||
}
|
||||
vertexData->loadPositions(offset, positions);
|
||||
@@ -552,6 +558,8 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
||||
vertexData->loadTexCoords(offset, i, texCoords[i]);
|
||||
}
|
||||
vertexData->loadNormals(offset, normals);
|
||||
vertexData->loadTangents(offset, tangents);
|
||||
vertexData->loadBitangents(offset, biTangents);
|
||||
vertexData->loadColors(offset, colors);
|
||||
|
||||
Array<uint32> indices(mesh->mNumFaces * 3);
|
||||
@@ -575,7 +583,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
||||
globalMeshes[meshIndex]->blas = graphics->createBottomLevelAccelerationStructure(Gfx::BottomLevelASCreateInfo{
|
||||
.mesh = globalMeshes[meshIndex],
|
||||
});
|
||||
// vertexData->registerBottomLevelAccelerationStructure(globalMeshes[meshIndex]->blas);
|
||||
vertexData->registerBottomLevelAccelerationStructure(globalMeshes[meshIndex]->blas);
|
||||
});
|
||||
}
|
||||
getThreadPool().runAndWait(std::move(work));
|
||||
|
||||
@@ -26,7 +26,7 @@ class MeshLoader {
|
||||
|
||||
private:
|
||||
void findMeshRoots(aiNode* node, List<aiNode*>& meshNodes);
|
||||
uint32 encodeQTangent(Matrix3 m);
|
||||
Vector4 encodeQTangent(Matrix3 m);
|
||||
|
||||
void loadTextures(const aiScene* scene, const std::filesystem::path& meshDirectory, const std::string& importPath,
|
||||
Array<PTextureAsset>& textures);
|
||||
|
||||
+12
-1
@@ -96,6 +96,13 @@ int main() {
|
||||
.filePath = sourcePath / "import/textures/skybox.jpg",
|
||||
.type = TextureImportType::TEXTURE_CUBEMAP,
|
||||
});
|
||||
AssetImporter::importTexture(TextureImportArgs{
|
||||
.filePath = sourcePath / "import/textures/brickwall.jpg",
|
||||
});
|
||||
AssetImporter::importTexture(TextureImportArgs{
|
||||
.filePath = sourcePath / "import/textures/brickwall_normal.jpg",
|
||||
.type = TextureImportType::TEXTURE_NORMAL,
|
||||
});
|
||||
// AssetImporter::importMesh(MeshImportArgs{
|
||||
// .filePath = sourcePath / "import/models/ship.fbx",
|
||||
// .importPath = "ship",
|
||||
@@ -113,7 +120,11 @@ int main() {
|
||||
.filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
|
||||
.importPath = "Whitechapel",
|
||||
});
|
||||
// AssetImporter::importMesh(MeshImportArgs{521
|
||||
//AssetImporter::importMesh(MeshImportArgs{
|
||||
// .filePath = sourcePath / "import/models/plane.obj",
|
||||
// .importPath = "",
|
||||
//});
|
||||
// AssetImporter::importMesh(MeshImportArgs{
|
||||
// .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj",
|
||||
// .importPath = "suburbs",
|
||||
// });
|
||||
|
||||
@@ -79,8 +79,8 @@ BasePass::BasePass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics,
|
||||
});
|
||||
}
|
||||
skybox = Seele::Component::Skybox{
|
||||
.day = AssetRegistry::findTexture("", "skyboxsun5deg_tn")->getTexture().cast<Gfx::TextureCube>(),
|
||||
.night = AssetRegistry::findTexture("", "skyboxsun5deg_tn")->getTexture().cast<Gfx::TextureCube>(),
|
||||
.day = AssetRegistry::findTexture("", "skybox")->getTexture().cast<Gfx::TextureCube>(),
|
||||
.night = AssetRegistry::findTexture("", "skybox")->getTexture().cast<Gfx::TextureCube>(),
|
||||
.fogColor = Vector(0.1, 0.1, 0.8),
|
||||
.blendFactor = 0,
|
||||
};
|
||||
|
||||
@@ -18,31 +18,38 @@ StaticMeshVertexData* StaticMeshVertexData::getInstance() {
|
||||
return &instance;
|
||||
}
|
||||
|
||||
void StaticMeshVertexData::loadPositions(uint64 offset, const Array<Vector>& data) {
|
||||
void StaticMeshVertexData::loadPositions(uint64 offset, const Array<PositionType>& data) {
|
||||
assert(offset + data.size() <= head);
|
||||
std::memcpy(posData.data() + offset, data.data(), data.size() * sizeof(Vector));
|
||||
// positions->updateContents(offset * sizeof(Vector4), data.size() * sizeof(Vector4), data.data());
|
||||
std::memcpy(posData.data() + offset, data.data(), data.size() * sizeof(PositionType));
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void StaticMeshVertexData::loadTexCoords(uint64 offset, uint64 index, const Array<U16Vector2>& data) {
|
||||
void StaticMeshVertexData::loadTexCoords(uint64 offset, uint64 index, const Array<TexCoordType>& data) {
|
||||
assert(offset + data.size() <= head);
|
||||
std::memcpy(texData[index].data() + offset, data.data(), data.size() * sizeof(U16Vector2));
|
||||
// texCoords[index]->updateContents(offset * sizeof(Vector2), data.size() * sizeof(Vector2), data.data());
|
||||
std::memcpy(texData[index].data() + offset, data.data(), data.size() * sizeof(TexCoordType));
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void StaticMeshVertexData::loadNormals(uint64 offset, const Array<uint32>& data) {
|
||||
void StaticMeshVertexData::loadNormals(uint64 offset, const Array<NormalType>& data) {
|
||||
assert(offset + data.size() <= head);
|
||||
std::memcpy(norData.data() + offset, data.data(), data.size() * sizeof(uint32));
|
||||
// normals->updateContents(offset * sizeof(Vector4), data.size() * sizeof(Vector4), data.data());
|
||||
std::memcpy(norData.data() + offset, data.data(), data.size() * sizeof(NormalType));
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void StaticMeshVertexData::loadColors(uint64 offset, const Array<U16Vector>& data) {
|
||||
void StaticMeshVertexData::loadTangents(uint64 offset, const Array<TangentType>& data) {
|
||||
assert(offset + data.size() <= head);
|
||||
std::memcpy(colData.data() + offset, data.data(), data.size() * sizeof(U16Vector));
|
||||
// colors->updateContents(offset * sizeof(Vector4), data.size() * sizeof(Vector4), data.data());
|
||||
std::memcpy(tanData.data() + offset, data.data(), data.size() * sizeof(TangentType));
|
||||
dirty = true;
|
||||
}
|
||||
void StaticMeshVertexData::loadBitangents(uint64 offset, const Array<BiTangentType>& data) {
|
||||
assert(offset + data.size() <= head);
|
||||
std::memcpy(bitData.data() + offset, data.data(), data.size() * sizeof(BiTangentType));
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void StaticMeshVertexData::loadColors(uint64 offset, const Array<ColorType>& data) {
|
||||
assert(offset + data.size() <= head);
|
||||
std::memcpy(colData.data() + offset, data.data(), data.size() * sizeof(ColorType));
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
@@ -53,20 +60,26 @@ void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveB
|
||||
std::unique_lock l(vertexDataLock);
|
||||
offset = meshOffsets[id];
|
||||
}
|
||||
Array<U16Vector2> tex[MAX_TEXCOORDS];
|
||||
Array<TexCoordType> tex[MAX_TEXCOORDS];
|
||||
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
|
||||
tex[i].resize(numVertices);
|
||||
std::memcpy(tex[i].data(), texData[i].data() + offset, numVertices * sizeof(U16Vector2));
|
||||
std::memcpy(tex[i].data(), texData[i].data() + offset, numVertices * sizeof(TexCoordType));
|
||||
Serialization::save(buffer, tex[i]);
|
||||
}
|
||||
Array<Vector> pos(numVertices);
|
||||
Array<uint32> nor(numVertices);
|
||||
Array<U16Vector> col(numVertices);
|
||||
std::memcpy(pos.data(), posData.data() + offset, numVertices * sizeof(Vector));
|
||||
std::memcpy(nor.data(), norData.data() + offset, numVertices * sizeof(uint32));
|
||||
std::memcpy(col.data(), colData.data() + offset, numVertices * sizeof(U16Vector));
|
||||
Array<PositionType> pos(numVertices);
|
||||
Array<NormalType> nor(numVertices);
|
||||
Array<TangentType> tan(numVertices);
|
||||
Array<BiTangentType> bit(numVertices);
|
||||
Array<ColorType> col(numVertices);
|
||||
std::memcpy(pos.data(), posData.data() + offset, numVertices * sizeof(PositionType));
|
||||
std::memcpy(nor.data(), norData.data() + offset, numVertices * sizeof(NormalType));
|
||||
std::memcpy(tan.data(), tanData.data() + offset, numVertices * sizeof(TangentType));
|
||||
std::memcpy(bit.data(), bitData.data() + offset, numVertices * sizeof(BiTangentType));
|
||||
std::memcpy(col.data(), colData.data() + offset, numVertices * sizeof(ColorType));
|
||||
Serialization::save(buffer, pos);
|
||||
Serialization::save(buffer, nor);
|
||||
Serialization::save(buffer, tan);
|
||||
Serialization::save(buffer, bit);
|
||||
Serialization::save(buffer, col);
|
||||
}
|
||||
|
||||
@@ -77,36 +90,61 @@ uint64 StaticMeshVertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer) {
|
||||
std::unique_lock l(vertexDataLock);
|
||||
offset = meshOffsets[id];
|
||||
}
|
||||
Array<U16Vector2> tex[MAX_TEXCOORDS];
|
||||
Array<TexCoordType> tex[MAX_TEXCOORDS];
|
||||
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
|
||||
Serialization::load(buffer, tex[i]);
|
||||
loadTexCoords(offset, i, tex[i]);
|
||||
result += tex[i].size() * sizeof(U16Vector2);
|
||||
result += tex[i].size() * sizeof(TexCoordType);
|
||||
}
|
||||
Array<Vector> pos;
|
||||
Array<uint32> nor;
|
||||
Array<U16Vector> col;
|
||||
Array<PositionType> pos;
|
||||
Array<NormalType> nor;
|
||||
Array<TangentType> tan;
|
||||
Array<BiTangentType> bit;
|
||||
Array<ColorType> col;
|
||||
Serialization::load(buffer, pos);
|
||||
Serialization::load(buffer, nor);
|
||||
Serialization::load(buffer, tan);
|
||||
Serialization::load(buffer, bit);
|
||||
Serialization::load(buffer, col);
|
||||
loadPositions(offset, pos);
|
||||
loadNormals(offset, nor);
|
||||
loadTangents(offset, tan);
|
||||
loadBitangents(offset, bit);
|
||||
loadColors(offset, col);
|
||||
result += pos.size() * sizeof(Vector);
|
||||
result += nor.size() * sizeof(uint32);
|
||||
result += col.size() * sizeof(U16Vector);
|
||||
result += pos.size() * sizeof(PositionType);
|
||||
result += nor.size() * sizeof(NormalType);
|
||||
result += tan.size() * sizeof(TangentType);
|
||||
result += bit.size() * sizeof(BiTangentType);
|
||||
result += col.size() * sizeof(ColorType);
|
||||
return result;
|
||||
}
|
||||
|
||||
void StaticMeshVertexData::init(Gfx::PGraphics _graphics) {
|
||||
VertexData::init(_graphics);
|
||||
descriptorLayout = _graphics->createDescriptorLayout("pVertexData");
|
||||
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
|
||||
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
|
||||
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
|
||||
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 0,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
});
|
||||
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 1,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
});
|
||||
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 2,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
});
|
||||
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 3,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
});
|
||||
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 4,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
});
|
||||
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 5,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.descriptorCount = MAX_TEXCOORDS,
|
||||
});
|
||||
descriptorLayout->create();
|
||||
@@ -120,6 +158,8 @@ void StaticMeshVertexData::destroy() {
|
||||
}
|
||||
positions = nullptr;
|
||||
normals = nullptr;
|
||||
tangents = nullptr;
|
||||
biTangents = nullptr;
|
||||
colors = nullptr;
|
||||
descriptorSet = nullptr;
|
||||
descriptorLayout = nullptr;
|
||||
@@ -136,6 +176,8 @@ Gfx::PDescriptorSet StaticMeshVertexData::getVertexDataSet() { return descriptor
|
||||
void StaticMeshVertexData::resizeBuffers() {
|
||||
posData.resize(verticesAllocated);
|
||||
norData.resize(verticesAllocated);
|
||||
tanData.resize(verticesAllocated);
|
||||
bitData.resize(verticesAllocated);
|
||||
colData.resize(verticesAllocated);
|
||||
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
|
||||
texData[i].resize(verticesAllocated);
|
||||
@@ -146,7 +188,7 @@ void StaticMeshVertexData::updateBuffers() {
|
||||
positions = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData =
|
||||
{
|
||||
.size = verticesAllocated * sizeof(Vector),
|
||||
.size = verticesAllocated * sizeof(PositionType),
|
||||
.data = (uint8*)posData.data(),
|
||||
},
|
||||
.usage = Gfx::SE_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR,
|
||||
@@ -155,15 +197,31 @@ void StaticMeshVertexData::updateBuffers() {
|
||||
normals = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData =
|
||||
{
|
||||
.size = verticesAllocated * sizeof(uint32),
|
||||
.size = verticesAllocated * sizeof(NormalType),
|
||||
.data = (uint8*)norData.data(),
|
||||
},
|
||||
.name = "Normals",
|
||||
});
|
||||
tangents = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData =
|
||||
{
|
||||
.size = verticesAllocated * sizeof(TangentType),
|
||||
.data = (uint8*)tanData.data(),
|
||||
},
|
||||
.name = "Tangents",
|
||||
});
|
||||
biTangents = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData =
|
||||
{
|
||||
.size = verticesAllocated * sizeof(BiTangentType),
|
||||
.data = (uint8*)bitData.data(),
|
||||
},
|
||||
.name = "BiTangents",
|
||||
});
|
||||
colors = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData =
|
||||
{
|
||||
.size = verticesAllocated * sizeof(U16Vector),
|
||||
.size = verticesAllocated * sizeof(ColorType),
|
||||
.data = (uint8*)colData.data(),
|
||||
},
|
||||
.name = "Colors",
|
||||
@@ -172,7 +230,7 @@ void StaticMeshVertexData::updateBuffers() {
|
||||
texCoords[i] = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData =
|
||||
{
|
||||
.size = verticesAllocated * sizeof(U16Vector2),
|
||||
.size = verticesAllocated * sizeof(TexCoordType),
|
||||
.data = (uint8*)texData[i].data(),
|
||||
},
|
||||
.name = "TexCoords",
|
||||
@@ -182,9 +240,11 @@ void StaticMeshVertexData::updateBuffers() {
|
||||
descriptorSet = descriptorLayout->allocateDescriptorSet();
|
||||
descriptorSet->updateBuffer(0, 0, positions);
|
||||
descriptorSet->updateBuffer(1, 0, normals);
|
||||
descriptorSet->updateBuffer(2, 0, colors);
|
||||
descriptorSet->updateBuffer(2, 0, tangents);
|
||||
descriptorSet->updateBuffer(3, 0, biTangents);
|
||||
descriptorSet->updateBuffer(4, 0, colors);
|
||||
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
|
||||
descriptorSet->updateBuffer(3, i, texCoords[i]);
|
||||
descriptorSet->updateBuffer(5, i, texCoords[i]);
|
||||
}
|
||||
descriptorSet->writeChanges();
|
||||
}
|
||||
|
||||
@@ -9,13 +9,22 @@
|
||||
namespace Seele {
|
||||
class StaticMeshVertexData : public VertexData {
|
||||
public:
|
||||
using PositionType = Vector;
|
||||
using NormalType = Vector;
|
||||
using TangentType = Vector;
|
||||
using BiTangentType = Vector;
|
||||
using TexCoordType = U16Vector2;
|
||||
using ColorType = U16Vector;
|
||||
|
||||
StaticMeshVertexData();
|
||||
virtual ~StaticMeshVertexData();
|
||||
static StaticMeshVertexData* getInstance();
|
||||
void loadPositions(uint64 offset, const Array<Vector>& data);
|
||||
void loadTexCoords(uint64 offset, uint64 index, const Array<U16Vector2>& data);
|
||||
void loadNormals(uint64 offset, const Array<uint32>& data);
|
||||
void loadColors(uint64 offset, const Array<U16Vector>& data);
|
||||
void loadPositions(uint64 offset, const Array<PositionType>& data);
|
||||
void loadTexCoords(uint64 offset, uint64 index, const Array<TexCoordType>& data);
|
||||
void loadNormals(uint64 offset, const Array<NormalType>& data);
|
||||
void loadTangents(uint64 offset, const Array<TangentType>& data);
|
||||
void loadBitangents(uint64 offset, const Array<BiTangentType>& data);
|
||||
void loadColors(uint64 offset, const Array<ColorType>& data);
|
||||
virtual void serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) override;
|
||||
virtual uint64 deserializeMesh(MeshId id, ArchiveBuffer& buffer) override;
|
||||
virtual void init(Gfx::PGraphics graphics) override;
|
||||
@@ -30,14 +39,19 @@ class StaticMeshVertexData : public VertexData {
|
||||
virtual void resizeBuffers() override;
|
||||
virtual void updateBuffers() override;
|
||||
|
||||
|
||||
Gfx::OShaderBuffer positions;
|
||||
Gfx::OShaderBuffer texCoords[MAX_TEXCOORDS];
|
||||
Gfx::OShaderBuffer normals;
|
||||
Gfx::OShaderBuffer tangents;
|
||||
Gfx::OShaderBuffer biTangents;
|
||||
Gfx::OShaderBuffer colors;
|
||||
Array<Vector> posData;
|
||||
Array<U16Vector2> texData[MAX_TEXCOORDS];
|
||||
Array<Quaternion> norData;
|
||||
Array<U16Vector4> colData;
|
||||
Array<PositionType> posData;
|
||||
Array<TexCoordType> texData[MAX_TEXCOORDS];
|
||||
Array<NormalType> norData;
|
||||
Array<TangentType> tanData;
|
||||
Array<BiTangentType> bitData;
|
||||
Array<ColorType> colData;
|
||||
Gfx::ODescriptorLayout descriptorLayout;
|
||||
Gfx::PDescriptorSet descriptorSet;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user