Fix click-drag regression in fix for T86116
[blender.git] / source / blender / nodes / intern / math_functions.cc
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16
17 #include "NOD_math_functions.hh"
18
19 namespace blender::nodes {
20
21 const FloatMathOperationInfo *get_float_math_operation_info(const int operation)
22 {
23
24 #define RETURN_OPERATION_INFO(title_case_name, shader_name) \
25   { \
26     static const FloatMathOperationInfo info{title_case_name, shader_name}; \
27     return &info; \
28   } \
29   ((void)0)
30
31   switch (operation) {
32     case NODE_MATH_ADD:
33       RETURN_OPERATION_INFO("Add", "math_add");
34     case NODE_MATH_SUBTRACT:
35       RETURN_OPERATION_INFO("Subtract", "math_subtract");
36     case NODE_MATH_MULTIPLY:
37       RETURN_OPERATION_INFO("Multiply", "math_multiply");
38     case NODE_MATH_DIVIDE:
39       RETURN_OPERATION_INFO("Divide", "math_divide");
40     case NODE_MATH_SINE:
41       RETURN_OPERATION_INFO("Sine", "math_sine");
42     case NODE_MATH_COSINE:
43       RETURN_OPERATION_INFO("Cosine", "math_cosine");
44     case NODE_MATH_TANGENT:
45       RETURN_OPERATION_INFO("Tangent", "math_tangent");
46     case NODE_MATH_ARCSINE:
47       RETURN_OPERATION_INFO("Arc Sine", "math_arcsine");
48     case NODE_MATH_ARCCOSINE:
49       RETURN_OPERATION_INFO("Arc Cosine", "math_arccosine");
50     case NODE_MATH_ARCTANGENT:
51       RETURN_OPERATION_INFO("Arc Tangent", "math_arctangent");
52     case NODE_MATH_POWER:
53       RETURN_OPERATION_INFO("Power", "math_power");
54     case NODE_MATH_LOGARITHM:
55       RETURN_OPERATION_INFO("Logarithm", "math_logarithm");
56     case NODE_MATH_MINIMUM:
57       RETURN_OPERATION_INFO("Minimum", "math_minimum");
58     case NODE_MATH_MAXIMUM:
59       RETURN_OPERATION_INFO("Maximum", "math_maximum");
60     case NODE_MATH_ROUND:
61       RETURN_OPERATION_INFO("Round", "math_round");
62     case NODE_MATH_LESS_THAN:
63       RETURN_OPERATION_INFO("Less Than", "math_less_than");
64     case NODE_MATH_GREATER_THAN:
65       RETURN_OPERATION_INFO("Greater Than", "math_greater_than");
66     case NODE_MATH_MODULO:
67       RETURN_OPERATION_INFO("Modulo", "math_modulo");
68     case NODE_MATH_ABSOLUTE:
69       RETURN_OPERATION_INFO("Absolute", "math_absolute");
70     case NODE_MATH_ARCTAN2:
71       RETURN_OPERATION_INFO("Arc Tangent 2", "math_arctan2");
72     case NODE_MATH_FLOOR:
73       RETURN_OPERATION_INFO("Floor", "math_floor");
74     case NODE_MATH_CEIL:
75       RETURN_OPERATION_INFO("Ceil", "math_ceil");
76     case NODE_MATH_FRACTION:
77       RETURN_OPERATION_INFO("Fraction", "math_fraction");
78     case NODE_MATH_SQRT:
79       RETURN_OPERATION_INFO("Sqrt", "math_sqrt");
80     case NODE_MATH_INV_SQRT:
81       RETURN_OPERATION_INFO("Inverse Sqrt", "math_inversesqrt");
82     case NODE_MATH_SIGN:
83       RETURN_OPERATION_INFO("Sign", "math_sign");
84     case NODE_MATH_EXPONENT:
85       RETURN_OPERATION_INFO("Exponent", "math_exponent");
86     case NODE_MATH_RADIANS:
87       RETURN_OPERATION_INFO("Radians", "math_radians");
88     case NODE_MATH_DEGREES:
89       RETURN_OPERATION_INFO("Degrees", "math_degrees");
90     case NODE_MATH_SINH:
91       RETURN_OPERATION_INFO("Hyperbolic Sine", "math_sinh");
92     case NODE_MATH_COSH:
93       RETURN_OPERATION_INFO("Hyperbolic Cosine", "math_cosh");
94     case NODE_MATH_TANH:
95       RETURN_OPERATION_INFO("Hyperbolic Tangent", "math_tanh");
96     case NODE_MATH_TRUNC:
97       RETURN_OPERATION_INFO("Truncate", "math_trunc");
98     case NODE_MATH_SNAP:
99       RETURN_OPERATION_INFO("Snap", "math_snap");
100     case NODE_MATH_WRAP:
101       RETURN_OPERATION_INFO("Wrap", "math_wrap");
102     case NODE_MATH_COMPARE:
103       RETURN_OPERATION_INFO("Compare", "math_compare");
104     case NODE_MATH_MULTIPLY_ADD:
105       RETURN_OPERATION_INFO("Multiply Add", "math_multiply_add");
106     case NODE_MATH_PINGPONG:
107       RETURN_OPERATION_INFO("Ping Pong", "math_pingpong");
108     case NODE_MATH_SMOOTH_MIN:
109       RETURN_OPERATION_INFO("Smooth Min", "math_smoothmin");
110     case NODE_MATH_SMOOTH_MAX:
111       RETURN_OPERATION_INFO("Smooth Max", "math_smoothmax");
112   }
113
114 #undef RETURN_OPERATION_INFO
115
116   return nullptr;
117 }
118
119 const FloatMathOperationInfo *get_float_compare_operation_info(const int operation)
120 {
121
122 #define RETURN_OPERATION_INFO(title_case_name, shader_name) \
123   { \
124     static const FloatMathOperationInfo info{title_case_name, shader_name}; \
125     return &info; \
126   } \
127   ((void)0)
128
129   switch (operation) {
130     case NODE_FLOAT_COMPARE_LESS_THAN:
131       RETURN_OPERATION_INFO("Less Than", "math_less_than");
132     case NODE_FLOAT_COMPARE_LESS_EQUAL:
133       RETURN_OPERATION_INFO("Less Than or Equal", "math_less_equal");
134     case NODE_FLOAT_COMPARE_GREATER_THAN:
135       RETURN_OPERATION_INFO("Greater Than", "math_greater_than");
136     case NODE_FLOAT_COMPARE_GREATER_EQUAL:
137       RETURN_OPERATION_INFO("Greater Than or Equal", "math_greater_equal");
138     case NODE_FLOAT_COMPARE_EQUAL:
139       RETURN_OPERATION_INFO("Equal", "math_equal");
140     case NODE_FLOAT_COMPARE_NOT_EQUAL:
141       RETURN_OPERATION_INFO("Not Equal", "math_not_equal");
142   }
143
144 #undef RETURN_OPERATION_INFO
145
146   return nullptr;
147 }
148
149 const FloatMathOperationInfo *get_float3_math_operation_info(const int operation)
150 {
151
152 #define RETURN_OPERATION_INFO(title_case_name, shader_name) \
153   { \
154     static const FloatMathOperationInfo info{title_case_name, shader_name}; \
155     return &info; \
156   } \
157   ((void)0)
158
159   switch (operation) {
160     case NODE_VECTOR_MATH_ADD:
161       RETURN_OPERATION_INFO("Add", "vector_math_add");
162     case NODE_VECTOR_MATH_SUBTRACT:
163       RETURN_OPERATION_INFO("Subtract", "vector_math_subtract");
164     case NODE_VECTOR_MATH_MULTIPLY:
165       RETURN_OPERATION_INFO("Multiply", "vector_math_multiply");
166     case NODE_VECTOR_MATH_DIVIDE:
167       RETURN_OPERATION_INFO("Divide", "vector_math_divide");
168     case NODE_VECTOR_MATH_CROSS_PRODUCT:
169       RETURN_OPERATION_INFO("Cross Product", "vector_math_cross");
170     case NODE_VECTOR_MATH_PROJECT:
171       RETURN_OPERATION_INFO("Project", "vector_math_project");
172     case NODE_VECTOR_MATH_REFLECT:
173       RETURN_OPERATION_INFO("Reflect", "vector_math_reflect");
174     case NODE_VECTOR_MATH_DOT_PRODUCT:
175       RETURN_OPERATION_INFO("Dot Product", "vector_math_dot");
176     case NODE_VECTOR_MATH_DISTANCE:
177       RETURN_OPERATION_INFO("Distance", "vector_math_distance");
178     case NODE_VECTOR_MATH_LENGTH:
179       RETURN_OPERATION_INFO("Length", "vector_math_length");
180     case NODE_VECTOR_MATH_SCALE:
181       RETURN_OPERATION_INFO("Scale", "vector_math_scale");
182     case NODE_VECTOR_MATH_NORMALIZE:
183       RETURN_OPERATION_INFO("Normalize", "vector_math_normalize");
184     case NODE_VECTOR_MATH_SNAP:
185       RETURN_OPERATION_INFO("Snap", "vector_math_snap");
186     case NODE_VECTOR_MATH_FLOOR:
187       RETURN_OPERATION_INFO("Floor", "vector_math_floor");
188     case NODE_VECTOR_MATH_CEIL:
189       RETURN_OPERATION_INFO("Ceiling", "vector_math_ceil");
190     case NODE_VECTOR_MATH_MODULO:
191       RETURN_OPERATION_INFO("Modulo", "vector_math_modulo");
192     case NODE_VECTOR_MATH_FRACTION:
193       RETURN_OPERATION_INFO("Fraction", "vector_math_fraction");
194     case NODE_VECTOR_MATH_ABSOLUTE:
195       RETURN_OPERATION_INFO("Absolute", "vector_math_absolute");
196     case NODE_VECTOR_MATH_MINIMUM:
197       RETURN_OPERATION_INFO("Minimum", "vector_math_minimum");
198     case NODE_VECTOR_MATH_MAXIMUM:
199       RETURN_OPERATION_INFO("Maximum", "vector_math_maximum");
200     case NODE_VECTOR_MATH_WRAP:
201       RETURN_OPERATION_INFO("Wrap", "vector_math_wrap");
202     case NODE_VECTOR_MATH_SINE:
203       RETURN_OPERATION_INFO("Sine", "vector_math_sine");
204     case NODE_VECTOR_MATH_COSINE:
205       RETURN_OPERATION_INFO("Cosine", "vector_math_cosine");
206     case NODE_VECTOR_MATH_TANGENT:
207       RETURN_OPERATION_INFO("Tangent", "vector_math_tangent");
208   }
209
210 #undef RETURN_OPERATION_INFO
211
212   return nullptr;
213 }
214
215 }  // namespace blender::nodes