From 1645ddcae1d96751680075b1ba0c03ea7144ff5b Mon Sep 17 00:00:00 2001 From: Silverlan Date: Sun, 29 Dec 2024 21:35:51 +0100 Subject: [PATCH] feat(lua): add shader graph bindings --- .../include/pragma/rendering/shader_graph/manager.hpp | 2 ++ core/client/src/lua/c_luaclass.cpp | 5 +++++ core/client/src/rendering/shader_graph/manager.cpp | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/core/client/include/pragma/rendering/shader_graph/manager.hpp b/core/client/include/pragma/rendering/shader_graph/manager.hpp index 05418eb6a..4134a16c3 100644 --- a/core/client/include/pragma/rendering/shader_graph/manager.hpp +++ b/core/client/include/pragma/rendering/shader_graph/manager.hpp @@ -36,6 +36,7 @@ namespace pragma::rendering { void ReloadShader(const std::string &identifier); std::shared_ptr GetGraph(const std::string &identifier) const; const std::shared_ptr &GetNodeRegistry() const { return m_nodeRegistry; } + const std::unordered_map> &GetGraphs() const { return m_graphs; } private: friend ShaderGraphManager; void RegisterGraph(const std::string &identifier, std::shared_ptr graph); @@ -62,6 +63,7 @@ namespace pragma::rendering { std::shared_ptr LoadShader(const std::string &identifier, std::string &outErr, bool reload = false); void ReloadShader(const std::string &identifier); std::shared_ptr GetGraph(const std::string &identifier) const; + void SetGraph(const std::string &type, const std::string &identifier, const std::shared_ptr &graph); std::shared_ptr GetNodeRegistry(const std::string &type) const; ShaderGraphModuleManager &GetModuleManager(); diff --git a/core/client/src/lua/c_luaclass.cpp b/core/client/src/lua/c_luaclass.cpp index 8cc0dbf49..680cd1ed7 100644 --- a/core/client/src/lua/c_luaclass.cpp +++ b/core/client/src/lua/c_luaclass.cpp @@ -649,6 +649,11 @@ void ClientState::RegisterSharedLuaClasses(Lua::Interface &lua, bool bGUI) return {nullptr, std::optional {err}}; return {graph, std::optional {}}; })]; + modShader[luabind::def( + "set_shader_graph", +[](const std::string &type, const std::string &identifier, const std::shared_ptr &graph) { + auto &manager = c_engine->GetShaderGraphManager(); + manager.SetGraph(type, identifier, graph); + })]; // These have to match shaders/modules/fs_tonemapping.gls! enum class ToneMapping : uint8_t { diff --git a/core/client/src/rendering/shader_graph/manager.cpp b/core/client/src/rendering/shader_graph/manager.cpp index 00cba4f56..7a639b0f7 100644 --- a/core/client/src/rendering/shader_graph/manager.cpp +++ b/core/client/src/rendering/shader_graph/manager.cpp @@ -13,6 +13,7 @@ extern DLLCLIENT CEngine *c_engine; using namespace pragma::rendering; +#pragma optimize("", off) void ShaderGraphTypeManager::RegisterGraph(const std::string &identifier, std::shared_ptr graph) { auto fragFilePath = util::FilePath(ShaderGraphManager::GetShaderFilePath(m_typeName, identifier)); @@ -142,6 +143,13 @@ std::shared_ptr ShaderGraphManager::GetGraph(const std::string return nullptr; return it->second->GetGraph(identifier); } +void ShaderGraphManager::SetGraph(const std::string &type, const std::string &identifier, const std::shared_ptr &graph) +{ + auto it = m_shaderGraphTypeManagers.find(type); + if(it == m_shaderGraphTypeManagers.end()) + return; + it->second->RegisterGraph(identifier, graph); +} std::shared_ptr ShaderGraphManager::GetNodeRegistry(const std::string &type) const {