forked from Maxon-Computer/Redshift-OSL-Shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UberScalarMath.osl
226 lines (226 loc) · 5.83 KB
/
UberScalarMath.osl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
shader UberScalarMath (
int operation = 0
[[
string label = "Operation",
string widget = "popup",
string options = "\
Add|Subtract|Multiply|Divide|Multiply Add|Power|Logarithm|Square Root|\
Inverse Square Root|Absolute|Exponent|Minimum|Maximum|Less Than|\
Greater Than|Sign|Compare|Round|Floor|\
Ceil|Truncate|Fraction|Modulo|Wrap|Snap|Ping-Pong|Sine|Cosine|Tangent|\
Arcsine|Arccosine|Arctangent|Arctan2|Hyperbolic Sine|Hyperbolic Cosine|\
Hyperbolic Tangent|To Radians|To Degrees"
]],
float input1 = 0.0
[[
float min = -1000.0,
float max = 1000.0,
float sensitivity = 0.1
]],
float input2 = 0.0
[[
float min = -1000.0,
float max = 1000.0,
float sensitivity = 0.1
]],
float input3 = 0.0
[[
float min = -1000.0,
float max = 1000.0,
float sensitivity = 0.1
]],
output float Out = 0.0,
) {
// Add
// input1 = Value 1, input2 = Value 2
if (operation == 0) {
Out = input1 + input2;
}
//Subtract
// input1 = Value 1, input2 = Value 2
else if (operation == 1) {
Out = input1 - input2;
}
// Multiply
// input1 = Value 1, input2 = Value 2
else if (operation == 2) {
Out = input1 * input2;
}
// Divide
// input1 = Value 1, input2 = Value 2
else if (operation == 3) {
Out = input1 / input2;
}
// Multiply Add
// input1 = Value, input2 = Multiplier, input3 = Addend
else if (operation == 4) {
float temp = input1 * input2;
Out = input3 + temp;
}
// Power
// input1 = Base, input2 = Exponent
else if (operation == 5) {
Out = pow(input1, input2);
}
// Logarithm
// input1 = Value, input2 = Base
else if (operation == 6) {
Out = log(input1, input2);
}
// Square Root
// input1 = Value
else if (operation == 7) {
Out = sqrt(input1);
}
// Inverse Square Root
// input1 = Value
else if (operation == 8) {
Out = inversesqrt(input1);
}
// Absolute
// input1 = Value
else if (operation == 9) {
Out = abs(input1);
}
// Exponent
// input1 = Value
else if (operation == 10) {
Out = exp(input1);
}
// Minimum
// input1 = Value 1, input2 = Value 2
else if (operation == 11) {
Out = min(input1, input2);
}
// Maximum
// input1 = Value 1, input2 = Value 2
else if (operation == 12) {
Out = max(input1, input2);
}
// Less Than
// input1 = Value, input2 = Threshold
else if (operation == 13) {
Out = select(1.0, 0.0, input1 < input2);
}
// Greater Than
// input1 = Value, input2 = Threshold
else if (operation == 14) {
Out = select(1.0, 0.0, input1 > input2);
}
// Sign
// input1 = Value
else if (operation == 15) {
Out = sign(input1);
}
// Compare
// input1 = Value 1, input2 = Value 2, input3 = Epsilon
else if (operation == 16) {
Out = select(1.0, 0.0, (input1 - input2) <= input3);
}
// Round
// input1 = Value
else if (operation == 17) {
Out = round(input1);
}
// Floor
// input1 = Value
else if (operation == 18) {
Out = floor(input1);
}
// Ceil
// input1 = Value
else if (operation == 19) {
Out = ceil(input1);
}
// Truncate
// input1 = Value
else if (operation == 20) {
Out = trunc(input1);
}
// Fraction
// input1 = Value
else if (operation == 21) {
float temp = trunc(input1);
Out = input1 - temp;
}
// Modulo
// input1 = Value 1, input2 = Value 2
else if (operation == 22) {
Out = mod(input1, input2);
}
// Wrap
// input1 = Value, input2 = Min, input3 = Max
else if (operation == 23) {
Out = fmod(((fmod((input1 - input2), (input3 - input2))) + (input3 - input2)), (input3 - input2)) + input2;
}
// Snap
// input1 = Value, input2 = Increment
else if (operation == 24) {
Out = (input1 + (input2 / 2)) - fmod((input1 + (input2 / 2)), input2);
}
// Ping-Pong
// input1 = Value, input2 = Scale
else if (operation == 25) {
Out = 0.0 + fabs(fmod((input1 + input2), (input2 * 2)) - input2);
}
// Sine
// input1 = Value
else if (operation == 26) {
Out = sin(input1);
}
// Cosine
// input1 = Value
else if (operation == 27) {
Out = cos(input1);
}
// Tangent
// input1 = Value
else if (operation == 28) {
Out = tan(input1);
}
// Arcsine
// input1 = Value
else if (operation == 29) {
Out = asin(input1);
}
// input1 = Value
// Arccosine
else if (operation == 30) {
Out = acos(input1);
}
// Arctangent
// input1 = Value
else if (operation == 31) {
Out = atan(input1);
}
// Arctan2
// input1 = Value 1, input2 = Value 2
else if (operation == 32) {
Out = atan2(input1, input2);
}
// Hyperbolic Sine
// input1 = Value
else if (operation == 33) {
Out = sinh(input1);
}
// Hyperbolic Cosine
// input1 = Value
else if (operation == 34) {
Out = cosh(input1);
}
// Hyperbolic Tangent
// input1 = Value
else if (operation == 35) {
Out = tanh(input1);
}
// To Radians
// input1 = Value
else if (operation == 36) {
Out = radians(input1);
}
// To Degrees
// input1 = Value
else if (operation == 37) {
Out = degrees(input1);
}
}