diff --git a/rootex/core/renderer/rendering_device.cpp b/rootex/core/renderer/rendering_device.cpp index 501a78b46..ed9e94db0 100644 --- a/rootex/core/renderer/rendering_device.cpp +++ b/rootex/core/renderer/rendering_device.cpp @@ -354,6 +354,39 @@ void RenderingDevice::createOffScreenViews(int width, int height) GFX_ERR_CHECK(m_Device->CreateShaderResourceView(m_OffScreenTexture.Get(), &shaderResourceViewDesc, &m_OffScreenSRV)); } +void RenderingDevice::createShaderPasses(int width, int height) +{ + D3D11_TEXTURE2D_DESC bufferTexture; + ZeroMemory(&bufferTexture, sizeof(bufferTexture)); + bufferTexture.Width = width; + bufferTexture.Height = height; + bufferTexture.MipLevels = 1; + bufferTexture.ArraySize = 1; + bufferTexture.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; + bufferTexture.SampleDesc.Count = 1; + bufferTexture.Usage = D3D11_USAGE_DEFAULT; + bufferTexture.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; + bufferTexture.CPUAccessFlags = 0; + bufferTexture.MiscFlags = 0; + + GFX_ERR_CHECK(m_DeviceBg->CreateTexture2D(&bufferTexture, NULL, &m_ShaderPass)); + + D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewBuffer; + renderTargetViewBuffer.Format = bufferTexture.Format; + renderTargetViewBuffer.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; + renderTargetViewBuffer.Texture2D.MipSlice = 0; + //enable a scene to be rendered to a temporary intermediate buffer, rather than to the back buffer to be rendered to the screen + GFX_ERR_CHECK(m_DeviceBg->CreateRenderTargetView(m_ShaderPass.Get(), &renderTargetViewBuffer, &m_ShaderPassRTV)); + + D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewBuffer; + shaderResourceViewBuffer.Format = bufferTexture.Format; + shaderResourceViewBuffer.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + shaderResourceViewBuffer.Texture2D.MostDetailedMip = 0; + shaderResourceViewBuffer.Texture2D.MipLevels = 1; + //typically wrap textures in a format that the shaders can access them + GFX_ERR_CHECK(m_DeviceBg->CreateShaderResourceView(m_ShaderPass.Get(), &shaderResourceViewBuffer, &m_ShaderPassSRV)); +} + void RenderingDevice::createSwapChainAndRTVs(int width, int height, const HWND& hWnd) { DXGI_SWAP_CHAIN_DESC sd = { 0 }; diff --git a/rootex/core/renderer/rendering_device.h b/rootex/core/renderer/rendering_device.h index f8f86e96d..c8ab13f5b 100644 --- a/rootex/core/renderer/rendering_device.h +++ b/rootex/core/renderer/rendering_device.h @@ -47,6 +47,11 @@ class RenderingDevice Microsoft::WRL::ComPtr m_OffScreenRTV; Microsoft::WRL::ComPtr m_OffScreenSRV; + Microsoft::WRL::ComPtr m_DeviceBg; + Microsoft::WRL::ComPtr m_ShaderPass; + Microsoft::WRL::ComPtr m_ShaderPassRTV; + Microsoft::WRL::ComPtr m_ShaderPassSRV; + Microsoft::WRL::ComPtr m_DSState; UINT m_StencilRef; Microsoft::WRL::ComPtr m_SkyDSState; @@ -85,6 +90,7 @@ class RenderingDevice static RenderingDevice* GetSingleton(); void initialize(HWND hWnd, int width, int height); void createOffScreenViews(int width, int height); + void createShaderPasses(int width, int height); /// Create resources which depend on window height and width void createSwapChainAndRTVs(int width, int height, const HWND& hWnd); void setScreenState(bool fullscreen); diff --git a/rootex/core/resource_files/custom_material_resource_file.cpp b/rootex/core/resource_files/custom_material_resource_file.cpp index eabf937a2..a327ee865 100644 --- a/rootex/core/resource_files/custom_material_resource_file.cpp +++ b/rootex/core/resource_files/custom_material_resource_file.cpp @@ -6,20 +6,27 @@ #include "framework/systems/render_system.h" #include "resource_loader.h" #define MAX_NUMBER_OF_CUSTOM_CB 8 +#define MAX_NUMBER_OF_PIXEL_SHADERS 64 void to_json(JSON::json& j, const CustomMaterialData& s) { j["pixelShader"] = s.pixelShaderPath; + j["pixelShaderCount"] = s.pixelShaderCount; + j["vertexShader"] = s.vertexShaderPath; + j["vertexShaderTextures"] = JSON::json::array(); + for (auto& texture : s.vertexShaderTextures) + { + j["vertexShaderTextures"].push_back(texture->getPath().generic_string()); + } j["pixelShaderTextures"] = JSON::json::array(); + j["pixelShaderTexturesMapping"] = JSON::json::array(); for (auto& texture : s.pixelShaderTextures) { j["pixelShaderTextures"].push_back(texture->getPath().generic_string()); } - j["vertexShader"] = s.vertexShaderPath; - j["vertexShaderTextures"] = JSON::json::array(); - for (auto& texture : s.vertexShaderTextures) + for (auto& index : s.pixelShaderTexturesMapping) { - j["vertexShaderTextures"].push_back(texture->getPath().generic_string()); + j["pixelShaderTexturesMapping"].push_back(index); } for (auto& customConstantBuffers : s.customConstantBuffers) { @@ -29,26 +36,33 @@ void to_json(JSON::json& j, const CustomMaterialData& s) { j["typeOfCustomConstantBuffers"].push_back(typeOfCustomConstantBuffers); } + j["vertexShaderPath"] = s.dummyVertexShaderPath; } void from_json(const JSON::json& j, CustomMaterialData& s) { s.vertexShaderPath = j.value("vertexShader", CustomMaterialResourceFile::s_DefaultCustomVSPath); s.pixelShaderPath = j.value("pixelShader", CustomMaterialResourceFile::s_DefaultCustomPSPath); - for (auto& texturePath : j.value("pixelShaderTextures", Vector({ "rootex/assets/rootex.png" }))) + s.pixelShaderCount = j.value("pixelShaderCount", 1); + s.dummyVertexShaderPath = j.value("vertexShaderPath", CustomMaterialResourceFile::s_DefaultCustomVSPath); + for (auto& texturePath : j.value("vertexShaderTextures", Vector())) { if (Ref texture = ResourceLoader::CreateImageResourceFile(texturePath)) { - s.pixelShaderTextures.push_back(texture); + s.vertexShaderTextures.push_back(texture); } } - for (auto& texturePath : j.value("vertexShaderTextures", Vector())) + for (auto& texturePath : j.value("pixelShaderTextures", Vector({ "rootex/assets/rootex.png" }))) { if (Ref texture = ResourceLoader::CreateImageResourceFile(texturePath)) { - s.vertexShaderTextures.push_back(texture); + s.pixelShaderTextures.push_back(texture); } } + for (auto& index : j.value("pixelShaderTexturesMapping", Vector())) + { + s.pixelShaderTexturesMapping.push_back(index); + } for (auto& customConstantBuffers : j.value("customConstantBuffers", Vector())) { s.customConstantBuffers.push_back(customConstantBuffers); @@ -72,21 +86,37 @@ void CustomMaterialResourceFile::Destroy() CustomMaterialResourceFile::CustomMaterialResourceFile(const FilePath& path) : MaterialResourceFile(ResourceFile::Type::CustomMaterial, path) { + m_PixelShaderCount = 0; + m_DummyVertexShaderPath = "rootex/core/renderer/shaders/custom_vertex_shader.hlsl"; reimport(); } -void CustomMaterialResourceFile::pushPSTexture(Ref texture) +void CustomMaterialResourceFile::pushPSTexture(Ref texture, int ind) { if (!texture) { WARN("Skipping null PS texture which was tried to be pushed"); return; } - + int a; + a = m_MaterialData.pixelShaderTextures.size(); + if ((ind + 1) < m_MaterialData.pixelShaderTexturesMapping.size()) + a = m_MaterialData.pixelShaderTexturesMapping[ind + 1]; + Ref nextTexture; + for (int i = a; i < m_MaterialData.pixelShaderTextures.size(); i++) + { + nextTexture = m_MaterialData.pixelShaderTextures[i]; + m_MaterialData.pixelShaderTextures[i] = texture; + texture = nextTexture; + } + for (int i = ind + 1; i < m_MaterialData.pixelShaderTexturesMapping.size(); i++) + { + m_MaterialData.pixelShaderTexturesMapping[i] = m_MaterialData.pixelShaderTexturesMapping[i] + 1; + } m_MaterialData.pixelShaderTextures.push_back(texture); } -void CustomMaterialResourceFile::setPSTexture(const String& newtexturePath, int position) +void CustomMaterialResourceFile::setPSTexture(const String& newtexturePath, int position, int ind) { if (position >= m_MaterialData.pixelShaderTextures.size() || position < 0) { @@ -94,20 +124,40 @@ void CustomMaterialResourceFile::setPSTexture(const String& newtexturePath, int return; } + int a = m_MaterialData.pixelShaderTexturesMapping[ind]; if (Ref image = ResourceLoader::CreateImageResourceFile(newtexturePath)) { - m_MaterialData.pixelShaderTextures[position] = image; + m_MaterialData.pixelShaderTextures[a + position] = image; } } -void CustomMaterialResourceFile::popPSTexture() +void CustomMaterialResourceFile::popPSTexture(int ind) { if (m_MaterialData.pixelShaderTextures.empty()) { WARN("PS texture list is empty."); return; } - + bool bl = false; + if ((ind + 1) < m_MaterialData.pixelShaderTexturesMapping.size()) + bl = true; + int a; + if (bl) + a = m_MaterialData.pixelShaderTexturesMapping[ind + 1]; + else + a = m_MaterialData.pixelShaderTextures.size(); + int j = a; + a--; + Ref nextTexture, texture; + for (int i = a; i < m_MaterialData.pixelShaderTextures.size() - 1; i++) + { + nextTexture = m_MaterialData.pixelShaderTextures[i + 1]; + m_MaterialData.pixelShaderTextures[i] = nextTexture; + } + for (int i = ind + 1; i < m_MaterialData.pixelShaderTexturesMapping.size(); i++) + { + m_MaterialData.pixelShaderTexturesMapping[i]--; + } m_MaterialData.pixelShaderTextures.pop_back(); } @@ -154,15 +204,21 @@ Vector> CustomMaterialResourceFile::getTextures() const { textures.push_back(imageRes->getGPUTexture()); } - for (auto& imageRes : m_MaterialData.pixelShaderTextures) + int j = m_MaterialData.pixelShaderTexturesMapping[index]; + int a = m_MaterialData.pixelShaderTexturesMapping[index]; + if (a >= m_MaterialData.pixelShaderTexturesMapping.size()) + a = m_MaterialData.pixelShaderTexturesMapping.size(); + for (; j < a;) { + auto imageRes = m_MaterialData.pixelShaderTextures[j]; textures.push_back(imageRes->getGPUTexture()); + j++; } return textures; } -void CustomMaterialResourceFile::setShaders(const String& vertexShader, const String& pixelShader) +void CustomMaterialResourceFile::setShaders(int ind, const String& vertexShader, const String& pixelShader) { if (!OS::IsExists(pixelShader) || !OS::IsExists(vertexShader)) { @@ -181,33 +237,42 @@ void CustomMaterialResourceFile::setShaders(const String& vertexShader, const St { m_MaterialData.pixelShaderPath = pixelShader; m_MaterialData.vertexShaderPath = vertexShader; - m_Shader = std::move(shader); + if (ind >= m_Shader.size()) + m_Shader.emplace_back(std::move(shader)); + else + m_Shader[ind] = std::move(shader); } } -void CustomMaterialResourceFile::setVS(const String& vertexShader) +void CustomMaterialResourceFile::setVS(int ind, const String& vertexShader) { - setShaders(vertexShader, m_MaterialData.pixelShaderPath); + setShaders(ind, vertexShader, m_MaterialData.pixelShaderPath); } -void CustomMaterialResourceFile::setPS(const String& pixelShader) +void CustomMaterialResourceFile::setPS(int ind, const String& pixelShader) { - setShaders(m_MaterialData.vertexShaderPath, pixelShader); + if (ind == 0) + setShaders(ind, m_MaterialData.vertexShaderPath, pixelShader); + else + setShaders(ind, m_DummyVertexShaderPath, pixelShader); } -void CustomMaterialResourceFile::recompileShaders() +void CustomMaterialResourceFile::recompileShaders(int ind) { - setShaders(m_MaterialData.vertexShaderPath, m_MaterialData.pixelShaderPath); + setShaders(ind, m_MaterialData.vertexShaderPath, m_MaterialData.pixelShaderPath); } void CustomMaterialResourceFile::bindShader() { - m_Shader->bind(); + int k = 0; + m_Shader[index]->bind(); + k = 1; } void CustomMaterialResourceFile::bindTextures() { - if (!m_MaterialData.pixelShaderTextures.empty()) + int a = m_MaterialData.pixelShaderTexturesMapping[index]; + if (m_MaterialData.pixelShaderTextures.size() <= a) { static Vector textureSRVs; textureSRVs.clear(); @@ -276,7 +341,10 @@ void CustomMaterialResourceFile::reimport() customConstantBuffers = m_MaterialData.customConstantBuffers; typeOfCustomConstantBuffers = m_MaterialData.typeOfCustomConstantBuffers; - recompileShaders(); + for (int i = 0; i < m_PixelShaderCount; i++) + { + recompileShaders(i); + } float fakeArray[MAX_NUMBER_OF_CUSTOM_CB * 4]; m_PSCB = RenderingDevice::GetSingleton()->createBuffer((const char*)fakeArray, sizeof(fakeArray), D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE); m_VSCB = RenderingDevice::GetSingleton()->createBuffer(PerModelVSCBData(), D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE); @@ -360,14 +428,21 @@ void CustomMaterialResourceFile::draw() if (ImGui::Button("Recompile " ICON_ROOTEX_REFRESH)) { - recompileShaders(); + for (int ind = 0; ind < m_PixelShaderCount; ind++) + recompileShaders(ind); } if (ImGui::TreeNode("Vertex Shader")) { if (ImGui::InputTextWithHint("Path", "Path to Vertex Shader", &m_MaterialData.vertexShaderPath, ImGuiInputTextFlags_EnterReturnsTrue)) { - setVS(m_MaterialData.vertexShaderPath); + for (int ind = 0; ind < m_PixelShaderCount; ind++) + { + if (ind == 0) + setVS(ind, m_MaterialData.vertexShaderPath); + else + setVS(ind, m_DummyVertexShaderPath); + } } if (ImGui::Button(ICON_ROOTEX_PENCIL_SQUARE_O "##Edit VS")) @@ -379,7 +454,13 @@ void CustomMaterialResourceFile::draw() { if (Optional result = OS::SelectFile("Vertex Shader(*.hlsl)\0*.hlsl\0", "game/assets/shaders/")) { - setVS(*result); + for (int ind = 0; ind < m_PixelShaderCount; ind++) + { + if (ind == 0) + setVS(ind, *result); + else + setVS(ind, m_DummyVertexShaderPath); + } } } ImGui::SameLine(); @@ -390,7 +471,13 @@ void CustomMaterialResourceFile::draw() ImGui::SameLine(); if (ImGui::Button(ICON_ROOTEX_WINDOW_CLOSE "##Reset VS")) { - setVS(s_DefaultCustomVSPath); + for (int ind = 0; ind < m_PixelShaderCount; ind++) + { + if (ind == 0) + setVS(ind, s_DefaultCustomVSPath); + else + setVS(ind, m_DummyVertexShaderPath); + } } if (ImGui::ListBoxHeader("Textures##VS")) @@ -436,7 +523,13 @@ void CustomMaterialResourceFile::draw() FileBuffer defaultShaderBuffer = OS::LoadFileContents(s_DefaultCustomVSPath); OS::SaveFile(shaderFileName, defaultShaderBuffer.data(), defaultShaderBuffer.size()); - setVS(shaderFileName); + for (int ind = 0; ind < m_PixelShaderCount; ind++) + { + if (ind == 0) + setVS(ind, shaderFileName); + else + setVS(ind, m_DummyVertexShaderPath); + } EventManager::GetSingleton()->call(EditorEvents::EditorEditFile, shaderFileName); newVSPath.clear(); @@ -451,62 +544,129 @@ void CustomMaterialResourceFile::draw() if (ImGui::TreeNode("Pixel Shader")) { - if (ImGui::InputTextWithHint("Path", "Path to Pixel Shader", &m_MaterialData.pixelShaderPath, ImGuiInputTextFlags_EnterReturnsTrue)) - { - setPS(m_MaterialData.pixelShaderPath); - } - - if (ImGui::Button(ICON_ROOTEX_PENCIL_SQUARE_O "##Edit PS")) - { - EventManager::GetSingleton()->call(EditorEvents::EditorEditFile, m_MaterialData.pixelShaderPath); - } - ImGui::SameLine(); - if (ImGui::Button(ICON_ROOTEX_FOLDER_OPEN "##Find PS")) + int ind = 0; + String s1, s2, s3, s4; + for (; ind < m_PixelShaderCount; ind++) { - if (Optional result = OS::SelectFile("Pixel Shader(*.hlsl)\0*.hlsl\0", "game/assets/shaders/")) + index = ind; + ImGui::PushID(ind); + s1 = "Path" + std::to_string(ind); + bool bl = false; + if (ind >= m_Shader.size()) + setPS(ind, s_DefaultCustomPSPath); + if (ImGui::InputTextWithHint(s1.c_str(), "Path to Pixel Shader", &m_MaterialData.pixelShaderPath, ImGuiInputTextFlags_EnterReturnsTrue)) { - setPS(*result); + setPS(ind, m_MaterialData.pixelShaderPath); } - } - ImGui::SameLine(); - if (ImGui::Button(ICON_ROOTEX_PLUS "##Create PS")) - { - ImGui::OpenPopup("Create PS"); - } - ImGui::SameLine(); - if (ImGui::Button(ICON_ROOTEX_WINDOW_CLOSE "##Reset PS")) - { - setPS(s_DefaultCustomPSPath); - } - - if (ImGui::ListBoxHeader("Textures##PS")) - { - int i = 0; - for (auto& texture : m_MaterialData.pixelShaderTextures) + s2 = "Create PS" + std::to_string(ind); + if (ImGui::Button(ICON_ROOTEX_PENCIL_SQUARE_O "##Edit PS")) { - String textureName = "Slot " + std::to_string(i) + " " + ICON_ROOTEX_FOLDER_OPEN; - RootexSelectableImage(textureName.c_str(), texture, [this, i](const String& newTexturePath) { setPSTexture(newTexturePath, i); }); - i++; - ImGui::Separator(); + EventManager::GetSingleton()->call(EditorEvents::EditorEditFile, m_MaterialData.pixelShaderPath); + } + ImGui::SameLine(); + if (ImGui::Button(ICON_ROOTEX_FOLDER_OPEN "##Find PS")) + { + if (Optional result = OS::SelectFile("Pixel Shader(*.hlsl)\0*.hlsl\0", "game/assets/shaders/")) + { + setPS(ind, *result); + } + } + ImGui::SameLine(); + if (ImGui::Button(ICON_ROOTEX_PLUS "##Create PS")) + { + ImGui::OpenPopup(s2.c_str(), true); + bl = true; + } + ImGui::SameLine(); + if (ImGui::Button(ICON_ROOTEX_WINDOW_CLOSE "##Reset PS")) + { + setPS(ind, s_DefaultCustomPSPath); } - if (ImGui::Button(ICON_ROOTEX_PLUS "##Push PS")) + if (ImGui::ListBoxHeader("Textures##PS")) { - if (Optional result = OS::SelectFile(SupportedFiles.at(ResourceFile::Type::Image), "game/assets/")) + int i = 0; + int a = m_MaterialData.pixelShaderTexturesMapping[ind]; + int b = m_MaterialData.pixelShaderTextures.size(); + if (ind < (m_PixelShaderCount - 1)) + b = m_MaterialData.pixelShaderTexturesMapping[ind + 1]; + for (i = a; i < b; i++) { - if (Ref image = ResourceLoader::CreateImageResourceFile(*result)) + Ref texture = m_MaterialData.pixelShaderTextures[i]; + String textureName = "Slot " + std::to_string((i)) + " " + ICON_ROOTEX_FOLDER_OPEN; + RootexSelectableImage(textureName.c_str(), texture, [this, i, ind, a](const String& newTexturePath) { setPSTexture(newTexturePath, i - a, ind); }); + ImGui::Separator(); + } + + if (ImGui::Button(ICON_ROOTEX_PLUS "##Push PS")) + { + if (Optional result = OS::SelectFile(SupportedFiles.at(ResourceFile::Type::Image), "game/assets/")) { - pushPSTexture(image); + if (Ref image = ResourceLoader::CreateImageResourceFile(*result)) + { + pushPSTexture(image, ind); + } } } + ImGui::SameLine(); + if (ImGui::Button(ICON_ROOTEX_MINUS "##Pop PS")) + { + popPSTexture(ind); + } + + ImGui::ListBoxFooter(); } - ImGui::SameLine(); - if (ImGui::Button(ICON_ROOTEX_MINUS "##Pop PS")) + if (ImGui::Button("Remove This Shader")) { - popPSTexture(); + if (m_PixelShaderCount > 0) + { + int i = 0; + auto itr = m_Shader.begin(); + while (i != ind) + { + itr++; + i++; + } + int a = m_MaterialData.pixelShaderTexturesMapping[ind]; + int b = m_MaterialData.pixelShaderTextures.size(); + + if (ind + 1 < m_PixelShaderCount) + b = m_MaterialData.pixelShaderTexturesMapping[ind + 1]; + for (int k = a; k < b; k++) + { + popPSTexture(ind); + } + for (int j = ind; j < m_MaterialData.pixelShaderTexturesMapping.size() - 1; j++) + { + m_MaterialData.pixelShaderTexturesMapping[j] = m_MaterialData.pixelShaderTexturesMapping[j + 1]; + } + m_MaterialData.pixelShaderTexturesMapping.pop_back(); + if (m_Shader.size() > ind) + { + m_Shader.erase(itr); + m_PixelShaderCount--; + } + } + else + { + ERROR("No pixel shaders left to be removed"); + } } + ImGui::PopID(); + ImGui::Separator(); + } - ImGui::ListBoxFooter(); + if (ImGui::Button("Add Pixel Shader")) + { + if (m_PixelShaderCount < MAX_NUMBER_OF_PIXEL_SHADERS) + { + m_PixelShaderCount++; + m_MaterialData.pixelShaderTexturesMapping.push_back(m_MaterialData.pixelShaderTextures.size()); + } + else + { + ERROR("Exceeded maximum pixel shader count"); + } } if (ImGui::BeginPopup("Create PS")) @@ -522,7 +682,8 @@ void CustomMaterialResourceFile::draw() FileBuffer defaultShaderBuffer = OS::LoadFileContents(s_DefaultCustomPSPath); OS::SaveFile(shaderFileName, defaultShaderBuffer.data(), defaultShaderBuffer.size()); - setPS(shaderFileName); + for (int ind = 0; ind < m_PixelShaderCount; ind++) + setPS(ind, shaderFileName); EventManager::GetSingleton()->call(EditorEvents::EditorEditFile, shaderFileName); newPSPath.clear(); @@ -598,4 +759,6 @@ void CustomMaterialResourceFile::draw() } m_MaterialData.customConstantBuffers = customConstantBuffers; m_MaterialData.typeOfCustomConstantBuffers = typeOfCustomConstantBuffers; + m_MaterialData.dummyVertexShaderPath = m_DummyVertexShaderPath; + m_MaterialData.pixelShaderCount = m_PixelShaderCount; } diff --git a/rootex/core/resource_files/custom_material_resource_file.h b/rootex/core/resource_files/custom_material_resource_file.h index e45c15d93..ab6e11cbe 100644 --- a/rootex/core/resource_files/custom_material_resource_file.h +++ b/rootex/core/resource_files/custom_material_resource_file.h @@ -15,13 +15,16 @@ class CustomMaterialResourceFile : public MaterialResourceFile CustomMaterialData m_MaterialData; - Ptr m_Shader; + String m_DummyVertexShaderPath; + int m_PixelShaderCount; + int index = 0; + std::vector> m_Shader; Microsoft::WRL::ComPtr m_PSCB; Microsoft::WRL::ComPtr m_VSCB; - void pushPSTexture(Ref texture); - void setPSTexture(const String& newtexturePath, int position); - void popPSTexture(); + void pushPSTexture(Ref texture, int ind); + void setPSTexture(const String& newtexturePath, int position, int ind); + void popPSTexture(int ind); void pushVSTexture(Ref texture); void setVSTexture(const String& newtexturePath, int position); @@ -37,12 +40,20 @@ class CustomMaterialResourceFile : public MaterialResourceFile explicit CustomMaterialResourceFile(const FilePath& path); ~CustomMaterialResourceFile() = default; - void setShaders(const String& vertexShader, const String& pixelShader); - void setVS(const String& vertexShader); - void setPS(const String& pixelShader); - void recompileShaders(); - - const Shader* getShader() const override { return m_Shader.get(); }; + void setShaders(int ind, const String& vertexShader, const String& pixelShader); + void setVS(int ind, const String& vertexShader); + void setPS(int ind, const String& pixelShader); + void recompileShaders(int ind); + + const Shader* getShader() const override + { + if (!(m_Shader.empty())) + { + return m_Shader[0].get(); + } + else + return nullptr; + }; Vector> getTextures() const override; void bindShader() override; diff --git a/rootex/core/resource_files/material_resource_file.h b/rootex/core/resource_files/material_resource_file.h index 5ed428913..ab4665a9b 100644 --- a/rootex/core/resource_files/material_resource_file.h +++ b/rootex/core/resource_files/material_resource_file.h @@ -134,8 +134,11 @@ struct CustomMaterialData String pixelShaderPath; Vector> vertexShaderTextures; Vector> pixelShaderTextures; + Vector pixelShaderTexturesMapping; Vector customConstantBuffers; Vector typeOfCustomConstantBuffers; + String dummyVertexShaderPath; + int pixelShaderCount; }; void to_json(JSON::json& j, const CustomMaterialData& s);