OpenShaderDesigner 0.0.1
Loading...
Searching...
No Matches
Shaders.h
1// =====================================================================================================================
2// OpenShaderDesigner, an open source software utility to create materials and shaders.
3// Copyright (C) 2024 Medusa Slockbower
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17// =====================================================================================================================
18
19#ifndef OSD_SHADERS_H
20#define OSD_SHADERS_H
21
22#include <glm/vec4.hpp>
23#include <Graph/ShaderGraph.h>
24
25#include "glw/shader.h"
26
27namespace OpenShaderDesigner::Nodes::Shaders
28{
29
30// Header Colors =======================================================================================================
31
32inline static constexpr ImColor HeaderColor = ImColor(0xA9, 0x85, 0xC1);
33inline static constexpr ImColor HeaderHoveredColor = ImColor(0xBB, 0x96, 0xD4);
34inline static constexpr ImColor HeaderActiveColor = ImColor(0x8D, 0x68, 0xA6);
35
36inline static const std::string HeaderMarker = "\uF42E ";
37
38// =====================================================================================================================
39// Shaders
40// =====================================================================================================================
41
42
43// Function Inputs -----------------------------------------------------------------------------------------------------
44
45class FunctionInputs : public Node
46{
47public:
48 FunctionInputs(ShaderGraph& graph, ImVec2 pos);
49 ~FunctionInputs() override = default;
50
51 [[nodiscard]] Node* Copy(ShaderGraph& graph) const override;
52 void Inspect() override;
53
54 std::string GetCode() const override;
55};
56
57
58// Function ------------------------------------------------------------------------------------------------------------
59
66class Function : public Node, public ShaderAsset
67{
68public:
69 Function(const FileManager::Path& path, ShaderGraph& graph);
70 ~Function() override;
71
72 [[nodiscard]] Node* Copy(ShaderGraph& graph) const override;
73 void Inspect() override;
74
75 void Compile() override;
76 void Open() override;
77
78 static Asset* Create(const FileManager::Path& path);
79 static Asset* Load(const FileManager::Path& path);
80 static Asset* Import(const FileManager::Path& src, const FileManager::Path& dst);
81
82 std::string GetCode() const override;
83 void View(HDRTexture::HandleType* Target) override;
84
85private:
86 using InputMap = ocu::map<int, glw::enum_t>;
87
88 enum FuncInput_ : glw::enum_t
89 {
90 FuncInput_Custom = 0
91
92 , FuncInput_X
93 , FuncInput_Y
94 , FuncInput_XY
95
96 , FuncInput_U
97 , FuncInput_V
98 , FuncInput_UV
99
100 , FuncInput_Time
101 , FuncInput_DeltaTime
102 };
103
104 inline static const std::vector<glw::enum_t> InputTypes[] = {
105 /* PinType_UInt */ { FuncInput_Custom, FuncInput_X, FuncInput_Y }
106 , /* PinType_Int */ { FuncInput_Custom, FuncInput_X, FuncInput_Y }
107 , /* PinType_Float */ { FuncInput_Custom, FuncInput_X, FuncInput_Y, FuncInput_U, FuncInput_V, FuncInput_Time, FuncInput_DeltaTime }
108 , /* PinType_Vector */ { FuncInput_Custom, FuncInput_XY, FuncInput_UV }
109 };
110
111 inline static const std::string InputNames[] = {
112 "Custom..."
113
114 , "X"
115 , "Y"
116 , "XY"
117
118 , "U"
119 , "V"
120 , "UV"
121
122 , "Time"
123 , "Delta Time"
124 };
125
126 inline static const std::string InputVars[] = {
127 ""
128 , "x"
129 , "y"
130 , "xy"
131
132 , "u"
133 , "v"
134 , "uv"
135
136 , "t"
137 , "dt"
138 };
139
140 void DrawImage_(HDRTexture::HandleType* Target);
141 void DrawInputs_();
142 void Render_(HDRTexture::HandleType* Target);
143 void CompileDisplayShader_();
144
145 glw::shader* Shader_;
146 std::string DisplayCode_;
147 FunctionInputs Inputs_;
148 NodeId ID_, InputsID_;
149 InputMap InputValues_;
150 uint32_t DisplayVar_;
151};
152
153
154}
155
156#endif // OSD_SHADERS_H
Functions are a Shader function that takes inputs and outputs.
Definition Shaders.h:67
Definition ShaderGraph.h:214
Definition ShaderGraph.h:246
Definition ShaderGraph.h:142