Skip to content

Commit

Permalink
feat(lua): add shader graph bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Silverlan committed Dec 29, 2024
1 parent 602ab92 commit 1645ddc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/client/include/pragma/rendering/shader_graph/manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace pragma::rendering {
void ReloadShader(const std::string &identifier);
std::shared_ptr<ShaderGraphData> GetGraph(const std::string &identifier) const;
const std::shared_ptr<pragma::shadergraph::NodeRegistry> &GetNodeRegistry() const { return m_nodeRegistry; }
const std::unordered_map<std::string, std::shared_ptr<ShaderGraphData>> &GetGraphs() const { return m_graphs; }
private:
friend ShaderGraphManager;
void RegisterGraph(const std::string &identifier, std::shared_ptr<pragma::shadergraph::Graph> graph);
Expand All @@ -62,6 +63,7 @@ namespace pragma::rendering {
std::shared_ptr<pragma::shadergraph::Graph> LoadShader(const std::string &identifier, std::string &outErr, bool reload = false);
void ReloadShader(const std::string &identifier);
std::shared_ptr<ShaderGraphData> GetGraph(const std::string &identifier) const;
void SetGraph(const std::string &type, const std::string &identifier, const std::shared_ptr<pragma::shadergraph::Graph> &graph);
std::shared_ptr<pragma::shadergraph::NodeRegistry> GetNodeRegistry(const std::string &type) const;

ShaderGraphModuleManager &GetModuleManager();
Expand Down
5 changes: 5 additions & 0 deletions core/client/src/lua/c_luaclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,11 @@ void ClientState::RegisterSharedLuaClasses(Lua::Interface &lua, bool bGUI)
return {nullptr, std::optional<std::string> {err}};
return {graph, std::optional<std::string> {}};
})];
modShader[luabind::def(
"set_shader_graph", +[](const std::string &type, const std::string &identifier, const std::shared_ptr<pragma::shadergraph::Graph> &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 {
Expand Down
8 changes: 8 additions & 0 deletions core/client/src/rendering/shader_graph/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<pragma::shadergraph::Graph> graph)
{
auto fragFilePath = util::FilePath(ShaderGraphManager::GetShaderFilePath(m_typeName, identifier));
Expand Down Expand Up @@ -142,6 +143,13 @@ std::shared_ptr<ShaderGraphData> 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<pragma::shadergraph::Graph> &graph)
{
auto it = m_shaderGraphTypeManagers.find(type);
if(it == m_shaderGraphTypeManagers.end())
return;
it->second->RegisterGraph(identifier, graph);
}

std::shared_ptr<pragma::shadergraph::NodeRegistry> ShaderGraphManager::GetNodeRegistry(const std::string &type) const
{
Expand Down

0 comments on commit 1645ddc

Please sign in to comment.