mat inspector properties handling (WIP)

This commit is contained in:
Sri Sham Haran 2022-11-01 21:49:42 +08:00
parent 26591e8c24
commit 129f92e4b6
3 changed files with 80 additions and 39 deletions

View File

@ -3,22 +3,22 @@
#include "Editor/SHImGuiHelpers.hpp" #include "Editor/SHImGuiHelpers.hpp"
#include <imgui.h> #include <imgui.h>
//#include "Assets/SHAssetManager.h" #include "Assets/SHAssetManager.h"
//#include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h" #include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h"
//#include "Editor/SHEditorWidgets.hpp" #include "Editor/SHEditorWidgets.hpp"
//#include "Resource/SHResourceManager.h" #include "Resource/SHResourceManager.h"
namespace SHADE namespace SHADE
{ {
SHMaterialInspector::SHMaterialInspector() SHMaterialInspector::SHMaterialInspector()
:SHEditorWindow("Material Inspector", ImGuiWindowFlags_MenuBar)//,isNewMaterial(false), currentViewedMaterial(0) :SHEditorWindow("Material Inspector", ImGuiWindowFlags_MenuBar), isNewMaterial(false), currentViewedMaterial(0)
{ {
} }
void SHMaterialInspector::OpenMaterial(AssetID const& assetId) noexcept void SHMaterialInspector::OpenMaterial(AssetID const& assetId) noexcept
{ {
//Get mat data //Get mat data
//isNewMaterial = false; isNewMaterial = false;
} }
void SHMaterialInspector::Init() void SHMaterialInspector::Init()
@ -30,30 +30,20 @@ namespace SHADE
{ {
SHEditorWindow::Update(); SHEditorWindow::Update();
//if(Begin()) if(Begin())
//{ {
// DrawMenuBar(); DrawMenuBar();
// if(SHEditorWidgets::DragDropReadOnlyField<AssetID>("Vertex Shader", std::to_string(currentMatSpec.vertexShader), [&](){return currentMatSpec.vertexShader;}, [&](AssetID const& id){currentMatSpec.vertexShader = id;}, SHDragDrop::DRAG_RESOURCE)) if(SHEditorWidgets::DragDropReadOnlyField<AssetID>("Vertex Shader", std::to_string(currentMatSpec.vertexShader), [&](){return currentMatSpec.vertexShader;}, [&](AssetID const& id){currentMatSpec.vertexShader = id;}, SHDragDrop::DRAG_RESOURCE))
// { {
// vertShaderHandle = SHResourceManager::LoadOrGet<SHVkShaderModule>(currentMatSpec.vertexShader); vertShaderHandle = SHResourceManager::LoadOrGet<SHVkShaderModule>(currentMatSpec.vertexShader);
// } }
// if(SHEditorWidgets::DragDropReadOnlyField<AssetID>("Fragment Shader", std::to_string(currentMatSpec.fragShader), [&](){return currentMatSpec.fragShader;}, [&](AssetID const& id){currentMatSpec.fragShader = id;}, SHDragDrop::DRAG_RESOURCE)) if(SHEditorWidgets::DragDropReadOnlyField<AssetID>("Fragment Shader", std::to_string(currentMatSpec.fragShader), [&](){return currentMatSpec.fragShader;}, [&](AssetID const& id){currentMatSpec.fragShader = id;}, SHDragDrop::DRAG_RESOURCE))
// { {
// fragShaderHandle = SHResourceManager::LoadOrGet<SHVkShaderModule>(currentMatSpec.fragShader); fragShaderHandle = SHResourceManager::LoadOrGet<SHVkShaderModule>(currentMatSpec.fragShader);
// } }
}
// auto vertInterface = vertShaderHandle->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA); ImGui::End();
// int const varCount = static_cast<int>(vertInterface->GetVariableCount());
//
// for(int i = 0; i < varCount; ++i)
// {
// auto variable = vertInterface->GetVariable(i);
// }
//}
//ImGui::End();
} }
void SHMaterialInspector::Exit() void SHMaterialInspector::Exit()
@ -63,12 +53,12 @@ namespace SHADE
void SHMaterialInspector::CreateNewMaterial() void SHMaterialInspector::CreateNewMaterial()
{ {
//isNewMaterial = true; isNewMaterial = true;
////prompt for a name //prompt for a name
//currentViewedMaterial = SHAssetManager::CreateNewAsset(AssetType::MATERIAL, "NewMaterial"); currentViewedMaterial = SHAssetManager::CreateNewAsset(AssetType::MATERIAL, "NewMaterial");
//currentMatSpec = {}; currentMatSpec = {};
//vertShaderHandle = {}; vertShaderHandle = {};
//fragShaderHandle = {}; fragShaderHandle = {};
} }
void SHMaterialInspector::DrawMenuBar() void SHMaterialInspector::DrawMenuBar()
@ -78,4 +68,50 @@ namespace SHADE
ImGui::EndMenuBar(); ImGui::EndMenuBar();
} }
} }
void SHMaterialInspector::DrawShaderProperties(Handle<SHVkShaderModule> shaderModule)
{
auto interface = shaderModule->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA);
int const varCount = static_cast<int>(interface->GetVariableCount());
for(int i = 0; i < varCount; ++i)
{
auto variable = interface->GetVariable(i);
const std::string& VAR_NAME = interface->GetVariableName(i);
switch (variable->type)
{
case SHShaderBlockInterface::Variable::Type::FLOAT:
SHEditorWidgets::DragFloat(VAR_NAME, [&]()
{
if(currentMatSpec.properties[VAR_NAME].IsDefined())
return currentMatSpec.properties[VAR_NAME].as<float>();
else
return 0.0f;
},
[&](float const& value)
{
currentMatSpec.properties[VAR_NAME] = value;
}
);
break;
case SHShaderBlockInterface::Variable::Type::INT:
break;
case SHShaderBlockInterface::Variable::Type::VECTOR2:
break;
case SHShaderBlockInterface::Variable::Type::VECTOR3:
break;
case SHShaderBlockInterface::Variable::Type::VECTOR4:
break;
case SHShaderBlockInterface::Variable::Type::OTHER:
default:
continue;
break;
}
}
}
} }

View File

@ -1,6 +1,9 @@
#pragma once #pragma once
#include "Assets/SHAssetMacros.h" #include "Assets/SHAssetMacros.h"
#include "Editor/EditorWindow/SHEditorWindow.h" #include "Editor/EditorWindow/SHEditorWindow.h"
#include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h"
#include "Graphics/Shaders/SHVkShaderModule.h"
#include "Resource/SHHandle.h"
namespace SHADE namespace SHADE
@ -19,10 +22,11 @@ namespace SHADE
void OpenMaterial(AssetID const& assetId) noexcept; void OpenMaterial(AssetID const& assetId) noexcept;
private: private:
void DrawMenuBar(); void DrawMenuBar();
void DrawShaderProperties(Handle<SHVkShaderModule> shaderModule);
//bool isNewMaterial; bool isNewMaterial;
//AssetID currentViewedMaterial; AssetID currentViewedMaterial;
//SHMaterialSpec currentMatSpec; SHMaterialSpec currentMatSpec;
//Handle<SHVkShaderModule> vertShaderHandle, fragShaderHandle; Handle<SHVkShaderModule> vertShaderHandle, fragShaderHandle;
}; };
} }

View File

@ -16,6 +16,7 @@ of DigiPen Institute of Technology is prohibited.
#include <utility> #include <utility>
// Project Includes // Project Includes
#include "Assets/SHAssetMacros.h" #include "Assets/SHAssetMacros.h"
#include <yaml-cpp/yaml.h>
namespace SHADE namespace SHADE
{ {