Merge branch 'main' into SP3-6-c-scripting

This commit is contained in:
Kah Wei 2023-02-01 23:49:44 +08:00
commit ee03722153
32 changed files with 559 additions and 75 deletions

2
.gitignore vendored
View File

@ -363,8 +363,6 @@ MigrationBackup/
*.filters
Assets/Editor/Layouts/UserLayout.ini
JSON/Schemas/Catalog/
Assets/Editor/Editor.SHConfig

View File

@ -1,4 +1,4 @@
Start in Fullscreen: false
Starting Scene ID: 87244611
Starting Scene ID: 97158628
Window Size: {x: 1920, y: 1080}
Window Title: SHADE Engine

View File

@ -0,0 +1,165 @@
[Window][MainStatusBar]
Pos=0,989
Size=1920,20
Collapsed=0
[Window][SHEditorMenuBar]
Pos=0,48
Size=1920,941
Collapsed=0
[Window][Hierarchy Panel]
Pos=0,187
Size=300,802
Collapsed=0
DockId=0x00000004,0
[Window][Debug##Default]
Pos=60,60
Size=400,400
Collapsed=0
[Window][Inspector]
Pos=1604,48
Size=316,941
Collapsed=0
DockId=0x00000006,0
[Window][Profiler]
Pos=0,48
Size=300,137
Collapsed=0
DockId=0x00000003,0
[Window][Viewport]
Pos=227,48
Size=1457,1012
Collapsed=0
DockId=0x0000000B,0
[Window][ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌð‡Žoû]
Pos=60,60
Size=32,64
Collapsed=0
[Window][ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ]
Pos=60,60
Size=999,581
Collapsed=0
[Window][ð‡]
Pos=60,60
Size=32,64
Collapsed=0
[Window][ÌÌÌÌ]
Pos=60,60
Size=553,422
Collapsed=0
[Window][]
Pos=60,60
Size=770,394
Collapsed=0
[Window][ Viewport]
Pos=227,48
Size=1457,1012
Collapsed=0
DockId=0x0000000B,0
[Window][ Viewport]
Pos=227,48
Size=1457,1012
Collapsed=0
DockId=0x0000000B,0
[Window][î<> Viewport]
Pos=302,48
Size=1300,836
Collapsed=0
DockId=0x0000000B,0
[Window][V]
Pos=310,722
Size=1501,338
Collapsed=0
DockId=0x00000008,0
[Window][p£€Ê]
Pos=310,750
Size=1501,310
Collapsed=0
DockId=0x0000000A,0
[Window][ Asset Browser]
Pos=302,886
Size=1300,103
Collapsed=0
DockId=0x0000000C,0
[Window][Material Inspector]
Pos=1604,48
Size=316,941
Collapsed=0
DockId=0x00000006,1
[Window][Save scene as...]
Pos=1197,693
Size=165,120
Collapsed=0
[Window][Create New Asset]
Pos=896,472
Size=464,144
Collapsed=0
[Window][Collider Tag Panel]
Pos=60,60
Size=625,744
Collapsed=0
[Window][Input Bindings Panel]
Pos=60,60
Size=154,204
Collapsed=0
[Window][Save Scene As]
Pos=877,444
Size=165,120
Collapsed=0
[Table][0x9D40AE32,17]
Column 0 Weight=1.0000
Column 1 Weight=1.0000
Column 2 Weight=1.0000
Column 3 Weight=1.0000
Column 4 Weight=1.0000
Column 5 Weight=1.0000
Column 6 Weight=1.0000
Column 7 Weight=1.0000
Column 8 Weight=1.0000
Column 9 Weight=1.0000
Column 10 Weight=1.0000
Column 11 Weight=1.0000
Column 12 Weight=1.0000
Column 13 Weight=1.0000
Column 14 Weight=1.0000
Column 15 Weight=1.0000
Column 16 Weight=1.0000
[Docking][Data]
DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=0,71 Size=1920,941 Split=X
DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1602,1036 Split=X
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=300,1036 Split=Y Selected=0x1E6EB881
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,147 Selected=0x1E6EB881
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=225,863 Selected=0xE096E5AE
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1300,1036 Split=Y Selected=0xB41284E7
DockNode ID=0x00000007 Parent=0x00000002 SizeRef=1501,672 Split=Y Selected=0xB41284E7
DockNode ID=0x00000009 Parent=0x00000007 SizeRef=1501,700 Split=Y Selected=0xB41284E7
DockNode ID=0x0000000B Parent=0x00000009 SizeRef=1501,836 CentralNode=1 Selected=0xB41284E7
DockNode ID=0x0000000C Parent=0x00000009 SizeRef=1501,103 Selected=0xB128252A
DockNode ID=0x0000000A Parent=0x00000007 SizeRef=1501,310 Selected=0xD446F7B6
DockNode ID=0x00000008 Parent=0x00000002 SizeRef=1501,338 Selected=0xD9F31532
DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=316,1036 Selected=0xE7039252

View File

@ -1,6 +1,6 @@
- VertexShader: 46580970
FragmentShader: 35983630
SubPass: G-Buffer Write
SubPass: UI
Properties:
data.color: {x: 1, y: 1, z: 1, w: 1}
data.textureIndex: 54324293

View File

@ -1,6 +1,6 @@
- VertexShader: 46580970
FragmentShader: 35983630
SubPass: G-Buffer Write
SubPass: UI
Properties:
data.color: {x: 1, y: 1, z: 1, w: 1}
data.textureIndex: 54429632

View File

@ -1,6 +1,6 @@
- VertexShader: 46580970
FragmentShader: 35983630
SubPass: G-Buffer Write
SubPass: UI
Properties:
data.color: {x: 1, y: 1, z: 1, w: 1}
data.textureIndex: 57302694

View File

@ -33,18 +33,11 @@ layout (std430, set = 2, binding = 0) buffer MaterialProperties // For mater
MatPropData data[];
} MatProp;
layout(location = 0) out vec4 position;
layout(location = 0) out vec4 fragColor;
layout(location = 1) out uint outEntityID;
layout(location = 2) out uint lightLayerIndices;
layout(location = 3) out vec4 normals;
layout(location = 4) out vec4 albedo;
void main()
{
position = In.vertPos;
normals = In.normal;
albedo = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv);
fragColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv);
outEntityID = In2.eid;
lightLayerIndices = In2.lightLayerIndex;
}

Binary file not shown.

View File

@ -27,6 +27,7 @@
#include "Libraries/Compilers/SHShaderSourceCompiler.h"
#include "Filesystem/SHFileSystem.h"
#include <rttr/registration.h>
namespace SHADE
{
@ -733,3 +734,25 @@ namespace SHADE
}
}
}
namespace rttr
{
using namespace SHADE;
RTTR_REGISTRATION
{
registration::enumeration<AssetType>("Asset Type")
(
value("Invalid", AssetType::INVALID),
value("Shader", AssetType::SHADER),
value("Shader [Built-In]", AssetType::SHADER_BUILT_IN),
value("Texture", AssetType::TEXTURE),
value("Model", AssetType::MODEL),
value("Scene", AssetType::SCENE),
value("Prefab", AssetType::PREFAB),
value("Material", AssetType::MATERIAL),
value("Mesh", AssetType::MESH),
value("Script", AssetType::SCRIPT),
value("Font", AssetType::FONT)
);
}
}

View File

@ -314,7 +314,7 @@ namespace SHADE
camera.orthoProjMatrix(3, 3) = 1.0f;
//camera.perspProjMatrix = SHMatrix::OrthographicLH(9.0f, 9.0f, 0.1f, 20.0f);
camera.orthoProjMatrix = SHMatrix::OrthographicRH(camera.GetWidth(), camera.GetHeight(), camera.GetNear(), camera.GetFar());
//camera.orthoProjMatrix = SHMatrix::OrthographicLH(camera.GetWidth(), camera.GetHeight(), camera.GetNear(), camera.GetFar());
//camera.perspProjMatrix = SHMatrix::OrthographicLH(5.0f, 5.0f, 0.1f, 20.0f);
//camera.projMatrix.Transpose();

View File

@ -16,6 +16,9 @@
#include "Editor/EditorWindow/SHEditorWindowManager.h"
#include "Scripting/SHVSUtilities.h"
#include "Scripting/SHScriptEngine.h"
#include "Tools/Utilities/SHStringUtilities.h"
#include <filesystem>
#include <rttr/type>
namespace SHADE
{
@ -27,6 +30,13 @@ namespace SHADE
void SHAssetBrowser::Init()
{
SHEditorWindow::Init();
rttr::array_range<rttr::string_view> typeNames = typeEnumAlign.get_names();
for(auto const& name : typeNames)
{
uint64_t val = typeEnumAlign.name_to_value(name).to_uint64();
typeFilters[val] = true;
}
}
void SHAssetBrowser::Update()
@ -34,7 +44,10 @@ namespace SHADE
SHEditorWindow::Update();
if (Begin())
{
RecursivelyDrawTree(rootFolder);
for(auto subFolder : rootFolder->subFolders)
{
RecursivelyDrawTree(subFolder);
}
DrawMenuBar();
DrawCurrentFolder();
DrawAssetBeingCreated();
@ -50,6 +63,11 @@ namespace SHADE
refreshQueued = true;
}
void SHAssetBrowser::SetScrollTo(AssetID assetid)
{
assetToScrollTo = assetid;
}
void SHAssetBrowser::Refresh() noexcept
{
SHAssetManager::RefreshDirectory();
@ -69,6 +87,7 @@ namespace SHADE
{
isAssetBeingCreated = true;
}
DrawAssetBrowserFilter();
ImGui::EndMenuBar();
}
}
@ -81,13 +100,34 @@ namespace SHADE
auto files = folder->files;
const bool isSelected = std::ranges::find(selectedFolders, folder) != selectedFolders.end();
ImGuiTreeNodeFlags flags = (subFolders.empty() && files.empty()) ? ImGuiTreeNodeFlags_Leaf : ImGuiTreeNodeFlags_OpenOnArrow;
if(!filter.empty() && (!subFolders.empty() || !files.empty()))
{
ImGui::SetNextItemOpen(true);
}
if (isSelected)
flags |= ImGuiTreeNodeFlags_Selected;
if (folder == rootFolder)
flags |= ImGuiTreeNodeFlags_DefaultOpen;
bool isOpen = ImGui::TreeNodeEx(folder, flags, "%s %s", ICON_MD_FOLDER, folder->name.data());
ImGuiID folderID = ImGui::GetItemID();
if(assetToScrollTo != 0)
{
if(auto asset = SHAssetManager::GetAsset(assetToScrollTo))
{
if(!asset->path.empty())
{
ImGui::SetNextItemOpen(SHStringUtilities::StringFindInsensitive(asset->path.string(), folder->name.data()) != std::string::npos);
}
else if(auto parent = SHAssetManager::GetAsset(asset->parent))
{
ImGui::SetNextItemOpen(SHStringUtilities::StringFindInsensitive(parent->path.string(), folder->name.data()) != std::string::npos);
}
}
}
bool isOpen = false;
if(filter.empty())
isOpen = ImGui::TreeNodeEx(folder, flags, "%s %s", ICON_MD_FOLDER, folder->name.data());
const ImRect nodeRect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
//if (ImGui::BeginPopupContextItem())
@ -101,7 +141,7 @@ namespace SHADE
selectedFolders.push_back(folder);
}
if (isOpen)
if (isOpen || !filter.empty())
{
const ImColor treeLineColor = ImGui::GetColorU32(ImGuiCol_CheckMark);
const float horizontalOffset = 0.0f;
@ -127,7 +167,8 @@ namespace SHADE
}
drawList->AddLine(vertLineStart, vertLineEnd, treeLineColor, 1);
ImGui::TreePop();
if(filter.empty())
ImGui::TreePop();
}
return nodeRect;
}
@ -167,8 +208,26 @@ namespace SHADE
{
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_Leaf;
static constexpr std::string_view icon = ICON_MD_FILE_PRESENT;
bool highlighted = false;
if (!filter.empty())
{
if (SHStringUtilities::StringFindInsensitive(file.name.data(), filter) == std::string::npos)
{
return ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
}
else
{
highlighted = true;
ImGui::PushStyleColor(ImGuiCol_Text, highlightedColor);
}
}
ImGui::PushID(file.name.data());
bool const isOpen = ImGui::TreeNodeEx(file.name.data(), flags, "%s %s%s", icon.data(), file.name.data(), file.ext.data());
if(highlighted)
{
ImGui::PopStyleColor();
}
const ImRect nodeRect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
if(ImGui::BeginPopupContextItem())
{
@ -194,6 +253,27 @@ namespace SHADE
{
if (asset == nullptr)
return ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
if (!typeFilters[static_cast<uint64_t>(asset->type)])
{
return ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
}
bool highlighted = false;
if(!filter.empty())
{
ImGui::SetNextItemOpen(true);
if(SHStringUtilities::StringFindInsensitive(asset->name.data(), filter) == std::string::npos)
{
return ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
}
else
{
highlighted = true;
ImGui::PushStyleColor(ImGuiCol_Text, highlightedColor);
}
}
const bool isSelected = std::ranges::find(selectedAssets, asset->id) != selectedAssets.end();
ImGuiTreeNodeFlags flags = (!asset->subAssets.empty()) ? ImGuiTreeNodeFlags_OpenOnArrow : ImGuiTreeNodeFlags_Leaf;
if (isSelected)
@ -214,8 +294,34 @@ namespace SHADE
case AssetType::MAX_COUNT: break;
default:;
}
if(assetToScrollTo != 0)
{
if(asset->id == assetToScrollTo)
{
ImGui::SetScrollHereY();
selectedAssets.clear();
selectedAssets.push_back(asset->id);
assetToScrollTo = 0;
}
else
{
for (auto const& subAsset : asset->subAssets)
{
if(subAsset->id == assetToScrollTo)
{
ImGui::SetNextItemOpen(true);
}
}
}
}
bool const isOpen = ImGui::TreeNodeEx(asset, flags, "%s %s%s", icon.data(), asset->name.data(), ext.data());
if(highlighted)
{
ImGui::PopStyleColor();
}
const ImRect nodeRect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
if (SHDragDrop::BeginSource())
{
@ -339,4 +445,43 @@ namespace SHADE
// QueueRefresh();
//}
}
void SHAssetBrowser::DrawAssetBrowserFilter()
{
if (ImGui::InputTextWithHint("##hierarchyPanelFilter", "Filter", &filter))
{
}
if (ImGui::Button("x"))
{
filter.clear();
}
if(ImGui::BeginMenu("Type"))
{
if (ImGui::Button("All"))
{
for (auto& [id, value] : typeFilters)
value = true;
}
ImGui::SameLine();
if (ImGui::Button("None"))
{
for (auto& [id, value] : typeFilters)
value = false;
}
for (auto& [id, value] : typeFilters)
{
if(ImGui::Checkbox(typeEnumAlign.value_to_name(id).data(), &value))
{
}
if(ImGui::IsItemClicked(ImGuiMouseButton_Right))
{
for (auto& [id2, value2] : typeFilters)
value2 = false;
value = true;
}
}
ImGui::EndMenu();
}
}
}

View File

@ -4,18 +4,21 @@
#include "Assets/SHAsset.h"
#include "Editor/EditorWindow/SHEditorWindow.h"
#include "Filesystem/SHFolder.h"
#include <rttr/enumeration.h>
namespace SHADE
{
class SHAssetBrowser final : public SHEditorWindow
{
public:
static constexpr ImVec4 highlightedColor = ImVec4(0.f, 0.7f, 0.0f, 1.0f);
SHAssetBrowser();
void Init();
void Update();
void QueueRefresh() noexcept;
void SetScrollTo(AssetID assetid);
private:
void DrawMenuBar();
ImRect RecursivelyDrawTree(FolderPointer folder);
@ -23,6 +26,7 @@ namespace SHADE
ImRect DrawFile(SHFile& file) noexcept;
ImRect DrawAsset(SHAsset const* const asset, FileExt const& ext = "") noexcept;
void DrawAssetBeingCreated() noexcept;
void DrawAssetBrowserFilter();
void Refresh() noexcept;
@ -30,9 +34,13 @@ namespace SHADE
std::vector<FolderPointer> selectedFolders;
std::vector<AssetID> selectedAssets;
static constexpr float tileWidth = 50.0f;
static constexpr std::string_view newAssetPopup = "Create New Asset";
std::string nameOfAssetBeingCreated, filter;
rttr::enumeration typeEnumAlign = rttr::type::get<AssetType>().get_enumeration();
std::unordered_map<uint64_t, bool> typeFilters;
AssetID assetToScrollTo = 0;
bool refreshQueued = false;
bool isAssetBeingCreated = false;
static constexpr std::string_view newAssetPopup = "Create New Asset";
std::string nameOfAssetBeingCreated;
};
}

View File

@ -15,11 +15,11 @@
namespace SHADE
{
class SHSceneNode;
constexpr ImVec4 highlightedColor = ImVec4(0.f, 0.7f, 0.0f, 1.0f);
class SHHierarchyPanel final : public SHEditorWindow
{
public:
static constexpr ImVec4 highlightedColor = ImVec4(0.f, 0.7f, 0.0f, 1.0f);
SHHierarchyPanel();
void Init() override;
void Update() override;

View File

@ -24,6 +24,8 @@
#include "SHInspectorCommands.h"
#include "Physics/Collision/SHCollisionTagMatrix.h"
#include "Animation/SHAnimatorComponent.h"
#include "../SHEditorWindowManager.h"
#include "../AssetBrowser/SHAssetBrowser.h"
namespace SHADE
{
template<typename T>
@ -502,6 +504,15 @@ namespace SHADE
SHResourceManager::FinaliseChanges();
}, SHDragDrop::DRAG_RESOURCE);
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{
if(Handle<SHMesh> const& mesh = component->GetMesh())
{
AssetID assetID = SHResourceManager::GetAssetID<SHMesh>(mesh).value_or(0);
SHEditorWindowManager::GetEditorWindow<SHAssetBrowser>()->SetScrollTo(assetID);
}
}
const auto MAT_NAME = mat ? SHResourceManager::GetAssetName<SHMaterial>(mat->GetBaseMaterial()).value_or("") : "";
SHEditorWidgets::DragDropReadOnlyField<AssetID>("Material", MAT_NAME,
[component]()
@ -521,6 +532,15 @@ namespace SHADE
auto gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
component->SetMaterial(gfxSystem->AddOrGetBaseMaterialInstance(SHResourceManager::LoadOrGet<SHMaterial>(id)));
}, SHDragDrop::DRAG_RESOURCE);
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{
if(Handle<SHMaterialInstance> const& mat = component->GetMaterial())
{
AssetID assetID = SHResourceManager::GetAssetID<SHMaterial>(mat->GetBaseMaterial()).value_or(0);
SHEditorWindowManager::GetEditorWindow<SHAssetBrowser>()->SetScrollTo(assetID);
}
}
}
else
{
@ -558,7 +578,14 @@ namespace SHADE
component->SetFont(SHResourceManager::LoadOrGet<SHFont>(id));
SHResourceManager::FinaliseChanges();
}, SHDragDrop::DRAG_RESOURCE);
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{
if (Handle<SHFont> const& font = component->GetFont())
{
AssetID assetID = SHResourceManager::GetAssetID<SHFont>(font).value_or(0);
SHEditorWindowManager::GetEditorWindow<SHAssetBrowser>()->SetScrollTo(assetID);
}
}
SHEditorWidgets::InputText("Text",
[component](void)
{
@ -606,7 +633,14 @@ namespace SHADE
component->SetRig(SHResourceManager::LoadOrGet<SHRig>(id));
SHResourceManager::FinaliseChanges();
}, SHDragDrop::DRAG_RESOURCE);
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{
if (Handle<SHRig> const& rig = component->GetRig())
{
AssetID assetID = SHResourceManager::GetAssetID<SHRig>(rig).value_or(0);
SHEditorWindowManager::GetEditorWindow<SHAssetBrowser>()->SetScrollTo(assetID);
}
}
Handle<SHAnimationClip> const& clip = component->GetCurrentClip();
const auto CLIP_NAME = clip ? SHResourceManager::GetAssetName<SHAnimationClip>(clip).value_or("") : "";
SHEditorWidgets::DragDropReadOnlyField<AssetID>("Clip", CLIP_NAME,
@ -624,6 +658,14 @@ namespace SHADE
}
component->SetClip(SHResourceManager::LoadOrGet<SHAnimationClip>(id));
}, SHDragDrop::DRAG_RESOURCE);
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{
if (Handle<SHAnimationClip> const& clip = component->GetCurrentClip())
{
AssetID assetID = SHResourceManager::GetAssetID<SHAnimationClip>(clip).value_or(0);
SHEditorWindowManager::GetEditorWindow<SHAssetBrowser>()->SetScrollTo(assetID);
}
}
}
else
{

View File

@ -1,8 +1,11 @@
#include "SHpch.h"
#include <memory>
#include <imgui.h>
#include "Serialization/SHSerializationHelper.hpp"
#include "SHMaterialInspector.h"
#include "Editor/SHImGuiHelpers.hpp"
#include <imgui.h>
#include "Assets/SHAssetManager.h"
#include "Editor/IconsMaterialDesign.h"
@ -89,11 +92,17 @@ namespace SHADE
if (vertShader && fragShader && gfxSystem)
{
// - Retrieve pipeline from pipeline library
auto renderPass = gfxSystem->GetPrimaryRenderpass();
auto subPass = renderPass->GetSubpass(currentMatSpec->subpassName);
auto pipeline = renderPass->GetOrCreatePipeline({ vertShader, fragShader }, subPass);
// - Set Pipeline
matHandle->SetPipeline(pipeline);
auto subPass = gfxSystem->GetUsableSubpass(currentMatSpec->subpassName);
if (subPass)
{
// Set Pipeline if valid
auto pipeline = subPass->GetParentNode()->GetOrCreatePipeline({vertShader, fragShader}, subPass);
matHandle->SetPipeline(pipeline);
}
else
{
SHLOG_ERROR("[SHMaterialInspector] Failed to find material subpass of type \"{}\"", currentMatSpec->subpassName);
}
}
}
@ -176,7 +185,7 @@ namespace SHADE
const std::string VERT_SHADER_NAME = VERT_SHADER_INFO ? VERT_SHADER_INFO->name : "Unknown Shader";
isDirty |= SHEditorWidgets::DragDropReadOnlyField<AssetID>
(
"Fragment Shader", VERT_SHADER_NAME.data(),
"Vertex Shader", VERT_SHADER_NAME.data(),
[this]() { return currentMatSpec->vertexShader; },
[this](const AssetID& id) { currentMatSpec->vertexShader = id; },
SHDragDrop::DRAG_RESOURCE
@ -191,6 +200,37 @@ namespace SHADE
SHDragDrop::DRAG_RESOURCE
);
// Subpass
const auto& SP_NAMES = SHGraphicsConstants::RenderGraphEntityNames::USABLE_SUBPASSES;
ImGui::Text("Subpass");
ImGui::SameLine();
if (ImGui::BeginCombo("##", currentMatSpec->subpassName.data(), ImGuiComboFlags_None))
{
for (const auto& NAME : SP_NAMES)
{
const bool IS_SELECTED = currentMatSpec->subpassName == NAME;
if (ImGui::Selectable(NAME.data(), IS_SELECTED))
{
isDirty = true;
SHCommandManager::PerformCommand
(
std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<std::string>>
(
currentMatSpec->subpassName,
std::string(NAME),
[&](const std::string& newName){ currentMatSpec->subpassName = newName; }
)),
false
);
}
if (IS_SELECTED)
{
ImGui::SetItemDefaultFocus();
}
}
ImGui::EndCombo();
}
// Load the shader to access it's data
auto fragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(currentMatSpec->fragShader);
if (!fragShader)

View File

@ -96,8 +96,10 @@ namespace SHADE
SHLOG_CRITICAL("Failed to create ImGui Context")
}
}
#ifdef SHEDITOR
editorConfig = &SHConfigurationManager::LoadEditorConfig();
#endif
//Add editor windows
SHEditorWindowManager::CreateEditorWindow<SHEditorMenuBar>();
@ -131,8 +133,9 @@ namespace SHADE
InitBackend();
#ifdef SHEDITOR
SetStyle(static_cast<Style>(editorConfig->style));
#endif // SHEDITOR
for (const auto& window : SHEditorWindowManager::editorWindows | std::views::values)
{
@ -340,13 +343,18 @@ namespace SHADE
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
#ifdef SHEDITOR
editorConfig->startMaximized = shWindow->GetWindowData().isMaximised;
SHConfigurationManager::SaveEditorConfig();
#endif // SHEDITOR
}
void SHEditor::SetStyle(Style style)
{
#ifdef SHEDITOR
editorConfig->style = static_cast<uint32_t>(style);
#endif // SHEDITOR
switch (style)
{
default:
@ -550,7 +558,10 @@ namespace SHADE
SHSceneManager::SetCurrentSceneName(newSceneName);
SHSceneManager::SetCurrentSceneAssetID(SHAssetManager::CreateNewAsset(AssetType::SCENE, newSceneName));
#ifdef SHEDITOR
editorConfig->workingSceneID = SHSceneManager::GetCurrentSceneAssetID();
#endif // SHEDITOR
}
//Get data, if data is null, asset doesn't exist, prompt for a name and create a new asset with the name
@ -559,7 +570,10 @@ namespace SHADE
{
if(shWindow->IsUnsavedChanges())
shWindow->ToggleUnsavedChanges();
#ifdef SHEDITOR
editorConfig->workingSceneID = SHSceneManager::GetCurrentSceneAssetID();
#endif // SHEDITOR
return true;
}
return false;
@ -624,7 +638,11 @@ namespace SHADE
editorState = SHEditor::State::STOP;
SHCommandManager::SwapStacks();
SHEventManager::BroadcastEvent<SHEditorStateChangeEvent>(STATE_CHANGE_EVENT, SH_EDITOR_ON_STOP_EVENT);
#ifdef SHEDITOR
LoadScene(editorConfig->workingSceneID);
#endif // SHEDITOR
}
void SHEditor::ProcessShortcuts()
@ -679,7 +697,9 @@ namespace SHADE
if(width > 0 && height > 0)
{
auto [width, height] = shWindow->GetWindowSize();
#ifdef SHEditor
editorConfig->windowSize = { static_cast<float>(width), static_cast<float>(height) };
#endif // SHEditor
}
});
}

View File

@ -127,8 +127,9 @@ namespace SHADE
std::vector<EntityID> selectedEntities;
State editorState = State::STOP;
#ifdef SHEDITOR
SHEditorConfig* editorConfig;
#endif // SHEDITOR
private:
/**

View File

@ -98,9 +98,9 @@ namespace SHADE
static bool IsItemHovered();
/*-----------------------------------------------------------------------------*/
/* ImGui Wrapper Functions - Menu */
/*-----------------------------------------------------------------------------*/
static bool BeginMenu(const std::string& label);
/* ImGui Wrapper Functions - Menu */
/*-----------------------------------------------------------------------------*/
static bool BeginMenu(const std::string& label);
static bool BeginMenu(const std::string& label, const char* icon);
static void EndMenu();
static void BeginTooltip();
@ -164,8 +164,8 @@ namespace SHADE
/// </summary>
/// <param name="title">Text to display.</param>
/// <returns>True if button was pressed.</returns>
static bool Button(const std::string& title);
static bool Selectable(const std::string& label);
static bool Button(const std::string& title);
static bool Selectable(const std::string& label);
static bool Selectable(const std::string& label, const char* icon);
/// <summary>
/// Creates a checkbox widget for boolean input.

View File

@ -424,7 +424,7 @@ namespace SHADE
ImGui::BeginGroup();
ImGui::PushID(label.data());
TextLabel(label);
bool changed = ImGui::InputText("##inputText", &text, ImGuiInputTextFlags_ReadOnly, nullptr, nullptr);
bool changed = ImGui::InputText("##inputText", &text, ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_AutoSelectAll, nullptr, nullptr);
if(SHDragDrop::BeginTarget())
{
if(T* payload = SHDragDrop::AcceptPayload<T>(dragDropTag))

View File

@ -10,6 +10,7 @@ namespace SHADE
enum class SH_PHYSICAL_DEVICE_TYPE
{
BEST,
DEDICATED,
};
class SHVkPhysicalDevice

View File

@ -160,9 +160,31 @@ namespace SHADE
}
}
return bestDevice;
}
vk::PhysicalDevice SHVkPhysicalDeviceLibrary::GetFirstDedicatedDevice(uint32_t apiVersion /*= SHVulkanAPIVersion::V_1_2*/)
{
if (!queried || physicalDevices.empty())
return nullptr;
for (auto const& device : physicalDevices)
{
// Check for API version and device type. Ignore if queried device doesn't support version passed in
if (device.getProperties().apiVersion < static_cast<uint32_t>(apiVersion))
continue;
//VkDeviceSize biggestDeviceHeapSize = device.getMemoryProperties().;
if (device.getProperties().deviceType == vk::PhysicalDeviceType::eDiscreteGpu)
return device;
}
return nullptr;
}
/***************************************************************************/
/*!
@ -181,10 +203,10 @@ namespace SHADE
}
#ifdef DEBUG
SHLOG_TRACE("Successfully queried Physical Devices:");
SHLOG_INFO("Successfully queried Physical Devices:");
for (auto const& device : physicalDevices)
{
SHLOG_TRACE(std::string_view (std::string("\t-") + GetDeviceTypeName(device.getProperties().deviceType) + device.getProperties().deviceName.operator std::string()));
SHLOG_INFO(std::string_view (std::string("\t-") + GetDeviceTypeName(device.getProperties().deviceType) + device.getProperties().deviceName.operator std::string()));
}
#endif

View File

@ -26,6 +26,7 @@ namespace SHADE
static void QueryPhysicalDevices(bool printInfo) noexcept;
//static std::vector<std::shared_ptr<SHPhysicalDevice>> GetDevicesByType(VkPhysicalDeviceType gpuType, SHVulkanAPIVersion apiVersion = SHVulkanAPIVersion::V_1_2) noexcept;
static vk::PhysicalDevice GetBestDevice(uint32_t apiVersion = VK_API_VERSION_1_3);
static vk::PhysicalDevice GetFirstDedicatedDevice(uint32_t apiVersion = VK_API_VERSION_1_3);
};
}

View File

@ -213,6 +213,8 @@ namespace SHADE
{
case SH_PHYSICAL_DEVICE_TYPE::BEST:
return resourceManager.Create<SHVkPhysicalDevice>(SHVkPhysicalDeviceLibrary::GetBestDevice());
case SH_PHYSICAL_DEVICE_TYPE::DEDICATED:
return resourceManager.Create<SHVkPhysicalDevice>(SHVkPhysicalDeviceLibrary::GetFirstDedicatedDevice());
default:
return resourceManager.Create<SHVkPhysicalDevice>(SHVkPhysicalDeviceLibrary::GetBestDevice());
}

View File

@ -13,6 +13,7 @@ of DigiPen Institute of Technology is prohibited.
// STL Includes
#include <cstdint>
#include <string>
namespace SHADE
{
@ -114,7 +115,14 @@ namespace SHADE
static constexpr std::string_view DEFERRED_COMPOSITE_COMPUTE = "Deferred Composite";
static constexpr std::string_view GBUFFER_WRITE_SUBPASS = "G-Buffer Write";
static constexpr std::string_view UI_SUBPASS = "UI";
static constexpr std::array USABLE_SUBPASSES =
{
GBUFFER_WRITE_SUBPASS,
UI_SUBPASS
};
};
struct DescriptorSetBindings

View File

@ -65,7 +65,7 @@ namespace SHADE
#endif
// Get Physical Device
physicalDevice = SHVkInstance::CreatePhysicalDevice(SH_PHYSICAL_DEVICE_TYPE::BEST);
physicalDevice = SHVkInstance::CreatePhysicalDevice(SH_PHYSICAL_DEVICE_TYPE::DEDICATED);
if (!physicalDevice->GetVkPhysicalDevice())
{
throw std::runtime_error("[Graphics System] No supported Vulkan 1.3 compatible GPU was detected!");
@ -133,6 +133,9 @@ namespace SHADE
//SHAssetManager::CompileAsset("../../Assets/Shaders/PureCopy_CS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_VS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_FS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/UI_VS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/UI_FS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/Text_VS.glsl", false);
// Load Built In Shaders
static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEFAULT);
@ -232,7 +235,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/
/* G-BUFFER SUBPASS INIT */
/*-----------------------------------------------------------------------*/
auto gBufferSubpass = gBufferNode->AddSubpass("G-Buffer Write", worldViewport, worldRenderer);
auto gBufferSubpass = gBufferNode->AddSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_SUBPASS.data(), worldViewport, worldRenderer);
gBufferSubpass->AddColorOutput("Position");
gBufferSubpass->AddColorOutput("Entity ID");
gBufferSubpass->AddColorOutput("Light Layer Indices");
@ -241,6 +244,7 @@ namespace SHADE
gBufferSubpass->AddColorOutput("Position World Space");
gBufferSubpass->AddDepthOutput("Depth Buffer", SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL);
usableSubpassesMapping.emplace (std::string (SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_SUBPASS.data()), gBufferSubpass);
/*-----------------------------------------------------------------------*/
/* SSAO PASS AND DATA INIT */
@ -319,7 +323,7 @@ namespace SHADE
/* SCREEN SPACE PASS */
/*-----------------------------------------------------------------------*/
auto screenSpaceNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS.data(), {"Scene", "Entity ID"}, {SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data(), SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data(), SHGraphicsConstants::RenderGraphEntityNames::DEBUG_DRAW.data()});
auto uiSubpass = screenSpaceNode->AddSubpass("UI", worldViewport, screenRenderer);
auto uiSubpass = screenSpaceNode->AddSubpass(SHGraphicsConstants::RenderGraphEntityNames::UI_SUBPASS.data(), worldViewport, screenRenderer);
uiSubpass->AddColorOutput("Scene");
uiSubpass->AddColorOutput("Entity ID");
uiSubpass->AddExteriorDrawCalls([=](Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHRenderer> renderer, uint32_t frameIndex)
@ -327,6 +331,8 @@ namespace SHADE
textRenderingSubSystem->Render(cmdBuffer, renderer, frameIndex);
});
usableSubpassesMapping.emplace(SHGraphicsConstants::RenderGraphEntityNames::UI_SUBPASS.data(), uiSubpass);
/*-----------------------------------------------------------------------*/
/* RENDER TO SWAPCHAIN IMAGE FOR PRESENT PASS */
/*-----------------------------------------------------------------------*/
@ -416,12 +422,12 @@ namespace SHADE
.addressMode = vk::SamplerAddressMode::eClampToBorder,
})
);
textRenderingSubSystem = resourceManager.Create<SHTextRenderingSubSystem>();
// initialize the text renderer
auto uiNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS.data());
textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS);
textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::UI_SUBPASS), descPool, textVS, textFS);
SHGlobalDescriptorSets::SetLightingSubSystem(lightingSubSystem);
@ -448,7 +454,7 @@ namespace SHADE
defaultMaterial = AddMaterial
(
defaultVertShader, defaultFragShader,
renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass("G-Buffer Write")
renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_SUBPASS)
);
defaultMaterial->SetProperty("data.textureIndex", defaultTexture->TextureArrayIndex);
defaultAnimMaterial = AddMaterial
@ -573,7 +579,7 @@ namespace SHADE
else
renderer->UpdateData(frameIndex);
#else
renderers[renIndex]->UpdateDataAndBind(frameIndex);
renderer->UpdateData(frameIndex);
#endif
}
@ -589,16 +595,8 @@ namespace SHADE
renderGraph->Begin(frameIndex);
auto cmdBuffer = renderGraph->GetCommandBuffer(frameIndex);
// Bind all the buffers required for meshes
for (auto& [buffer, bindingPoint] : MESH_DATA)
{
if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eVertexBuffer)
cmdBuffer->BindVertexBuffer(bindingPoint, buffer, 0);
else if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eIndexBuffer)
cmdBuffer->BindIndexBuffer(buffer, 0);
}
renderGraph->Execute(frameIndex, descPool);
renderGraph->Execute(frameIndex, descPool, MESH_DATA);
renderGraph->End(frameIndex);
graphicsQueue->SubmitCommandBuffer
@ -774,7 +772,7 @@ namespace SHADE
auto const& EVENT_DATA = reinterpret_cast<const SHEventSpec<SHLightEnableShadowEvent>*>(eventPtr.get())->data;
auto* lightComp = SHComponentManager::GetComponent<SHLightComponent>(EVENT_DATA->lightEntity);
std::string resourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity);
Handle<SHSubpass> companionSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass("G-Buffer Write");
Handle<SHSubpass> companionSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_SUBPASS);
if (EVENT_DATA->generateRenderer)
{
@ -1196,6 +1194,16 @@ namespace SHADE
return fontLibrary;
}
Handle <SHSubpass> SHGraphicsSystem::GetUsableSubpass(std::string const& subpassName) const noexcept
{
if (usableSubpassesMapping.contains(subpassName))
{
return usableSubpassesMapping.at (subpassName);
}
else
return {};
}
Handle<SHVkPipeline> SHGraphicsSystem::createDebugDrawPipeline(Handle<SHVkRenderpass> renderPass, Handle<SHSubpass> subpass, bool filled, bool triMesh, bool instanced)
{
auto pipelineLayout = resourceManager.Create<SHVkPipelineLayout>

View File

@ -399,6 +399,7 @@ namespace SHADE
uint32_t GetCurrentFrameIndex(void) const noexcept { return renderContext.GetCurrentFrame(); }
SHFontLibrary const& GetFontLibrary (void) const noexcept;
const SHMeshLibrary& GetMeshLibrary() const noexcept { return meshLibrary; };
Handle <SHSubpass> GetUsableSubpass(std::string const& subpassName) const noexcept;
/*-----------------------------------------------------------------------------*/
/* Getters */
@ -509,6 +510,8 @@ namespace SHADE
uint32_t resizeHeight = 1;
bool restoredFromMinimize = false;
std::unordered_map<std::string, Handle<SHSubpass>> usableSubpassesMapping{};
/*---------------------------------------------------------------------------------*/
/* Helper Functions */
/*---------------------------------------------------------------------------------*/

View File

@ -565,7 +565,7 @@ namespace SHADE
// TODO: The graph scope buffers were meant to bind vertex buffers and index buffers for meshes. Find a
// better way to manage these
void SHRenderGraph::Execute(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool) noexcept
void SHRenderGraph::Execute(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool, const std::initializer_list<std::pair<Handle<SHVkBuffer>, uint32_t>> MESH_DATA) noexcept
{
auto cmdBuffer = commandBuffers[frameIndex];
cmdBuffer->BeginLabeledSegment(name);
@ -577,6 +577,7 @@ namespace SHADE
cmdBuffer->ForceSetPipelineLayout(batchingSystemData.dummyPipelineLayout, SH_PIPELINE_TYPE::COMPUTE);
auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING);
for (auto& node : nodes)
{
@ -585,6 +586,15 @@ namespace SHADE
// bind static global data
SHGlobalDescriptorSets::BindStaticGlobalData(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.at(SHPredefinedDescriptorTypes::STATIC_DATA));
// Bind all the buffers required for meshes
for (auto& [buffer, bindingPoint] : MESH_DATA)
{
if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eVertexBuffer)
cmdBuffer->BindVertexBuffer(bindingPoint, buffer, 0);
else if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eIndexBuffer)
cmdBuffer->BindIndexBuffer(buffer, 0);
}
node->Execute(cmdBuffer, descPool, frameIndex);
}
}

View File

@ -143,7 +143,7 @@ namespace SHADE
void Generate (void) noexcept;
void CheckForNodeComputes (void) noexcept;
void Execute (uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool) noexcept;
void Execute (uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool, const std::initializer_list<std::pair<Handle<SHVkBuffer>, uint32_t>> MESH_DATA) noexcept;
void Begin (uint32_t frameIndex) noexcept;
void End (uint32_t frameIndex) noexcept;
void FinaliseBatch (uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool);

View File

@ -474,7 +474,7 @@ namespace SHADE
*/
/***************************************************************************/
Handle<SHRenderGraphNode> const& SHSubpass::GetParentNode(void) const noexcept
Handle<SHRenderGraphNode> SHSubpass::GetParentNode(void) const noexcept
{
return parentNode;
}

View File

@ -159,7 +159,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/
void SetCompanionSubpass (Handle<SHSubpass> companion, Handle<SHVkPipeline> pipeline) noexcept;
Handle<SHRenderGraphNode> const& GetParentNode(void) const noexcept;
Handle<SHRenderGraphNode> GetParentNode(void) const noexcept;
SHSubPassIndex GetIndex() const noexcept;
Handle<SHSuperBatch> GetSuperBatch(void) const noexcept;
std::vector<vk::AttachmentReference> const& GetColorAttachmentReferences (void) const noexcept;

View File

@ -280,14 +280,8 @@ namespace SHADE
return {};
}
// Grab subpass from worldRenderer
auto renderPass = gfxSystem->GetPrimaryRenderpass();
if (!renderPass)
{
SHLOG_ERROR("[SHResourceManager] Failed to load material as RenderPass could not be found.");
return {};
}
auto subPass = renderPass->GetSubpass(assetData.subpassName);
// Grab subpass
auto subPass = gfxSystem->GetUsableSubpass(assetData.subpassName);
if (!subPass)
{
SHLOG_ERROR("[SHResourceManager] Failed to load material as SubPass could not be found.");

View File

@ -182,7 +182,7 @@ namespace SHADE
mousePos.x = x;
mousePos.y = y;
auto ws = SHSystemManager::GetSystem<SHGraphicsSystem>()->GetWindow()->GetWindowSize();
windowSize = { ws.first,ws.second };
windowSize = { static_cast<float>(ws.first), static_cast<float>(ws.second) };
mousePos /= windowSize;
#endif
@ -300,7 +300,7 @@ namespace SHADE
mousePos.x = x;
mousePos.y = y;
auto ws = SHSystemManager::GetSystem<SHGraphicsSystem>()->GetWindow()->GetWindowSize();
windowSize = { ws.first,ws.second };
windowSize = { static_cast<float>(ws.first), static_cast<float>(ws.second) };
mousePos /= windowSize;
#endif