diff --git a/TGEngine/CMakeLists.txt b/TGEngine/CMakeLists.txt index 54dfb28..7470e97 100644 --- a/TGEngine/CMakeLists.txt +++ b/TGEngine/CMakeLists.txt @@ -32,7 +32,7 @@ set(ENGINE_DATA "private/graphics/GUIModule.cpp" "private/imgui/imgui_impl_vulkan.cpp" -) + ) if(WIN32) list(APPEND ENGINE_DATA diff --git a/TGEngine/assets/lightPass.frag b/TGEngine/assets/lightPass.frag index 2d6b4a9..b6f99e5 100644 --- a/TGEngine/assets/lightPass.frag +++ b/TGEngine/assets/lightPass.frag @@ -11,6 +11,7 @@ "layout(input_attachment_index=3, set=0, binding = 3) uniform subpassInput POSITION;", "struct Light {", " vec3 pos;", + " float minRatio;", " vec3 color;", " float intensity;", "};", @@ -28,7 +29,7 @@ " for(int x = 0; x < lights.lightCount; x++) {", " Light lightInfo = lights.light[x];", " vec3 distance = pos - lightInfo.pos;", - " float distanceFallof = 1/dot(distance, distance);", + " float distanceFallof = max(1/dot(distance, distance), lightInfo.minRatio);", " vec3 l = normalize(distance);", " float ratio = max(0, dot(normal, l));", " multiplier += lightInfo.color * ratio * distanceFallof * lightInfo.intensity;", diff --git a/TGEngine/private/IO/IOModule.cpp b/TGEngine/private/IO/IOModule.cpp index f10a624..3196c50 100644 --- a/TGEngine/private/IO/IOModule.cpp +++ b/TGEngine/private/IO/IOModule.cpp @@ -54,7 +54,10 @@ LRESULT CALLBACK callback(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { for (const auto io : ios) io->mouseEvent({zDelta, zDelta, SCROLL}); } break; case WM_KEYDOWN: { - for (const auto io : ios) io->keyboardEvent({(uint32_t)wParam}); + for (const auto io : ios) io->keyboardEvent({(uint32_t)wParam, PressMode::CLICKED}); + } break; + case WM_KEYUP: { + for (const auto io : ios) io->keyboardEvent({ (uint32_t)wParam, PressMode::RELEASED }); } break; default: break; diff --git a/TGEngine/private/graphics/GameGraphicsModule.cpp b/TGEngine/private/graphics/GameGraphicsModule.cpp index 922b50c..556271d 100644 --- a/TGEngine/private/graphics/GameGraphicsModule.cpp +++ b/TGEngine/private/graphics/GameGraphicsModule.cpp @@ -844,8 +844,10 @@ namespace tge::graphics { const auto parentID = !nodeInfo.parentHolder ? allocation.beginIndex + nodeInfo.parent : nodeInfo.parentHolder.internalHandle; parent[i] = parentID; - const auto currentOffset = nodeHolder.translationTable[parentID]; - children[currentOffset].push_back(allocation.beginIndex + i); + if (parentID != INVALID_SIZE_T) { + const auto currentOffset = nodeHolder.translationTable[parentID]; + children[currentOffset].push_back(allocation.beginIndex + i); + } cache[i].offset = i * sizeof(ValueSystem); debug[i] = nodeInfo.debugInfo; diff --git a/TGEngine/private/graphics/Vulkan/VulkanShaderModule.cpp b/TGEngine/private/graphics/Vulkan/VulkanShaderModule.cpp index 2c867c5..80964fb 100644 --- a/TGEngine/private/graphics/Vulkan/VulkanShaderModule.cpp +++ b/TGEngine/private/graphics/Vulkan/VulkanShaderModule.cpp @@ -306,6 +306,7 @@ VulkanShaderPipe* __implLoadShaderPipeAndCompile( } __implIntermToVulkanPipe(shaderPipe, shader->getIntermediate(), getLangFromShaderLang(pair.language), createInfo); + shaderPipe->shaderNames.push_back(pair.debug); } return shaderPipe; @@ -316,6 +317,7 @@ ShaderPipe VulkanShaderModule::compile(const std::vector& vector, std::lock_guard guard(this->mutex); const auto loadedPipes = __implLoadShaderPipeAndCompile(vector, createInfo); if (loadedPipes) __implCreateDescSets(loadedPipes, this); + if (loadedPipes) this->shaderPipes.push_back(loadedPipes); return loadedPipes; } @@ -331,7 +333,7 @@ ShaderPipe VulkanShaderModule::loadShaderPipeAndCompile( PLOG_WARNING << "File [" << name << "] not found"; continue; } - vector.push_back({getLang(abrivation), content}); + vector.push_back({ getLang(abrivation), content, {}, name }); } return compile(vector, createInfo); } diff --git a/TGEngine/public/IO/IOModule.hpp b/TGEngine/public/IO/IOModule.hpp index 149090f..879b69d 100644 --- a/TGEngine/public/IO/IOModule.hpp +++ b/TGEngine/public/IO/IOModule.hpp @@ -15,6 +15,7 @@ enum class PressMode { struct KeyboardEvent { unsigned int signal; + PressMode mode; }; struct MouseEvent { diff --git a/TGEngine/public/graphics/APILayer.hpp b/TGEngine/public/graphics/APILayer.hpp index ee6e18b..990757c 100644 --- a/TGEngine/public/graphics/APILayer.hpp +++ b/TGEngine/public/graphics/APILayer.hpp @@ -29,7 +29,7 @@ struct CacheIndex { }; struct PushConstRanges { - std::vector pushConstData; + std::span pushConstData; shader::ShaderType type; }; @@ -85,7 +85,7 @@ struct SamplerInfo { struct Light { glm::vec3 pos; - float __alignment = 0; + float minRatio = 0; glm::vec3 color; float intensity; diff --git a/TGEngine/public/graphics/GameShaderModule.hpp b/TGEngine/public/graphics/GameShaderModule.hpp index ba5e903..562b63d 100644 --- a/TGEngine/public/graphics/GameShaderModule.hpp +++ b/TGEngine/public/graphics/GameShaderModule.hpp @@ -55,6 +55,7 @@ struct ShaderInfo { ShaderType language = ShaderType::INVALID; std::vector code; std::vector additionalCode; + std::string debug; }; #ifdef DEBUG diff --git a/TGEngine/public/graphics/ShaderUI.hpp b/TGEngine/public/graphics/ShaderUI.hpp new file mode 100644 index 0000000..2803db2 --- /dev/null +++ b/TGEngine/public/graphics/ShaderUI.hpp @@ -0,0 +1,69 @@ +#include "GUIModule.hpp" +#include "headerlibs/json.hpp" +#include "vulkan/VulkanShaderModule.hpp" +#include + +class ShaderUI { + size_t selected = 0; + nlohmann::json jsonObj; + +public: + void renderGUI(tge::shader::ShaderAPI* shader) { + if (shader == nullptr) return; + tge::shader::VulkanShaderModule* shaderModule = (tge::shader::VulkanShaderModule*) shader; + std::vector namesUsed; + namesUsed.reserve(2 * shaderModule->shaderPipes.size()); + for (auto value : shaderModule->shaderPipes) { + for (auto& name : value->shaderNames) { + if (name.empty()) + continue; + namesUsed.push_back(name); + } + } + if (namesUsed.empty()) + return; + size_t container = 0; + if (ImGui::Begin("ShaderUI")) { + const auto combobox = selected >= namesUsed.size() ? "Unknown" : namesUsed[selected].c_str(); + if (ImGui::BeginCombo("Shader", combobox)) { + for (auto& string : namesUsed) { + container++; + if (ImGui::Selectable(string.c_str())) { + selected = container; + std::ifstream stream(string); + jsonObj << stream; + } + } + ImGui::EndCombo(); + } + if (namesUsed.size() > selected) { + size_t index = 0; + for (auto& jelement : jsonObj["codes"]) { + const auto blockName = "Block" + std::to_string(index); + auto& codeShader = jelement["code"]; + std::string text; + for (auto& string : codeShader) { + text += string.get() + "\n"; + } + if (text.size() < 400) + text.resize(400); + ImGui::InputTextMultiline(blockName.c_str(), text.data(), text.size()); + if (ImGui::TreeNode(blockName.c_str())) { + auto& dependable = jelement["dependsOn"]; + std::string dependables; + for (auto& string : dependable) { + dependables += string.get() + "; "; + } + if (dependables.size() < 400) + dependables.resize(100); + ImGui::InputText("Depends on", dependables.data(), dependables.size()); + ImGui::TreePop(); + } + index++; + } + } + } + ImGui::End(); + } + +}; \ No newline at end of file diff --git a/TGEngine/public/graphics/vulkan/VulkanShaderPipe.hpp b/TGEngine/public/graphics/vulkan/VulkanShaderPipe.hpp index 553ed8b..d9d75c0 100644 --- a/TGEngine/public/graphics/vulkan/VulkanShaderPipe.hpp +++ b/TGEngine/public/graphics/vulkan/VulkanShaderPipe.hpp @@ -27,6 +27,7 @@ struct VulkanShaderPipe { std::mutex pipeMutex; std::vector> modules; + std::vector shaderNames; }; diff --git a/TGEngine/public/headerlibs/ShaderPermute.hpp b/TGEngine/public/headerlibs/ShaderPermute.hpp index 1ae45e6..8ec90b5 100644 --- a/TGEngine/public/headerlibs/ShaderPermute.hpp +++ b/TGEngine/public/headerlibs/ShaderPermute.hpp @@ -61,7 +61,7 @@ } #if !defined(SPR_NO_GLSL) && !defined(SPR_NO_GLSL_INCLUDE) -#include +#include #include #endif