Now able to import stuff properly

This commit is contained in:
Dynamitos
2024-05-06 18:36:16 +02:00
parent 05bb1d0cee
commit af7d624d06
21 changed files with 189 additions and 79 deletions
+3 -2
View File
@@ -32,7 +32,8 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
result += pLightEnv.pointLights[lightIndex].illuminate(lightingParams, brdf);
}
result += brdf.evaluateAmbient();
// gamma correction
result = result / (result + float3(1.0));
float3 gammaCorrected = pow(result, float3(1.0/2.2));
return float4(gammaCorrected, 1.0f);
result = pow(result, float3(1.0/2.2));
return float4(result, 1.0f);
}
+15
View File
@@ -0,0 +1,15 @@
{
"name": "Placeholder",
"params": {
},
"code": [
{
"exp": "BRDF",
"profile": "BlinnPhong",
"values": {
"baseColor": "float3(0, 1, 0)",
"normal": "float3(0, 0, 1)"
}
}
]
}
+7 -6
View File
@@ -21,12 +21,12 @@ struct Phong : IBRDF
float3 evaluate(float3x3 tbn, float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
{
float3 n = normalize(normal);
float3 nDotL = dot(n, lightDir_TS);
float3 r = 2 * (nDotL) * n - lightDir_TS;
float3 normal_TS = normalize(normal);
float3 nDotL = dot(normal_TS, lightDir_TS);
float3 r = 2 * (nDotL) * normal_TS - lightDir_TS;
float rDotV = dot(r, viewDir_TS);
return baseColor * max(nDotL, 0.0) * lightColor + specular * pow(max(rDotV, 0.0), shininess) * lightColor;
return baseColor * max(nDotL, 0.0) * lightColor + specular * pow(max(rDotV, 0.0), shininess);
}
float3 evaluateAmbient()
@@ -40,6 +40,7 @@ struct BlinnPhong : IBRDF
float3 baseColor;
float3 specularColor;
float3 normal;
float shininess;
float3 ambient;
__init()
@@ -52,9 +53,9 @@ struct BlinnPhong : IBRDF
float3 normal_TS = normalize(normal);
float diffuse = max(dot(normal_TS, lightDir_TS), 0);
float3 h = normalize(lightDir_TS + viewDir_TS);
float specular = saturate(dot(normal_TS, h));
float specular = pow(saturate(dot(normal_TS, h)), shininess);
return (baseColor * diffuse * lightColor) + (specularColor * specular) * lightColor;
return (baseColor * diffuse * lightColor) + (specularColor * specular);
}
float3 evaluateAmbient()
+1
View File
@@ -1,5 +1,6 @@
const static float PI = 3.1415926535897932f;
const static uint BLOCK_SIZE = 32;
static const uint64_t MAX_TEXCOORDS = 8;
struct ViewParameter
{
+5 -5
View File
@@ -33,21 +33,21 @@ struct PointLight : ILightEnv
return illuminance * brdf.evaluate(params.tbn, params.viewDir_TS, -normalize(lightDir_TS), colorRange.xyz);
}
bool insidePlane(Plane plane, float3 position_VS)
bool insidePlane(Plane plane, float3 position)
{
return dot(plane.n, position_VS) - plane.d < -colorRange.w;
return dot(plane.n, position) - plane.d < -colorRange.w;
}
bool insideFrustum(Frustum frustum, float3 position_VS, float minDepth, float maxDepth)
bool insideFrustum(Frustum frustum, float3 position, float minDepth, float maxDepth)
{
bool result = true;
if(position_VS.z - colorRange.w > minDepth || position_VS.z + colorRange.w < maxDepth)
if(position.z - colorRange.w > minDepth || position.z + colorRange.w < maxDepth)
{
result = false;
}
for(int i = 0; i < 4 && result; ++i)
{
if(insidePlane(frustum.sides[i], position_VS))
if(insidePlane(frustum.sides[i], position))
{
result = false;
}
+14 -8
View File
@@ -3,7 +3,7 @@ import Common;
struct MaterialParameter
{
float3 position_WS;
float2 texCoords[1];
float2 texCoords[MAX_TEXCOORDS];
float3 vertexColor;
};
@@ -25,13 +25,16 @@ struct FragmentParameter
float3 biTangent_WS : TANGENT1;
float3 position_WS : POSITION2;
float3 vertexColor : COLOR0;
float2 texCoords : TEXCOORD0;
float2 texCoords[MAX_TEXCOORDS] : TEXCOORD0;
MaterialParameter getMaterialParameter()
{
MaterialParameter result;
result.position_WS = position_WS;
result.vertexColor = vertexColor;
result.texCoords[0] = texCoords;
for(uint i = 0; i < MAX_TEXCOORDS; ++i)
{
result.texCoords[i] = texCoords[i];
}
return result;
}
LightingParameter getLightingParameter()
@@ -52,16 +55,16 @@ struct VertexAttributes
float3 tangent_MS;
float3 biTangent_MS;
float3 vertexColor;
float2 texCoords;
float2 texCoords[MAX_TEXCOORDS];
FragmentParameter getParameter(float4x4 transformMatrix)
{
float4 modelPos = float4(position_MS, 1);
float4 worldPos = mul(transformMatrix, modelPos);
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
float3 tangent_WS = mul(float3x3(transformMatrix), tangent_MS);
float3 biTangent_WS = mul(float3x3(transformMatrix), biTangent_MS);
float3 normal_WS = mul(float3x3(transformMatrix), normal_MS);
float3 tangent_WS = normalize(mul(transformMatrix, float4(tangent_MS, 0.0)).xyz);
float3 biTangent_WS = normalize(mul(transformMatrix, float4(biTangent_MS, 0.0)).xyz);
float3 normal_WS = normalize(mul(transformMatrix, float4(normal_MS, 0.0)).xyz);
FragmentParameter result;
result.viewDir_WS = pViewParams.cameraPos_WS.xyz - worldPos.xyz;
result.normal_WS = normal_WS;
@@ -70,7 +73,10 @@ struct VertexAttributes
result.position_WS = worldPos.xyz;
result.position_CS = clipPos;
result.vertexColor = vertexColor;
result.texCoords = texCoords;
for(uint i = 0; i < MAX_TEXCOORDS; ++i)
{
result.texCoords[i] = texCoords[i];
}
return result;
}
};
+5 -2
View File
@@ -11,14 +11,17 @@ struct StaticMeshVertexData : IVertexData
attributes.normal_MS = float3(normals[3 * index + 0], normals[3 * index + 1], normals[3 * index + 2]);
attributes.tangent_MS = float3(tangents[3 * index + 0], tangents[3 * index + 1], tangents[3 * index + 2]);
attributes.biTangent_MS = float3(biTangents[3 * index + 0], biTangents[3 * index + 1], biTangents[3 * index + 2]);
attributes.texCoords = float2(texCoords[2 * index + 0], texCoords[2 * index + 1]);
for(uint i = 0; i < MAX_TEXCOORDS; ++i)
{
attributes.texCoords[i] = float2(texCoords[i][2 * index + 0], texCoords[i][2 * index + 1]);
}
attributes.vertexColor = float3(color[3 * index + 0], color[3 * index + 1], color[3 * index + 2]);
return attributes;
}
StructuredBuffer<float> positions;
StructuredBuffer<float> texCoords;
StructuredBuffer<float> normals;
StructuredBuffer<float> tangents;
StructuredBuffer<float> biTangents;
StructuredBuffer<float> color;
StructuredBuffer<float> texCoords[MAX_TEXCOORDS];
};
+45 -21
View File
@@ -52,7 +52,7 @@ void MeshLoader::convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numP
dst[i * 4 + 3] = src[i].a;
}
}
void MeshLoader::loadTextures(const aiScene* scene, const std::filesystem::path& meshDirectory, const std::string& importPath, Map<std::string, PTextureAsset>& textures)
void MeshLoader::loadTextures(const aiScene* scene, const std::filesystem::path& meshDirectory, const std::string& importPath, Array<PTextureAsset>& textures)
{
for (uint32 i = 0; i < scene->mNumTextures; ++i)
{
@@ -66,6 +66,7 @@ void MeshLoader::loadTextures(const aiScene* scene, const std::filesystem::path&
}
else
{
texPath = (meshDirectory / texPath).replace_extension("png");
if (tex->mHeight == 0)
{
// already compressed, just dump it to the disk
@@ -87,7 +88,7 @@ void MeshLoader::loadTextures(const aiScene* scene, const std::filesystem::path&
.filePath = texPath,
.importPath = importPath,
});
textures[texPath.string()] = AssetRegistry::findTexture(importPath, texPath.string());
textures.add(AssetRegistry::findTexture(importPath, texPath.stem().string()));
}
}
@@ -107,7 +108,7 @@ constexpr const char* KEY_ROUGHNESS_TEXTURE = "tex_r";
constexpr const char* KEY_METALLIC_TEXTURE = "tex_m";
constexpr const char* KEY_AMBIENT_OCCLUSION_TEXTURE = "tex_ao";
void MeshLoader::loadMaterials(const aiScene* scene, const Map<std::string, PTextureAsset>& textures, const std::string& baseName, const std::filesystem::path& meshDirectory, const std::string& importPath, Array<PMaterialInstanceAsset>& globalMaterials)
void MeshLoader::loadMaterials(const aiScene* scene, const Array<PTextureAsset>& textures, const std::string& baseName, const std::filesystem::path& meshDirectory, const std::string& importPath, Array<PMaterialInstanceAsset>& globalMaterials)
{
for(uint32 i = 0; i < scene->mNumMaterials; ++i)
{
@@ -150,7 +151,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Map<std::string, PTex
parameters.add(paramKey);
};
auto addTextureParameter = [&](std::string paramKey, aiTextureType type, int index, std::string& result, StaticArray<int32, 4> extractMask = {0, 1, 2, -1})
auto addTextureParameter = [&](std::string paramKey, aiTextureType type, int index, std::string& result, StaticArray<int32, 4> extractMask = { 0, 1, 2, -1 })
{
aiString texPath;
aiTextureMapping mapping;
@@ -162,13 +163,14 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Map<std::string, PTex
{
std::cout << "fuck" << std::endl;
}
std::string textureKey = fmt::format("{0}Texture{1}", paramKey, index);
auto texFilename = std::filesystem::path(texPath.C_Str());
PTextureAsset texture;
if (textures.contains(texFilename.string()))
if (texFilename.string()[0] == '*')
{
texture = textures[texFilename.string()];
texture = textures[atoi(texFilename.string().substr(1).c_str())];
}
else if (std::filesystem::exists(texFilename))
{
@@ -380,21 +382,32 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Map<std::string, PTex
brdf.variables["baseColor"] = outputDiffuse;
if (!outputNormal.empty())
{
brdf.variables["normal"] = outputNormal;
expressions.add(new MulExpression());
expressions.back()->key = "NormalMul";
expressions.back()->inputs["lhs"].source = "2";
expressions.back()->inputs["rhs"].source = outputNormal;
expressions.add(new SubExpression());
expressions.back()->key = "NormalSub";
expressions.back()->inputs["lhs"].source = "NormalMul";
expressions.back()->inputs["rhs"].source = "float3(1,1,1)";
brdf.variables["normal"] = "NormalSub";
}
aiShadingMode mode;
material->Get(AI_MATKEY_SHADING_MODEL, mode);
switch (mode) {
case aiShadingMode_Blinn:
brdf.profile = "Phong";
brdf.variables["specular"] = outputSpecular;
brdf.profile = "BlinnPhong";
brdf.variables["specularColor"] = outputSpecular;
brdf.variables["ambient"] = outputAmbient;
brdf.variables["shininess"] = outputShininess;
break;
case aiShadingMode_Phong:
brdf.profile = "BlinnPhong";
brdf.variables["specularColor"] = outputSpecular;
brdf.profile = "Phong";
brdf.variables["specular"] = outputSpecular;
brdf.variables["ambient"] = outputAmbient;
brdf.variables["shininess"] = outputShininess;
break;
case aiShadingMode_Toon:
brdf.profile = "CelShading";
@@ -458,7 +471,11 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
// assume static mesh for now
Array<Vector> positions(mesh->mNumVertices);
Array<Vector2> texCoords(mesh->mNumVertices);
StaticArray<Array<Vector2>, MAX_TEXCOORDS> texCoords;
for (size_t i = 0; i < MAX_TEXCOORDS; ++i)
{
texCoords[i].resize(mesh->mNumVertices);
}
Array<Vector> normals(mesh->mNumVertices);
Array<Vector> tangents(mesh->mNumVertices);
Array<Vector> biTangents(mesh->mNumVertices);
@@ -469,13 +486,16 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
for (int32 i = 0; i < mesh->mNumVertices; ++i)
{
positions[i] = Vector(mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z);
if (mesh->HasTextureCoords(0))
for (size_t j = 0; j < MAX_TEXCOORDS; ++j)
{
texCoords[i] = Vector2(mesh->mTextureCoords[0][i].x, mesh->mTextureCoords[0][i].y);
}
else
{
texCoords[i] = Vector2(0, 0);
if (mesh->HasTextureCoords(j))
{
texCoords[j][i] = Vector2(mesh->mTextureCoords[j][i].x, mesh->mTextureCoords[j][i].y);
}
else
{
texCoords[j][i] = Vector2(0, 0);
}
}
normals[i] = Vector(mesh->mNormals[i].x, mesh->mNormals[i].y, mesh->mNormals[i].z);
if (mesh->HasTangentsAndBitangents())
@@ -499,7 +519,11 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
}
MeshId id = vertexData->allocateVertexData(mesh->mNumVertices);
vertexData->loadPositions(id, positions);
vertexData->loadTexCoords(id, texCoords);
for (size_t i = 0; i < MAX_TEXCOORDS; ++i)
{
vertexData->loadTexCoords(id, i, texCoords[i]);
}
vertexData->loadNormals(id, normals);
vertexData->loadTangents(id, tangents);
vertexData->loadBiTangents(id, biTangents);
@@ -570,7 +594,7 @@ void MeshLoader::import(MeshImportArgs args, PMeshAsset meshAsset)
const aiScene *scene = importer.ApplyPostProcessing(aiProcess_CalcTangentSpace);
std::cout << importer.GetErrorString() << std::endl;
Map<std::string, PTextureAsset> textures;
Array<PTextureAsset> textures;
loadTextures(scene, args.filePath.parent_path(), args.importPath, textures);
Array<PMaterialInstanceAsset> globalMaterials(scene->mNumMaterials);
loadMaterials(scene, textures, args.filePath.stem().string(), args.filePath.parent_path(), args.importPath, globalMaterials);
+2 -2
View File
@@ -27,8 +27,8 @@ public:
~MeshLoader();
void importAsset(MeshImportArgs args);
private:
void loadTextures(const aiScene* scene, const std::filesystem::path& meshDirectory, const std::string& importPath, Map<std::string, PTextureAsset>& textures);
void loadMaterials(const aiScene* scene, const Map<std::string, PTextureAsset>& textures, const std::string& baseName, const std::filesystem::path& meshDirectory, const std::string& importPath, Array<PMaterialInstanceAsset>& globalMaterials);
void loadTextures(const aiScene* scene, const std::filesystem::path& meshDirectory, const std::string& importPath, Array<PTextureAsset>& textures);
void loadMaterials(const aiScene* scene, const Array<PTextureAsset>& textures, const std::string& baseName, const std::filesystem::path& meshDirectory, const std::string& importPath, Array<PMaterialInstanceAsset>& globalMaterials);
void loadGlobalMeshes(const aiScene* scene, const Array<PMaterialInstanceAsset>& materials, Array<OMesh>& globalMeshes, Component::Collider& collider);
void convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels);
+1 -1
View File
@@ -62,7 +62,7 @@ int main() {
// .filePath = sourcePath / "import/models/Arissa.fbx",
// });
AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.fbx",
.filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
.importPath = "Whitechapel"
});
//AssetImporter::importMesh(MeshImportArgs{
+1
View File
@@ -61,6 +61,7 @@ public:
virtual void writeChanges() = 0;
virtual void updateBuffer(uint32 binding, PUniformBuffer uniformBuffer) = 0;
virtual void updateBuffer(uint32 binding, PShaderBuffer ShaderBuffer) = 0;
virtual void updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) = 0;
virtual void updateSampler(uint32 binding, PSampler sampler) = 0;
virtual void updateTexture(uint32 binding, PTexture texture, PSampler samplerState = nullptr) = 0;
virtual void updateTextureArray(uint32_t binding, Array<PTexture> texture) = 0;
+2 -2
View File
@@ -99,7 +99,7 @@ void BasePass::render()
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = collection->pipelineLayout;
pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL;
pipelineInfo.multisampleState.samples = viewport->getSamples();
pipelineInfo.colorBlend.attachmentCount = 1;
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
@@ -112,7 +112,7 @@ void BasePass::render()
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = collection->pipelineLayout;
pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL;
pipelineInfo.multisampleState.samples = viewport->getSamples();
pipelineInfo.colorBlend.attachmentCount = 1;
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
@@ -79,7 +79,7 @@ void DepthPrepass::render()
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = collection->pipelineLayout;
pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER;
pipelineInfo.multisampleState.samples = viewport->getSamples();
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
@@ -92,7 +92,7 @@ void DepthPrepass::render()
pipelineInfo.pipelineLayout = collection->pipelineLayout;
pipelineInfo.renderPass = renderPass;
//pipelineInfo.depthStencilState.depthWriteEnable = false;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER;
pipelineInfo.multisampleState.samples = viewport->getSamples();
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
@@ -147,7 +147,6 @@ void DepthPrepass::publishOutputs()
Gfx::RenderTargetAttachment(depthBuffer,
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_GENERAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
depthAttachment.clear.depthStencil.depth = 1.0f;
resources->registerRenderPassOutput("DEPTHPREPASS_DEPTH", depthAttachment);
}
@@ -76,7 +76,6 @@ void UIPass::publishOutputs()
Gfx::RenderTargetAttachment(depthBuffer,
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
depthAttachment.clear.depthStencil.depth = 1.0f;
resources->registerRenderPassOutput("UIPASS_DEPTH", depthAttachment);
TextureCreateInfo colorBufferInfo = {
+39 -21
View File
@@ -32,7 +32,7 @@ void StaticMeshVertexData::loadPositions(MeshId id, const Array<Vector>& data)
dirty = true;
}
void StaticMeshVertexData::loadTexCoords(MeshId id, const Array<Vector2>& data)
void StaticMeshVertexData::loadTexCoords(MeshId id, uint64 index, const Array<Vector2>& data)
{
uint64 offset;
{
@@ -40,7 +40,7 @@ void StaticMeshVertexData::loadTexCoords(MeshId id, const Array<Vector2>& data)
offset = meshOffsets[id];
}
assert(offset + data.size() <= head);
std::memcpy(texCoordsData.data() + offset, data.data(), data.size() * sizeof(Vector2));
std::memcpy(texCoordsData[index].data() + offset, data.data(), data.size() * sizeof(Vector2));
dirty = true;
}
@@ -100,19 +100,23 @@ void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveB
offset = meshOffsets[id];
}
Array<Vector> pos(numVertices);
Array<Vector2> tex(numVertices);
Array<Vector2> tex[MAX_TEXCOORDS];
for (size_t i = 0; i < MAX_TEXCOORDS; ++i)
{
tex[i].resize(numVertices);
std::memcpy(tex[i].data(), texCoordsData[i].data() + offset, numVertices * sizeof(Vector2));
Serialization::save(buffer, tex[i]);
}
Array<Vector> nor(numVertices);
Array<Vector> tan(numVertices);
Array<Vector> bit(numVertices);
Array<Vector> col(numVertices);
std::memcpy(pos.data(), positionData.data() + offset, numVertices * sizeof(Vector));
std::memcpy(tex.data(), texCoordsData.data() + offset, numVertices * sizeof(Vector2));
std::memcpy(nor.data(), normalData.data() + offset, numVertices * sizeof(Vector));
std::memcpy(tan.data(), tangentData.data() + offset, numVertices * sizeof(Vector));
std::memcpy(bit.data(), biTangentData.data() + offset, numVertices * sizeof(Vector));
std::memcpy(col.data(), colorData.data() + offset, numVertices * sizeof(Vector));
Serialization::save(buffer, pos);
Serialization::save(buffer, tex);
Serialization::save(buffer, nor);
Serialization::save(buffer, tan);
Serialization::save(buffer, bit);
@@ -122,19 +126,22 @@ void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveB
void StaticMeshVertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer)
{
Array<Vector> pos;
Array<Vector2> tex;
Array<Vector2> tex[MAX_TEXCOORDS];
for (size_t i = 0; i < MAX_TEXCOORDS; ++i)
{
Serialization::load(buffer, tex[i]);
loadTexCoords(id, i, tex[i]);
}
Array<Vector> nor;
Array<Vector> tan;
Array<Vector> bit;
Array<Vector> col;
Serialization::load(buffer, pos);
Serialization::load(buffer, tex);
Serialization::load(buffer, nor);
Serialization::load(buffer, tan);
Serialization::load(buffer, bit);
Serialization::load(buffer, col);
loadPositions(id, pos);
loadTexCoords(id, tex);
loadNormals(id, nor);
loadTangents(id, tan);
loadBiTangents(id, bit);
@@ -150,7 +157,7 @@ void StaticMeshVertexData::init(Gfx::PGraphics _graphics)
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});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 5, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .descriptorCount = MAX_TEXCOORDS });
descriptorLayout->create();
descriptorSet = descriptorLayout->allocateDescriptorSet();
}
@@ -159,7 +166,10 @@ void StaticMeshVertexData::destroy()
{
VertexData::destroy();
positions = nullptr;
texCoords = nullptr;
for (size_t i = 0; i < MAX_TEXCOORDS; ++i)
{
texCoords[i] = nullptr;
}
normals = nullptr;
tangents = nullptr;
biTangents = nullptr;
@@ -204,10 +214,13 @@ void StaticMeshVertexData::resizeBuffers()
createInfo.sourceData.size = verticesAllocated * sizeof(Vector2);
createInfo.name = "TexCoords";
createInfo.numElements = verticesAllocated * 2;
texCoords = graphics->createShaderBuffer(createInfo);
for (size_t i = 0; i < MAX_TEXCOORDS; ++i)
{
texCoords[i] = graphics->createShaderBuffer(createInfo);
texCoordsData[i].resize(verticesAllocated);
}
positionData.resize(verticesAllocated);
texCoordsData.resize(verticesAllocated);
normalData.resize(verticesAllocated);
tangentData.resize(verticesAllocated);
biTangentData.resize(verticesAllocated);
@@ -220,10 +233,13 @@ void StaticMeshVertexData::updateBuffers()
.size = positionData.size() * sizeof(Vector),
.data = (uint8*)positionData.data(),
});
texCoords->updateContents(DataSource{
.size = texCoordsData.size() * sizeof(Vector2),
.data = (uint8*)texCoordsData.data(),
});
for (size_t i = 0; i < MAX_TEXCOORDS; ++i)
{
texCoords[i]->updateContents(DataSource{
.size = texCoordsData[i].size() * sizeof(Vector2),
.data = (uint8*)texCoordsData[i].data(),
});
}
normals->updateContents(DataSource{
.size = normalData.size() * sizeof(Vector),
.data = (uint8*)normalData.data(),
@@ -243,10 +259,12 @@ void StaticMeshVertexData::updateBuffers()
descriptorLayout->reset();
descriptorSet = descriptorLayout->allocateDescriptorSet();
descriptorSet->updateBuffer(0, positions);
descriptorSet->updateBuffer(1, texCoords);
descriptorSet->updateBuffer(2, normals);
descriptorSet->updateBuffer(3, tangents);
descriptorSet->updateBuffer(4, biTangents);
descriptorSet->updateBuffer(5, colors);
descriptorSet->updateBuffer(1, normals);
descriptorSet->updateBuffer(2, tangents);
descriptorSet->updateBuffer(3, biTangents);
descriptorSet->updateBuffer(4, colors);
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
descriptorSet->updateBuffer(5, i, texCoords[i]);
}
descriptorSet->writeChanges();
}
+3 -3
View File
@@ -13,7 +13,7 @@ public:
virtual ~StaticMeshVertexData();
static StaticMeshVertexData* getInstance();
void loadPositions(MeshId id, const Array<Vector>& data);
void loadTexCoords(MeshId id, const Array<Vector2>& data);
void loadTexCoords(MeshId id, uint64 index, const Array<Vector2>& data);
void loadNormals(MeshId id, const Array<Vector>& data);
void loadTangents(MeshId id, const Array<Vector>& data);
void loadBiTangents(MeshId id, const Array<Vector>& data);
@@ -32,8 +32,8 @@ private:
std::mutex mutex;
Gfx::OShaderBuffer positions;
Array<Vector> positionData;
Gfx::OShaderBuffer texCoords;
Array<Vector2> texCoordsData;
Gfx::OShaderBuffer texCoords[MAX_TEXCOORDS];
Array<Vector2> texCoordsData[MAX_TEXCOORDS];
Gfx::OShaderBuffer normals;
Array<Vector> normalData;
Gfx::OShaderBuffer tangents;
+2
View File
@@ -8,6 +8,8 @@
#include "Graphics/Buffer.h"
#include "Meshlet.h"
constexpr uint64 MAX_TEXCOORDS = 8;
namespace Seele
{
DECLARE_REF(Mesh)
+27
View File
@@ -218,6 +218,33 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuff
cachedData[binding] = vulkanBuffer.getHandle();
}
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer shaderBuffer) {
PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>();
ShaderBuffer* cachedBuffer = reinterpret_cast<ShaderBuffer*>(cachedData[binding]);
if (vulkanBuffer.getHandle() == cachedBuffer) {
return;
}
bufferInfos.add(VkDescriptorBufferInfo{
.buffer = vulkanBuffer->getHandle(),
.offset = 0,
.range = vulkanBuffer->getSize(),
});
writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr,
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = index,
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
.pBufferInfo = &bufferInfos.back(),
});
cachedData[binding] = vulkanBuffer.getHandle();
}
void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) {
PSampler vulkanSampler = samplerState.cast<Sampler>();
Sampler* cachedSampler = reinterpret_cast<Sampler*>(cachedData[binding]);
+1
View File
@@ -50,6 +50,7 @@ public:
virtual void writeChanges() override;
virtual void updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) override;
virtual void updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer) override;
virtual void updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) override;
virtual void updateSampler(uint32_t binding, Gfx::PSampler samplerState) override;
virtual void updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr) override;
virtual void updateTextureArray(uint32_t binding, Array<Gfx::PTexture> texture) override;
+2 -2
View File
@@ -361,8 +361,8 @@ Viewport::Viewport(PWindow owner, const ViewportCreateInfo &viewportInfo)
handle.x = static_cast<float>(offsetX);
handle.y = static_cast<float>(offsetY) + handle.height;
handle.height = -handle.height;
handle.minDepth = 0.f;
handle.maxDepth = 1.f;
handle.minDepth = 1.f;
handle.maxDepth = 0.f;
}
Viewport::~Viewport()
+12
View File
@@ -31,6 +31,18 @@ Matrix4 Viewport::getProjectionMatrix() const
{
if (fieldOfView > 0.0f)
{
//float h = 1.0 / tan(fieldOfView * 0.5);
//float w = h / (sizeX / static_cast<float>(sizeY));
//float zFar = 1000.0f;
//float zNear = 0.1f;
//float a = -zNear / (zFar - zNear);
//float b = (zNear * zFar) / (zFar - zNear);
//return Matrix4(
// w, 0, 0, 0,
// 0, -h, 0, 0,
// 0, 0, a, b,
// 0, 0, 1, 0
//);
return glm::perspective(fieldOfView, sizeX / static_cast<float>(sizeY), 0.1f, 10000.0f);
}
else