Fixed material inspector saving not saving the correct texture ID into the runtime material

This commit is contained in:
Kah Wei 2022-11-16 19:25:17 +08:00
parent c5bca4111b
commit fe91f58d28
1 changed files with 15 additions and 2 deletions

View File

@ -78,6 +78,7 @@ namespace SHADE
ImGui::BeginDisabled(!isDirty); ImGui::BeginDisabled(!isDirty);
if(ImGui::Button(std::format("{} Save", ICON_MD_SAVE).data())) if(ImGui::Button(std::format("{} Save", ICON_MD_SAVE).data()))
{ {
auto gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
// Replace Material if it's been instantiated // Replace Material if it's been instantiated
auto matHandle = SHResourceManager::Get<SHMaterial>(currentViewedMaterial); auto matHandle = SHResourceManager::Get<SHMaterial>(currentViewedMaterial);
if (matHandle) if (matHandle)
@ -85,7 +86,6 @@ namespace SHADE
// - Get Shader Modules // - Get Shader Modules
auto vertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(currentMatSpec->vertexShader); auto vertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(currentMatSpec->vertexShader);
auto fragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(currentMatSpec->fragShader); auto fragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(currentMatSpec->fragShader);
auto gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
if (vertShader && fragShader && gfxSystem) if (vertShader && fragShader && gfxSystem)
{ {
// - Retrieve pipeline from pipeline library // - Retrieve pipeline from pipeline library
@ -121,7 +121,20 @@ namespace SHADE
currentMaterial->SetProperty(VARIABLE->offset, PROP_NODE.as<float>()); currentMaterial->SetProperty(VARIABLE->offset, PROP_NODE.as<float>());
break; break;
case SHADE::SHShaderBlockInterface::Variable::Type::INT: case SHADE::SHShaderBlockInterface::Variable::Type::INT:
currentMaterial->SetProperty(VARIABLE->offset, PROP_NODE.as<int>()); {
Handle<SHTexture> texture = SHResourceManager::LoadOrGet<SHTexture>(PROP_NODE.as<int>());
// HACK: Need to split this out to a separate pass before loading the materials and subsequently, the scenes
gfxSystem->BuildTextures();
if (texture)
{
matHandle->SetProperty(VARIABLE->offset, texture->TextureArrayIndex);
}
else
{
SHLOG_WARNING("[] Attempted to load invalid texture! Setting to 0.");
matHandle->SetProperty(VARIABLE->offset, 0);
}
}
break; break;
case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR2: case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR2:
currentMaterial->SetProperty(VARIABLE->offset, PROP_NODE.as<SHVec2>()); currentMaterial->SetProperty(VARIABLE->offset, PROP_NODE.as<SHVec2>());