From fe91f58d2809162d8159e9daabc8f016736848bb Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Wed, 16 Nov 2022 19:25:17 +0800 Subject: [PATCH] Fixed material inspector saving not saving the correct texture ID into the runtime material --- .../MaterialInspector/SHMaterialInspector.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp index 2f87a97c..3ffed8e3 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp @@ -78,6 +78,7 @@ namespace SHADE ImGui::BeginDisabled(!isDirty); if(ImGui::Button(std::format("{} Save", ICON_MD_SAVE).data())) { + auto gfxSystem = SHSystemManager::GetSystem(); // Replace Material if it's been instantiated auto matHandle = SHResourceManager::Get(currentViewedMaterial); if (matHandle) @@ -85,7 +86,6 @@ namespace SHADE // - Get Shader Modules auto vertShader = SHResourceManager::LoadOrGet(currentMatSpec->vertexShader); auto fragShader = SHResourceManager::LoadOrGet(currentMatSpec->fragShader); - auto gfxSystem = SHSystemManager::GetSystem(); if (vertShader && fragShader && gfxSystem) { // - Retrieve pipeline from pipeline library @@ -121,7 +121,20 @@ namespace SHADE currentMaterial->SetProperty(VARIABLE->offset, PROP_NODE.as()); break; case SHADE::SHShaderBlockInterface::Variable::Type::INT: - currentMaterial->SetProperty(VARIABLE->offset, PROP_NODE.as()); + { + Handle texture = SHResourceManager::LoadOrGet(PROP_NODE.as()); + // 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; case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR2: currentMaterial->SetProperty(VARIABLE->offset, PROP_NODE.as());