From 485b60c6d86c6960881f758ce4ad228ab95046eb Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Mon, 21 Nov 2022 00:38:45 +0800 Subject: [PATCH 01/15] Added debug check in SHGraphicsSystem to compile assets only in debug --- .../src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 160e82c6..17dcf2d7 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -119,6 +119,7 @@ namespace SHADE SHFreetypeInstance::Init(); +#ifdef _DEBUG SHAssetManager::CompileAsset("../../Assets/Shaders/Text_VS.glsl", false); SHAssetManager::CompileAsset("../../Assets/Shaders/Text_FS.glsl", false); SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_VS.glsl", false); @@ -126,6 +127,8 @@ namespace SHADE SHAssetManager::CompileAsset("../../Assets/Shaders/UI_FS.glsl", false); SHAssetManager::CompileAsset("../../Assets/Models/Quad.gltf", false); +#endif + // Load Built In Shaders static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet(VS_DEFAULT); From 0a9dea1c83b83dca0b0ce53856626d84eee5b712 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Mon, 21 Nov 2022 12:14:07 +0800 Subject: [PATCH 02/15] Disabled xmldoc generation warnings for SHADE projects --- SHADE_Application/premake5.lua | 5 ++++- SHADE_Engine/premake5.lua | 5 ++++- SHADE_Managed/premake5.lua | 6 +++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/SHADE_Application/premake5.lua b/SHADE_Application/premake5.lua index faa741a6..014df726 100644 --- a/SHADE_Application/premake5.lua +++ b/SHADE_Application/premake5.lua @@ -78,7 +78,10 @@ project "SHADE_Application" "26451", "26437", "4275", - "4635" + "4633", + "4634", + "4635", + "4638" } linkoptions { "-IGNORE:4006" } diff --git a/SHADE_Engine/premake5.lua b/SHADE_Engine/premake5.lua index 88df50d7..7fb7291d 100644 --- a/SHADE_Engine/premake5.lua +++ b/SHADE_Engine/premake5.lua @@ -79,7 +79,10 @@ project "SHADE_Engine" "26451", "26437", "4275", - "4635" + "4633", + "4634", + "4635", + "4638" } linkoptions { "-IGNORE:4006" } diff --git a/SHADE_Managed/premake5.lua b/SHADE_Managed/premake5.lua index 2384cae8..70b01e18 100644 --- a/SHADE_Managed/premake5.lua +++ b/SHADE_Managed/premake5.lua @@ -62,7 +62,11 @@ project "SHADE_Managed" disablewarnings { - "4251" + "4251", + "4633", + "4634", + "4635", + "4638" } defines From 819607925ff45b5b0febfaa9764789fa8f0fd441 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Mon, 21 Nov 2022 15:41:15 +0800 Subject: [PATCH 03/15] Added GameObject.Null for setting GameObjects to null. --- SHADE_Managed/src/Engine/GameObject.cxx | 8 ++++++++ SHADE_Managed/src/Engine/GameObject.hxx | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/SHADE_Managed/src/Engine/GameObject.cxx b/SHADE_Managed/src/Engine/GameObject.cxx index 200b2079..3557e8f1 100644 --- a/SHADE_Managed/src/Engine/GameObject.cxx +++ b/SHADE_Managed/src/Engine/GameObject.cxx @@ -54,6 +54,14 @@ namespace SHADE return GameObject(ENTITY_ID); } + /*---------------------------------------------------------------------------------*/ + /* Static Properties */ + /*---------------------------------------------------------------------------------*/ + GameObject GameObject::Null::get() + { + return GameObject(); + } + /*---------------------------------------------------------------------------------*/ /* Properties */ /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Engine/GameObject.hxx b/SHADE_Managed/src/Engine/GameObject.hxx index 64d1b428..1ebfc250 100644 --- a/SHADE_Managed/src/Engine/GameObject.hxx +++ b/SHADE_Managed/src/Engine/GameObject.hxx @@ -62,6 +62,17 @@ namespace SHADE /// GameObject that has the specified name. Null if not found. static System::Nullable Find(System::String^ name); + /*-----------------------------------------------------------------------------*/ + /* Static Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Default empty GameObject. + /// + static property GameObject Null + { + GameObject get(); + } + /*-----------------------------------------------------------------------------*/ /* Properties */ /*-----------------------------------------------------------------------------*/ From e3c573baa7764ab081427e0b83a37eddf00c3fd3 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Mon, 21 Nov 2022 17:16:16 +0800 Subject: [PATCH 04/15] Added support for enabling and disabling scripts OnEnable and OnDisable are not called on GameObject active toggling for now but will be added in future --- SHADE_Engine/src/Editor/SHEditorUI.cpp | 141 ++++++++++++++-------- SHADE_Managed/src/Editor/Editor.cxx | 6 + SHADE_Managed/src/Scripts/Script.cxx | 47 +++++++- SHADE_Managed/src/Scripts/Script.hxx | 46 ++++++- SHADE_Managed/src/Scripts/ScriptStore.cxx | 12 +- 5 files changed, 188 insertions(+), 64 deletions(-) diff --git a/SHADE_Engine/src/Editor/SHEditorUI.cpp b/SHADE_Engine/src/Editor/SHEditorUI.cpp index 40e08042..9fdcbde7 100644 --- a/SHADE_Engine/src/Editor/SHEditorUI.cpp +++ b/SHADE_Engine/src/Editor/SHEditorUI.cpp @@ -4,9 +4,9 @@ \par email: kahwei.tng\@digipen.edu \date Nov 7, 2021 \brief Contains the implementation of the EditorUI class. - + Copyright (C) 2021 DigiPen Institute of Technology. -Reproduction or disclosure of this file or its contents without the prior written consent +Reproduction or disclosure of this file or its contents without the prior written consent of DigiPen Institute of Technology is prohibited. *//*************************************************************************************/ // Precompiled Header @@ -57,10 +57,10 @@ namespace SHADE { const bool OPENED = ImGui::CollapsingHeader(title.c_str(), ImGuiTreeNodeFlags_DefaultOpen); if (isHovered) - *isHovered = ImGui::IsItemHovered(); + *isHovered = ImGui::IsItemHovered(); return OPENED; } - + void SHEditorUI::SameLine() { ImGui::SameLine(); @@ -98,7 +98,7 @@ namespace SHADE void SHEditorUI::EndTooltip() { - ImGui::EndTooltip(); + ImGui::EndTooltip(); } /*-----------------------------------------------------------------------------------*/ @@ -146,7 +146,7 @@ namespace SHADE bool SHEditorUI::Selectable(const std::string& label) { - return ImGui::Selectable(label.data()); + return ImGui::Selectable(label.data()); } bool SHEditorUI::Selectable(const std::string& label, const char* icon) @@ -156,30 +156,41 @@ namespace SHADE bool SHEditorUI::InputCheckbox(const std::string& label, bool& value, bool* isHovered) { - ImGui::Text(label.c_str()); + if (!label.empty()) + { + ImGui::Text(label.c_str()); + ImGui::SameLine(); + } if (isHovered) - *isHovered = ImGui::IsItemHovered(); - ImGui::SameLine(); + *isHovered = ImGui::IsItemHovered(); return ImGui::Checkbox("##", &value); } bool SHEditorUI::InputInt(const std::string& label, int& value, bool* isHovered) { - ImGui::Text(label.c_str()); + if (!label.empty()) + { + ImGui::Text(label.c_str()); + ImGui::SameLine(); + } if (isHovered) - *isHovered = ImGui::IsItemHovered(); + *isHovered = ImGui::IsItemHovered(); ImGui::SameLine(); return ImGui::DragInt("##", &value, 0.001f, - std::numeric_limits::min(), - std::numeric_limits::max(), - "%d", - ImGuiInputTextFlags_EnterReturnsTrue); + std::numeric_limits::min(), + std::numeric_limits::max(), + "%d", + ImGuiInputTextFlags_EnterReturnsTrue); } bool SHEditorUI::InputUnsignedInt(const std::string& label, unsigned int& value, bool* isHovered) { int signedVal = static_cast(value); - ImGui::Text(label.c_str()); + if (!label.empty()) + { + ImGui::Text(label.c_str()); + ImGui::SameLine(); + } if (isHovered) - *isHovered = ImGui::IsItemHovered(); + *isHovered = ImGui::IsItemHovered(); ImGui::SameLine(); const bool CHANGED = InputInt("##", signedVal); if (CHANGED) @@ -191,15 +202,19 @@ namespace SHADE } bool SHEditorUI::InputFloat(const std::string& label, float& value, bool* isHovered) { - ImGui::Text(label.c_str()); + if (!label.empty()) + { + ImGui::Text(label.c_str()); + ImGui::SameLine(); + } if (isHovered) - *isHovered = ImGui::IsItemHovered(); + *isHovered = ImGui::IsItemHovered(); ImGui::SameLine(); return ImGui::DragFloat("##", &value, 0.001f, - std::numeric_limits::lowest(), - std::numeric_limits::max(), - "%.3f", - ImGuiInputTextFlags_EnterReturnsTrue); + std::numeric_limits::lowest(), + std::numeric_limits::max(), + "%.3f", + ImGuiInputTextFlags_EnterReturnsTrue); } bool SHEditorUI::InputDouble(const std::string& label, double& value, bool* isHovered) { @@ -213,48 +228,56 @@ namespace SHADE } bool SHEditorUI::InputSlider(const std::string& label, int min, int max, int& value, bool* isHovered /*= nullptr*/) { + if (!label.empty()) + { ImGui::Text(label.c_str()); - if (isHovered) - *isHovered = ImGui::IsItemHovered(); ImGui::SameLine(); - return ImGui::SliderInt("##", &value, - static_cast(min), static_cast(max), "%d", - ImGuiInputTextFlags_EnterReturnsTrue); + } + if (isHovered) + *isHovered = ImGui::IsItemHovered(); + ImGui::SameLine(); + return ImGui::SliderInt("##", &value, + static_cast(min), static_cast(max), "%d", + ImGuiInputTextFlags_EnterReturnsTrue); } bool SHEditorUI::InputSlider(const std::string& label, unsigned int min, unsigned int max, unsigned int& value, bool* isHovered /*= nullptr*/) { - int val = static_cast(value); - const bool CHANGED = InputSlider(label, min, max, val, isHovered); - if (CHANGED) - { - value = static_cast(val); - } + int val = static_cast(value); + const bool CHANGED = InputSlider(label, min, max, val, isHovered); + if (CHANGED) + { + value = static_cast(val); + } - return CHANGED; + return CHANGED; } bool SHEditorUI::InputSlider(const std::string& label, float min, float max, float& value, bool* isHovered) { + if (!label.empty()) + { ImGui::Text(label.c_str()); - if (isHovered) - *isHovered = ImGui::IsItemHovered(); ImGui::SameLine(); - return ImGui::SliderFloat("##", &value, - static_cast(min), static_cast(max), "%.3f", - ImGuiInputTextFlags_EnterReturnsTrue); + } + if (isHovered) + *isHovered = ImGui::IsItemHovered(); + ImGui::SameLine(); + return ImGui::SliderFloat("##", &value, + static_cast(min), static_cast(max), "%.3f", + ImGuiInputTextFlags_EnterReturnsTrue); } bool SHEditorUI::InputSlider(const std::string& label, double min, double max, double& value, bool* isHovered /*= nullptr*/) { - float val = static_cast(value); - const bool CHANGED = InputSlider(label, min, max, val, isHovered); - if (CHANGED) - { - value = static_cast(val); - } + float val = static_cast(value); + const bool CHANGED = InputSlider(label, min, max, val, isHovered); + if (CHANGED) + { + value = static_cast(val); + } - return CHANGED; + return CHANGED; } bool SHEditorUI::InputVec2(const std::string& label, SHVec2& value, bool* isHovered) @@ -264,7 +287,7 @@ namespace SHADE } bool SHEditorUI::InputVec3(const std::string& label, SHVec3& value, bool* isHovered) { - static const std::vector COMPONENT_LABELS = { "X", "Y", "Z"}; + static const std::vector COMPONENT_LABELS = { "X", "Y", "Z" }; return SHEditorWidgets::DragN(label, COMPONENT_LABELS, { &value.x, &value.y, &value.z }, 0.1f, "%.3f", float{}, float{}, 0, isHovered); } @@ -272,9 +295,13 @@ namespace SHADE { std::array buffer = { '\0' }; strcpy_s(buffer.data(), TEXT_FIELD_MAX_LENGTH, value.c_str()); - ImGui::Text(label.c_str()); + if (!label.empty()) + { + ImGui::Text(label.c_str()); + ImGui::SameLine(); + } if (isHovered) - *isHovered = ImGui::IsItemHovered(); + *isHovered = ImGui::IsItemHovered(); ImGui::SameLine(); const bool CHANGED = ImGui::InputText("##", &buffer[0], TEXT_FIELD_MAX_LENGTH); if (CHANGED) @@ -286,7 +313,11 @@ namespace SHADE bool SHEditorUI::InputGameObjectField(const std::string& label, uint32_t& value, bool* isHovered, bool alwaysNull) { - ImGui::Text(label.c_str()); + if (!label.empty()) + { + ImGui::Text(label.c_str()); + ImGui::SameLine(); + } if (isHovered) *isHovered = ImGui::IsItemHovered(); ImGui::SameLine(); @@ -326,9 +357,13 @@ namespace SHADE const std::string& INITIAL_NAME = v >= static_cast(enumNames.size()) ? "Unknown" : enumNames[v]; bool b = false; - ImGui::Text(label.c_str()); + if (!label.empty()) + { + ImGui::Text(label.c_str()); + ImGui::SameLine(); + } if (isHovered) - *isHovered = ImGui::IsItemHovered(); + *isHovered = ImGui::IsItemHovered(); ImGui::SameLine(); if (ImGui::BeginCombo("##", INITIAL_NAME.c_str(), ImGuiComboFlags_None)) { diff --git a/SHADE_Managed/src/Editor/Editor.cxx b/SHADE_Managed/src/Editor/Editor.cxx index 7b2e0982..beb667e3 100644 --- a/SHADE_Managed/src/Editor/Editor.cxx +++ b/SHADE_Managed/src/Editor/Editor.cxx @@ -117,6 +117,12 @@ namespace SHADE // Header SHEditorUI::PushID(index); + bool enabled = script->Enabled; + if (SHEditorUI::InputCheckbox("", enabled)) + { + script->Enabled = enabled; + } + SHEditorUI::SameLine(); if (SHEditorUI::CollapsingHeader(LABEL)) { SHEditorUI::PushID(LABEL); diff --git a/SHADE_Managed/src/Scripts/Script.cxx b/SHADE_Managed/src/Scripts/Script.cxx index a2af38a3..2ee7dbf7 100644 --- a/SHADE_Managed/src/Scripts/Script.cxx +++ b/SHADE_Managed/src/Scripts/Script.cxx @@ -22,6 +22,36 @@ of DigiPen Institute of Technology is prohibited. namespace SHADE { + /*---------------------------------------------------------------------------------*/ + /* Properties */ + /*---------------------------------------------------------------------------------*/ + GameObject Script::Owner::get() + { + return owner; + } + GameObject Script::GameObject::get() + { + return owner; + } + bool Script::Enabled::get() + { + return enabled; + } + void Script::Enabled::set(bool value) + { + // Same, don't set + if (value == enabled) + return; + + enabled = value; + + // There's a change, so call the appropriate function + if (enabled) + OnEnable(); + else + OnDisable(); + } + /*---------------------------------------------------------------------------------*/ /* Component Access Functions */ /*---------------------------------------------------------------------------------*/ @@ -104,11 +134,10 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* "All-time" Lifecycle Functions */ /*---------------------------------------------------------------------------------*/ - void Script::Initialize(GameObject newOwner) + void Script::Initialize(SHADE::GameObject newOwner) { owner = newOwner; } - void Script::OnAttached() { SAFE_NATIVE_CALL_BEGIN @@ -131,6 +160,12 @@ namespace SHADE awake(); SAFE_NATIVE_CALL_END(this) } + void Script::OnEnable() + { + SAFE_NATIVE_CALL_BEGIN + onEnable(); + SAFE_NATIVE_CALL_END(this) + } void Script::Start() { SAFE_NATIVE_CALL_BEGIN @@ -162,6 +197,12 @@ namespace SHADE onDrawGizmos(); SAFE_NATIVE_CALL_END(this) } + void Script::OnDisable() + { + SAFE_NATIVE_CALL_BEGIN + onDisable(); + SAFE_NATIVE_CALL_END(this) + } void Script::OnDestroy() { SAFE_NATIVE_CALL_BEGIN @@ -228,6 +269,7 @@ namespace SHADE /* Virtual Lifecycle Functions */ /*---------------------------------------------------------------------------------*/ void Script::awake() {} + void Script::onEnable() {} void Script::start() {} void Script::fixedUpdate() {} void Script::update() {} @@ -236,6 +278,7 @@ namespace SHADE { OnGizmosDrawOverriden = false; } + void Script::onDisable() {} void Script::onDestroy() {} /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Scripts/Script.hxx b/SHADE_Managed/src/Scripts/Script.hxx index 46736245..62c5015c 100644 --- a/SHADE_Managed/src/Scripts/Script.hxx +++ b/SHADE_Managed/src/Scripts/Script.hxx @@ -38,11 +38,28 @@ namespace SHADE /* Properties */ /*-----------------------------------------------------------------------------*/ /// + /// GameObject that this Script belongs to. This is a legacy interface, use + /// GameObject instead. + /// + [System::ObsoleteAttribute("Use GameObject instead.", false)] + property SHADE::GameObject Owner + { + SHADE::GameObject get(); + } + /// /// GameObject that this Script belongs to. /// - property GameObject Owner + property SHADE::GameObject GameObject { - GameObject get() { return owner; } + SHADE::GameObject get(); + } + /// + /// Whether or not this Script should have it's update functions be executed. + /// + property bool Enabled + { + bool get(); + void set(bool value); } /*-----------------------------------------------------------------------------*/ @@ -127,7 +144,7 @@ namespace SHADE /// /// /// Type of script to get. - /// This needs to be a default constructable Script. + /// This needs to be a default constructible Script. /// /// Reference to the script added generic where T : ref class, Script @@ -206,7 +223,7 @@ namespace SHADE /// /// Used to initialize a Script with a GameObject. /// - void Initialize(GameObject newOwner); + void Initialize(SHADE::GameObject newOwner); /// /// Used to call onAttached(). This is called immediately when this script is /// attached to a GameObject. @@ -232,6 +249,11 @@ namespace SHADE /// void Start(); /// + /// Used to call onEnable. This should be called right when a script is enabled + /// directly. + /// + void OnEnable(); + /// /// Used to call fixedUpdate(). This should be called in sync with Physics /// update steps and thus in most cases will execute more than Update() will. /// This will be called immediately before a Physics update step. @@ -253,6 +275,11 @@ namespace SHADE /// void OnDrawGizmos(); /// + /// Used to call onDisable. This should be called right when a script is disabled + /// directly. + /// + void OnDisable(); + /// /// Used to call onDestroy(). This should be called at the end of the frame /// where the attached GameObject or this script is destroyed directly or /// indirectly due to destruction of the owner. @@ -329,6 +356,10 @@ namespace SHADE /// virtual void awake(); /// + /// Called when this script is enabled. + /// + virtual void onEnable(); + /// /// Called on the first frame that the attached GameObject is active but always /// after Awake(). /// @@ -353,6 +384,10 @@ namespace SHADE /// virtual void onDrawGizmos(); /// + /// Called when this script is disabled. + /// + virtual void onDisable(); + /// /// Called just before the end of the frame where the attached GameObject or /// this script is destroyed directly or indirectly due to destruction of the /// owner. @@ -403,7 +438,8 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /* Data Members */ /*-----------------------------------------------------------------------------*/ - GameObject owner; + SHADE::GameObject owner; + bool enabled = true; }; } diff --git a/SHADE_Managed/src/Scripts/ScriptStore.cxx b/SHADE_Managed/src/Scripts/ScriptStore.cxx index 29ba6e52..96eb7361 100644 --- a/SHADE_Managed/src/Scripts/ScriptStore.cxx +++ b/SHADE_Managed/src/Scripts/ScriptStore.cxx @@ -528,7 +528,8 @@ namespace SHADE ScriptList^ scripts = entity.Value; for (int i = 0; i < scripts->Count; ++i) { - scripts[i]->FixedUpdate(); + if (scripts[i]->Enabled) + scripts[i]->FixedUpdate(); } } SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore") @@ -546,7 +547,8 @@ namespace SHADE ScriptList^ scripts = entity.Value; for (int i = 0; i < scripts->Count; ++i) { - scripts[i]->Update(); + if (scripts[i]->Enabled) + scripts[i]->Update(); } } SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore") @@ -564,7 +566,8 @@ namespace SHADE ScriptList^ scripts = entity.Value; for (int i = 0; i < scripts->Count; ++i) { - scripts[i]->LateUpdate(); + if (scripts[i]->Enabled) + scripts[i]->LateUpdate(); } } SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore") @@ -583,7 +586,8 @@ namespace SHADE ScriptList^ scripts = entity.Value; for (int i = 0; i < scripts->Count; ++i) { - scripts[i]->OnDrawGizmos(); + if (scripts[i]->Enabled) + scripts[i]->OnDrawGizmos(); } } SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore") From 1d692d330113a2d56d68d43071fc9f39039dd53b Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Mon, 21 Nov 2022 19:59:32 +0800 Subject: [PATCH 05/15] Physics works without SHEDITOR defines. Mass is temporarily auto computed. --- SHADE_Application/premake5.lua | 2 +- .../src/Application/SBApplication.cpp | 20 ++++- SHADE_Application/src/Scenes/SBMainScene.cpp | 10 +++ .../Inspector/SHEditorComponentView.hpp | 3 +- .../Physics/Interface/SHColliderComponent.cpp | 8 ++ .../Interface/SHRigidBodyComponent.cpp | 39 +++++---- .../Physics/Interface/SHRigidBodyComponent.h | 2 +- .../Physics/PhysicsObject/SHPhysicsObject.cpp | 27 +++++-- .../Physics/PhysicsObject/SHPhysicsObject.h | 12 +-- .../System/SHPhysicsDebugDrawSystem.cpp | 56 ++++++++++--- .../Physics/System/SHPhysicsDebugDrawSystem.h | 14 ++-- .../src/Physics/System/SHPhysicsSystem.cpp | 79 ++++++++++++++++--- .../src/Physics/System/SHPhysicsSystem.h | 20 ++--- .../{SHSceneGraphEvents.h => SHSceneEvents.h} | 18 ++--- SHADE_Engine/src/Scene/SHSceneGraph.h | 2 +- SHADE_Engine/src/Scene/SHSceneManager.cpp | 1 - SHADE_Engine/src/Scripting/SHScriptEngine.cpp | 2 +- .../src/Serialization/SHYAMLConverters.h | 4 + SHADE_Managed/src/Components/RigidBody.cxx | 2 +- 19 files changed, 237 insertions(+), 84 deletions(-) rename SHADE_Engine/src/Scene/{SHSceneGraphEvents.h => SHSceneEvents.h} (72%) diff --git a/SHADE_Application/premake5.lua b/SHADE_Application/premake5.lua index faa741a6..c2312805 100644 --- a/SHADE_Application/premake5.lua +++ b/SHADE_Application/premake5.lua @@ -87,7 +87,7 @@ project "SHADE_Application" filter "configurations:Debug" symbols "On" - defines {"_DEBUG", "SHEDITOR"} + defines {"_DEBUG"} filter "configurations:Release" optimize "On" diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index e80b247b..a0375811 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -84,6 +84,7 @@ namespace Sandbox SHSystemManager::CreateSystem(); SHGraphicsSystem* graphicsSystem = static_cast(SHSystemManager::GetSystem()); + SHPhysicsSystem* physicsSystem = SHSystemManager::GetSystem(); // Link up SHDebugDraw SHSystemManager::CreateSystem(); @@ -175,11 +176,15 @@ namespace Sandbox #ifdef SHEDITOR if(editor->editorState == SHEditor::State::PLAY) - SHSceneManager::SceneUpdate(0.016f); - SHSystemManager::RunRoutines(editor->editorState != SHEditor::State::PLAY, 0.016f); - editor->PollPicking(); -#endif +#endif + SHSceneManager::SceneUpdate(0.016f); +#ifdef SHEDITOR + SHSystemManager::RunRoutines(editor->editorState != SHEditor::State::PLAY, SHFrameRateController::GetRawDeltaTime()); + editor->PollPicking(); +#else + SHSystemManager::RunRoutines(false, SHFrameRateController::GetRawDeltaTime()); +#endif // TODO: Move into an Editor menu static bool drawColliders = false; if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::F10)) @@ -193,6 +198,13 @@ namespace Sandbox drawRays = !drawRays; SHSystemManager::GetSystem()->SetDebugDrawFlag(SHPhysicsDebugDrawSystem::DebugDrawFlags::RAYCASTS, drawRays); } + static bool drawContacts = false; + if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::F9)) + { + drawContacts = !drawContacts; + SHSystemManager::GetSystem()->SetDebugDrawFlag(SHPhysicsDebugDrawSystem::DebugDrawFlags::CONTACT_POINTS, drawContacts); + SHSystemManager::GetSystem()->SetDebugDrawFlag(SHPhysicsDebugDrawSystem::DebugDrawFlags::CONTACT_NORMALS, drawContacts); + } } // Finish all graphics jobs first graphicsSystem->AwaitGraphicsExecution(); diff --git a/SHADE_Application/src/Scenes/SBMainScene.cpp b/SHADE_Application/src/Scenes/SBMainScene.cpp index 9da68729..929d28fa 100644 --- a/SHADE_Application/src/Scenes/SBMainScene.cpp +++ b/SHADE_Application/src/Scenes/SBMainScene.cpp @@ -7,6 +7,7 @@ #include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Scene/SHSceneManager.h" #include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h" +#include "Physics/System/SHPhysicsSystem.h" #include "Scripting/SHScriptEngine.h" #include "Math/Transform/SHTransformComponent.h" #include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h" @@ -43,6 +44,15 @@ namespace Sandbox { sceneName = SHSerialization::DeserializeSceneFromFile(sceneAssetID); + auto* physicsSystem = SHSystemManager::GetSystem(); + if (!physicsSystem) + { + SHLOGV_CRITICAL("Failed to get the physics system for building the scene!") + return; + } + + physicsSystem->BuildScene(SHSceneManager::GetCurrentSceneGraph()); + /*-----------------------------------------------------------------------*/ /* TESTING CODE */ /*-----------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index ab844b88..fd36c102 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -252,7 +252,7 @@ namespace SHADE if(rbType == SHRigidBodyComponent::Type::DYNAMIC) //Dynamic only fields { SHEditorWidgets::CheckBox("Use Gravity", [component]{return component->IsGravityEnabled();}, [component](bool const& value){component->SetGravityEnabled(value);}, "Gravity"); - SHEditorWidgets::DragFloat("Mass", [component] {return component->GetMass(); }, [component](float const& value) {component->SetMass(value); }, "Mass"); + //SHEditorWidgets::DragFloat("Mass", [component] {return component->GetMass(); }, [component](float const& value) {component->SetMass(value); }, "Mass"); } if (rbType == SHRigidBodyComponent::Type::DYNAMIC || rbType == SHRigidBodyComponent::Type::KINEMATIC) //Dynamic or Kinematic only fields { @@ -284,6 +284,7 @@ namespace SHADE //Debug Info (Read-Only) if(ImGui::CollapsingHeader("Debug Information", ImGuiTreeNodeFlags_DefaultOpen))//Dynamic or Kinematic only fields { + SHEditorWidgets::DragFloat("Mass", [component] { return component->GetMass(); }, [](float value){}, "Mass", 0.1f, 0.0f, std::numeric_limits::infinity(), "%.3f", ImGuiSliderFlags_ReadOnly); SHEditorWidgets::DragVec3("Position", { "X", "Y", "Z" }, [component] {return component->GetPosition(); }, [](SHVec3 const& value) {}, false, "Position", 0.1f, "%.3f", 0.0f, 0.0f, ImGuiSliderFlags_ReadOnly); SHEditorWidgets::DragVec3("Rotation", { "X", "Y", "Z" }, [component] {return component->GetRotation(); }, [](SHVec3 const& value) {}, false, "Rotation", 0.1f, "%.3f", 0.0f, 0.0f, ImGuiSliderFlags_ReadOnly); if (rbType == SHRigidBodyComponent::Type::DYNAMIC || rbType == SHRigidBodyComponent::Type::KINEMATIC) //Dynamic or Kinematic only fields diff --git a/SHADE_Engine/src/Physics/Interface/SHColliderComponent.cpp b/SHADE_Engine/src/Physics/Interface/SHColliderComponent.cpp index 877d238f..135e7e42 100644 --- a/SHADE_Engine/src/Physics/Interface/SHColliderComponent.cpp +++ b/SHADE_Engine/src/Physics/Interface/SHColliderComponent.cpp @@ -80,6 +80,14 @@ namespace SHADE } system = physicsSystem; + + // Sync with transform if one already exists + if (auto* transformComponent = SHComponentManager::GetComponent_s(GetEID()); transformComponent) + { + position = transformComponent->GetWorldPosition(); + orientation = transformComponent->GetWorldOrientation(); + scale = transformComponent->GetWorldScale(); + } } void SHColliderComponent::OnDestroy() diff --git a/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.cpp b/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.cpp index 28b6f842..4fddc892 100644 --- a/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.cpp +++ b/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.cpp @@ -322,25 +322,25 @@ namespace SHADE // dirtyFlags |= 1U << FLAG_POS; //} - void SHRigidBodyComponent::SetMass(float newMass) noexcept - { - static constexpr int FLAG_POS = 9; + //void SHRigidBodyComponent::SetMass(float newMass) noexcept + //{ + // static constexpr int FLAG_POS = 9; - if (newMass < 0.0f) - return; + // if (newMass < 0.0f) + // return; - if (type != Type::DYNAMIC) - { - SHLOG_WARNING("Cannot set mass of a non-dynamic object {}", GetEID()) - return; - } + // if (type != Type::DYNAMIC) + // { + // SHLOG_WARNING("Cannot set mass of a non-dynamic object {}", GetEID()) + // return; + // } - dirtyFlags |= 1U << FLAG_POS; - mass = newMass; + // dirtyFlags |= 1U << FLAG_POS; + // mass = newMass; - // Turn off automass - flags &= ~(1U << FLAG_POS); - } + // // Turn off automass + // flags &= ~(1U << FLAG_POS); + //} void SHRigidBodyComponent::SetDrag(float newDrag) noexcept { @@ -411,6 +411,13 @@ namespace SHADE } system = physicsSystem; + + // Sync with transform if one already exists + if (auto* transformComponent = SHComponentManager::GetComponent_s(GetEID()); transformComponent) + { + position = transformComponent->GetWorldPosition(); + orientation = transformComponent->GetWorldOrientation(); + } } void SHRigidBodyComponent::AddForce(const SHVec3& force) const noexcept @@ -489,7 +496,7 @@ RTTR_REGISTRATION registration::class_("RigidBody Component") .property("Type" , &SHRigidBodyComponent::GetType , &SHRigidBodyComponent::SetType ) - .property("Mass" , &SHRigidBodyComponent::GetMass , &SHRigidBodyComponent::SetMass ) + //.property("Mass" , &SHRigidBodyComponent::GetMass , &SHRigidBodyComponent::SetMass ) .property("Drag" , &SHRigidBodyComponent::GetDrag , &SHRigidBodyComponent::SetDrag ) .property("Angular Drag" , &SHRigidBodyComponent::GetAngularDrag , &SHRigidBodyComponent::SetAngularDrag ) .property("Use Gravity" , &SHRigidBodyComponent::IsGravityEnabled , &SHRigidBodyComponent::SetGravityEnabled ) diff --git a/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.h b/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.h index d5204d94..532b3312 100644 --- a/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.h +++ b/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.h @@ -114,7 +114,7 @@ namespace SHADE void SetInterpolate (bool allowInterpolation) noexcept; //void SetAutoMass (bool autoMass) noexcept; - void SetMass (float newMass) noexcept; + //void SetMass (float newMass) noexcept; void SetDrag (float newDrag) noexcept; void SetAngularDrag (float newAngularDrag) noexcept; diff --git a/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.cpp b/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.cpp index 8de928f0..00f280e9 100644 --- a/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.cpp +++ b/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.cpp @@ -94,7 +94,7 @@ namespace SHADE /* Public Function Member Definitions */ /*-----------------------------------------------------------------------------------*/ - int SHPhysicsObject::AddCollisionShape(int index) const + int SHPhysicsObject::AddCollisionShape(int index) { // Get collider component auto* colliderComponent = SHComponentManager::GetComponent_s(entityID); @@ -123,13 +123,19 @@ namespace SHADE default: break; } - rp3dBody->updateLocalCenterOfMassFromColliders(); - rp3dBody->updateLocalInertiaTensorFromColliders(); + if (rp3dBody->getType() == rp3d::BodyType::DYNAMIC) + { + rp3dBody->updateMassPropertiesFromColliders(); + + auto* rigidBodyComponent = SHComponentManager::GetComponent_s(entityID); + if (rigidBodyComponent) + rigidBodyComponent->mass = rp3dBody->getMass(); + } return index; } - void SHPhysicsObject::RemoveCollisionShape(int index) const + void SHPhysicsObject::RemoveCollisionShape(int index) { const int NUM_COLLIDERS = static_cast(rp3dBody->getNbColliders()); if (NUM_COLLIDERS == 0) @@ -140,6 +146,15 @@ namespace SHADE auto* collider = rp3dBody->getCollider(index); rp3dBody->removeCollider(collider); + + if (rp3dBody->getType() == rp3d::BodyType::DYNAMIC) + { + rp3dBody->updateMassPropertiesFromColliders(); + + auto* rigidBodyComponent = SHComponentManager::GetComponent_s(entityID); + if (rigidBodyComponent) + rigidBodyComponent->mass = rp3dBody->getMass(); + } } void SHPhysicsObject::RemoveAllCollisionShapes() const noexcept @@ -254,9 +269,7 @@ namespace SHADE } case 9: // Mass { - rp3dBody->setMass(component.mass); - rp3dBody->updateLocalCenterOfMassFromColliders(); - rp3dBody->updateLocalInertiaTensorFromColliders(); + //rp3dBody->setMass(component.mass); //if (component.GetAutoMass()) //{ diff --git a/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.h b/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.h index fefc983f..818e5471 100644 --- a/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.h +++ b/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.h @@ -71,8 +71,8 @@ namespace SHADE /* Function Members */ /*---------------------------------------------------------------------------------*/ - int AddCollisionShape (int index) const; - void RemoveCollisionShape (int index) const; + int AddCollisionShape (int index); + void RemoveCollisionShape (int index); void RemoveAllCollisionShapes () const noexcept; void SyncRigidBody (SHRigidBodyComponent& component) const noexcept; @@ -98,12 +98,12 @@ namespace SHADE // Box Shapes - void addBoxShape (SHCollisionShape& boxShape) const noexcept; - void syncBoxShape (int index, SHCollisionShape& boxShape) const noexcept; + void addBoxShape (SHCollisionShape& boxShape) const noexcept; + void syncBoxShape (int index, SHCollisionShape& boxShape) const noexcept; // Sphere Shapes - void addSphereShape (SHCollisionShape& sphereShape) const noexcept; - void syncSphereShape (int index, SHCollisionShape& sphereShape) const noexcept; + void addSphereShape (SHCollisionShape& sphereShape) const noexcept; + void syncSphereShape (int index, SHCollisionShape& sphereShape) const noexcept; }; } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsDebugDrawSystem.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsDebugDrawSystem.cpp index bf1debac..3c80883c 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsDebugDrawSystem.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsDebugDrawSystem.cpp @@ -15,6 +15,7 @@ // Project Headers #include "ECS_Base/Managers/SHSystemManager.h" +#include "Editor/SHEditor.h" #include "Scene/SHSceneManager.h" namespace SHADE @@ -118,11 +119,22 @@ namespace SHADE return; } + rp3d::DebugRenderer* rp3dRenderer = nullptr; + #ifdef SHEDITOR + const auto* EDITOR = SHSystemManager::GetSystem(); + if (EDITOR && EDITOR->editorState != SHEditor::State::STOP) + { + rp3dRenderer = &system->physicsSystem->worldState.world->getDebugRenderer(); + rp3dRenderer->setIsDebugItemDisplayed(rp3d::DebugRenderer::DebugItem::CONTACT_POINT, false); + rp3dRenderer->setIsDebugItemDisplayed(rp3d::DebugRenderer::DebugItem::CONTACT_NORMAL, false); + } + #endif + for (int i = 0; i < SHUtilities::ConvertEnum(DebugDrawFlags::NUM_FLAGS); ++i) { const bool DRAW = (system->debugDrawFlags & (1U << i)) > 0; if (DRAW) - drawFunctions[i](debugDrawSystem); + drawFunctions[i](debugDrawSystem, rp3dRenderer); } // Automatically clear the container of raycasts despite debug drawing state @@ -134,7 +146,7 @@ namespace SHADE /* Private Function Member Definitions */ /*-----------------------------------------------------------------------------------*/ - void SHPhysicsDebugDrawSystem::drawColliders(SHDebugDrawSystem* debugRenderer) noexcept + void SHPhysicsDebugDrawSystem::drawColliders(SHDebugDrawSystem* debugRenderer, rp3d::DebugRenderer* rp3dRenderer) noexcept { const auto& COLLIDER_SET = SHComponentManager::GetDense(); for (const auto& COLLIDER : COLLIDER_SET) @@ -155,27 +167,53 @@ namespace SHADE } } - void SHPhysicsDebugDrawSystem::drawColliderAABBs(SHDebugDrawSystem* debugRenderer) noexcept + void SHPhysicsDebugDrawSystem::drawColliderAABBs(SHDebugDrawSystem* debugRenderer, rp3d::DebugRenderer* rp3dRenderer) noexcept { } - void SHPhysicsDebugDrawSystem::drawBroadPhaseAABBs(SHDebugDrawSystem* debugRenderer) noexcept + void SHPhysicsDebugDrawSystem::drawBroadPhaseAABBs(SHDebugDrawSystem* debugRenderer, rp3d::DebugRenderer* rp3dRenderer) noexcept { } - void SHPhysicsDebugDrawSystem::drawContactPoints(SHDebugDrawSystem* debugRenderer) noexcept + void SHPhysicsDebugDrawSystem::drawContactPoints(SHDebugDrawSystem* debugRenderer, rp3d::DebugRenderer* rp3dRenderer) noexcept { - + #ifdef SHEDITOR + const auto* EDITOR = SHSystemManager::GetSystem(); + if (EDITOR && EDITOR->editorState != SHEditor::State::STOP) + { + rp3dRenderer->setIsDebugItemDisplayed(rp3d::DebugRenderer::DebugItem::CONTACT_POINT, true); + const int NUM_TRIS = static_cast(rp3dRenderer->getNbTriangles()); + if (NUM_TRIS == 0) + return; + + const auto& TRI_ARRAY = rp3dRenderer->getTrianglesArray(); + for (int i = 0; i < NUM_TRIS; ++i) + debugRenderer->DrawTri(SHColour::RED, TRI_ARRAY[i].point1, TRI_ARRAY[i].point2, TRI_ARRAY[i].point3); + } + #endif } - void SHPhysicsDebugDrawSystem::drawContactNormals(SHDebugDrawSystem* debugRenderer) noexcept + void SHPhysicsDebugDrawSystem::drawContactNormals(SHDebugDrawSystem* debugRenderer, rp3d::DebugRenderer* rp3dRenderer) noexcept { - + #ifdef SHEDITOR + const auto* EDITOR = SHSystemManager::GetSystem(); + if (EDITOR && EDITOR->editorState != SHEditor::State::STOP) + { + rp3dRenderer->setIsDebugItemDisplayed(rp3d::DebugRenderer::DebugItem::CONTACT_NORMAL, true); + const int NUM_LINES = static_cast(rp3dRenderer->getNbLines()); + if (NUM_LINES == 0) + return; + + const auto& LINE_ARRAY = rp3dRenderer->getLinesArray(); + for (int i = 0; i < NUM_LINES; ++i) + debugRenderer->DrawLine(SHColour::RED, LINE_ARRAY[i].point1, LINE_ARRAY[i].point2); + } + #endif } - void SHPhysicsDebugDrawSystem::drawRaycasts(SHDebugDrawSystem* debugRenderer) noexcept + void SHPhysicsDebugDrawSystem::drawRaycasts(SHDebugDrawSystem* debugRenderer, rp3d::DebugRenderer* rp3dRenderer) noexcept { auto* physicsSystem = SHSystemManager::GetSystem(); if (!physicsSystem) diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsDebugDrawSystem.h b/SHADE_Engine/src/Physics/System/SHPhysicsDebugDrawSystem.h index 867a6e11..dc703092 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsDebugDrawSystem.h +++ b/SHADE_Engine/src/Physics/System/SHPhysicsDebugDrawSystem.h @@ -93,7 +93,7 @@ namespace SHADE /* Type Definitions */ /*---------------------------------------------------------------------------------*/ - using DebugDrawFunction = void(*)(SHDebugDrawSystem*) noexcept; + using DebugDrawFunction = void(*)(SHDebugDrawSystem*, rp3d::DebugRenderer*) noexcept; /*---------------------------------------------------------------------------------*/ /* Data Members */ @@ -118,12 +118,12 @@ namespace SHADE // Generic Draw Functions - static void drawColliders (SHDebugDrawSystem* debugRenderer) noexcept; - static void drawColliderAABBs (SHDebugDrawSystem* debugRenderer) noexcept; - static void drawBroadPhaseAABBs (SHDebugDrawSystem* debugRenderer) noexcept; - static void drawContactPoints (SHDebugDrawSystem* debugRenderer) noexcept; - static void drawContactNormals (SHDebugDrawSystem* debugRenderer) noexcept; - static void drawRaycasts (SHDebugDrawSystem* debugRenderer) noexcept; + static void drawColliders (SHDebugDrawSystem* debugRenderer, rp3d::DebugRenderer* rp3dRenderer) noexcept; + static void drawColliderAABBs (SHDebugDrawSystem* debugRenderer, rp3d::DebugRenderer* rp3dRenderer) noexcept; + static void drawBroadPhaseAABBs (SHDebugDrawSystem* debugRenderer, rp3d::DebugRenderer* rp3dRenderer) noexcept; + static void drawContactPoints (SHDebugDrawSystem* debugRenderer, rp3d::DebugRenderer* rp3dRenderer) noexcept; + static void drawContactNormals (SHDebugDrawSystem* debugRenderer, rp3d::DebugRenderer* rp3dRenderer) noexcept; + static void drawRaycasts (SHDebugDrawSystem* debugRenderer, rp3d::DebugRenderer* rp3dRenderer) noexcept; // Shape Generation Functions diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp index 396edd93..89be2614 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp @@ -97,6 +97,13 @@ namespace SHADE defaultCollisionTagNameFilePath.append("CollisionTags.SHConfig"); SHCollisionTagMatrix::Init(defaultCollisionTagNameFilePath); + // Link Physics Object Manager with System & Raycaster + objectManager.SetFactory(factory); + raycaster.SetObjectManager(&objectManager); + + // Link Collision Listener with System + collisionListener.BindToSystem(this); + // Subscribe to component events const std::shared_ptr ADD_COMPONENT_RECEIVER { std::make_shared>(this, &SHPhysicsSystem::addPhysicsComponent) }; const ReceiverPtr ADD_COMPONENT_RECEIVER_PTR = std::dynamic_pointer_cast(ADD_COMPONENT_RECEIVER); @@ -118,12 +125,7 @@ namespace SHADE SHEventManager::SubscribeTo(SH_EDITOR_ON_STOP_EVENT, ON_STOP_RECEIVER_PTR); #endif - // Link Physics Object Manager with System & Raycaster - objectManager.SetFactory(factory); - raycaster.SetObjectManager(&objectManager); - - // Link Collision Listener with System - collisionListener.BindToSystem(this); + } void SHPhysicsSystem::Exit() @@ -136,6 +138,55 @@ namespace SHADE SHCollisionTagMatrix::Exit(defaultCollisionTagNameFilePath); } + void SHPhysicsSystem::BuildScene(SHSceneGraph& sceneGraph) + { + static const auto BUILD_NEW_SCENE_PHYSICS_OBJECT = [&](SHSceneNode* node) + { + const EntityID EID = node->GetEntityID(); + + if (SHComponentManager::HasComponent(EID)) + objectManager.AddRigidBody(EID); + + if (SHComponentManager::HasComponent(EID)) + objectManager.AddCollider(EID); + }; + + //////////////////////////////// + + // Destroy an existing world + if (worldState.world != nullptr) + { + objectManager.RemoveAllObjects(); + objectManager.SetWorld(nullptr); + + collisionListener.ClearContainers(); + raycaster.ClearFrame(); + + worldState.DestroyWorld(factory); + } + + worldState.CreateWorld(factory); + #ifdef _PUBLISH + worldState.world->setIsDebugRenderingEnabled(false); + #else + worldState.world->setIsDebugRenderingEnabled(true); + #endif + + // Link Collision Listener & Raycaster + collisionListener.BindToWorld(worldState.world); + raycaster.BindToWorld(worldState.world); + + // Link with object manager & create all physics objects + objectManager.SetWorld(worldState.world); + + // When building a scene, clear the object manager command queue and build scene objects again. + // This is done to avoid duplicate adds. + while (!objectManager.commandQueue.empty()) + objectManager.commandQueue.pop(); + + sceneGraph.Traverse(BUILD_NEW_SCENE_PHYSICS_OBJECT); + } + void SHPhysicsSystem::ForceUpdate() { if (!worldState.world) @@ -228,10 +279,13 @@ namespace SHADE { objectManager.AddCollisionShape(entityID, index); + auto* colliderComponent = SHComponentManager::GetComponent(entityID); + auto& collisionShape = colliderComponent->GetCollisionShape(index); + const SHPhysicsColliderAddedEvent COLLIDER_ADDED_EVENT_DATA { .entityID = entityID - , .colliderType = SHComponentManager::GetComponent(entityID)->GetCollisionShape(index).GetType() + , .colliderType = collisionShape.GetType() , .colliderIndex = index }; @@ -367,6 +421,11 @@ namespace SHADE return onPlayEvent->handle; worldState.CreateWorld(factory); + #ifdef _PUBLISH + worldState.world->setIsDebugRenderingEnabled(false); + #else + worldState.world->setIsDebugRenderingEnabled(true); + #endif // Link Collision Listener & Raycaster collisionListener.BindToWorld(worldState.world); @@ -375,8 +434,8 @@ namespace SHADE // Link with object manager & create all physics objects objectManager.SetWorld(worldState.world); - const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); - SCENE_GRAPH.Traverse(BUILD_PHYSICS_OBJECT); + // Build scene + SHSceneManager::GetCurrentSceneGraph().Traverse(BUILD_PHYSICS_OBJECT); return onPlayEvent->handle; } @@ -390,11 +449,11 @@ namespace SHADE // Clear all collision info // Collision listener is automatically unbound when world is destroyed collisionListener.ClearContainers(); + raycaster.ClearFrame(); // Destroy the world worldState.DestroyWorld(factory); return onStopEvent->handle; } - } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h index f92be4cd..f7340d31 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h @@ -27,7 +27,7 @@ #include "Physics/Interface/SHColliderComponent.h" #include "Physics/PhysicsObject/SHPhysicsObjectManager.h" #include "Physics/SHPhysicsWorld.h" - +#include "Scene/SHSceneGraph.h" namespace SHADE { @@ -74,10 +74,12 @@ namespace SHADE /* Function Members */ /*---------------------------------------------------------------------------------*/ - void Init () override; - void Exit () override; + void Init () override; + void Exit () override; + + void BuildScene (SHSceneGraph& sceneGraph); + void ForceUpdate (); - void ForceUpdate (); /** * @brief Casts a ray into the world. @@ -280,11 +282,11 @@ namespace SHADE /* Function Members */ /*---------------------------------------------------------------------------------*/ - SHEventHandle addPhysicsComponent (SHEventPtr addComponentEvent) noexcept; - SHEventHandle removePhysicsComponent (SHEventPtr removeComponentEvent) noexcept; - - SHEventHandle onPlay (SHEventPtr onPlayEvent); - SHEventHandle onStop (SHEventPtr onStopEvent); + SHEventHandle addPhysicsComponent (SHEventPtr addComponentEvent) noexcept; + SHEventHandle removePhysicsComponent (SHEventPtr removeComponentEvent) noexcept; + SHEventHandle onPlay (SHEventPtr onPlayEvent); + SHEventHandle onStop (SHEventPtr onStopEvent); + SHEventHandle buildScene (SHEventPtr onSceneChangeEvent); }; } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Scene/SHSceneGraphEvents.h b/SHADE_Engine/src/Scene/SHSceneEvents.h similarity index 72% rename from SHADE_Engine/src/Scene/SHSceneGraphEvents.h rename to SHADE_Engine/src/Scene/SHSceneEvents.h index ccdf06be..c0d7dbc1 100644 --- a/SHADE_Engine/src/Scene/SHSceneGraphEvents.h +++ b/SHADE_Engine/src/Scene/SHSceneEvents.h @@ -1,7 +1,7 @@ /**************************************************************************************** - * \file SHSceneGraphEvents.h + * \file SHSceneEvents.h * \author Diren D Bharwani, diren.dbharwani, 390002520 - * \brief Interface for Scene Graph Events. + * \brief Interface for Scene Events. * * \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or * disclosure of this file or its contents without the prior written consent @@ -21,21 +21,21 @@ namespace SHADE struct SHSceneGraphChangeParentEvent { - SHSceneNode* node; - SHSceneNode* oldParent; - SHSceneNode* newParent; + SHSceneNode* node = nullptr; + SHSceneNode* oldParent = nullptr; + SHSceneNode* newParent = nullptr; }; struct SHSceneGraphAddChildEvent { - SHSceneNode* parent; - SHSceneNode* childAdded; + SHSceneNode* parent = nullptr; + SHSceneNode* childAdded = nullptr; }; struct SHSceneGraphRemoveChildEvent { - SHSceneNode* parent; - SHSceneNode* childRemoved; + SHSceneNode* parent = nullptr; + SHSceneNode* childRemoved = nullptr; }; } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Scene/SHSceneGraph.h b/SHADE_Engine/src/Scene/SHSceneGraph.h index 5747be7b..37d0e063 100644 --- a/SHADE_Engine/src/Scene/SHSceneGraph.h +++ b/SHADE_Engine/src/Scene/SHSceneGraph.h @@ -16,7 +16,7 @@ #include "ECS_Base/Entity/SHEntity.h" #include "SH_API.h" #include "SHSceneNode.h" -#include "SHSceneGraphEvents.h" +#include "SHSceneEvents.h" namespace SHADE { diff --git a/SHADE_Engine/src/Scene/SHSceneManager.cpp b/SHADE_Engine/src/Scene/SHSceneManager.cpp index be9c7755..110aaea6 100644 --- a/SHADE_Engine/src/Scene/SHSceneManager.cpp +++ b/SHADE_Engine/src/Scene/SHSceneManager.cpp @@ -85,7 +85,6 @@ namespace SHADE currentScene->Load(); currentScene->Init(); } - } else // restarting scene { diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index 84b50373..90121994 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -27,7 +27,7 @@ of DigiPen Institute of Technology is prohibited. #include "Events/SHEventManager.hpp" #include "Physics/System/SHPhysicsSystem.h" #include "Physics/SHPhysicsEvents.h" -#include "Scene/SHSceneGraphEvents.h" +#include "Scene/SHSceneEvents.h" #include "Assets/SHAssetMacros.h" diff --git a/SHADE_Engine/src/Serialization/SHYAMLConverters.h b/SHADE_Engine/src/Serialization/SHYAMLConverters.h index d66a7506..4fe28153 100644 --- a/SHADE_Engine/src/Serialization/SHYAMLConverters.h +++ b/SHADE_Engine/src/Serialization/SHYAMLConverters.h @@ -113,6 +113,7 @@ namespace YAML static constexpr const char* Bounciness = "Bounciness"; static constexpr const char* Density = "Density"; static constexpr const char* PositionOffset = "Position Offset"; + static constexpr const char* RotationOffset = "Rotation Offset"; static Node encode(SHCollisionShape& rhs) { @@ -148,6 +149,7 @@ namespace YAML node[Bounciness] = rhs.GetBounciness(); node[Density] = rhs.GetDensity(); node[PositionOffset] = rhs.GetPositionOffset(); + node[RotationOffset] = rhs.GetRotationOffset(); return node; } @@ -188,6 +190,8 @@ namespace YAML rhs.SetDensity(node[Density].as()); if (node[PositionOffset].IsDefined()) rhs.SetPositionOffset(node[PositionOffset].as()); + if (node[RotationOffset].IsDefined()) + rhs.SetRotationOffset(node[RotationOffset].as()); return true; } diff --git a/SHADE_Managed/src/Components/RigidBody.cxx b/SHADE_Managed/src/Components/RigidBody.cxx index cdaa296a..a564402f 100644 --- a/SHADE_Managed/src/Components/RigidBody.cxx +++ b/SHADE_Managed/src/Components/RigidBody.cxx @@ -58,7 +58,7 @@ namespace SHADE } void RigidBody::Mass::set(float value) { - return GetNativeComponent()->SetMass(value); + /*return GetNativeComponent()->SetMass(value);*/ } float RigidBody::Drag::get() { From 9cc008eaf4e1231cb3f6e0147a1ca4b7dc1479dd Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Mon, 21 Nov 2022 20:21:08 +0800 Subject: [PATCH 06/15] Fixed ghosts of a renderable being rendered when a material is changed --- SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp index 91728d71..ec19691f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp @@ -55,7 +55,7 @@ namespace SHADE void SHSuperBatch::Remove(const SHRenderable* renderable) noexcept { - Handle baseMat = renderable->GetMaterial()->GetBaseMaterial(); + Handle baseMat = (renderable->HasMaterialChanged() ? renderable->GetPrevMaterial() : renderable->GetMaterial())->GetBaseMaterial(); const Handle PIPELINE = baseMat->HasPipelineChanged() ? baseMat->GetPrevPipeline() : baseMat->GetPipeline(); // Check if we have a Batch with the same pipeline yet From 1ed0181c9e2019e12871077436b53224cbca1074 Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Mon, 21 Nov 2022 20:27:38 +0800 Subject: [PATCH 07/15] Reverted premake changes --- SHADE_Application/premake5.lua | 7 +++++-- SHADE_Engine/premake5.lua | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/SHADE_Application/premake5.lua b/SHADE_Application/premake5.lua index c2312805..014df726 100644 --- a/SHADE_Application/premake5.lua +++ b/SHADE_Application/premake5.lua @@ -78,7 +78,10 @@ project "SHADE_Application" "26451", "26437", "4275", - "4635" + "4633", + "4634", + "4635", + "4638" } linkoptions { "-IGNORE:4006" } @@ -87,7 +90,7 @@ project "SHADE_Application" filter "configurations:Debug" symbols "On" - defines {"_DEBUG"} + defines {"_DEBUG", "SHEDITOR"} filter "configurations:Release" optimize "On" diff --git a/SHADE_Engine/premake5.lua b/SHADE_Engine/premake5.lua index 88df50d7..7fb7291d 100644 --- a/SHADE_Engine/premake5.lua +++ b/SHADE_Engine/premake5.lua @@ -79,7 +79,10 @@ project "SHADE_Engine" "26451", "26437", "4275", - "4635" + "4633", + "4634", + "4635", + "4638" } linkoptions { "-IGNORE:4006" } From 4172362790652a92426bc728af11efacc9bbafe9 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Mon, 21 Nov 2022 20:35:31 +0800 Subject: [PATCH 08/15] Renamed SHTextRenderer to SHTextRenderable --- SHADE_Application/src/Scenes/SBMainScene.cpp | 2 +- .../Inspector/SHEditorComponentView.hpp | 4 ++-- .../Inspector/SHEditorInspector.cpp | 6 +++--- ...nent.cpp => SHTextRenderableComponent.cpp} | 20 +++++++++---------- ...omponent.h => SHTextRenderableComponent.h} | 2 +- .../SHTextRenderingSubSystem.cpp | 20 +++++++++---------- .../TextRendering/SHTextRenderingSubSystem.h | 4 ++-- .../src/Serialization/SHSerialization.cpp | 6 +++--- .../src/Serialization/SHYAMLConverters.h | 8 ++++---- 9 files changed, 36 insertions(+), 36 deletions(-) rename SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/{SHTextRendererComponent.cpp => SHTextRenderableComponent.cpp} (66%) rename SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/{SHTextRendererComponent.h => SHTextRenderableComponent.h} (95%) diff --git a/SHADE_Application/src/Scenes/SBMainScene.cpp b/SHADE_Application/src/Scenes/SBMainScene.cpp index a0e80556..ddf0dd5f 100644 --- a/SHADE_Application/src/Scenes/SBMainScene.cpp +++ b/SHADE_Application/src/Scenes/SBMainScene.cpp @@ -13,7 +13,7 @@ #include "Physics/Interface/SHRigidBodyComponent.h" #include "Physics/Interface/SHColliderComponent.h" #include "Graphics/MiddleEnd/Lights/SHLightComponent.h" -#include "Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h" +#include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h" #include "Assets/SHAssetManager.h" #include "Camera/SHCameraComponent.h" diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 386f0988..4e659e85 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -497,11 +497,11 @@ namespace SHADE } template<> - static void DrawComponent(SHTextRendererComponent* component) + static void DrawComponent(SHTextRenderableComponent* component) { if (!component) return; - ImGui::PushID(SHFamilyID::GetID()); + ImGui::PushID(SHFamilyID::GetID()); const auto componentType = rttr::type::get(*component); SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; }, "Is Component Active"); ImGui::SameLine(); diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp index b08d27f6..c4287e6f 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp @@ -22,7 +22,7 @@ #include "UI/SHCanvasComponent.h" #include "SHEditorComponentView.h" #include "AudioSystem/SHAudioListenerComponent.h" -#include "Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h" +#include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h" namespace SHADE { @@ -145,7 +145,7 @@ namespace SHADE { DrawComponent(uiComponent); } - if (auto textRendererComponent = SHComponentManager::GetComponent_s(eid)) + if (auto textRendererComponent = SHComponentManager::GetComponent_s(eid)) { DrawComponent(textRendererComponent); } @@ -167,7 +167,7 @@ namespace SHADE DrawAddComponentWithEnforcedComponentButton(eid); DrawAddComponentWithEnforcedComponentButton(eid); DrawAddComponentWithEnforcedComponentButton(eid); - DrawAddComponentWithEnforcedComponentButton(eid); + DrawAddComponentWithEnforcedComponentButton(eid); ImGui::EndMenu(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.cpp similarity index 66% rename from SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.cpp rename to SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.cpp index 26fb97aa..b407b599 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.cpp @@ -1,15 +1,15 @@ #include "SHpch.h" -#include "SHTextRendererComponent.h" +#include "SHTextRenderableComponent.h" namespace SHADE { - void SHTextRendererComponent::MakeDirty(void) noexcept + void SHTextRenderableComponent::MakeDirty(void) noexcept { requiresRecompute = true; } - void SHTextRendererComponent::Clean(void) noexcept + void SHTextRenderableComponent::Clean(void) noexcept { requiresRecompute = false; } @@ -22,7 +22,7 @@ namespace SHADE */ /***************************************************************************/ - void SHTextRendererComponent::OnCreate(void) + void SHTextRenderableComponent::OnCreate(void) { text = "My name is Brandon."; requiresRecompute = true; @@ -31,7 +31,7 @@ namespace SHADE color = SHColour::WHITE; } - void SHTextRendererComponent::OnDestroy(void) + void SHTextRenderableComponent::OnDestroy(void) { } @@ -49,13 +49,13 @@ namespace SHADE */ /***************************************************************************/ - void SHTextRendererComponent::SetText(std::string_view newText) noexcept + void SHTextRenderableComponent::SetText(std::string_view newText) noexcept { text = newText; MakeDirty(); } - void SHTextRendererComponent::SetFont(Handle font) noexcept + void SHTextRenderableComponent::SetFont(Handle font) noexcept { fontHandle = font; MakeDirty(); @@ -72,12 +72,12 @@ namespace SHADE */ /***************************************************************************/ - std::string const& SHTextRendererComponent::GetText(void) const noexcept + std::string const& SHTextRenderableComponent::GetText(void) const noexcept { return text; } - Handle SHTextRendererComponent::GetFont(void) const noexcept + Handle SHTextRenderableComponent::GetFont(void) const noexcept { return fontHandle; } @@ -90,6 +90,6 @@ namespace rttr { using namespace SHADE; - registration::class_("Text Renderer Component"); + registration::class_("Text Renderer Component"); }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h similarity index 95% rename from SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h rename to SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h index 45738e93..ef907409 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h @@ -13,7 +13,7 @@ namespace SHADE class SHVkDescriptorSetGroup; class SHVkBuffer; - class SH_API SHTextRendererComponent final : public SHComponent + class SH_API SHTextRenderableComponent final : public SHComponent { public: static constexpr uint32_t MAX_CHARACTERS = 500; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp index 8fbdd33b..6748311e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp @@ -1,6 +1,6 @@ #include "SHpch.h" #include "SHTextRenderingSubSystem.h" -#include "Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h" +#include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h" #include "ECS_Base/Managers/SHComponentManager.h" #include "Math/Vector/SHVec4.h" #include "Graphics/Devices/SHVkLogicalDevice.h" @@ -14,20 +14,20 @@ namespace SHADE { - void SHTextRenderingSubSystem::RecomputePositions(SHTextRendererComponent& textComp) noexcept + void SHTextRenderingSubSystem::RecomputePositions(SHTextRenderableComponent& textComp) noexcept { if (textComp.text.empty() || !textComp.fontHandle) return; // Create the buffer if (!textComp.indexingDataBuffer) - textComp.indexingDataBuffer = logicalDevice->CreateBuffer(SHTextRendererComponent::MAX_CHARACTERS * sizeof(uint32_t), nullptr, SHTextRendererComponent::MAX_CHARACTERS * sizeof(uint32_t), vk::BufferUsageFlagBits::eVertexBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT); + textComp.indexingDataBuffer = logicalDevice->CreateBuffer(SHTextRenderableComponent::MAX_CHARACTERS * sizeof(uint32_t), nullptr, SHTextRenderableComponent::MAX_CHARACTERS * sizeof(uint32_t), vk::BufferUsageFlagBits::eVertexBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT); if (!textComp.charPositionDataBuffer) - textComp.charPositionDataBuffer = logicalDevice->CreateBuffer(SHTextRendererComponent::MAX_CHARACTERS * sizeof(SHVec4), nullptr, SHTextRendererComponent::MAX_CHARACTERS * sizeof(SHVec4), vk::BufferUsageFlagBits::eVertexBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT); + textComp.charPositionDataBuffer = logicalDevice->CreateBuffer(SHTextRenderableComponent::MAX_CHARACTERS * sizeof(SHVec4), nullptr, SHTextRenderableComponent::MAX_CHARACTERS * sizeof(SHVec4), vk::BufferUsageFlagBits::eVertexBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT); // For indexing font transformation in the shader - std::vector indexingData; + std::vector indexingData; // For placing glyphs correctly std::vector charPositionData; @@ -49,7 +49,7 @@ namespace SHADE // for every character for (uint32_t i = 0; i < numChars; ++i) { - SHTextRendererComponent::TextIndexingType index = glyphTransformIndices.at(textComp.text[i]); + SHTextRenderableComponent::TextIndexingType index = glyphTransformIndices.at(textComp.text[i]); // Copy baseline SHVec4 characterPos = baselineOrigin; @@ -83,7 +83,7 @@ namespace SHADE //} } - textComp.indexingDataBuffer->WriteToMemory(indexingData.data(), static_cast(indexingData.size()) * sizeof (SHTextRendererComponent::TextIndexingType),0, 0); + textComp.indexingDataBuffer->WriteToMemory(indexingData.data(), static_cast(indexingData.size()) * sizeof (SHTextRenderableComponent::TextIndexingType),0, 0); textComp.charPositionDataBuffer->WriteToMemory(charPositionData.data(), static_cast(charPositionData.size()) * sizeof (SHVec4), 0, 0); indexingData.clear(); @@ -93,7 +93,7 @@ namespace SHADE void SHTextRenderingSubSystem::Init(Handle device, Handle compatibleRenderpass, Handle subpass, Handle descPool, Handle textVS, Handle textFS, std::function, uint32_t)> const& bindFunction) noexcept { - SHComponentManager::CreateComponentSparseSet(); + SHComponentManager::CreateComponentSparseSet(); cameraDescSetBind = bindFunction; @@ -179,7 +179,7 @@ namespace SHADE void SHTextRenderingSubSystem::Run(uint32_t frameIndex) noexcept { - auto& textRendererComps = SHComponentManager::GetDense(); + auto& textRendererComps = SHComponentManager::GetDense(); for (auto& comp : textRendererComps) { @@ -194,7 +194,7 @@ namespace SHADE void SHTextRenderingSubSystem::Render(Handle cmdBuffer, uint32_t frameIndex) noexcept { - auto& textRendererComps = SHComponentManager::GetDense(); + auto& textRendererComps = SHComponentManager::GetDense(); for (auto& comp : textRendererComps) { auto* transform = SHComponentManager::GetComponent(comp.GetEID()); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h index d569ca91..05ab01da 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h @@ -14,7 +14,7 @@ namespace SHADE class SHVkBuffer; class SHLightComponent; class SHVkCommandBuffer; - class SHTextRendererComponent; + class SHTextRenderableComponent; class SHVkPipeline; class SHVkPipelineLayout; class SHVkRenderpass; @@ -48,7 +48,7 @@ namespace SHADE std::function, uint32_t)> cameraDescSetBind; private: - void RecomputePositions(SHTextRendererComponent& textComp) noexcept; + void RecomputePositions(SHTextRenderableComponent& textComp) noexcept; public: void Init(Handle device, Handle compatibleRenderpass, Handle subpass, Handle descPool, Handle textVS, Handle textFS, std::function, uint32_t)> const& bindFunction) noexcept; diff --git a/SHADE_Engine/src/Serialization/SHSerialization.cpp b/SHADE_Engine/src/Serialization/SHSerialization.cpp index 607b4666..be7c9cf0 100644 --- a/SHADE_Engine/src/Serialization/SHSerialization.cpp +++ b/SHADE_Engine/src/Serialization/SHSerialization.cpp @@ -211,7 +211,7 @@ namespace SHADE AddComponentToComponentNode(components, eid); AddComponentToComponentNode(components, eid); AddConvComponentToComponentNode(components, eid); - AddConvComponentToComponentNode(components, eid); + AddConvComponentToComponentNode(components, eid); node[ComponentsNode] = components; @@ -263,7 +263,7 @@ namespace SHADE AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); - AddComponentID(componentIDList, componentsNode); + AddComponentID(componentIDList, componentsNode); return componentIDList; } @@ -340,7 +340,7 @@ namespace SHADE SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); - SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); + SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); } } diff --git a/SHADE_Engine/src/Serialization/SHYAMLConverters.h b/SHADE_Engine/src/Serialization/SHYAMLConverters.h index eb273a15..90a7228d 100644 --- a/SHADE_Engine/src/Serialization/SHYAMLConverters.h +++ b/SHADE_Engine/src/Serialization/SHYAMLConverters.h @@ -12,7 +12,7 @@ #include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h" #include "SHSerializationTools.h" #include "Physics/Interface/SHColliderComponent.h" -#include "Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h" +#include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h" #include "Graphics/MiddleEnd/TextRendering/SHFont.h" namespace YAML @@ -327,12 +327,12 @@ namespace YAML }; template<> - struct convert + struct convert { static constexpr std::string_view TEXT_YAML_TAG = "Text"; static constexpr std::string_view FONT_YAML_TAG = "Font"; - static YAML::Node encode(SHTextRendererComponent const& rhs) + static YAML::Node encode(SHTextRenderableComponent const& rhs) { YAML::Node node; node[TEXT_YAML_TAG.data()] = rhs.GetText(); @@ -347,7 +347,7 @@ namespace YAML } return node; } - static bool decode(YAML::Node const& node, SHTextRendererComponent& rhs) + static bool decode(YAML::Node const& node, SHTextRenderableComponent& rhs) { if (node[TEXT_YAML_TAG.data()].IsDefined()) { From 6550846b0f3c5da5241d26836b2aaff78df74df6 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Mon, 21 Nov 2022 20:58:47 +0800 Subject: [PATCH 09/15] Added C# interface for Fonts and TextRenderable --- SHADE_Managed/premake5.lua | 6 ++ SHADE_Managed/src/Assets/Font.cxx | 32 +++++++++ SHADE_Managed/src/Assets/Font.hxx | 41 ++++++++++++ SHADE_Managed/src/Assets/NativeAsset.h++ | 1 + .../src/Components/TextRenderable.cxx | 57 ++++++++++++++++ .../src/Components/TextRenderable.hxx | 65 +++++++++++++++++++ SHADE_Managed/src/Utility/Convert.cxx | 2 + 7 files changed, 204 insertions(+) create mode 100644 SHADE_Managed/src/Assets/Font.cxx create mode 100644 SHADE_Managed/src/Assets/Font.hxx create mode 100644 SHADE_Managed/src/Components/TextRenderable.cxx create mode 100644 SHADE_Managed/src/Components/TextRenderable.hxx diff --git a/SHADE_Managed/premake5.lua b/SHADE_Managed/premake5.lua index 70b01e18..463e80b8 100644 --- a/SHADE_Managed/premake5.lua +++ b/SHADE_Managed/premake5.lua @@ -33,6 +33,8 @@ project "SHADE_Managed" "%{IncludeDir.imgui}", "%{IncludeDir.imguizmo}", "%{IncludeDir.imnodes}", + "%{IncludeDir.msdf_atlas_gen}", + "%{IncludeDir.msdfgen}", "%{IncludeDir.yamlcpp}", "%{IncludeDir.SDL}\\include", "%{IncludeDir.RTTR}/include", @@ -53,6 +55,8 @@ project "SHADE_Managed" links { "yaml-cpp", + "msdfgen", + "msdf-atlas-gen", "imgui", "SDL2.lib", "SDL2main.lib", @@ -89,6 +93,8 @@ project "SHADE_Managed" dependson { "yaml-cpp", + "msdfgen", + "msdf-atlas-gen", "imgui", "SHADE_Engine" } diff --git a/SHADE_Managed/src/Assets/Font.cxx b/SHADE_Managed/src/Assets/Font.cxx new file mode 100644 index 00000000..782b0688 --- /dev/null +++ b/SHADE_Managed/src/Assets/Font.cxx @@ -0,0 +1,32 @@ +/************************************************************************************//*! +\file Font.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the implementation of the functions of the managed Font class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "Font.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Explicit Template Instantiation */ + /*---------------------------------------------------------------------------------*/ + template ref class NativeAsset; + + /*---------------------------------------------------------------------------------*/ + /* Constructors/Destructor */ + /*---------------------------------------------------------------------------------*/ + Font::Font(Handle font) + : NativeAsset { font } + {} +} diff --git a/SHADE_Managed/src/Assets/Font.hxx b/SHADE_Managed/src/Assets/Font.hxx new file mode 100644 index 00000000..fd194d1a --- /dev/null +++ b/SHADE_Managed/src/Assets/Font.hxx @@ -0,0 +1,41 @@ +/************************************************************************************//*! +\file Font.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the definition of the managed Font class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +// External Dependencies +#include "Resource/SHHandle.h" +#include "Graphics/MiddleEnd/TextRendering/SHFont.h" +// Project Includes +#include "NativeAsset.hxx" +#include "Engine/GenericHandle.hxx" + +namespace SHADE +{ + /// + /// Managed counterpart of the native Font object that can be fed to TextRenderables + /// for rendering. + /// + public ref class Font : public NativeAsset + { + internal: + /*-----------------------------------------------------------------------------*/ + /* Constructors/Destructor */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructor for the Font. + /// + /// Handle to the font object. + Font(Handle font); + }; +} diff --git a/SHADE_Managed/src/Assets/NativeAsset.h++ b/SHADE_Managed/src/Assets/NativeAsset.h++ index a4cd94b4..6b583a5c 100644 --- a/SHADE_Managed/src/Assets/NativeAsset.h++ +++ b/SHADE_Managed/src/Assets/NativeAsset.h++ @@ -16,6 +16,7 @@ of DigiPen Institute of Technology is prohibited. // Primary Include #include "NativeAsset.hxx" +#include "Utility/Convert.hxx" namespace SHADE { diff --git a/SHADE_Managed/src/Components/TextRenderable.cxx b/SHADE_Managed/src/Components/TextRenderable.cxx new file mode 100644 index 00000000..c5859854 --- /dev/null +++ b/SHADE_Managed/src/Components/TextRenderable.cxx @@ -0,0 +1,57 @@ +/************************************************************************************//*! +\file TextRenderable.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the definition of the functions of the managed TextRenderable + class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "TextRenderable.hxx" +#include "Assets/NativeAsset.hxx" +#include "Utility/Convert.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Constructors */ + /*---------------------------------------------------------------------------------*/ + TextRenderable::TextRenderable(Entity entity) + : Component(entity) + {} + + /*---------------------------------------------------------------------------------*/ + /* Properties */ + /*---------------------------------------------------------------------------------*/ + System::String^ TextRenderable::Text::get() + { + return Convert::ToCLI(GetNativeComponent()->GetText()); + } + void TextRenderable::Text::set(System::String^ value) + { + GetNativeComponent()->SetText(Convert::ToNative(value)); + } + SHADE::Font^ TextRenderable::Font::get() + { + return gcnew SHADE::Font(GetNativeComponent()->GetFont()); + } + void TextRenderable::Font::set(SHADE::Font^ value) + { + if (value == nullptr) + { + GetNativeComponent()->SetFont(Handle()); + } + else + { + GetNativeComponent()->SetFont(Handle(Convert::ToNative(value->NativeObjectHandle))); + } + } +} diff --git a/SHADE_Managed/src/Components/TextRenderable.hxx b/SHADE_Managed/src/Components/TextRenderable.hxx new file mode 100644 index 00000000..5418b6e5 --- /dev/null +++ b/SHADE_Managed/src/Components/TextRenderable.hxx @@ -0,0 +1,65 @@ +/************************************************************************************//*! +\file TextRenderable.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 21, 2022 +\brief Contains the definition of the managed TextRenderable class with the + declaration of functions for working with it. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +// External Dependencies +#include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h" +// Project Includes +#include "Components/Component.hxx" +#include "Math/Vector3.hxx" +#include "Math/Quaternion.hxx" +#include "Assets/Font.hxx" + +namespace SHADE +{ + /// + /// CLR version of the SHADE Engine's SHTextRenderableComponent. + /// + public ref class TextRenderable : public Component + { + internal: + /*-----------------------------------------------------------------------------*/ + /* Constructors */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructs a TextRenderable Component that represents a native TextRenderable + /// component tied to the specified Entity. + /// + /// Entity that this Component will be tied to. + TextRenderable(Entity entity); + + public: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Text to render using this TextRenderable. + /// + property System::String^ Text + { + System::String^ get(); + void set(System::String^ value); + } + /// + /// Font to use to render using this TextRenderable. + /// + property SHADE::Font^ Font + { + SHADE::Font^ get(); + void set(SHADE::Font^ value); + } + }; +} + diff --git a/SHADE_Managed/src/Utility/Convert.cxx b/SHADE_Managed/src/Utility/Convert.cxx index 38ea2f50..590a3cf0 100644 --- a/SHADE_Managed/src/Utility/Convert.cxx +++ b/SHADE_Managed/src/Utility/Convert.cxx @@ -89,6 +89,8 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ std::string Convert::ToNative(System::String^ str) { + if (str == nullptr) + return ""; return msclr::interop::marshal_as(str); } From 07efa1ab5154f94d0937b77e2ec19ea7268a8920 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 22 Nov 2022 00:39:53 +0800 Subject: [PATCH 10/15] Added an abstract base class for NativeAsset to prepare to support serialization of Assets for scripts --- SHADE_Managed/src/Assets/NativeAsset.cxx | 13 ++++++- SHADE_Managed/src/Assets/NativeAsset.h++ | 8 +---- SHADE_Managed/src/Assets/NativeAsset.hxx | 46 +++++++++++++++++------- 3 files changed, 46 insertions(+), 21 deletions(-) diff --git a/SHADE_Managed/src/Assets/NativeAsset.cxx b/SHADE_Managed/src/Assets/NativeAsset.cxx index 674207a1..9cdb1840 100644 --- a/SHADE_Managed/src/Assets/NativeAsset.cxx +++ b/SHADE_Managed/src/Assets/NativeAsset.cxx @@ -21,6 +21,17 @@ of DigiPen Institute of Technology is prohibited. namespace SHADE { /*---------------------------------------------------------------------------------*/ - /* Explicit Tempalte Instantiations */ + /* Properties */ /*---------------------------------------------------------------------------------*/ + GenericHandle Asset::NativeObjectHandle::get() + { + return nativeObjHandle; + } + + /*---------------------------------------------------------------------------------*/ + /* Constructors */ + /*---------------------------------------------------------------------------------*/ + Asset::Asset(Handle nativeHandle) + : nativeObjHandle { Convert::ToCLI(Handle(nativeHandle)) } + {} } \ No newline at end of file diff --git a/SHADE_Managed/src/Assets/NativeAsset.h++ b/SHADE_Managed/src/Assets/NativeAsset.h++ index 6b583a5c..05be83b4 100644 --- a/SHADE_Managed/src/Assets/NativeAsset.h++ +++ b/SHADE_Managed/src/Assets/NativeAsset.h++ @@ -24,11 +24,6 @@ namespace SHADE /* Properties */ /*---------------------------------------------------------------------------------*/ template - GenericHandle NativeAsset::NativeObjectHandle::get() - { - return nativeObjHandle; - } - template Handle NativeAsset::NativeObject::get() try { @@ -44,7 +39,6 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ template NativeAsset::NativeAsset(Handle nativeObj) - : nativeObjHandle{ Convert::ToCLI(Handle(nativeObj)) } + : Asset { Handle(nativeObj) } {} - } diff --git a/SHADE_Managed/src/Assets/NativeAsset.hxx b/SHADE_Managed/src/Assets/NativeAsset.hxx index 68addb75..4d53ce6b 100644 --- a/SHADE_Managed/src/Assets/NativeAsset.hxx +++ b/SHADE_Managed/src/Assets/NativeAsset.hxx @@ -19,13 +19,9 @@ of DigiPen Institute of Technology is prohibited. namespace SHADE { /// - /// Generalised template class for a managed representation of a native asset + /// Abstract base class that all Native Assets will inherit from. /// - /// - /// The type of the asset's native representation. - /// - template - public ref class NativeAsset + public ref class Asset abstract { internal: /*-----------------------------------------------------------------------------*/ @@ -38,6 +34,36 @@ namespace SHADE { GenericHandle get(); } + + /*-----------------------------------------------------------------------------*/ + /* Constructors/Destructor */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructor for the asset. + /// + /// Native asset object handle. + Asset(Handle nativeHandle); + + protected: + /*-----------------------------------------------------------------------------*/ + /* Data Members */ + /*-----------------------------------------------------------------------------*/ + GenericHandle nativeObjHandle; + }; + + /// + /// Generalised template class for a managed representation of a native asset + /// + /// + /// The type of the asset's native representation. + /// + template + public ref class NativeAsset abstract : Asset + { + internal: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ /// /// Copy of the Handle to the native object. /// @@ -52,14 +78,8 @@ namespace SHADE /// /// Constructor for the native asset /// - /// Native asset object. + /// Native asset object handle. NativeAsset(Handle ptr); - - protected: - /*-----------------------------------------------------------------------------*/ - /* Data Members */ - /*-----------------------------------------------------------------------------*/ - GenericHandle nativeObjHandle; }; } From 964b375ccdb10d0ed0627531f01cefc7a64a29d4 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Tue, 22 Nov 2022 09:05:56 +0800 Subject: [PATCH 11/15] Write to swapchain image without SHEDITOR defined WIP --- Assets/Fonts/ALGER.shfont | Bin 698700 -> 698700 bytes Assets/Fonts/SegoeUI.shfont | Bin 559876 -> 559876 bytes Assets/Shaders/ToSwapchain_FS.glsl | 9 ++---- Assets/Shaders/ToSwapchain_FS.shshaderb | Bin 0 -> 881 bytes .../Shaders/ToSwapchain_FS.shshaderb.shmeta | 3 ++ Assets/Shaders/ToSwapchain_VS.glsl | 8 +---- Assets/Shaders/ToSwapchain_VS.shshaderb | Bin 0 -> 1597 bytes .../Shaders/ToSwapchain_VS.shshaderb.shmeta | 3 ++ .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 10 +++++-- .../MiddleEnd/Interface/SHGraphicsSystem.h | 2 ++ .../SHRenderToSwapchainImageSystem.cpp | 28 ++++++++++++++++-- .../src/Graphics/RenderGraph/SHSubpass.cpp | 2 +- 12 files changed, 45 insertions(+), 20 deletions(-) create mode 100644 Assets/Shaders/ToSwapchain_FS.shshaderb create mode 100644 Assets/Shaders/ToSwapchain_FS.shshaderb.shmeta create mode 100644 Assets/Shaders/ToSwapchain_VS.shshaderb create mode 100644 Assets/Shaders/ToSwapchain_VS.shshaderb.shmeta diff --git a/Assets/Fonts/ALGER.shfont b/Assets/Fonts/ALGER.shfont index 1acab9da4e7191479536fae42fe4d0181cc87dae..738af82d86df84ae1df6bf24a46f82732e7c7bf1 100644 GIT binary patch delta 1272 zcmYk*KWNlY90%~;_0Oe$Y-=yIJrwOA9F#5&;)6?a2o;?!f`|pTr{gUmqyYzq7Hczz z5~MCUQ5-vXQ-f!66z;&GF4w^;MF&B;WGI3)P*A@wzj&|18$SHHLY6*eq-_R{wN{L2L0s1KAf*UOX-U{%j#Souij0ixB1 z>1=?xFhRS;0H4X1EuJ%6Hi4e)du93#0G^wqaePsEpi?CVEWVb`Hi^f!CY#g))VeQp z%2ZS~W~dS;m60H7J;Q9L#RQkbcBQJhHlQ{(0>|rWt`Eq3fN1e?n$Oh9d=mW62ax#y zGM_vuy?g+f4G8`5R3+cAHcZXpwXFEj7Fo)7ySSx zK7o-)+~_%H-(?6JezWiF-n|!o7lYr$;A>TBCdo&dB;za(6<6Xl&0Uq~WZLmU4|vG( zLbwE`$OvP=Wx1;{Gs0;&zzbi%BQl!^LV=x6+_S~Z3JAyuPryf-7Xm*^(mV)rV2;c- zGi5nm=*9{P;Rm1bJwg*ZfU7e@TxYo#n88jV@TIrN2<`ZpYcNCLGcPd19tb?`4jF;9 zb#PCU89rf%jIacH$OtO{j|-bSuEoqBc6g6acC-*~V+BEA^m2Bd{TSk1#AV z!g++-Wv1Nm!d00OK4S$z;Iny8n;92B^Mc(YSZxApLj`V+8D5G5{2HuHU@C7_sASD^8{cdUYG*BN0`N(AXsf3X5R5qW&|G1nQra`f#odm zdpl$%0e&XA7hZ9|2)|LmdLY<*j+n9e2-Y`&JwTyBu=yM_Q|@@ddLY<*gfHo8tOqB|*nHMt-vm~``3N?jQ)YNH=Ob8cg3U*;`J6Fh^AT)5g3U*;+Ir0J uAI$j(f0H<$&7C0dpLLNwyZ(#oSFoyBHLNYHZLB(01FMPE`gZ-D?%O}!iTsHG diff --git a/Assets/Fonts/SegoeUI.shfont b/Assets/Fonts/SegoeUI.shfont index 321f62c853e249cbb78261997b870b07c717f7fc..3f709c2ae0d358bca8aa02a837630d2b279423f4 100644 GIT binary patch delta 1238 zcmXZbYe-Z<6bEqDSF>uGX{(V$FO$OZTINo=clJv@5Tb_#K~IPtvJqD^D3U1JluQu1 zVXzgFQkJna6_%iTuh0Xmh$MShVlT@OV=sl|hqC@Vb3e?7ALpK#GiT2AH!tuvFW}!D zWOvRSlgy7{y5*pRpV-P0auiipqA1BdR>pF>$5mYe1|Pj*~diKgW8p}Hcmfd=%oInBz}Gpf#ku20!ULJn7T3m8ecp*H4~;G7srTw6vw4T}RF zT?2|!y=Ibo$fI)+$qfzeNyj-r-#_8VJv zIhd}*QL>`sy`2LLe*Gvv<3MrhIVL`{fH#5LGNMewZcTm(4QNsH!1$&{!+3*^=s z(AeK$=KvEglS750nV22mW{1-dgQU!$Wc@#vAtD;!-geR$Yj44uMj~E+h|KqUbPEV} z?o|60CgV+0u$z8FKD`F?wXHX1?@q+O05p7?kP!>;{=Ft6%FM`I&npz;q5%Wp+f3#F z(FtX&vek*&fWZExJpxK9CFe#HP0<|<$POrxzY*sE?x7}C<^Xq}RvR)W4Np?K&YQz~ zF>gRqZHFPiBawEqM^s<|L%dZUs?3T+en@CQRa=TFbAX9oz4m>8wKbV$IP@DmaA7Fs z8cd!8JeYpE=h^aZ^bM#eA7%m;Q1d)X6;RSq&ZRr{IY4=3mHdnY-Q#0L@_m5oEqTlr uT!nujgOXNfy!}2veqL8(DAZFtqn>9tu%fV{v0|`dvEs0%-RBu(Q}ut-FUd&& delta 1238 zcmYk)FK<*q6b10vcH2H+f!BZV1cEdO1Y$%*MfbfG6%`0X1)`#Y4{$^H0GqH0$R;mo zkSmenYFAbwkto65b8FBN!RDW8E^|s+dgg) zO&7w4t~X(cigkSwE>XEaMz|=5+suTrfe8!Xq3u(tpe-OHL{x5Z&XAcoupIX$aGbZu z2rJ+k86o&NJIrt#Ol?9gNb3q`6DnlRyFTu2W`uvppe?O|w!8)^agP~qGl8?!$Osbv zx03}9Iz*;ohJ()A-UP2CffvHrge$atM&=1K@5`Vj@Ov;$5^7YK5#E%x_>`GHrOku~ z&j@T|M&Jg#gJ;Z4JtO=AaEVFqtIC3J9Y@Se$_6I*1W7pca|E9{K4<0(75pwHjLHT{ zU>j!>9^dB$GaQs}D!lWI@U0*V{4M!CFPS+iuuUZ42IqXiIl>aSMy6)QD<<%tj z%z-H~g12QMc;<*1zRw65fo(t%c)ge)3w~%kX2xLx{{v=(1;C8(8#u*mubA8!0yF>s diff --git a/Assets/Shaders/ToSwapchain_FS.glsl b/Assets/Shaders/ToSwapchain_FS.glsl index 9a35d1c4..a68fa0c7 100644 --- a/Assets/Shaders/ToSwapchain_FS.glsl +++ b/Assets/Shaders/ToSwapchain_FS.glsl @@ -3,17 +3,12 @@ #extension GL_ARB_shading_language_420pack : enable #extension GL_EXT_nonuniform_qualifier : require -layout (input_attachment_index = 0, set = 4, binding = 0) uniform subpassInput vec4 sceneTexture; +layout (input_attachment_index = 0, set = 4, binding = 0) uniform subpassInput sceneTexture; -layout(location = 0) in struct -{ - vec2 uv; // location = 0 - -} In; layout(location = 0) out vec4 fragColor; void main() { - fragColor = vec4 (texture (sceneTexture, In.uv).rgb, 1.0f); + fragColor = vec4 (subpassLoad(sceneTexture).rgb, 1.0f); } \ No newline at end of file diff --git a/Assets/Shaders/ToSwapchain_FS.shshaderb b/Assets/Shaders/ToSwapchain_FS.shshaderb new file mode 100644 index 0000000000000000000000000000000000000000..b10a9d6cc18532c8501c040dbbba8899a7e9af1a GIT binary patch literal 881 zcmY+B-A~j|5XA?U0xklJ2#616(H9d4AqI_!QKN?RWs~)T2j6Z=_wG_H?b;8cZ~krm zRlb;be%)@ePBNXDbI(09ciOw|SYw^#M{8zF*0oK$KZ9(?mW5aoA1iLyYEy@UPlMC4 z8l9d$J%hSsGZDDk;;bm*H&K!)*e!Wa956Le){(N=Z(Uf?X*h6iKE8FOpGHMgc~@RX zBVV}u>Wh!7@_&wwl5FDAD4W#L#Jlq+XVWPDDxGz7E9Hz8nrV#}1T(!JT9GT8z8z)s23Ka_+tz_br&)pj}X2e`J6J{@g%(Te~F=pJ9Vqb5Z zHmd!oU9D|Ag>u#8V{n$Qvb;Vy`5z({bVI%2)Q^wrjn_`A+jaWU z$G~#}KlGfo-}73Lf9}B>%kccL6%5*0LQ#zDT}AbHMRy$bJU8-A25x(Gu)b?dQJ-<) z=Uy-JF5Vt#DsMi)KYW$u~Rw7%RoSe+Zm+$+58QU2v{oD#~}=o_m(^p395Z z^m++Zp*krUa2B~v-;exGD0DQ&(JRLNFgo==X$)=3gEynU_+?>m*w2Z@ zb1KVNWyQP-418Y9u^2aILAguX6DM_e879WyQ)^PbEThLt8c$_nYR<~IpFHt`j5VvO z*X6;v<0hb%jc>)#mwkKgwqp9B=lk;XVB-hc(*ynNDo>2gwlC^GmTB#;NpsFsWndVy z@`Hhgj`q%V?WwUS^qD+)uq91`&h`vBjNWSU%uAkLh?Cz~QkNb#Wi0sm3B-JAZK^l4 zrUw>vehVqeQ;WG*WXw*CucYywVroB>G5cr5=*>F=d!=e{iFZ;B*0kq03H~+3o@ft_ zKAhn`FzTb*mJIAfeDv5(F}WeOlVWJsRF};5LI#%{-!E&ttjuidEoq;vcSkYr8{F0_YY(2Sx2zc4)@!D^ P+!e-M(VS_DEFAULT); @@ -137,6 +138,8 @@ namespace SHADE static constexpr AssetID SSAO_BLUR = 39760835; ssaoBlurShader = SHResourceManager::LoadOrGet(SSAO_BLUR); static constexpr AssetID TEXT_VS = 39816727; textVS = SHResourceManager::LoadOrGet(TEXT_VS); static constexpr AssetID TEXT_FS = 38024754; textFS = SHResourceManager::LoadOrGet(TEXT_FS); + static constexpr AssetID RENDER_SC_VS = 48082949; renderToSwapchainVS = SHResourceManager::LoadOrGet(RENDER_SC_VS); + static constexpr AssetID RENDER_SC_FS = 36869006; renderToSwapchainFS = SHResourceManager::LoadOrGet(RENDER_SC_FS); } void SHGraphicsSystem::InitSceneRenderGraph(void) noexcept @@ -300,6 +303,7 @@ namespace SHADE textRenderingSubSystem->Render(cmdBuffer, frameIndex); }); +#ifdef SHEDITOR { // Dummy Node to transition scene render graph resource auto dummyNode = screenRenderGraph->AddNode("Dummy Pass", { "Scene" }, { "Screen Space Pass" }); // no predecessors @@ -307,7 +311,9 @@ namespace SHADE dummySubpass->AddInput("Scene"); } - //screenRenderGraph->AddRenderToSwapchainNode ("Scene", "Present", ) +#else + screenRenderGraph->AddRenderToSwapchainNode("Scene", "Present", {"Screen Space Pass"}, {renderToSwapchainVS, renderToSwapchainFS}); +#endif screenRenderGraph->Generate(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index c201e9a5..8c65f233 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -444,6 +444,8 @@ namespace SHADE Handle ssaoBlurShader; Handle textVS; Handle textFS; + Handle renderToSwapchainVS; + Handle renderToSwapchainFS; // Fonts Handle testFont; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp index e4f020e4..770217ee 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp @@ -3,6 +3,8 @@ #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" #include "Graphics/RenderGraph/SHRenderGraphNode.h" +#include "Graphics/RenderGraph/SHSubpass.h" +#include "Graphics/SHVkUtil.h" namespace SHADE { @@ -25,14 +27,34 @@ namespace SHADE .globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts(), }); - auto newPipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderGraphNode->GetRenderpass(), subpass); + pipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderGraphNode->GetRenderpass(), subpass); SHInputAssemblyState inputAssembly{}; inputAssembly.topology = vk::PrimitiveTopology::eTriangleFan; - newPipeline->GetPipelineState().SetInputAssemblyState(inputAssembly); + pipeline->GetPipelineState().SetInputAssemblyState(inputAssembly); - newPipeline->ConstructPipeline(); + SHColorBlendState colorBlendState{}; + colorBlendState.logic_op_enable = VK_FALSE; + colorBlendState.logic_op = vk::LogicOp::eCopy; + + auto const& subpassColorReference = subpass->GetColorAttachmentReferences()[0]; + colorBlendState.attachments.push_back(vk::PipelineColorBlendAttachmentState + { + .blendEnable = SHVkUtil::IsBlendCompatible(subpass->GetFormatFromAttachmentReference(subpassColorReference.attachment)), + .srcColorBlendFactor = vk::BlendFactor::eSrcAlpha, + .dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha, + .colorBlendOp = vk::BlendOp::eAdd, + .srcAlphaBlendFactor = vk::BlendFactor::eOne, + .dstAlphaBlendFactor = vk::BlendFactor::eZero, + .alphaBlendOp = vk::BlendOp::eAdd, + .colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA, + } + ); + + pipeline->GetPipelineState().SetColorBlenState(colorBlendState); + + pipeline->ConstructPipeline(); } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index 1eae9768..0900852c 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -281,7 +281,7 @@ namespace SHADE } //// maybe do this in handle resize? - //UpdateWriteDescriptors(); + UpdateWriteDescriptors(); } void SHSubpass::UpdateWriteDescriptors(void) noexcept From 4377972315becdda76684a6e26d63ba4d2d2b589 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Tue, 22 Nov 2022 10:09:52 +0800 Subject: [PATCH 12/15] Added functionality for graphics system to render to swapchain image - Added functionality for graphics system to render to swapchain image when SHEDITOR is disabled. This is done via rendering a simple quad on screen and using an input attachment as a texture to the shader. --- Assets/Fonts/ALGER.shfont | Bin 698700 -> 698700 bytes Assets/Fonts/SegoeUI.shfont | Bin 559876 -> 559876 bytes Assets/Shaders/ToSwapchain_VS.glsl | 2 +- Assets/Shaders/ToSwapchain_VS.shshaderb | Bin 1597 -> 1633 bytes .../src/Application/SBApplication.cpp | 4 ++-- .../Graphics/RenderGraph/SHRenderGraph.cpp | 4 +++- .../src/Graphics/RenderGraph/SHSubpass.cpp | 22 ++++++++++++++---- .../src/Graphics/RenderGraph/SHSubpass.h | 8 +++++-- 8 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Assets/Fonts/ALGER.shfont b/Assets/Fonts/ALGER.shfont index 738af82d86df84ae1df6bf24a46f82732e7c7bf1..1acab9da4e7191479536fae42fe4d0181cc87dae 100644 GIT binary patch delta 1272 zcmYk*FH=H66b0}HD1Q_c6%}R-27|*82!svt9>G8`5R3+cAHcZXpwXFEj7Fo)7ySSx zK7o-)+~_%H-(?6JezWiF-n|!o7lYr$;A>TBCdo&dB;za(6<6Xl&0Uq~WZLmU4|vG( zLbwE`$OvP=Wx1;{Gs0;&zzbi%BQl!^LV=x6+_S~Z3JAyuPryf-7Xm*^(mV)rV2;c- zGi5nm=*9{P;Rm1bJwg*ZfU7e@TxYo#n88jV@TIrN2<`ZpYcNCLGcPd19tb?`4jF;9 zb#PCU89rf%jIacH$OtO{j|-bSuEoqBc6g6acC-*~V+BEA^m2Bd{TSk1#AV z!g++-Wv1Nm!d00OK4S$z;Iny8n;92B^Mc(YSZxApLj`V+8D5G5{2HuHU@C7_sASD^8{cdUYG*BN0`N(AXsf3X5R5qW&|G1nQra`f#odm zdpl$%0e&XA7hZ9|2)|LmdLY<*j+n9e2-Y`&JwTyBu=yM_Q|@@ddLY<*gfHo8tOqB|*nHMt-vm~``3N?jQ)YNH=Ob8cg3U*;`J6Fh^AT)5g3U*;+Ir0J uAI$j(f0H<$&7C0dpLLNwyZ(#oSFoyBHLNYHZLB(01FMPE`gZ-D?%O}!iTsHG delta 1272 zcmYk*KWNlY90%~;_0Oe$Y-=yIJrwOA9F#5&;)6?a2o;?!f`|pTr{gUmqyYzq7Hczz z5~MCUQ5-vXQ-f!66z;&GF4w^;MF&B;WGI3)P*A@wzj&|18$SHHLY6*eq-_R{wN{L2L0s1KAf*UOX-U{%j#Souij0ixB1 z>1=?xFhRS;0H4X1EuJ%6Hi4e)du93#0G^wqaePsEpi?CVEWVb`Hi^f!CY#g))VeQp z%2ZS~W~dS;m60H7J;Q9L#RQkbcBQJhHlQ{(0>|rWt`Eq3fN1e?n$Oh9d=mW62ax#y zGM_vuy?g+f4o65b8FBN!RDW8E^|s+dgg) zO&7w4t~X(cigkSwE>XEaMz|=5+suTrfe8!Xq3u(tpe-OHL{x5Z&XAcoupIX$aGbZu z2rJ+k86o&NJIrt#Ol?9gNb3q`6DnlRyFTu2W`uvppe?O|w!8)^agP~qGl8?!$Osbv zx03}9Iz*;ohJ()A-UP2CffvHrge$atM&=1K@5`Vj@Ov;$5^7YK5#E%x_>`GHrOku~ z&j@T|M&Jg#gJ;Z4JtO=AaEVFqtIC3J9Y@Se$_6I*1W7pca|E9{K4<0(75pwHjLHT{ zU>j!>9^dB$GaQs}D!lWI@U0*V{4M!CFPS+iuuUZ42IqXiIl>aSMy6)QD<<%tj z%z-H~g12QMc;<*1zRw65fo(t%c)ge)3w~%kX2xLx{{v=(1;C8(8#u*mubA8!0yF>s delta 1238 zcmXZbYe-Z<6bEqDSF>uGX{(V$FO$OZTINo=clJv@5Tb_#K~IPtvJqD^D3U1JluQu1 zVXzgFQkJna6_%iTuh0Xmh$MShVlT@OV=sl|hqC@Vb3e?7ALpK#GiT2AH!tuvFW}!D zWOvRSlgy7{y5*pRpV-P0auiipqA1BdR>pF>$5mYe1|Pj*~diKgW8p}Hcmfd=%oInBz}Gpf#ku20!ULJn7T3m8ecp*H4~;G7srTw6vw4T}RF zT?2|!y=Ibo$fI)+$qfzeNyj-r-#_8VJv zIhd}*QL>`sy`2LLe*Gvv<3MrhIVL`{fH#5LGNMewZcTm(4QNsH!1$&{!+3*^=s z(AeK$=KvEglS750nV22mW{1-dgQU!$Wc@#vAtD;!-geR$Yj44uMj~E+h|KqUbPEV} z?o|60CgV+0u$z8FKD`F?wXHX1?@q+O05p7?kP!>;{=Ft6%FM`I&npz;q5%Wp+f3#F z(FtX&vek*&fWZExJpxK9CFe#HP0<|<$POrxzY*sE?x7}C<^Xq}RvR)W4Np?K&YQz~ zF>gRqZHFPiBawEqM^s<|L%dZUs?3T+en@CQRa=TFbAX9oz4m>8wKbV$IP@DmaA7Fs z8cd!8JeYpE=h^aZ^bM#eA7%m;Q1d)X6;RSq&ZRr{IY4=3mHdnY-Q#0L@_m5oEqTlr uT!nujgOXNfy!}2veqL8(DAZFtqn>9tu%fV{v0|`dvEs0%-RBu(Q}ut-FUd&& diff --git a/Assets/Shaders/ToSwapchain_VS.glsl b/Assets/Shaders/ToSwapchain_VS.glsl index b230301f..eee22015 100644 --- a/Assets/Shaders/ToSwapchain_VS.glsl +++ b/Assets/Shaders/ToSwapchain_VS.glsl @@ -10,6 +10,6 @@ vec2 CreateQuad(in uint vertexID) void main() { - vec2 vertexPos = CreateQuad(gl_VertexIndex) - vec2(0.5f); + vec2 vertexPos = 2 * (CreateQuad(gl_VertexIndex) - vec2(0.5f)); gl_Position = vec4 (vertexPos, 0.0f, 1.0f); } \ No newline at end of file diff --git a/Assets/Shaders/ToSwapchain_VS.shshaderb b/Assets/Shaders/ToSwapchain_VS.shshaderb index 1868d251be4744e6adef0a130d2b456d86c6cdc9..4c3157f98268ef9a629bdd8d60286af9c8b449a9 100644 GIT binary patch literal 1633 zcmYk6YflqF6o!Z1KoJqSc|j~15e2I#R}rcKvzj!agv9u5Q`?Q%WZ5?DmZ0&2iQoMn z#(!Z<{7Zh(_&&Qkb*DL;Iq!Mr%$av*7yMyZH2IhbXWVGHMnQJc@I&VJWSg?QemVIcA{MlRQ*)ieL#OuAZFV|t zFZvL8Zs3QW+w!|!GxAS8cq18}A2x%2D@!Pfk=?7P9xrH*{jS%DyrX`jwbWnTF{Y^B zsPI#-8+m814>T2$SMSEWi|0kND4*o(?Ou$P;@;l}?we#;*z(R;S1>EecN*QsNy=N7 z7q9Mh6RJXWQZnESa_ycU`R!2XaEzl@jQe49?0?j0S(D_@NxA*N?;QBOs1Y{3K@PRa z^@CuL<1A>*aMT}~bKd*1SL)dI0miUc@?H7j|1tK4$3B+F91N`;WvB;lQh)Ia!r(BU z7K`gtmNCkTxfK}rjF=-aZp^H5=QJly>TokmjKQbYxO`bgkIQL%DHBt3O2+==iDzYu zDOJ5956&Lf05xoUJ&rzC?YbL^>4%>0$kPL{<=@p@<2m^yP3VdKcG4K#ZJ+E{k!e&{ z^bM%qrpp}So}4x^V1dCpIsUWk)7m(-=lEg1v; zt~`8dZKyZ2rw0c3Zy`l_YN5lT3@wQ9+<*M8Vrp~GIQu8X=)as|d#VPPcsteLf#$qX z@GmLGKN4{C`I=&@nuDV`b?5<%J<)Po26iMq8a+)hxdEo9AM?<&u8ukHGZ|cR+z0N! z3)MiAJsG;86?+oH|D!LmB||Irrhf)^byGaF;C-Omn7q}A|1VZ2beWLB`>8tUc3H+< z2DjQxra1evo|rSUep&|hOY4beWZZr5@4~q2S7qS5fp21=&72IJvvOuzZ(j3ky_<@8 f1K_q^S#$7gy#>YKwq8Be<(4q^BL7!f5Tn~ad3$}2 literal 1597 zcmYk6TTc^F6on7Hfg%EO^MY73B3i7Xtz_br&)pj}X2e`J6J{@g%(Te~F=pJ9Vqb5Z zHmd!oU9D|Ag>u#8V{n$Qvb;Vy`5z({bVI%2)Q^wrjn_`A+jaWU z$G~#}KlGfo-}73Lf9}B>%kccL6%5*0LQ#zDT}AbHMRy$bJU8-A25x(Gu)b?dQJ-<) z=Uy-JF5Vt#DsMi)KYW$u~Rw7%RoSe+Zm+$+58QU2v{oD#~}=o_m(^p395Z z^m++Zp*krUa2B~v-;exGD0DQ&(JRLNFgo==X$)=3gEynU_+?>m*w2Z@ zb1KVNWyQP-418Y9u^2aILAguX6DM_e879WyQ)^PbEThLt8c$_nYR<~IpFHt`j5VvO z*X6;v<0hb%jc>)#mwkKgwqp9B=lk;XVB-hc(*ynNDo>2gwlC^GmTB#;NpsFsWndVy z@`Hhgj`q%V?WwUS^qD+)uq91`&h`vBjNWSU%uAkLh?Cz~QkNb#Wi0sm3B-JAZK^l4 zrUw>vehVqeQ;WG*WXw*CucYywVroB>G5cr5=*>F=d!=e{iFZ;B*0kq03H~+3o@ft_ zKAhn`FzTb*mJIAfeDv5(F}WeOlVWJsRF};5LI#%{-!E&ttjuidEoq;vcSkYr8{F0_YY(2Sx2zc4)@!D^ P+!e-M(); SHSystemManager::CreateSystem(); - std::system("FontCompiler.exe ../../Assets/Fonts/SegoeUI.ttf"); - std::system("FontCompiler.exe ../../Assets/Fonts/ALGER.ttf"); + //std::system("FontCompiler.exe ../../Assets/Fonts/SegoeUI.ttf"); + //std::system("FontCompiler.exe ../../Assets/Fonts/ALGER.ttf"); SHSystemManager::CreateSystem(); SHGraphicsSystem* graphicsSystem = static_cast(SHSystemManager::GetSystem()); diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index 0580d650..2ffd6d13 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -565,8 +565,10 @@ namespace SHADE { cmdBuffer->BindPipeline(renderToSwapchainImageSystem->GetPipeline()); + newSubpass->BindDescriptorInputDescriptorSets (cmdBuffer, frameIndex); + // draw a quad. - cmdBuffer->DrawIndexed(4, 0, 0); + cmdBuffer->DrawArrays(4, 1, 0, 0); }); } } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index 0900852c..c1d53632 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -40,7 +40,7 @@ namespace SHADE , inputReferences{} , name { name } , graphStorage{ renderGraphStorage } - , inputImageDescriptors {SHGraphicsConstants::NUM_FRAME_BUFFERS} + , inputImageDescriptorSets{} { } @@ -67,7 +67,7 @@ namespace SHADE , exteriorDrawCalls{ std::move(rhs.exteriorDrawCalls) } , graphStorage{ rhs.graphStorage } , inputNames{ std::move(rhs.inputNames) } - , inputImageDescriptors{ std::move(rhs.inputImageDescriptors) } + , inputImageDescriptorSets{ std::move(rhs.inputImageDescriptorSets) } , inputDescriptorLayout{ rhs.inputDescriptorLayout } , inputSamplers{ rhs.inputSamplers } , name { rhs.name } @@ -102,7 +102,7 @@ namespace SHADE exteriorDrawCalls = std::move(rhs.exteriorDrawCalls); graphStorage = rhs.graphStorage; inputNames = std::move(rhs.inputNames); - inputImageDescriptors = std::move(rhs.inputImageDescriptors); + inputImageDescriptorSets = std::move(rhs.inputImageDescriptorSets); inputDescriptorLayout = rhs.inputDescriptorLayout; inputSamplers = rhs.inputSamplers; name = std::move(rhs.name); @@ -202,6 +202,8 @@ namespace SHADE void SHSubpass::Execute(Handle& commandBuffer, Handle descPool, uint32_t frameIndex) noexcept { commandBuffer->BeginLabeledSegment(name); + + // Ensure correct transforms are provided superBatch->UpdateBuffers(frameIndex, descPool); @@ -221,6 +223,14 @@ namespace SHADE UpdateWriteDescriptors(); } + void SHSubpass::BindDescriptorInputDescriptorSets(Handle cmdBuffer, uint32_t frameIndex) const noexcept + { + if (!inputImageDescriptorSets.empty()) + { + cmdBuffer->BindDescriptorSet(inputImageDescriptorSets[frameIndex], SH_PIPELINE_TYPE::GRAPHICS, SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, { }); + } + } + void SHSubpass::AddExteriorDrawCalls(std::function&, uint32_t)> const& newDrawCall) noexcept { exteriorDrawCalls.push_back(newDrawCall); @@ -237,6 +247,8 @@ namespace SHADE if (inputNames.empty()) return; + inputImageDescriptorSets.resize(SHGraphicsConstants::NUM_FRAME_BUFFERS); + std::vector bindings{}; for (auto& input : inputReferences) @@ -280,7 +292,7 @@ namespace SHADE } } - //// maybe do this in handle resize? + // maybe do this in handle resize? UpdateWriteDescriptors(); } @@ -296,7 +308,7 @@ namespace SHADE // For every frame's descriptor set - for (auto& group : inputImageDescriptors) + for (auto& group : inputImageDescriptorSets) { if (group) group.Free(); diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h index c28ff919..69b8fd56 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h @@ -55,8 +55,11 @@ namespace SHADE //! For getting attachment reference indices using handles std::unordered_map const* resourceAttachmentMapping; - //! Descriptor set group to hold the images for input - std::vector> inputImageDescriptors; + //! Descriptor set group to hold the images for input. We have 3 here just in case + //! one of the images is a swapchain image. Practically speaking its not likely not + //! swapchain images will end up being images used in descriptor sets, but this is + //! to have the support for it. The cost is not much. + std::vector> inputImageDescriptorSets; //! Descriptor set layout for allocating descriptor set for inputs Handle inputDescriptorLayout; @@ -104,6 +107,7 @@ namespace SHADE // Runtime functions void Execute(Handle& commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; void HandleResize (void) noexcept; + void BindDescriptorInputDescriptorSets (Handle cmdBuffer, uint32_t frameIndex) const noexcept; void Init(SHResourceHub& resourceManager) noexcept; From dfe86ce7db8cdd32acd92d9ad1e0af10fcaeb2d7 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Tue, 22 Nov 2022 10:43:59 +0800 Subject: [PATCH 13/15] Fixed resizing bug --- .../src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 6aa988a5..af09c819 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -84,7 +84,7 @@ namespace SHADE if (width == 0 || height == 0) return; - PrepareResize(resizeWidth, resizeHeight); + PrepareResize(width, height); }); window->RegisterWindowCloseCallback([&](void) From ece0a92717289469223ef94acc85d1942ab27c58 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 22 Nov 2022 11:29:01 +0800 Subject: [PATCH 14/15] Fixed TextRenderable components not being retrievable by C# scripts --- SHADE_Managed/src/Engine/ECS.cxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SHADE_Managed/src/Engine/ECS.cxx b/SHADE_Managed/src/Engine/ECS.cxx index ffdffd12..c388f0cd 100644 --- a/SHADE_Managed/src/Engine/ECS.cxx +++ b/SHADE_Managed/src/Engine/ECS.cxx @@ -28,6 +28,7 @@ of DigiPen Institute of Technology is prohibited. #include "Scene/SHSceneGraph.h" #include "Tools/Logger/SHLog.h" #include "Graphics\MiddleEnd\Interface\SHRenderable.h" +#include "Graphics\MiddleEnd\TextRendering\SHTextRenderableComponent.h" // Project Headers #include "Utility/Convert.hxx" #include "Utility/Debug.hxx" @@ -38,6 +39,7 @@ of DigiPen Institute of Technology is prohibited. #include "Components/CameraArm.hxx" #include "Components/Light.hxx" #include "Components\Renderable.hxx" +#include "Components\TextRenderable.hxx" namespace SHADE { @@ -321,6 +323,7 @@ namespace SHADE componentMap.Add(createComponentSet()); componentMap.Add(createComponentSet()); componentMap.Add(createComponentSet()); + componentMap.Add(createComponentSet()); } /*---------------------------------------------------------------------------------*/ From 858e200fb3b5f80333c7daa5045ae84856545c16 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 22 Nov 2022 11:32:19 +0800 Subject: [PATCH 15/15] Bug fixes --- Assets/CollisionTags.SHConfig | 36 +++++++++---------- SHADE_Engine/src/Camera/SHCameraDirector.cpp | 2 ++ .../src/ECS_Base/Managers/SHEntityManager.cpp | 2 +- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/Assets/CollisionTags.SHConfig b/Assets/CollisionTags.SHConfig index 18a339dd..d3ebe7e2 100644 --- a/Assets/CollisionTags.SHConfig +++ b/Assets/CollisionTags.SHConfig @@ -1,20 +1,16 @@ -0 1 -1 2 -2 3 -3 4 -4 5 -5 6 -6 7 -7 8 -8 9 -9 10 -10 11 -11 12 -12 13 -13 14 -14 15 -15 16 - -note: -All collision tags should follow the above format "indextag name". -If it fails to follow this, the default tag names will be used. \ No newline at end of file +0 1 +1 2 +2 3 +3 4 +4 5 +5 6 +6 7 +7 8 +8 9 +9 10 +10 11 +11 12 +12 13 +13 14 +14 15 +15 16 diff --git a/SHADE_Engine/src/Camera/SHCameraDirector.cpp b/SHADE_Engine/src/Camera/SHCameraDirector.cpp index ec539fa1..29e2dcde 100644 --- a/SHADE_Engine/src/Camera/SHCameraDirector.cpp +++ b/SHADE_Engine/src/Camera/SHCameraDirector.cpp @@ -43,7 +43,9 @@ namespace SHADE if (!camComponent) { SHLOG_WARNING("Camera Director warning: Entity does not have a camera"); + return nullptr; } + return camComponent; } diff --git a/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.cpp b/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.cpp index 19eb5168..1c603c57 100644 --- a/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.cpp +++ b/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.cpp @@ -146,7 +146,7 @@ namespace SHADE //Call all the children to Destroy themselves first before the parent is destroyed. if (entityVec[eIndex]) { - auto& children = SHSceneManager::GetCurrentSceneGraph().GetChildren(eID); + auto children = SHSceneManager::GetCurrentSceneGraph().GetChildren(eID); for (auto& child : children) { DestroyEntity(child->GetEntityID());