basic sponza import

This commit is contained in:
Dynamitos
2025-03-31 11:39:17 +02:00
parent 7a3aa482c7
commit 4a34220cd7
10 changed files with 51 additions and 44 deletions
+1 -1
View File
@@ -101,5 +101,5 @@ float4 fragmentMain(
float factor = (output.texCoords.y - lowerLimit) / (upperLimit - lowerLimit); float factor = (output.texCoords.y - lowerLimit) / (upperLimit - lowerLimit);
factor = clamp(factor, 0.0, 1.0); factor = clamp(factor, 0.0, 1.0);
return lerp(float4(pSkyboxData.fogBlend.xyz, 1), finalColor, factor) * 100; return lerp(float4(pSkyboxData.fogBlend.xyz, 1), finalColor, factor);
} }
+1 -1
View File
@@ -109,7 +109,7 @@ float4 toneMapping(float2 uv : UV) : SV_Target
{ {
float3 hdrValue = pToneMappingParams.hdrInputTexture.Sample(pToneMappingParams.hdrSampler, uv).rgb; float3 hdrValue = pToneMappingParams.hdrInputTexture.Sample(pToneMappingParams.hdrSampler, uv).rgb;
float3 value = agx(hdrValue / 1000); float3 value = agx(hdrValue);
value = agxLook(value); value = agxLook(value);
value = agxEotf(value); value = agxEotf(value);
+4 -3
View File
@@ -16,8 +16,9 @@ struct StaticMeshVertexData
#ifndef POS_ONLY #ifndef POS_ONLY
//attributes.qTangent = qTangent[index]; //attributes.qTangent = qTangent[index];
attributes.normal_MS = float3(normals[index * 3 + 0], normals[index * 3 + 1], normals[index * 3 + 2]); attributes.normal_MS = float3(normals[index * 3 + 0], normals[index * 3 + 1], normals[index * 3 + 2]);
attributes.tangent_MS = float3(tangents[index * 3 + 0], tangents[index * 3 + 1], tangents[index * 3 + 2]); float4 tangentSign = float4(tangents[index * 4 + 0], tangents[index * 4 + 1], tangents[index * 4 + 2], tangents[index * 4 + 3]);
attributes.biTangent_MS = float3(biTangents[index * 3 + 0], biTangents[index * 3 + 1], biTangents[index * 3 + 2]); attributes.tangent_MS = tangentSign.xyz;
attributes.biTangent_MS = cross(attributes.normal_MS, attributes.tangent_MS) * -tangentSign.w;
for(uint i = 0; i < MAX_TEXCOORDS; ++i) for(uint i = 0; i < MAX_TEXCOORDS; ++i)
{ {
attributes.texCoords[i] = float2(uint16ToFloat(texCoords[i][index * 2 + 0]), uint16ToFloat(texCoords[i][index * 2 + 1])); attributes.texCoords[i] = float2(uint16ToFloat(texCoords[i][index * 2 + 0]), uint16ToFloat(texCoords[i][index * 2 + 1]));
@@ -27,9 +28,9 @@ struct StaticMeshVertexData
return attributes; return attributes;
} }
StructuredBuffer<float> positions; StructuredBuffer<float> positions;
//StructuredBuffer<float> qTangents;
StructuredBuffer<float> normals; StructuredBuffer<float> normals;
StructuredBuffer<float> tangents; StructuredBuffer<float> tangents;
StructuredBuffer<float> biTangents;
StructuredBuffer<uint16_t> color; StructuredBuffer<uint16_t> color;
StructuredBuffer<uint16_t> texCoords[MAX_TEXCOORDS]; StructuredBuffer<uint16_t> texCoords[MAX_TEXCOORDS];
}; };
+10 -5
View File
@@ -536,7 +536,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
} }
Array<StaticMeshVertexData::NormalType> normals(mesh->mNumVertices); Array<StaticMeshVertexData::NormalType> normals(mesh->mNumVertices);
Array<StaticMeshVertexData::TangentType> tangents(mesh->mNumVertices); Array<StaticMeshVertexData::TangentType> tangents(mesh->mNumVertices);
Array<StaticMeshVertexData::BiTangentType> biTangents(mesh->mNumVertices); //Array<StaticMeshVertexData::BiTangentType> biTangents(mesh->mNumVertices);
Array<StaticMeshVertexData::ColorType> colors(mesh->mNumVertices); Array<StaticMeshVertexData::ColorType> colors(mesh->mNumVertices);
for (uint32 i = 0; i < mesh->mNumVertices; ++i) { for (uint32 i = 0; i < mesh->mNumVertices; ++i) {
@@ -555,10 +555,15 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
tangent = Vector(mesh->mTangents[i].x, mesh->mTangents[i].y, mesh->mTangents[i].z); 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); biTangent = Vector(mesh->mBitangents[i].x, mesh->mBitangents[i].y, mesh->mBitangents[i].z);
} }
normals[i] = normal; // encodeQTangent(Matrix3(tangent, biTangent, normal));
tangents[i] = tangent;
biTangents[i] = biTangent;
normals[i] = normal; // encodeQTangent(Matrix3(tangent, biTangent, normal));
// the fourth component encodes the sign of the bitangent.
// in the shader we calc n x t, and b = (n x t) * sign
// so we try to cross the two, and see what is the result, and if it is
// the same as b, the dot product is 1, and if they are inverse, the dot product is
// -1, which is the sign we need
tangents[i] = Vector4(tangent, dot(glm::cross(normal, tangent), biTangent));
if (mesh->HasVertexColors(0)) { if (mesh->HasVertexColors(0)) {
colors[i] = StaticMeshVertexData::ColorType(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 { } else {
@@ -572,7 +577,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
} }
vertexData->loadNormals(offset, normals); vertexData->loadNormals(offset, normals);
vertexData->loadTangents(offset, tangents); vertexData->loadTangents(offset, tangents);
vertexData->loadBitangents(offset, biTangents); //vertexData->loadBitangents(offset, biTangents);
vertexData->loadColors(offset, colors); vertexData->loadColors(offset, colors);
Array<uint32> indices(mesh->mNumFaces * 3); Array<uint32> indices(mesh->mNumFaces * 3);
+5 -5
View File
@@ -42,7 +42,7 @@ void TextureLoader::importAsset(TextureImportArgs args) {
PTextureAsset ref = asset; PTextureAsset ref = asset;
asset->setStatus(Asset::Status::Loading); asset->setStatus(Asset::Status::Loading);
AssetRegistry::get().registerTexture(std::move(asset)); AssetRegistry::get().registerTexture(std::move(asset));
import(args, ref); getThreadPool().runAsync([=]() { import(args, ref); });
} }
PTextureAsset TextureLoader::getPlaceholderTexture() { return placeholderAsset; } PTextureAsset TextureLoader::getPlaceholderTexture() { return placeholderAsset; }
@@ -111,13 +111,13 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) {
ktxBasisParams basisParams = { ktxBasisParams basisParams = {
.structSize = sizeof(ktxBasisParams), .structSize = sizeof(ktxBasisParams),
.uastc = true, .uastc = true,
.threadCount = 14, .threadCount = 1,
.compressionLevel = 3, .compressionLevel = 2,
.uastcFlags = KTX_PACK_UASTC_LEVEL_FASTEST, .uastcFlags = KTX_PACK_UASTC_LEVEL_FASTER,
.uastcRDO = true, .uastcRDO = true,
}; };
KTX_ASSERT(ktxTexture2_CompressBasisEx(kTexture, &basisParams)); KTX_ASSERT(ktxTexture2_CompressBasisEx(kTexture, &basisParams));
KTX_ASSERT(ktxTexture2_DeflateZstd(kTexture, 20)); KTX_ASSERT(ktxTexture2_DeflateZstd(kTexture, 10));
char writer[100]; char writer[100];
snprintf(writer, sizeof(writer), "%s version %s", "SeeleEngine", "0.0.1"); snprintf(writer, sizeof(writer), "%s version %s", "SeeleEngine", "0.0.1");
+4 -4
View File
@@ -124,10 +124,10 @@ int main() {
.filePath = sourcePath / "import/models/rttest.glb", .filePath = sourcePath / "import/models/rttest.glb",
.importPath = "", .importPath = "",
}); });
//AssetImporter::importMesh(MeshImportArgs{ AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/main1_sponza/sponza.gltf", .filePath = sourcePath / "import/models/main1_sponza/sponza.gltf",
// .importPath = "sponza", .importPath = "sponza",
//}); });
// AssetImporter::importMesh(MeshImportArgs{ // AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/town_hall.glb", // .filePath = sourcePath / "import/models/town_hall.glb",
// .importPath = "", // .importPath = "",
+1 -2
View File
@@ -31,8 +31,7 @@ void TextureAsset::load(ArchiveBuffer& buffer) {
Serialization::load(buffer, ktxData); Serialization::load(buffer, ktxData);
KTX_ASSERT( KTX_ASSERT(
ktxTexture_CreateFromMemory(ktxData.data(), ktxData.size(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, (ktxTexture**)&ktxHandle)); ktxTexture_CreateFromMemory(ktxData.data(), ktxData.size(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, (ktxTexture**)&ktxHandle));
ktxTexture2_TranscodeBasis(ktxHandle, KTX_TTF_RGBA32, 0);
ktxTexture2_TranscodeBasis(ktxHandle, KTX_TTF_BC7_RGBA, 0);
Gfx::PGraphics graphics = buffer.getGraphics(); Gfx::PGraphics graphics = buffer.getGraphics();
TextureCreateInfo createInfo = { TextureCreateInfo createInfo = {
+17 -16
View File
@@ -41,11 +41,12 @@ void StaticMeshVertexData::loadTangents(uint64 offset, const Array<TangentType>&
std::memcpy(tanData.data() + offset, data.data(), data.size() * sizeof(TangentType)); std::memcpy(tanData.data() + offset, data.data(), data.size() * sizeof(TangentType));
dirty = true; dirty = true;
} }
void StaticMeshVertexData::loadBitangents(uint64 offset, const Array<BiTangentType>& data) {
/*void StaticMeshVertexData::loadBitangents(uint64 offset, const Array<BiTangentType>& data) {
assert(offset + data.size() <= head); assert(offset + data.size() <= head);
std::memcpy(bitData.data() + offset, data.data(), data.size() * sizeof(BiTangentType)); std::memcpy(bitData.data() + offset, data.data(), data.size() * sizeof(BiTangentType));
dirty = true; dirty = true;
} }*/
void StaticMeshVertexData::loadColors(uint64 offset, const Array<ColorType>& data) { void StaticMeshVertexData::loadColors(uint64 offset, const Array<ColorType>& data) {
assert(offset + data.size() <= head); assert(offset + data.size() <= head);
@@ -71,17 +72,17 @@ void StaticMeshVertexData::serializeMesh(MeshId id, ArchiveBuffer& buffer) {
Array<PositionType> pos(numVertices); Array<PositionType> pos(numVertices);
Array<NormalType> nor(numVertices); Array<NormalType> nor(numVertices);
Array<TangentType> tan(numVertices); Array<TangentType> tan(numVertices);
Array<BiTangentType> bit(numVertices); //Array<BiTangentType> bit(numVertices);
Array<ColorType> col(numVertices); Array<ColorType> col(numVertices);
std::memcpy(pos.data(), posData.data() + offset, numVertices * sizeof(PositionType)); std::memcpy(pos.data(), posData.data() + offset, numVertices * sizeof(PositionType));
std::memcpy(nor.data(), norData.data() + offset, numVertices * sizeof(NormalType)); std::memcpy(nor.data(), norData.data() + offset, numVertices * sizeof(NormalType));
std::memcpy(tan.data(), tanData.data() + offset, numVertices * sizeof(TangentType)); std::memcpy(tan.data(), tanData.data() + offset, numVertices * sizeof(TangentType));
std::memcpy(bit.data(), bitData.data() + offset, numVertices * sizeof(BiTangentType)); //std::memcpy(bit.data(), bitData.data() + offset, numVertices * sizeof(BiTangentType));
std::memcpy(col.data(), colData.data() + offset, numVertices * sizeof(ColorType)); std::memcpy(col.data(), colData.data() + offset, numVertices * sizeof(ColorType));
Serialization::save(buffer, pos); Serialization::save(buffer, pos);
Serialization::save(buffer, nor); Serialization::save(buffer, nor);
Serialization::save(buffer, tan); Serialization::save(buffer, tan);
Serialization::save(buffer, bit); //Serialization::save(buffer, bit);
Serialization::save(buffer, col); Serialization::save(buffer, col);
} }
@@ -101,22 +102,22 @@ uint64 StaticMeshVertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer) {
Array<PositionType> pos; Array<PositionType> pos;
Array<NormalType> nor; Array<NormalType> nor;
Array<TangentType> tan; Array<TangentType> tan;
Array<BiTangentType> bit; //Array<BiTangentType> bit;
Array<ColorType> col; Array<ColorType> col;
Serialization::load(buffer, pos); Serialization::load(buffer, pos);
Serialization::load(buffer, nor); Serialization::load(buffer, nor);
Serialization::load(buffer, tan); Serialization::load(buffer, tan);
Serialization::load(buffer, bit); //Serialization::load(buffer, bit);
Serialization::load(buffer, col); Serialization::load(buffer, col);
loadPositions(offset, pos); loadPositions(offset, pos);
loadNormals(offset, nor); loadNormals(offset, nor);
loadTangents(offset, tan); loadTangents(offset, tan);
loadBitangents(offset, bit); //loadBitangents(offset, bit);
loadColors(offset, col); loadColors(offset, col);
result += pos.size() * sizeof(PositionType); result += pos.size() * sizeof(PositionType);
result += nor.size() * sizeof(NormalType); result += nor.size() * sizeof(NormalType);
result += tan.size() * sizeof(TangentType); result += tan.size() * sizeof(TangentType);
result += bit.size() * sizeof(BiTangentType); //result += bit.size() * sizeof(BiTangentType);
result += col.size() * sizeof(ColorType); result += col.size() * sizeof(ColorType);
return result; return result;
} }
@@ -136,10 +137,10 @@ void StaticMeshVertexData::init(Gfx::PGraphics _graphics) {
.name = TANGENTS_NAME, .name = TANGENTS_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
}); });
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ /*descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.name = BITANGENTS_NAME, .name = BITANGENTS_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
}); });*/
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.name = COLORS_NAME, .name = COLORS_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
@@ -161,7 +162,7 @@ void StaticMeshVertexData::destroy() {
positions = nullptr; positions = nullptr;
normals = nullptr; normals = nullptr;
tangents = nullptr; tangents = nullptr;
biTangents = nullptr; //biTangents = nullptr;
colors = nullptr; colors = nullptr;
descriptorSet = nullptr; descriptorSet = nullptr;
descriptorLayout = nullptr; descriptorLayout = nullptr;
@@ -179,7 +180,7 @@ void StaticMeshVertexData::resizeBuffers() {
posData.resize(verticesAllocated); posData.resize(verticesAllocated);
norData.resize(verticesAllocated); norData.resize(verticesAllocated);
tanData.resize(verticesAllocated); tanData.resize(verticesAllocated);
bitData.resize(verticesAllocated); //bitData.resize(verticesAllocated);
colData.resize(verticesAllocated); colData.resize(verticesAllocated);
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) { for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
texData[i].resize(verticesAllocated); texData[i].resize(verticesAllocated);
@@ -212,14 +213,14 @@ void StaticMeshVertexData::updateBuffers() {
}, },
.name = "Tangents", .name = "Tangents",
}); });
biTangents = graphics->createShaderBuffer(ShaderBufferCreateInfo{ /*biTangents = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = .sourceData =
{ {
.size = verticesAllocated * sizeof(BiTangentType), .size = verticesAllocated * sizeof(BiTangentType),
.data = (uint8*)bitData.data(), .data = (uint8*)bitData.data(),
}, },
.name = "BiTangents", .name = "BiTangents",
}); });*/
colors = graphics->createShaderBuffer(ShaderBufferCreateInfo{ colors = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = .sourceData =
{ {
@@ -243,7 +244,7 @@ void StaticMeshVertexData::updateBuffers() {
descriptorSet->updateBuffer(POSITIONS_NAME, 0, positions); descriptorSet->updateBuffer(POSITIONS_NAME, 0, positions);
descriptorSet->updateBuffer(NORMALS_NAME, 0, normals); descriptorSet->updateBuffer(NORMALS_NAME, 0, normals);
descriptorSet->updateBuffer(TANGENTS_NAME, 0, tangents); descriptorSet->updateBuffer(TANGENTS_NAME, 0, tangents);
descriptorSet->updateBuffer(BITANGENTS_NAME, 0, biTangents); //descriptorSet->updateBuffer(BITANGENTS_NAME, 0, biTangents);
descriptorSet->updateBuffer(COLORS_NAME, 0, colors); descriptorSet->updateBuffer(COLORS_NAME, 0, colors);
for (uint32 i = 0; i < MAX_TEXCOORDS; ++i) { for (uint32 i = 0; i < MAX_TEXCOORDS; ++i) {
descriptorSet->updateBuffer(TEXCOORDS_NAME, i, texCoords[i]); descriptorSet->updateBuffer(TEXCOORDS_NAME, i, texCoords[i]);
+6 -6
View File
@@ -10,8 +10,8 @@ class StaticMeshVertexData : public VertexData {
public: public:
using PositionType = Vector; using PositionType = Vector;
using NormalType = Vector; using NormalType = Vector;
using TangentType = Vector; using TangentType = Vector4;
using BiTangentType = Vector; //using BiTangentType = Vector;
using TexCoordType = U16Vector2; using TexCoordType = U16Vector2;
using ColorType = U16Vector; using ColorType = U16Vector;
@@ -22,7 +22,7 @@ class StaticMeshVertexData : public VertexData {
void loadTexCoords(uint64 offset, uint64 index, const Array<TexCoordType>& data); void loadTexCoords(uint64 offset, uint64 index, const Array<TexCoordType>& data);
void loadNormals(uint64 offset, const Array<NormalType>& data); void loadNormals(uint64 offset, const Array<NormalType>& data);
void loadTangents(uint64 offset, const Array<TangentType>& data); void loadTangents(uint64 offset, const Array<TangentType>& data);
void loadBitangents(uint64 offset, const Array<BiTangentType>& data); //void loadBitangents(uint64 offset, const Array<BiTangentType>& data);
void loadColors(uint64 offset, const Array<ColorType>& data); void loadColors(uint64 offset, const Array<ColorType>& data);
virtual void serializeMesh(MeshId id, ArchiveBuffer& buffer) override; virtual void serializeMesh(MeshId id, ArchiveBuffer& buffer) override;
virtual uint64 deserializeMesh(MeshId id, ArchiveBuffer& buffer) override; virtual uint64 deserializeMesh(MeshId id, ArchiveBuffer& buffer) override;
@@ -46,15 +46,15 @@ class StaticMeshVertexData : public VertexData {
constexpr static const char* NORMALS_NAME = "normals"; constexpr static const char* NORMALS_NAME = "normals";
Gfx::OShaderBuffer tangents; Gfx::OShaderBuffer tangents;
constexpr static const char* TANGENTS_NAME = "tangents"; constexpr static const char* TANGENTS_NAME = "tangents";
Gfx::OShaderBuffer biTangents; //Gfx::OShaderBuffer biTangents;
constexpr static const char* BITANGENTS_NAME = "biTangents"; //constexpr static const char* BITANGENTS_NAME = "biTangents";
Gfx::OShaderBuffer colors; Gfx::OShaderBuffer colors;
constexpr static const char* COLORS_NAME = "colors"; constexpr static const char* COLORS_NAME = "colors";
Array<PositionType> posData; Array<PositionType> posData;
Array<TexCoordType> texData[MAX_TEXCOORDS]; Array<TexCoordType> texData[MAX_TEXCOORDS];
Array<NormalType> norData; Array<NormalType> norData;
Array<TangentType> tanData; Array<TangentType> tanData;
Array<BiTangentType> bitData; //Array<BiTangentType> bitData;
Array<ColorType> colData; Array<ColorType> colData;
Gfx::ODescriptorLayout descriptorLayout; Gfx::ODescriptorLayout descriptorLayout;
Gfx::PDescriptorSet descriptorSet; Gfx::PDescriptorSet descriptorSet;
+2 -1
View File
@@ -592,7 +592,8 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
}); });
} }
} }
uint32 hash = CRC::Calculate(shaderStages.data(), sizeof(VkPipelineShaderStageCreateInfo) * shaderStages.size(), CRC::CRC_32()); uint32 hash = CRC::Calculate(shaderStages.data(), sizeof(VkPipelineShaderStageCreateInfo) * shaderStages.size(), CRC::CRC_32(),
createInfo.pipelineLayout->getHash());
hash = CRC::Calculate(shaderGroups.data(), sizeof(VkRayTracingShaderGroupCreateInfoKHR) * shaderGroups.size(), CRC::CRC_32(), hash); hash = CRC::Calculate(shaderGroups.data(), sizeof(VkRayTracingShaderGroupCreateInfoKHR) * shaderGroups.size(), CRC::CRC_32(), hash);
if (rayTracingPipelines.contains(hash)) { if (rayTracingPipelines.contains(hash)) {
return rayTracingPipelines[hash]; return rayTracingPipelines[hash];