From f3c74d1d029abf17cbe178be346a128199f9d3e8 Mon Sep 17 00:00:00 2001 From: NehaGujar1 Date: Sat, 28 Jan 2023 00:06:07 +0530 Subject: [PATCH 1/5] WIP: Do changes for Shader Passes in custom_material_resource --- rootex/core/renderer/rendering_device.cpp | 33 +++ rootex/core/renderer/rendering_device.h | 6 + .../custom_material_resource_file.cpp | 218 ++++++++++++++++-- .../custom_material_resource_file.h | 25 +- .../resource_files/material_resource_file.h | 2 + 5 files changed, 256 insertions(+), 28 deletions(-) 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..6ca3fd81c 100644 --- a/rootex/core/resource_files/custom_material_resource_file.cpp +++ b/rootex/core/resource_files/custom_material_resource_file.cpp @@ -6,10 +6,12 @@ #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["pixelShaderTextures"] = JSON::json::array(); for (auto& texture : s.pixelShaderTextures) { @@ -29,12 +31,15 @@ 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); + s.pixelShaderCount = j.value("pixelShaderCount", 1); + s.dummyVertexShaderPath = j.value("vertexShaderPath", CustomMaterialResourceFile::s_DefaultCustomVSPath); for (auto& texturePath : j.value("pixelShaderTextures", Vector({ "rootex/assets/rootex.png" }))) { if (Ref texture = ResourceLoader::CreateImageResourceFile(texturePath)) @@ -72,6 +77,8 @@ void CustomMaterialResourceFile::Destroy() CustomMaterialResourceFile::CustomMaterialResourceFile(const FilePath& path) : MaterialResourceFile(ResourceFile::Type::CustomMaterial, path) { + m_PixelShaderCount=0; + m_DummyVertexShaderPath = "rootex/core/renderer/shaders/custom_pixel_shader.hlsl"; reimport(); } @@ -162,7 +169,7 @@ Vector> CustomMaterialResourceFile::getTextures() const 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,28 +188,39 @@ void CustomMaterialResourceFile::setShaders(const String& vertexShader, const St { m_MaterialData.pixelShaderPath = pixelShader; m_MaterialData.vertexShaderPath = vertexShader; - m_Shader = std::move(shader); + if (ind >= m_PixelShaderCount) + { + m_Shader.push_back(std::move(shader)); //read + } + else + { + m_Shader[ind] = std::move(shader); // current changes + } } } -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() +void CustomMaterialResourceFile::bindShader() //doubt?? { - m_Shader->bind(); + //for (int ind = 0; ind < m_PixelShaderCount; ind++) + //{ + m_Shader[index]->bind(); + //} } void CustomMaterialResourceFile::bindTextures() @@ -276,7 +294,9 @@ void CustomMaterialResourceFile::reimport() customConstantBuffers = m_MaterialData.customConstantBuffers; typeOfCustomConstantBuffers = m_MaterialData.typeOfCustomConstantBuffers; - recompileShaders(); + for(int i=0;icreateBuffer((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 +380,18 @@ void CustomMaterialResourceFile::draw() if (ImGui::Button("Recompile " ICON_ROOTEX_REFRESH)) { - recompileShaders(); + for(int ind=0;ind result = OS::SelectFile("Vertex Shader(*.hlsl)\0*.hlsl\0", "game/assets/shaders/")) { - setVS(*result); + for(int ind=0;indcall(EditorEvents::EditorEditFile, shaderFileName); newVSPath.clear(); @@ -451,9 +485,11 @@ void CustomMaterialResourceFile::draw() if (ImGui::TreeNode("Pixel Shader")) { + int ind=0; + index = ind; if (ImGui::InputTextWithHint("Path", "Path to Pixel Shader", &m_MaterialData.pixelShaderPath, ImGuiInputTextFlags_EnterReturnsTrue)) { - setPS(m_MaterialData.pixelShaderPath); + setPS(ind, m_MaterialData.pixelShaderPath); } if (ImGui::Button(ICON_ROOTEX_PENCIL_SQUARE_O "##Edit PS")) @@ -465,7 +501,7 @@ void CustomMaterialResourceFile::draw() { if (Optional result = OS::SelectFile("Pixel Shader(*.hlsl)\0*.hlsl\0", "game/assets/shaders/")) { - setPS(*result); + setPS(ind, *result); } } ImGui::SameLine(); @@ -476,7 +512,7 @@ void CustomMaterialResourceFile::draw() ImGui::SameLine(); if (ImGui::Button(ICON_ROOTEX_WINDOW_CLOSE "##Reset PS")) { - setPS(s_DefaultCustomPSPath); + setPS(ind, s_DefaultCustomPSPath); } if (ImGui::ListBoxHeader("Textures##PS")) @@ -485,7 +521,8 @@ void CustomMaterialResourceFile::draw() for (auto& texture : m_MaterialData.pixelShaderTextures) { String textureName = "Slot " + std::to_string(i) + " " + ICON_ROOTEX_FOLDER_OPEN; - RootexSelectableImage(textureName.c_str(), texture, [this, i](const String& newTexturePath) { setPSTexture(newTexturePath, i); }); + RootexSelectableImage(textureName.c_str(), texture, [this, i](const String& newTexturePath) + { setPSTexture(newTexturePath, i); }); i++; ImGui::Separator(); } @@ -508,6 +545,142 @@ void CustomMaterialResourceFile::draw() ImGui::ListBoxFooter(); } + // Remove current pixel shader + if (ImGui::Button("Remove This Shader")) + { + if (m_PixelShaderCount > 0) + { + //std::vector> temp; + //for (int j = 1; j < m_PixelShaderCount; j++) + //{ + //temp.push_back(m_Shader[j]); + //} + int i = 0; + auto itr = m_Shader.begin(); + while (i != ind) + { + itr++; + i++; + } + m_Shader.erase(itr); + m_PixelShaderCount--; + //m_Shader.clear(); + //for (int j = 0; j < m_PixelShaderCount; j++) + //{ + //m_Shader.push_back(temp[j]); + //} + } + else + { + ERROR("No pixel shaders left to be removed"); + } + } + for (ind = 1; ind < m_PixelShaderCount; ind++) + { + setPS(ind, s_DefaultCustomPSPath); + if (ImGui::InputTextWithHint("Path", "Path to Pixel Shader", &m_MaterialData.pixelShaderPath, ImGuiInputTextFlags_EnterReturnsTrue)) + { + setPS(ind,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")) + { + 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("Create PS"); + } + ImGui::SameLine(); + if (ImGui::Button(ICON_ROOTEX_WINDOW_CLOSE "##Reset PS")) + { + setPS(ind,s_DefaultCustomPSPath); + } + + if (ImGui::ListBoxHeader("Textures##PS")) + { + int i = 0; //i->ind + for (auto& texture : m_MaterialData.pixelShaderTextures) + { + 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(); + } + + if (ImGui::Button(ICON_ROOTEX_PLUS "##Push PS")) + { + if (Optional result = OS::SelectFile(SupportedFiles.at(ResourceFile::Type::Image), "game/assets/")) + { + if (Ref image = ResourceLoader::CreateImageResourceFile(*result)) + { + pushPSTexture(image); + } + } + } + ImGui::SameLine(); + if (ImGui::Button(ICON_ROOTEX_MINUS "##Pop PS")) + { + popPSTexture(); + } + + ImGui::ListBoxFooter(); + } + //Remove current pixel shader + if (ImGui::Button("Remove This Shader")) + { + if (m_PixelShaderCount > 0) + { + //std::vector> temp; + int j = 0; + auto itr = m_Shader.begin(); + while (ind != j) + { + j++; + itr++; + } + //for (int j = 0; j < m_PixelShaderCount; j++) + //{ + //if (j != ind) + //{ + //temp.push_back(std::move((m_Shader[j]))); + //} + //} + m_Shader.erase(itr); + m_PixelShaderCount--; + //m_Shader.clear(); + //for (int j = 0; j < m_PixelShaderCount; j++) + //{ + //m_Shader.push_back(std::move((temp[j]))); + //} + } + else + { + ERROR("No pixel shaders left to be removed"); + } + } + } + + if (ImGui::Button("Add Pixel Shader")) + { + if (m_PixelShaderCount < MAX_NUMBER_OF_PIXEL_SHADERS) + { + m_PixelShaderCount++; + } + else + { + ERROR("Exceeded maximum pixel shader count"); + } + } if (ImGui::BeginPopup("Create PS")) { @@ -522,7 +695,8 @@ void CustomMaterialResourceFile::draw() FileBuffer defaultShaderBuffer = OS::LoadFileContents(s_DefaultCustomPSPath); OS::SaveFile(shaderFileName, defaultShaderBuffer.data(), defaultShaderBuffer.size()); - setPS(shaderFileName); + for(int ind=0;indcall(EditorEvents::EditorEditFile, shaderFileName); newPSPath.clear(); @@ -598,4 +772,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..6dafa20be 100644 --- a/rootex/core/resource_files/custom_material_resource_file.h +++ b/rootex/core/resource_files/custom_material_resource_file.h @@ -15,7 +15,10 @@ 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; @@ -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; + }; // doubt?? 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..e79b233e5 100644 --- a/rootex/core/resource_files/material_resource_file.h +++ b/rootex/core/resource_files/material_resource_file.h @@ -136,6 +136,8 @@ struct CustomMaterialData Vector> pixelShaderTextures; Vector customConstantBuffers; Vector typeOfCustomConstantBuffers; + String dummyVertexShaderPath; + int pixelShaderCount; }; void to_json(JSON::json& j, const CustomMaterialData& s); From 409ad3f3fbfd57d9cdfa99b41086898e2cb4f06c Mon Sep 17 00:00:00 2001 From: NehaGujar1 Date: Mon, 20 Feb 2023 01:52:45 +0530 Subject: [PATCH 2/5] Complete ImGui changes for Shader Passes --- .../custom_material_resource_file.cpp | 291 +++++++++--------- .../custom_material_resource_file.h | 6 +- .../resource_files/material_resource_file.h | 1 + 3 files changed, 145 insertions(+), 153 deletions(-) diff --git a/rootex/core/resource_files/custom_material_resource_file.cpp b/rootex/core/resource_files/custom_material_resource_file.cpp index 6ca3fd81c..242e16d3f 100644 --- a/rootex/core/resource_files/custom_material_resource_file.cpp +++ b/rootex/core/resource_files/custom_material_resource_file.cpp @@ -12,16 +12,21 @@ 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) { @@ -40,20 +45,24 @@ void from_json(const JSON::json& j, CustomMaterialData& s) s.pixelShaderPath = j.value("pixelShader", CustomMaterialResourceFile::s_DefaultCustomPSPath); s.pixelShaderCount = j.value("pixelShaderCount", 1); s.dummyVertexShaderPath = j.value("vertexShaderPath", CustomMaterialResourceFile::s_DefaultCustomVSPath); - for (auto& texturePath : j.value("pixelShaderTextures", Vector({ "rootex/assets/rootex.png" }))) + 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); @@ -78,43 +87,90 @@ CustomMaterialResourceFile::CustomMaterialResourceFile(const FilePath& path) : MaterialResourceFile(ResourceFile::Type::CustomMaterial, path) { m_PixelShaderCount=0; - m_DummyVertexShaderPath = "rootex/core/renderer/shaders/custom_pixel_shader.hlsl"; + 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; } - - m_MaterialData.pixelShaderTextures.push_back(texture); + 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); //changes } -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) + if (position >= m_MaterialData.pixelShaderTextures.size() || position < 0) //make changes { WARN("PS position being set is out of bounds: " + std::to_string(position)); return; } + int a = m_MaterialData.pixelShaderTexturesMapping[ind]; + //Ref nextTexture,texture; if (Ref image = ResourceLoader::CreateImageResourceFile(newtexturePath)) { - m_MaterialData.pixelShaderTextures[position] = image; + m_MaterialData.pixelShaderTextures[a + position] = image; } + //for (int i = a; i < m_MaterialData.pixelShaderTextures.size()-1; 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.pixelShaderTextures.push_back(texture); //changes } -void CustomMaterialResourceFile::popPSTexture() +void CustomMaterialResourceFile::popPSTexture(int ind) { - if (m_MaterialData.pixelShaderTextures.empty()) + if (m_MaterialData.pixelShaderTextures.empty()) //make changes { 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; + //j++; + } + for (int i = ind + 1; i < m_MaterialData.pixelShaderTexturesMapping.size(); i++) + { + m_MaterialData.pixelShaderTexturesMapping[i]--; + } m_MaterialData.pixelShaderTextures.pop_back(); } @@ -161,9 +217,15 @@ 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; @@ -188,14 +250,10 @@ void CustomMaterialResourceFile::setShaders(int ind, const String& vertexShader, { m_MaterialData.pixelShaderPath = pixelShader; m_MaterialData.vertexShaderPath = vertexShader; - if (ind >= m_PixelShaderCount) - { - m_Shader.push_back(std::move(shader)); //read - } + if (ind >= m_Shader.size()) + m_Shader.emplace_back(std::move(shader)); // read else - { - m_Shader[ind] = std::move(shader); // current changes - } + m_Shader[ind] = std::move(shader); } } @@ -217,15 +275,18 @@ void CustomMaterialResourceFile::recompileShaders(int ind) void CustomMaterialResourceFile::bindShader() //doubt?? { + int k = 0; //for (int ind = 0; ind < m_PixelShaderCount; ind++) //{ 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(); @@ -486,103 +547,19 @@ void CustomMaterialResourceFile::draw() if (ImGui::TreeNode("Pixel Shader")) { int ind=0; - index = ind; - if (ImGui::InputTextWithHint("Path", "Path to Pixel Shader", &m_MaterialData.pixelShaderPath, ImGuiInputTextFlags_EnterReturnsTrue)) - { - setPS(ind, 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")) - { - 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("Create PS"); - } - ImGui::SameLine(); - if (ImGui::Button(ICON_ROOTEX_WINDOW_CLOSE "##Reset PS")) - { - setPS(ind, s_DefaultCustomPSPath); - } - - if (ImGui::ListBoxHeader("Textures##PS")) - { - int i = 0; - for (auto& texture : m_MaterialData.pixelShaderTextures) - { - 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(); - } - - if (ImGui::Button(ICON_ROOTEX_PLUS "##Push PS")) - { - if (Optional result = OS::SelectFile(SupportedFiles.at(ResourceFile::Type::Image), "game/assets/")) - { - if (Ref image = ResourceLoader::CreateImageResourceFile(*result)) - { - pushPSTexture(image); - } - } - } - ImGui::SameLine(); - if (ImGui::Button(ICON_ROOTEX_MINUS "##Pop PS")) - { - popPSTexture(); - } - - ImGui::ListBoxFooter(); - } - // Remove current pixel shader - if (ImGui::Button("Remove This Shader")) - { - if (m_PixelShaderCount > 0) - { - //std::vector> temp; - //for (int j = 1; j < m_PixelShaderCount; j++) - //{ - //temp.push_back(m_Shader[j]); - //} - int i = 0; - auto itr = m_Shader.begin(); - while (i != ind) - { - itr++; - i++; - } - m_Shader.erase(itr); - m_PixelShaderCount--; - //m_Shader.clear(); - //for (int j = 0; j < m_PixelShaderCount; j++) - //{ - //m_Shader.push_back(temp[j]); - //} - } - else - { - ERROR("No pixel shaders left to be removed"); - } - } - for (ind = 1; ind < m_PixelShaderCount; ind++) + String s1, s2, s3, s4; + for (; ind < m_PixelShaderCount; ind++) { - setPS(ind, s_DefaultCustomPSPath); - if (ImGui::InputTextWithHint("Path", "Path to Pixel Shader", &m_MaterialData.pixelShaderPath, ImGuiInputTextFlags_EnterReturnsTrue)) + 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(ind,m_MaterialData.pixelShaderPath); + setPS(ind, m_MaterialData.pixelShaderPath); } - + s2 = "Create PS"+std::to_string(ind); if (ImGui::Button(ICON_ROOTEX_PENCIL_SQUARE_O "##Edit PS")) { EventManager::GetSingleton()->call(EditorEvents::EditorEditFile, m_MaterialData.pixelShaderPath); @@ -592,28 +569,34 @@ void CustomMaterialResourceFile::draw() { if (Optional result = OS::SelectFile("Pixel Shader(*.hlsl)\0*.hlsl\0", "game/assets/shaders/")) { - setPS(ind,*result); + setPS(ind, *result); } } ImGui::SameLine(); if (ImGui::Button(ICON_ROOTEX_PLUS "##Create PS")) { - ImGui::OpenPopup("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); + setPS(ind, s_DefaultCustomPSPath); } if (ImGui::ListBoxHeader("Textures##PS")) { - int i = 0; //i->ind - for (auto& texture : m_MaterialData.pixelShaderTextures) + 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 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(); } @@ -623,51 +606,58 @@ void CustomMaterialResourceFile::draw() { if (Ref image = ResourceLoader::CreateImageResourceFile(*result)) { - pushPSTexture(image); + pushPSTexture(image,ind); } } } ImGui::SameLine(); if (ImGui::Button(ICON_ROOTEX_MINUS "##Pop PS")) { - popPSTexture(); + popPSTexture(ind); } ImGui::ListBoxFooter(); } - //Remove current pixel shader + // Remove current pixel shader if (ImGui::Button("Remove This Shader")) { if (m_PixelShaderCount > 0) { - //std::vector> temp; - int j = 0; + int i = 0; auto itr = m_Shader.begin(); - while (ind != j) + while (i != ind) { - j++; itr++; + i++; + } + //remove textures from the vector: make a new vector + 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 ind) + { + m_Shader.erase(itr); // not working + m_PixelShaderCount--; } - //for (int j = 0; j < m_PixelShaderCount; j++) - //{ - //if (j != ind) - //{ - //temp.push_back(std::move((m_Shader[j]))); - //} - //} - m_Shader.erase(itr); - m_PixelShaderCount--; - //m_Shader.clear(); - //for (int j = 0; j < m_PixelShaderCount; j++) - //{ - //m_Shader.push_back(std::move((temp[j]))); - //} } else { ERROR("No pixel shaders left to be removed"); } } + ImGui::PopID(); + ImGui::Separator(); } if (ImGui::Button("Add Pixel Shader")) @@ -675,6 +665,7 @@ void CustomMaterialResourceFile::draw() if (m_PixelShaderCount < MAX_NUMBER_OF_PIXEL_SHADERS) { m_PixelShaderCount++; + m_MaterialData.pixelShaderTexturesMapping.push_back(m_MaterialData.pixelShaderTextures.size()); } else { diff --git a/rootex/core/resource_files/custom_material_resource_file.h b/rootex/core/resource_files/custom_material_resource_file.h index 6dafa20be..e6c4fc58e 100644 --- a/rootex/core/resource_files/custom_material_resource_file.h +++ b/rootex/core/resource_files/custom_material_resource_file.h @@ -22,9 +22,9 @@ class CustomMaterialResourceFile : public MaterialResourceFile 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); diff --git a/rootex/core/resource_files/material_resource_file.h b/rootex/core/resource_files/material_resource_file.h index e79b233e5..ab4665a9b 100644 --- a/rootex/core/resource_files/material_resource_file.h +++ b/rootex/core/resource_files/material_resource_file.h @@ -134,6 +134,7 @@ struct CustomMaterialData String pixelShaderPath; Vector> vertexShaderTextures; Vector> pixelShaderTextures; + Vector pixelShaderTexturesMapping; Vector customConstantBuffers; Vector typeOfCustomConstantBuffers; String dummyVertexShaderPath; From 8d0b17f2118da5215f4b9713e9654dc75df039f8 Mon Sep 17 00:00:00 2001 From: NehaGujar1 Date: Mon, 20 Feb 2023 18:30:00 +0530 Subject: [PATCH 3/5] Clean code commit --- .../custom_material_resource_file.cpp | 25 +++---------------- .../custom_material_resource_file.h | 2 +- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/rootex/core/resource_files/custom_material_resource_file.cpp b/rootex/core/resource_files/custom_material_resource_file.cpp index 242e16d3f..7de6f6e9a 100644 --- a/rootex/core/resource_files/custom_material_resource_file.cpp +++ b/rootex/core/resource_files/custom_material_resource_file.cpp @@ -118,34 +118,22 @@ void CustomMaterialResourceFile::pushPSTexture(Ref texture, i void CustomMaterialResourceFile::setPSTexture(const String& newtexturePath, int position, int ind) { - if (position >= m_MaterialData.pixelShaderTextures.size() || position < 0) //make changes + if (position >= m_MaterialData.pixelShaderTextures.size() || position < 0) { WARN("PS position being set is out of bounds: " + std::to_string(position)); return; } int a = m_MaterialData.pixelShaderTexturesMapping[ind]; - //Ref nextTexture,texture; if (Ref image = ResourceLoader::CreateImageResourceFile(newtexturePath)) { m_MaterialData.pixelShaderTextures[a + position] = image; } - //for (int i = a; i < m_MaterialData.pixelShaderTextures.size()-1; 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.pixelShaderTextures.push_back(texture); //changes } void CustomMaterialResourceFile::popPSTexture(int ind) { - if (m_MaterialData.pixelShaderTextures.empty()) //make changes + if (m_MaterialData.pixelShaderTextures.empty()) { WARN("PS texture list is empty."); return; @@ -273,13 +261,10 @@ void CustomMaterialResourceFile::recompileShaders(int ind) setShaders(ind, m_MaterialData.vertexShaderPath, m_MaterialData.pixelShaderPath); } -void CustomMaterialResourceFile::bindShader() //doubt?? +void CustomMaterialResourceFile::bindShader() { int k = 0; - //for (int ind = 0; ind < m_PixelShaderCount; ind++) - //{ m_Shader[index]->bind(); - //} k = 1; } @@ -618,7 +603,6 @@ void CustomMaterialResourceFile::draw() ImGui::ListBoxFooter(); } - // Remove current pixel shader if (ImGui::Button("Remove This Shader")) { if (m_PixelShaderCount > 0) @@ -630,7 +614,6 @@ void CustomMaterialResourceFile::draw() itr++; i++; } - //remove textures from the vector: make a new vector int a = m_MaterialData.pixelShaderTexturesMapping[ind]; int b = m_MaterialData.pixelShaderTextures.size(); @@ -647,7 +630,7 @@ void CustomMaterialResourceFile::draw() m_MaterialData.pixelShaderTexturesMapping.pop_back(); if (m_Shader.size() > ind) { - m_Shader.erase(itr); // not working + m_Shader.erase(itr); 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 e6c4fc58e..c2b86b1ef 100644 --- a/rootex/core/resource_files/custom_material_resource_file.h +++ b/rootex/core/resource_files/custom_material_resource_file.h @@ -53,7 +53,7 @@ class CustomMaterialResourceFile : public MaterialResourceFile } else return nullptr; - }; // doubt?? + }; Vector> getTextures() const override; void bindShader() override; From 4890c33d81f0fdbe8b3baaffb577ce39e2d55626 Mon Sep 17 00:00:00 2001 From: NehaGujar1 Date: Mon, 20 Feb 2023 18:51:38 +0530 Subject: [PATCH 4/5] Complete shader passes implementation ImGui --- .../custom_material_resource_file.cpp | 111 ++++++++++-------- .../custom_material_resource_file.h | 10 +- 2 files changed, 68 insertions(+), 53 deletions(-) diff --git a/rootex/core/resource_files/custom_material_resource_file.cpp b/rootex/core/resource_files/custom_material_resource_file.cpp index 7de6f6e9a..63f38d445 100644 --- a/rootex/core/resource_files/custom_material_resource_file.cpp +++ b/rootex/core/resource_files/custom_material_resource_file.cpp @@ -86,7 +86,7 @@ void CustomMaterialResourceFile::Destroy() CustomMaterialResourceFile::CustomMaterialResourceFile(const FilePath& path) : MaterialResourceFile(ResourceFile::Type::CustomMaterial, path) { - m_PixelShaderCount=0; + m_PixelShaderCount = 0; m_DummyVertexShaderPath = "rootex/core/renderer/shaders/custom_vertex_shader.hlsl"; reimport(); } @@ -100,7 +100,7 @@ void CustomMaterialResourceFile::pushPSTexture(Ref texture, i } int a; a = m_MaterialData.pixelShaderTextures.size(); - if ((ind +1) < m_MaterialData.pixelShaderTexturesMapping.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++) @@ -111,9 +111,9 @@ void CustomMaterialResourceFile::pushPSTexture(Ref texture, i } for (int i = ind + 1; i < m_MaterialData.pixelShaderTexturesMapping.size(); i++) { - m_MaterialData.pixelShaderTexturesMapping[i] = m_MaterialData.pixelShaderTexturesMapping[i]+1; + m_MaterialData.pixelShaderTexturesMapping[i] = m_MaterialData.pixelShaderTexturesMapping[i] + 1; } - m_MaterialData.pixelShaderTextures.push_back(texture); //changes + m_MaterialData.pixelShaderTextures.push_back(texture); } void CustomMaterialResourceFile::setPSTexture(const String& newtexturePath, int position, int ind) @@ -133,7 +133,7 @@ void CustomMaterialResourceFile::setPSTexture(const String& newtexturePath, int void CustomMaterialResourceFile::popPSTexture(int ind) { - if (m_MaterialData.pixelShaderTextures.empty()) + if (m_MaterialData.pixelShaderTextures.empty()) { WARN("PS texture list is empty."); return; @@ -146,14 +146,13 @@ void CustomMaterialResourceFile::popPSTexture(int ind) a = m_MaterialData.pixelShaderTexturesMapping[ind + 1]; else a = m_MaterialData.pixelShaderTextures.size(); - int j=a; + int j = a; a--; - Ref nextTexture,texture; - for (int i = a; i < m_MaterialData.pixelShaderTextures.size()-1; i++) + Ref nextTexture, texture; + for (int i = a; i < m_MaterialData.pixelShaderTextures.size() - 1; i++) { - nextTexture = m_MaterialData.pixelShaderTextures[i+1]; + nextTexture = m_MaterialData.pixelShaderTextures[i + 1]; m_MaterialData.pixelShaderTextures[i] = nextTexture; - //j++; } for (int i = ind + 1; i < m_MaterialData.pixelShaderTexturesMapping.size(); i++) { @@ -239,21 +238,23 @@ void CustomMaterialResourceFile::setShaders(int ind, const String& vertexShader, m_MaterialData.pixelShaderPath = pixelShader; m_MaterialData.vertexShaderPath = vertexShader; if (ind >= m_Shader.size()) - m_Shader.emplace_back(std::move(shader)); // read + m_Shader.emplace_back(std::move(shader)); else m_Shader[ind] = std::move(shader); } } -void CustomMaterialResourceFile::setVS(int ind,const String& vertexShader) +void CustomMaterialResourceFile::setVS(int ind, const String& vertexShader) { - setShaders(ind,vertexShader, m_MaterialData.pixelShaderPath); + setShaders(ind, vertexShader, m_MaterialData.pixelShaderPath); } -void CustomMaterialResourceFile::setPS(int ind,const String& pixelShader) +void CustomMaterialResourceFile::setPS(int ind, const String& pixelShader) { - if(ind==0) setShaders(ind,m_MaterialData.vertexShaderPath, pixelShader); - else setShaders(ind,m_DummyVertexShaderPath, pixelShader); + if (ind == 0) + setShaders(ind, m_MaterialData.vertexShaderPath, pixelShader); + else + setShaders(ind, m_DummyVertexShaderPath, pixelShader); } void CustomMaterialResourceFile::recompileShaders(int ind) @@ -261,7 +262,7 @@ void CustomMaterialResourceFile::recompileShaders(int ind) setShaders(ind, m_MaterialData.vertexShaderPath, m_MaterialData.pixelShaderPath); } -void CustomMaterialResourceFile::bindShader() +void CustomMaterialResourceFile::bindShader() { int k = 0; m_Shader[index]->bind(); @@ -271,7 +272,7 @@ void CustomMaterialResourceFile::bindShader() void CustomMaterialResourceFile::bindTextures() { int a = m_MaterialData.pixelShaderTexturesMapping[index]; - if (m_MaterialData.pixelShaderTextures.size()<=a) + if (m_MaterialData.pixelShaderTextures.size() <= a) { static Vector textureSRVs; textureSRVs.clear(); @@ -340,7 +341,8 @@ void CustomMaterialResourceFile::reimport() customConstantBuffers = m_MaterialData.customConstantBuffers; typeOfCustomConstantBuffers = m_MaterialData.typeOfCustomConstantBuffers; - for(int i=0;i result = OS::SelectFile("Vertex Shader(*.hlsl)\0*.hlsl\0", "game/assets/shaders/")) { - for(int ind=0;indcall(EditorEvents::EditorEditFile, shaderFileName); newVSPath.clear(); @@ -531,7 +545,7 @@ void CustomMaterialResourceFile::draw() if (ImGui::TreeNode("Pixel Shader")) { - int ind=0; + int ind = 0; String s1, s2, s3, s4; for (; ind < m_PixelShaderCount; ind++) { @@ -539,12 +553,13 @@ void CustomMaterialResourceFile::draw() ImGui::PushID(ind); s1 = "Path" + std::to_string(ind); bool bl = false; - if(ind>=m_Shader.size()) setPS(ind, s_DefaultCustomPSPath); + 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(ind, m_MaterialData.pixelShaderPath); } - s2 = "Create PS"+std::to_string(ind); + s2 = "Create PS" + std::to_string(ind); if (ImGui::Button(ICON_ROOTEX_PENCIL_SQUARE_O "##Edit PS")) { EventManager::GetSingleton()->call(EditorEvents::EditorEditFile, m_MaterialData.pixelShaderPath); @@ -576,12 +591,12 @@ void CustomMaterialResourceFile::draw() int b = m_MaterialData.pixelShaderTextures.size(); if (ind < (m_PixelShaderCount - 1)) b = m_MaterialData.pixelShaderTexturesMapping[ind + 1]; - for (i=a;i 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); }); + RootexSelectableImage(textureName.c_str(), texture, [this, i, ind, a](const String& newTexturePath) + { setPSTexture(newTexturePath, i - a, ind); }); ImGui::Separator(); } @@ -591,7 +606,7 @@ void CustomMaterialResourceFile::draw() { if (Ref image = ResourceLoader::CreateImageResourceFile(*result)) { - pushPSTexture(image,ind); + pushPSTexture(image, ind); } } } @@ -619,18 +634,18 @@ void CustomMaterialResourceFile::draw() if (ind + 1 < m_PixelShaderCount) b = m_MaterialData.pixelShaderTexturesMapping[ind + 1]; - for (int k=a;k ind) { - m_Shader.erase(itr); + m_Shader.erase(itr); m_PixelShaderCount--; } } @@ -642,7 +657,7 @@ void CustomMaterialResourceFile::draw() ImGui::PopID(); ImGui::Separator(); } - + if (ImGui::Button("Add Pixel Shader")) { if (m_PixelShaderCount < MAX_NUMBER_OF_PIXEL_SHADERS) @@ -669,8 +684,8 @@ void CustomMaterialResourceFile::draw() FileBuffer defaultShaderBuffer = OS::LoadFileContents(s_DefaultCustomPSPath); OS::SaveFile(shaderFileName, defaultShaderBuffer.data(), defaultShaderBuffer.size()); - for(int ind=0;indcall(EditorEvents::EditorEditFile, shaderFileName); newPSPath.clear(); diff --git a/rootex/core/resource_files/custom_material_resource_file.h b/rootex/core/resource_files/custom_material_resource_file.h index c2b86b1ef..ab6e11cbe 100644 --- a/rootex/core/resource_files/custom_material_resource_file.h +++ b/rootex/core/resource_files/custom_material_resource_file.h @@ -17,7 +17,7 @@ class CustomMaterialResourceFile : public MaterialResourceFile String m_DummyVertexShaderPath; int m_PixelShaderCount; - int index=0; + int index = 0; std::vector> m_Shader; Microsoft::WRL::ComPtr m_PSCB; Microsoft::WRL::ComPtr m_VSCB; @@ -40,9 +40,9 @@ class CustomMaterialResourceFile : public MaterialResourceFile explicit CustomMaterialResourceFile(const FilePath& path); ~CustomMaterialResourceFile() = default; - 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 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 @@ -53,7 +53,7 @@ class CustomMaterialResourceFile : public MaterialResourceFile } else return nullptr; - }; + }; Vector> getTextures() const override; void bindShader() override; From 48c50745bc7e549234ba10d1760470effa241623 Mon Sep 17 00:00:00 2001 From: NehaGujar1 Date: Mon, 20 Feb 2023 19:08:50 +0530 Subject: [PATCH 5/5] Remove clang-format errors --- .../core/resource_files/custom_material_resource_file.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/rootex/core/resource_files/custom_material_resource_file.cpp b/rootex/core/resource_files/custom_material_resource_file.cpp index 63f38d445..a327ee865 100644 --- a/rootex/core/resource_files/custom_material_resource_file.cpp +++ b/rootex/core/resource_files/custom_material_resource_file.cpp @@ -486,8 +486,7 @@ void CustomMaterialResourceFile::draw() for (auto& texture : m_MaterialData.vertexShaderTextures) { String textureName = "Slot " + std::to_string(i) + " " + ICON_ROOTEX_FOLDER_OPEN; - RootexSelectableImage(textureName.c_str(), texture, [this, i](const String& newTexturePath) - { setVSTexture(newTexturePath, i); }); + RootexSelectableImage(textureName.c_str(), texture, [this, i](const String& newTexturePath) { setVSTexture(newTexturePath, i); }); i++; ImGui::Separator(); } @@ -595,8 +594,7 @@ void CustomMaterialResourceFile::draw() { 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); }); + RootexSelectableImage(textureName.c_str(), texture, [this, i, ind, a](const String& newTexturePath) { setPSTexture(newTexturePath, i - a, ind); }); ImGui::Separator(); }