Skip to content

Commit

Permalink
feat(shader_graph): update ui elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Silverlan committed Nov 23, 2024
1 parent be03e96 commit e8dfab9
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 25 deletions.
33 changes: 21 additions & 12 deletions assets/addons/shader_graph/lua/gui/shader_graph/node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ function Element:OnInitialize()
local box = gui.create("WIVBox", self, 0, 0, self:GetWidth(), self:GetHeight())
box:SetName("global_container")
box:SetFixedWidth(true)
box:AddCallback("SetSize", function()
self:SetHeight(box:GetBottom())
end)

local outputControls = gui.create("WIPFMControlsMenu", box, 0, 0, box:GetWidth(), box:GetHeight())
outputControls:SetAutoFillContentsToHeight(false)
Expand All @@ -28,9 +31,6 @@ function Element:OnInitialize()
gui.create("WIPFMControlsMenu", box, 0, outputControls:GetBottom(), box:GetWidth(), box:GetHeight())
inputControls:SetAutoFillContentsToHeight(false)
inputControls:SetFixedHeight(false)
inputControls:AddCallback("SetSize", function()
self:SetHeight(inputControls:GetBottom())
end)
self.m_inputControls = inputControls

self.m_inputs = {}
Expand All @@ -47,12 +47,17 @@ end
function Element:GetNode()
return self.m_node
end
function Element:AddControl(socketType, title, id)
function Element:AddControl(socketType, title, id, type)
local ctrlMenu = (socketType == gui.GraphNodeSocket.SOCKET_TYPE_INPUT) and self.m_inputControls
or self.m_outputControls
local elCtrl = ctrlMenu:AddSliderControl(title, id, 0.01, 0.0, 0.1, function(el, value)
--
end, 0.001)
local elCtrl
if socketType == gui.GraphNodeSocket.SOCKET_TYPE_INPUT and type ~= nil then
local wrapper = ctrlMenu:AddPropertyControl(type, id, title, {})
elCtrl = wrapper:GetWrapperElement()
else
local el, wrapper = ctrlMenu:AddText(title, id, "")
elCtrl = wrapper
end
local el = gui.create("WIGraphNodeSocket", elCtrl)
el:SetSocket(self, id, socketType)
el:SetMouseInputEnabled(true)
Expand All @@ -67,7 +72,7 @@ function Element:AddControl(socketType, title, id)
socketElement = el,
controlElement = elCtrl,
}
return el
return el, elCtrl
end
function Element:GetSocket(socketType, name)
local t = (socketType == gui.GraphNodeSocket.SOCKET_TYPE_INPUT) and self.m_inputs or self.m_outputs
Expand All @@ -82,12 +87,16 @@ end
function Element:GetOutputSocket(name)
return self:GetSocket(gui.GraphNodeSocket.SOCKET_TYPE_OUTPUT, name)
end
function Element:AddInput(name)
return self:AddControl(gui.GraphNodeSocket.SOCKET_TYPE_INPUT, name, name)
function Element:AddInput(name, type)
local elSocket, elCtrl = self:AddControl(gui.GraphNodeSocket.SOCKET_TYPE_INPUT, name, name, type)
elSocket:SetX(elSocket:GetWidth() * -0.5)
elSocket:SetY(elCtrl:GetHeight() * 0.5 - elSocket:GetHeight() * 0.5)
return elSocket
end
function Element:AddOutput(name)
local elSocket = self:AddControl(gui.GraphNodeSocket.SOCKET_TYPE_OUTPUT, name, name)
elSocket:SetX(self:GetWidth() - elSocket:GetWidth())
local elSocket, elCtrl = self:AddControl(gui.GraphNodeSocket.SOCKET_TYPE_OUTPUT, name, name)
elSocket:SetX(elCtrl:GetWidth() - elSocket:GetWidth() * 0.5)
elSocket:SetY(elCtrl:GetHeight() * 0.5 - elSocket:GetHeight() * 0.5)
elSocket:SetAnchor(1, 0, 1, 0)
return elSocket
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ function Element:OnInitialize()

self:SetSize(16, 16)

local bg = gui.create("WIRect", self, 0, 0, self:GetWidth(), self:GetHeight(), 0, 0, 1, 1)
bg:SetColor(Color.Red)
local bg = gui.create("WITexturedRect", self, 0, 0, self:GetWidth(), self:GetHeight(), 0, 0, 1, 1)
bg:SetMaterial("circle")
self.m_bg = bg
end
function Element:SetSocket(node, socket, socketType)
Expand Down
58 changes: 47 additions & 11 deletions assets/addons/shader_graph/lua/gui/shader_graph/shader_graph.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function Element:OnInitialize()
self.m_nameToElementData = {}
self.m_nodeData = {}
self.m_linkElements = {}
self:Clear()
self:SetSize(1280, 1024)

self:SetMouseInputEnabled(true)
Expand Down Expand Up @@ -80,31 +81,55 @@ function Element:MouseCallback(button, state, mods)
pFileDialog:SetRootPath("scripts/shader_data/graphs")
pFileDialog:Update()
end)
pContext:AddItem("Add Node", function()
local graphNode = self.m_graph:AddNode("math")
if graphNode ~= nil then
self:AddNode(graphNode)
self:InitializeLinks()
end
pContext:AddItem("Generate GLSL", function()
util.set_clipboard_string(self.m_graph:GenerateGlsl())
end)
local reg = shader.get_graph_node_registry("object")
if reg ~= nil then
local nodeTypes = reg:GetNodeTypes()
table.sort(nodeTypes)
local pItem, pSubMenu = pContext:AddSubMenu("Add Node")
for _, name in pairs(nodeTypes) do
pSubMenu:AddItem(name, function(pItem)
local graphNode = self.m_graph:AddNode(name)
if graphNode ~= nil then
local frame = self:AddNode(graphNode)
local pos = self:GetCursorPos()
frame:SetPos(pos.x - frame:GetWidth() * 0.5, pos.y - frame:GetHeight() * 0.5)
self:InitializeLinks()
end
end)
end
pSubMenu:Update()
end
pContext:Update()
return util.EVENT_REPLY_HANDLED
end
end
end
function Element:SetGraph(graph)
function Element:GetGraph()
return self.m_graph
end
function Element:Clear()
self:ClearLinks()
for _, t in ipairs(self.m_nodeData) do
util.remove(t.frame)
end
self.m_nodeData = {}
self.m_nameToElementData = {}
self.m_graph = shader.create_graph("object")
end
function Element:SetGraph(graph)
self:Clear()

self.m_graph = graph

local nodes = self.m_graph:GetNodes()
local offset = 0
for _, graphNode in ipairs(nodes) do
self:AddNode(graphNode)
local frame = self:AddNode(graphNode)
frame:SetX(offset)
offset = offset + frame:GetWidth() + 80
end

self:InitializeLinks()
Expand Down Expand Up @@ -146,6 +171,7 @@ function Element:AddLink(elOutputSocket, elInputSocket)
local l = gui.create("WIElementConnectorLine", self)
l:SetSize(self:GetSize())
l:SetAnchor(0, 0, 1, 1)
l:SetZPos(-1)
l:Setup(elOutputSocket, elInputSocket)
table.insert(self.m_linkElements, l)
end
Expand All @@ -172,7 +198,15 @@ function Element:AddNode(graphNode)
frame:SetTitle(name)
frame:SetDetachButtonEnabled(false)
frame:SetCloseButtonEnabled(false)
frame:SetResizable(false)
frame:SetSize(128, 128)
frame:SetZPos(0)
frame:AddCallback("OnDragStart", function(el, x, y)
el:SetZPos(1)
end)
frame:AddCallback("OnDragEnd", function(el, x, y)
el:SetZPos(0)
end)

frame:SetMouseInputEnabled(true)
frame:AddCallback("OnMouseEvent", function(el, button, state, mods)
Expand Down Expand Up @@ -201,16 +235,17 @@ function Element:AddNode(graphNode)
local elNode = gui.create("WIGraphNode", frame)
elNode:SetNode(graphNode:GetName())
elNode:SetY(31)
frame:SetX(#self.m_nodeData * 200)
elNode:AddCallback("SetSize", function()
frame:SetHeight(elNode:GetBottom())
end)
for _, output in ipairs(graphNode:GetOutputs()) do
local socket = output:GetSocket()
local elOutput = elNode:AddOutput(socket.name)
end
for _, input in ipairs(graphNode:GetInputs()) do
local socket = input:GetSocket()
local elInput = elNode:AddInput(socket.name)
local elInput = elNode:AddInput(socket.name, shader.Socket.to_udm_type(socket.type))
end
--x = elNode:GetRight() + 80

elNode:AddCallback("OnSocketClicked", function(elNode, elSocket, socketType, id)
if util.is_valid(self.m_outSocket) == false then
Expand Down Expand Up @@ -243,5 +278,6 @@ function Element:AddNode(graphNode)
}
table.insert(self.m_nodeData, t)
self.m_nameToElementData[graphNode:GetName()] = t
return frame
end
gui.register("WIShaderGraph", Element)
14 changes: 14 additions & 0 deletions core/client/include/pragma/rendering/shader_graph/nodes/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,18 @@ namespace pragma::rendering::shader_graph {
};
};

#if 0
layout(std140, LAYOUT_ID(SCENE, RENDER_SETTINGS)) uniform RenderSettings
{
vec4 posCam; // w component is fov
int flags;
float shadowRatioX;
float shadowRatioY;
float nearZ;
float farZ;
int shaderQuality; // 1 = lowest, 10 = highest
}
u_renderSettings;
#endif

#endif
1 change: 1 addition & 0 deletions core/client/src/rendering/shader_graph_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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

0 comments on commit e8dfab9

Please sign in to comment.