OpenShaderDesigner 0.0.1
Loading...
Searching...
No Matches
Functions.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_MATH_H
20#define OSD_MATH_H
21
22#include <glm/vec4.hpp>
23#include <Graph/ShaderGraph.h>
24
25namespace ocu = open_cpp_utils;
26
27namespace OpenShaderDesigner::Nodes::Math
28{
29
30// Header Colors =======================================================================================================
31
32inline static constexpr ImColor HeaderColor = ImColor(0xA7, 0x62, 0x53);
33inline static constexpr ImColor HeaderHoveredColor = ImColor(0xC5, 0x79, 0x67);
34inline static constexpr ImColor HeaderActiveColor = ImColor(0x82, 0x4C, 0x40);
35
36inline static const std::string HeaderMarker = "\uF3B9 ";
37
38
39
40// =====================================================================================================================
41// Operations
42// =====================================================================================================================
43
44
45// Math Op Prototype ---------------------------------------------------------------------------------------------------
46
47struct MathOp : public Node
48{
49 enum MathOpFlags_ : glw::enum_t
50 {
51 MathOpFlags_None = 0
52 , MathOpFlags_AllowMultipleInputTypes = 0x0000'0001
53 };
54
55 MathOp(ShaderGraph& graph, ImVec2 pos);
56 ~MathOp() override = default;
57
58 virtual bool CheckConnection(Pin*, Pin*) override;
59 virtual void ValidateConnections() override;
60
61 struct
62 {
63 glw::enum_t Flags;
64 } Math;
65};
66
67
68// Add -----------------------------------------------------------------------------------------------------------------
69
70struct Add : public MathOp
71{
72 Add(ShaderGraph& graph, ImVec2 pos);
73 ~Add() override = default;
74
75 [[nodiscard]] Node* Copy(ShaderGraph& graph) const override;
76 void Inspect() override;
77
78 std::string GetCode() const override;
79};
80
81
82// Subtract ------------------------------------------------------------------------------------------------------------
83
84struct Subtract : public MathOp
85{
86 Subtract(ShaderGraph& graph, ImVec2 pos);
87 ~Subtract() override = default;
88
89 [[nodiscard]] Node* Copy(ShaderGraph& graph) const override;
90 void Inspect() override;
91
92 std::string GetCode() const override;
93};
94
95// Multiply ------------------------------------------------------------------------------------------------------------
96
97struct Multiply : public MathOp
98{
99 Multiply(ShaderGraph& graph, ImVec2 pos);
100 ~Multiply() override = default;
101
102 [[nodiscard]] Node* Copy(ShaderGraph& graph) const override;
103 void Inspect() override;
104
105 std::string GetCode() const override;
106};
107
108
109// Divide --------------------------------------------------------------------------------------------------------------
110
111struct Divide : public MathOp
112{
113 Divide(ShaderGraph& graph, ImVec2 pos);
114 ~Divide() override = default;
115
116 [[nodiscard]] Node* Copy(ShaderGraph& graph) const override;
117 void Inspect() override;
118
119 std::string GetCode() const override;
120};
121
122
123// Abs --------------------------------------------------------------------------------------------------------------
124
125struct AbsoluteValue : public MathOp
126{
127 AbsoluteValue(ShaderGraph& graph, ImVec2 pos);
128 ~AbsoluteValue() override = default;
129
130 [[nodiscard]] Node* Copy(ShaderGraph& graph) const override;
131 void Inspect() override;
132
133 std::string GetCode() const override;
134};
135
136
137// SquareRoot --------------------------------------------------------------------------------------------------------------
138
139struct SquareRoot : public MathOp
140{
141 SquareRoot(ShaderGraph& graph, ImVec2 pos);
142 ~SquareRoot() override = default;
143
144 [[nodiscard]] Node* Copy(ShaderGraph& graph) const override;
145 void Inspect() override;
146
147 std::string GetCode() const override;
148};
149
150
151// Power --------------------------------------------------------------------------------------------------------------
152
153struct Power : public MathOp
154{
155 Power(ShaderGraph& graph, ImVec2 pos);
156 ~Power() override = default;
157
158 [[nodiscard]] Node* Copy(ShaderGraph& graph) const override;
159 void Inspect() override;
160
161 std::string GetCode() const override;
162};
163
164
165// Exponential --------------------------------------------------------------------------------------------------------------
166
167struct Exponential : public MathOp
168{
169 Exponential(ShaderGraph& graph, ImVec2 pos);
170 ~Exponential() override = default;
171
172 [[nodiscard]] Node* Copy(ShaderGraph& graph) const override;
173 void Inspect() override;
174
175 std::string GetCode() const override;
176};
177
178
179}
180
181#endif // OPEN_SHADER_DESIGNER_MATH_H
Definition ShaderGraph.h:246
Definition ShaderGraph.h:142
Definition Functions.h:71
Definition Functions.h:112
Definition Functions.h:154
Definition ShaderGraph.h:83