From ee412201e6e4e7b07af4042f3b6b0985e8be81e4 Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Sun, 4 May 2025 21:30:01 +0200 Subject: [PATCH] Trying to fix wrong tex coord imports --- res/shaders/BasePass.slang | 8 ++-- res/shaders/lib/LightEnv.slang | 37 ++++--------------- res/shaders/lib/MaterialParameter.slang | 10 ++--- res/shaders/lib/StaticMeshVertexData.slang | 8 ++-- src/Editor/Asset/MeshLoader.cpp | 21 ++++++----- src/Editor/main.cpp | 12 ++++-- src/Engine/Graphics/StaticMeshVertexData.cpp | 32 ++++++++-------- src/Engine/Graphics/StaticMeshVertexData.h | 12 +++--- src/Engine/Material/Material.cpp | 6 +-- src/Engine/Material/ShaderExpression.cpp | 4 ++ src/Engine/Material/ShaderExpression.h | 3 ++ src/Engine/Platform/Windows/GameInterface.cpp | 6 ++- src/Engine/System/CameraUpdater.cpp | 2 +- 13 files changed, 78 insertions(+), 83 deletions(-) diff --git a/res/shaders/BasePass.slang b/res/shaders/BasePass.slang index 1c4f529..137316c 100644 --- a/res/shaders/BasePass.slang +++ b/res/shaders/BasePass.slang @@ -16,7 +16,7 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target { LightingParameter lightingParams = params.getLightingParameter(); MaterialParameter materialParams = params.getMaterialParameter(); - let brdf = Material.prepare(materialParams); + var brdf = Material.prepare(materialParams); uint2 tileIndex = uint2(floor(params.position_CS.xy / BLOCK_SIZE)); uint startOffset = pLightCullingData.lightGrid[tileIndex].x; uint lightCount = pLightCullingData.lightGrid[tileIndex].y; @@ -25,10 +25,10 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target { result += pLightEnv.directionalLights[i].illuminate(lightingParams, brdf); } - for(uint i = 0; i < pLightEnv.numPointLights; ++i) + for (uint i = 0; i < lightCount; ++i) { - //uint lightIndex = pLightCullingData.lightIndexList[startOffset + i]; - result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf); + uint lightIndex = pLightCullingData.lightIndexList[startOffset + i]; + result += pLightEnv.pointLights[lightIndex].illuminate(lightingParams, brdf); } result += brdf.evaluateAmbient(lightingParams.viewDir_WS); return float4(result, brdf.getAlpha()); diff --git a/res/shaders/lib/LightEnv.slang b/res/shaders/lib/LightEnv.slang index 9cb289f..7d80d23 100644 --- a/res/shaders/lib/LightEnv.slang +++ b/res/shaders/lib/LightEnv.slang @@ -70,20 +70,15 @@ struct LightEnv layout(set=3) ParameterBlock pLightEnv; -[Differentiable] -float polynomial(float a, float b, float c, float x) { - return a * x * x + b * x + c; -} - interface IBRDF { float3 evaluate(float3 viewDir_WS, float3 lightDir_WS, float3 lightColor); - [mutating] void transformNormal(float3x3 tangentToWorld); float3 getNormal(); float3 getBaseColor(); float3 evaluateAmbient(float3 viewDir_WS); float getAlpha(); float3 getEmissive(); + [mutating] void setNormal(float3 n); }; struct Phong : IBRDF @@ -116,11 +111,6 @@ struct Phong : IBRDF return lightColor * (baseColor * max(nDotL, 0.0)) + specular * pow(max(rDotV, 0.0), max(shininess, 1)); } - [mutating] - void transformNormal(float3x3 tangentToWorld) - { - normal = normalize(mul(tangentToWorld, normal)); - } float3 getNormal() { return normal; @@ -141,6 +131,7 @@ struct Phong : IBRDF { return emissive; } + [mutating] void setNormal(float3 n) { normal = n; } }; struct BlinnPhong : IBRDF @@ -170,14 +161,9 @@ struct BlinnPhong : IBRDF float diffuse = max(dot(normal_WS, lightDir_WS), 0); float3 h = normalize(lightDir_WS + viewDir_WS); float specular = pow(saturate(dot(normal_WS, h)), shininess); - + return (baseColor * diffuse * lightColor) + (specularColor * specular); } - [mutating] - void transformNormal(float3x3 tangentToWorld) - { - normal = normalize(mul(tangentToWorld, normal)); - } float3 getNormal() { return normal; @@ -198,6 +184,7 @@ struct BlinnPhong : IBRDF { return emissive; } + [mutating] void setNormal(float3 n) { normal = n; } }; struct CelShading : IBRDF @@ -230,11 +217,6 @@ struct CelShading : IBRDF return darkenedBase * lightColor; } } - [mutating] - void transformNormal(float3x3 tangentToWorld) - { - normal = normalize(mul(tangentToWorld, normal)); - } float3 getNormal() { return normal; @@ -255,6 +237,7 @@ struct CelShading : IBRDF { return emissive; } + [mutating] void setNormal(float3 n) { normal = n; } }; // https://learnopengl.com/PBR/Theory @@ -315,7 +298,7 @@ struct CookTorrance : IBRDF float3 evaluate(float3 viewDir_WS, float3 lightDir_WS, float3 lightColor) { - float3 n = normal; + float3 n = normalize(normal); float3 h = normalize(lightDir_WS + viewDir_WS); float3 F0 = float3(0.04); @@ -337,12 +320,7 @@ struct CookTorrance : IBRDF float nDotL = max(dot(n, lightDir_WS), 0.0); float3 result = (k_d * baseColor / PI + specular) * nDotL * lightColor; - return baseColor; - } - [mutating] - void transformNormal(float3x3 tangentToWorld) - { - normal = normalize(mul(tangentToWorld, normal)); + return result; } float3 getNormal() { @@ -371,5 +349,6 @@ struct CookTorrance : IBRDF { return emissive; } + [mutating] void setNormal(float3 n) { normal = n; } }; diff --git a/res/shaders/lib/MaterialParameter.slang b/res/shaders/lib/MaterialParameter.slang index 27de2e1..8bc6282 100644 --- a/res/shaders/lib/MaterialParameter.slang +++ b/res/shaders/lib/MaterialParameter.slang @@ -98,13 +98,13 @@ struct FragmentParameter { // in theory, transposing would make this a world-to-tangent matrix, but because we are building the matrix ourselves // and something with matrix layouts is working the opposite direction, we need to transpose here - return transpose(float3x3(tangent_WS, biTangent_WS, normal_WS)); + return transpose(float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS))); } #endif static FragmentParameter interpolate(FragmentParameter f0, FragmentParameter f1, FragmentParameter f2, float3 barycentricCoords) { FragmentParameter result; - result.position_CS = f0.position_CS * barycentricCoords.x + f1.position_CS * barycentricCoords.y + f2.position_CS * barycentricCoords.z; + result.position_CS = f0.position_CS * barycentricCoords.x + f1.position_CS * barycentricCoords.y + f2.position_CS * barycentricCoords.z; #ifndef POS_ONLY result.normal_WS = f0.normal_WS * barycentricCoords.x + f1.normal_WS * barycentricCoords.y + f2.normal_WS * barycentricCoords.z; result.tangent_WS = f0.tangent_WS * barycentricCoords.x + f1.tangent_WS * barycentricCoords.y + f2.tangent_WS * barycentricCoords.z; @@ -142,9 +142,9 @@ struct VertexAttributes result.position_CS = clipPos; #ifndef POS_ONLY //float3x3 tbn = qTangentToMatrix(qTangent); - result.tangent_WS = normalize(mul(transformMatrix, float4(tangent_MS, 0)).xyz); - result.biTangent_WS = normalize(mul(transformMatrix, float4(biTangent_MS, 0)).xyz); - result.normal_WS = normalize(mul(transformMatrix, float4(normal_MS, 0)).xyz); + result.tangent_WS = mul(transformMatrix, float4(tangent_MS, 0)).xyz; + result.biTangent_WS = mul(transformMatrix, float4(biTangent_MS, 0)).xyz; + result.normal_WS = mul(transformMatrix, float4(normal_MS, 0)).xyz; result.vertexColor = vertexColor; result.position_WS = worldPos.xyz; result.texCoords0 = float4(texCoords[0], texCoords[1]); diff --git a/res/shaders/lib/StaticMeshVertexData.slang b/res/shaders/lib/StaticMeshVertexData.slang index 2007449..e456b2a 100644 --- a/res/shaders/lib/StaticMeshVertexData.slang +++ b/res/shaders/lib/StaticMeshVertexData.slang @@ -16,9 +16,8 @@ struct StaticMeshVertexData : IVertexData #ifndef POS_ONLY //attributes.qTangent = qTangent[index]; attributes.normal_MS = float3(normals[index * 3 + 0], normals[index * 3 + 1], normals[index * 3 + 2]); - float4 tangentSign = float4(tangents[index * 4 + 0], tangents[index * 4 + 1], tangents[index * 4 + 2], tangents[index * 4 + 3]); - attributes.tangent_MS = tangentSign.xyz; - attributes.biTangent_MS = cross(attributes.normal_MS, attributes.tangent_MS) * -tangentSign.w; + attributes.tangent_MS = float3(tangents[index * 3 + 0], tangents[index * 3 + 1], tangents[index * 3 + 2]); + attributes.biTangent_MS = float3(biTangents[index * 3 + 0], biTangents[index * 3 + 1], biTangents[index * 3 + 2]);; for(uint i = 0; i < MAX_TEXCOORDS; ++i) { attributes.texCoords[i] = float2(uint16ToFloat(texCoords[i][index * 2 + 0]), uint16ToFloat(texCoords[i][index * 2 + 1])); @@ -30,7 +29,8 @@ struct StaticMeshVertexData : IVertexData StructuredBuffer positions; //StructuredBuffer qTangents; StructuredBuffer normals; - StructuredBuffer tangents; + StructuredBuffer tangents; + StructuredBuffer biTangents; StructuredBuffer color; StructuredBuffer texCoords[MAX_TEXCOORDS]; }; diff --git a/src/Editor/Asset/MeshLoader.cpp b/src/Editor/Asset/MeshLoader.cpp index c8bb68b..9b0a2ed 100644 --- a/src/Editor/Asset/MeshLoader.cpp +++ b/src/Editor/Asset/MeshLoader.cpp @@ -152,9 +152,10 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array& aiTextureMapMode mapMode = aiTextureMapMode_Clamp; float blend = std::numeric_limits::max(); aiTextureOp op = aiTextureOp_Add; - if (material->GetTexture(type, index, &texPath, &mapping, &uvIndex, nullptr, nullptr, nullptr) != AI_SUCCESS) { + if (material->GetTexture(type, index, &texPath, &mapping, &uvIndex, &blend, &op, &mapMode) != AI_SUCCESS) { std::cout << "fuck" << std::endl; } + uvIndex = 1; std::string textureKey = fmt::format("{0}Texture{1}", paramKey, index); auto texFilename = std::filesystem::path(texPath.C_Str()); PTextureAsset texture; @@ -357,7 +358,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array& } // Emissive - //addScalarParameter(KEY_EMISSIVE_INTENSITY, AI_MATKEY_EMISSIVE_INTENSITY); + // addScalarParameter(KEY_EMISSIVE_INTENSITY, AI_MATKEY_EMISSIVE_INTENSITY); addVectorParameter(KEY_EMISSIVE_COLOR, AI_MATKEY_COLOR_EMISSIVE); std::string outputEmissive = KEY_EMISSIVE_COLOR; uint32 numEmissive = material->GetTextureCount(aiTextureType_EMISSION_COLOR); @@ -536,7 +537,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array normals(mesh->mNumVertices); Array tangents(mesh->mNumVertices); - //Array biTangents(mesh->mNumVertices); + Array biTangents(mesh->mNumVertices); Array colors(mesh->mNumVertices); for (uint32 i = 0; i < mesh->mNumVertices; ++i) { @@ -559,13 +560,15 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const ArrayHasVertexColors(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 { colors[i] = StaticMeshVertexData::ColorType(1, 1, 1); } @@ -577,7 +580,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const ArrayloadNormals(offset, normals); vertexData->loadTangents(offset, tangents); - //vertexData->loadBitangents(offset, biTangents); + vertexData->loadBitangents(offset, biTangents); vertexData->loadColors(offset, colors); Array indices(mesh->mNumFaces * 3); diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index 28777cd..25c9362 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -25,7 +25,7 @@ using namespace Seele::Editor; static Gfx::OGraphics graphics; int main() { - std::string gameName = "MinecraftClone"; + std::string gameName = "MeshShadingDemo"; std::filesystem::path outputPath = fmt::format("../../{0}Game", gameName); std::filesystem::path sourcePath = fmt::format("../../{0}", gameName); #ifdef WIN32 @@ -57,9 +57,13 @@ int main() { AssetImporter::importEnvironmentMap(EnvironmentImportArgs{ .filePath = sourcePath / "import" / "textures" / "newport_loft.hdr", }); - AssetImporter::importTexture(TextureImportArgs{ - .filePath = sourcePath / "import" / "textures" / "grass_block_side.png", - .importPath = "", + //AssetImporter::importTexture(TextureImportArgs{ + // .filePath = sourcePath / "import" / "textures" / "grass_block_side.png", + // .importPath = "", + //}); + AssetImporter::importMesh(MeshImportArgs{ + .filePath = sourcePath / "import" / "models" / "main1_sponza" / "floor.glb", + .importPath = "sponza", }); getThreadPool().waitIdle(); diff --git a/src/Engine/Graphics/StaticMeshVertexData.cpp b/src/Engine/Graphics/StaticMeshVertexData.cpp index c82b27c..5f24ed8 100644 --- a/src/Engine/Graphics/StaticMeshVertexData.cpp +++ b/src/Engine/Graphics/StaticMeshVertexData.cpp @@ -40,11 +40,11 @@ void StaticMeshVertexData::loadTangents(uint64 offset, const Array& dirty = true; } -/*void StaticMeshVertexData::loadBitangents(uint64 offset, const Array& data) { +void StaticMeshVertexData::loadBitangents(uint64 offset, const Array& 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& data) { assert(offset + data.size() <= head); @@ -70,17 +70,17 @@ void StaticMeshVertexData::serializeMesh(MeshId id, ArchiveBuffer& buffer) { Array pos(numVertices); Array nor(numVertices); Array tan(numVertices); - //Array bit(numVertices); + Array bit(numVertices); Array 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(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, bit); Serialization::save(buffer, col); } @@ -100,22 +100,22 @@ uint64 StaticMeshVertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer) { Array pos; Array nor; Array tan; - //Array bit; + Array bit; Array col; Serialization::load(buffer, pos); Serialization::load(buffer, nor); Serialization::load(buffer, tan); - //Serialization::load(buffer, bit); + Serialization::load(buffer, bit); Serialization::load(buffer, col); loadPositions(offset, pos); loadNormals(offset, nor); loadTangents(offset, tan); - //loadBitangents(offset, bit); + loadBitangents(offset, bit); loadColors(offset, col); result += pos.size() * sizeof(PositionType); result += nor.size() * sizeof(NormalType); result += tan.size() * sizeof(TangentType); - //result += bit.size() * sizeof(BiTangentType); + result += bit.size() * sizeof(BiTangentType); result += col.size() * sizeof(ColorType); return result; } @@ -135,10 +135,10 @@ void StaticMeshVertexData::init(Gfx::PGraphics _graphics) { .name = TANGENTS_NAME, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, }); - /*descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ + descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .name = BITANGENTS_NAME, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, - });*/ + }); descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .name = COLORS_NAME, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, @@ -160,7 +160,7 @@ void StaticMeshVertexData::destroy() { positions = nullptr; normals = nullptr; tangents = nullptr; - //biTangents = nullptr; + biTangents = nullptr; colors = nullptr; descriptorSet = nullptr; descriptorLayout = nullptr; @@ -170,7 +170,7 @@ void StaticMeshVertexData::resizeBuffers() { posData.resize(verticesAllocated); norData.resize(verticesAllocated); tanData.resize(verticesAllocated); - //bitData.resize(verticesAllocated); + bitData.resize(verticesAllocated); colData.resize(verticesAllocated); for (size_t i = 0; i < MAX_TEXCOORDS; ++i) { texData[i].resize(verticesAllocated); @@ -203,14 +203,14 @@ void StaticMeshVertexData::updateBuffers() { }, .name = "Tangents", }); - /*biTangents = graphics->createShaderBuffer(ShaderBufferCreateInfo{ + biTangents = graphics->createShaderBuffer(ShaderBufferCreateInfo{ .sourceData = { .size = verticesAllocated * sizeof(BiTangentType), .data = (uint8*)bitData.data(), }, .name = "BiTangents", - });*/ + }); colors = graphics->createShaderBuffer(ShaderBufferCreateInfo{ .sourceData = { @@ -234,7 +234,7 @@ void StaticMeshVertexData::updateBuffers() { descriptorSet->updateBuffer(POSITIONS_NAME, 0, positions); descriptorSet->updateBuffer(NORMALS_NAME, 0, normals); descriptorSet->updateBuffer(TANGENTS_NAME, 0, tangents); - //descriptorSet->updateBuffer(BITANGENTS_NAME, 0, biTangents); + descriptorSet->updateBuffer(BITANGENTS_NAME, 0, biTangents); descriptorSet->updateBuffer(COLORS_NAME, 0, colors); for (uint32 i = 0; i < MAX_TEXCOORDS; ++i) { descriptorSet->updateBuffer(TEXCOORDS_NAME, i, texCoords[i]); diff --git a/src/Engine/Graphics/StaticMeshVertexData.h b/src/Engine/Graphics/StaticMeshVertexData.h index 52b4f42..c6a5a70 100644 --- a/src/Engine/Graphics/StaticMeshVertexData.h +++ b/src/Engine/Graphics/StaticMeshVertexData.h @@ -10,8 +10,8 @@ class StaticMeshVertexData : public VertexData { public: using PositionType = Vector; using NormalType = Vector; - using TangentType = Vector4; - //using BiTangentType = Vector; + using TangentType = Vector; + using BiTangentType = Vector; using TexCoordType = U16Vector2; using ColorType = U16Vector; @@ -22,7 +22,7 @@ class StaticMeshVertexData : public VertexData { void loadTexCoords(uint64 offset, uint64 index, const Array& data); void loadNormals(uint64 offset, const Array& data); void loadTangents(uint64 offset, const Array& data); - //void loadBitangents(uint64 offset, const Array& data); + void loadBitangents(uint64 offset, const Array& data); void loadColors(uint64 offset, const Array& data); virtual void serializeMesh(MeshId id, ArchiveBuffer& buffer) override; virtual uint64 deserializeMesh(MeshId id, ArchiveBuffer& buffer) override; @@ -45,15 +45,15 @@ class StaticMeshVertexData : public VertexData { constexpr static const char* NORMALS_NAME = "normals"; Gfx::OShaderBuffer tangents; constexpr static const char* TANGENTS_NAME = "tangents"; - //Gfx::OShaderBuffer biTangents; - //constexpr static const char* BITANGENTS_NAME = "biTangents"; + Gfx::OShaderBuffer biTangents; + constexpr static const char* BITANGENTS_NAME = "biTangents"; Gfx::OShaderBuffer colors; constexpr static const char* COLORS_NAME = "colors"; Array posData; Array texData[MAX_TEXCOORDS]; Array norData; Array tanData; - //Array bitData; + Array bitData; Array colData; Gfx::ODescriptorLayout descriptorLayout; Gfx::PDescriptorSet descriptorSet; diff --git a/src/Engine/Material/Material.cpp b/src/Engine/Material/Material.cpp index d0785a4..40f771d 100644 --- a/src/Engine/Material/Material.cpp +++ b/src/Engine/Material/Material.cpp @@ -170,12 +170,10 @@ void Material::compile() { for (const auto& expr : codeExpressions) { codeStream << "\t\t" << expr->evaluate(varState); } - //for (const auto& [name, exp] : brdf.variables) { - for(auto it = brdf.variables.begin(); it != brdf.variables.end(); ++it){ - auto [name, exp] = *it; + for (const auto& [name, exp] : brdf.variables) { codeStream << "\t\tresult." << name << " = " << varState[exp] << ";" << std::endl; } - codeStream << "\t\tresult.transformNormal(input.tangentToWorld);" << std::endl; + codeStream << "\t\tresult.normal = mul(input.tangentToWorld, result.normal);" << std::endl; codeStream << "\t\treturn result;\n"; codeStream << "\t}\n"; codeStream << "};\n"; diff --git a/src/Engine/Material/ShaderExpression.cpp b/src/Engine/Material/ShaderExpression.cpp index 2798153..b845ce2 100644 --- a/src/Engine/Material/ShaderExpression.cpp +++ b/src/Engine/Material/ShaderExpression.cpp @@ -312,6 +312,10 @@ std::string MulExpression::evaluate(Map& varState) con if (varState.contains(rhs)) { rhs = varState[rhs]; } + if (inputs.at("lhs").type == ExpressionType::MATRIX2 || inputs.at("lhs").type == ExpressionType::MATRIX3 || + inputs.at("lhs").type == ExpressionType::MATRIX4) { // TODO + return fmt::format("let {} = mul({}, {});\n", varName, lhs, rhs); + } return fmt::format("let {} = {} * {};\n", varName, lhs, rhs); } diff --git a/src/Engine/Material/ShaderExpression.h b/src/Engine/Material/ShaderExpression.h index 0254885..6854005 100644 --- a/src/Engine/Material/ShaderExpression.h +++ b/src/Engine/Material/ShaderExpression.h @@ -11,6 +11,9 @@ enum class ExpressionType { FLOAT2, FLOAT3, FLOAT4, + MATRIX2, + MATRIX3, + MATRIX4, TEXTURE, SAMPLER, }; diff --git a/src/Engine/Platform/Windows/GameInterface.cpp b/src/Engine/Platform/Windows/GameInterface.cpp index 85f58df..b2718fb 100644 --- a/src/Engine/Platform/Windows/GameInterface.cpp +++ b/src/Engine/Platform/Windows/GameInterface.cpp @@ -14,7 +14,11 @@ void GameInterface::reload() { destroyInstance(game); FreeLibrary(lib); } - std::filesystem::copy(dllPath.parent_path().parent_path() / "res" / "shaders", "./shaders/game", std::filesystem::copy_options::overwrite_existing); + auto shaderPath = dllPath.parent_path().parent_path() / "res" / "shaders"; + if (std::filesystem::exists(shaderPath)) + { + std::filesystem::copy(shaderPath, "./shaders/game", std::filesystem::copy_options::overwrite_existing); + } lib = LoadLibraryA(dllPath.string().c_str()); createInstance = (decltype(createInstance))GetProcAddress(lib, "createInstance"); destroyInstance = (decltype(destroyInstance))GetProcAddress(lib, "destroyInstance"); diff --git a/src/Engine/System/CameraUpdater.cpp b/src/Engine/System/CameraUpdater.cpp index 77283f7..a6ae03f 100644 --- a/src/Engine/System/CameraUpdater.cpp +++ b/src/Engine/System/CameraUpdater.cpp @@ -9,6 +9,6 @@ CameraUpdater::~CameraUpdater() {} void CameraUpdater::update(Component::Camera& camera, Component::Transform& transform) { Vector eyePos = transform.getPosition(); - Vector lookAt = eyePos - transform.getForward(); + Vector lookAt = eyePos + transform.getForward(); camera.viewMatrix = glm::lookAt(eyePos, lookAt, Vector(0, 1, 0)); }