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 <imgui.h>
//#include "Assets/SHAssetManager.h"
//#include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h"
//#include "Editor/SHEditorWidgets.hpp"
//#include "Resource/SHResourceManager.h"
#include "Assets/SHAssetManager.h"
#include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h"
#include "Editor/SHEditorWidgets.hpp"
#include "Resource/SHResourceManager.h"
namespace SHADE
{
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
{
//Get mat data
//isNewMaterial = false;
isNewMaterial = false;
}
void SHMaterialInspector::Init()
@ -30,30 +30,20 @@ namespace SHADE
{
SHEditorWindow::Update();
//if(Begin())
//{
// DrawMenuBar();
if(Begin())
{
DrawMenuBar();
// 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);
// }
// 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);
// }
// auto vertInterface = vertShaderHandle->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA);
// int const varCount = static_cast<int>(vertInterface->GetVariableCount());
//
// for(int i = 0; i < varCount; ++i)
// {
// auto variable = vertInterface->GetVariable(i);
// }
//}
//ImGui::End();
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);
}
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);
}
}
ImGui::End();
}
void SHMaterialInspector::Exit()
@ -63,12 +53,12 @@ namespace SHADE
void SHMaterialInspector::CreateNewMaterial()
{
//isNewMaterial = true;
////prompt for a name
//currentViewedMaterial = SHAssetManager::CreateNewAsset(AssetType::MATERIAL, "NewMaterial");
//currentMatSpec = {};
//vertShaderHandle = {};
//fragShaderHandle = {};
isNewMaterial = true;
//prompt for a name
currentViewedMaterial = SHAssetManager::CreateNewAsset(AssetType::MATERIAL, "NewMaterial");
currentMatSpec = {};
vertShaderHandle = {};
fragShaderHandle = {};
}
void SHMaterialInspector::DrawMenuBar()
@ -78,4 +68,50 @@ namespace SHADE
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
#include "Assets/SHAssetMacros.h"
#include "Editor/EditorWindow/SHEditorWindow.h"
#include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h"
#include "Graphics/Shaders/SHVkShaderModule.h"
#include "Resource/SHHandle.h"
namespace SHADE
@ -19,10 +22,11 @@ namespace SHADE
void OpenMaterial(AssetID const& assetId) noexcept;
private:
void DrawMenuBar();
void DrawShaderProperties(Handle<SHVkShaderModule> shaderModule);
//bool isNewMaterial;
//AssetID currentViewedMaterial;
//SHMaterialSpec currentMatSpec;
//Handle<SHVkShaderModule> vertShaderHandle, fragShaderHandle;
bool isNewMaterial;
AssetID currentViewedMaterial;
SHMaterialSpec currentMatSpec;
Handle<SHVkShaderModule> vertShaderHandle, fragShaderHandle;
};
}

View File

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