Welcome to mirror list, hosted at ThFree Co, Russian Federation.

vector2.h « shaders « kernel « cycles « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c524735d892f693d9b0cb9b829b9735d6489b768 (plain)
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
// Open Shading Language : Copyright (c) 2009-2017 Sony Pictures Imageworks Inc., et al.
// https://github.com/imageworks/OpenShadingLanguage/blob/master/LICENSE

#pragma once
#define VECTOR2_H

// vector2 is a 2D vector
struct vector2 {
  float x;
  float y;
};

//
// For vector2, define math operators to match vector
//

vector2 __operator__neg__(vector2 a)
{
  return vector2(-a.x, -a.y);
}

vector2 __operator__add__(vector2 a, vector2 b)
{
  return vector2(a.x + b.x, a.y + b.y);
}

vector2 __operator__add__(vector2 a, int b)
{
  return a + vector2(b, b);
}

vector2 __operator__add__(vector2 a, float b)
{
  return a + vector2(b, b);
}

vector2 __operator__add__(int a, vector2 b)
{
  return vector2(a, a) + b;
}

vector2 __operator__add__(float a, vector2 b)
{
  return vector2(a, a) + b;
}

vector2 __operator__sub__(vector2 a, vector2 b)
{
  return vector2(a.x - b.x, a.y - b.y);
}

vector2 __operator__sub__(vector2 a, int b)
{
  return a - vector2(b, b);
}

vector2 __operator__sub__(vector2 a, float b)
{
  return a - vector2(b, b);
}

vector2 __operator__sub__(int a, vector2 b)
{
  return vector2(a, a) - b;
}

vector2 __operator__sub__(float a, vector2 b)
{
  return vector2(a, a) - b;
}

vector2 __operator__mul__(vector2 a, vector2 b)
{
  return vector2(a.x * b.x, a.y * b.y);
}

vector2 __operator__mul__(vector2 a, int b)
{
  return a * vector2(b, b);
}

vector2 __operator__mul__(vector2 a, float b)
{
  return a * vector2(b, b);
}

vector2 __operator__mul__(int a, vector2 b)
{
  return b * vector2(a, a);
}

vector2 __operator__mul__(float a, vector2 b)
{
  return b * vector2(a, a);
}

vector2 __operator__div__(vector2 a, vector2 b)
{
  return vector2(a.x / b.x, a.y / b.y);
}

vector2 __operator__div__(vector2 a, int b)
{
  float b_inv = 1 / b;
  return a * vector2(b_inv, b_inv);
}

vector2 __operator__div__(vector2 a, float b)
{
  float b_inv = 1 / b;
  return a * vector2(b_inv, b_inv);
}

vector2 __operator__div__(int a, vector2 b)
{
  return vector2(a, a) / b;
}

vector2 __operator__div__(float a, vector2 b)
{
  return vector2(a, a) / b;
}

int __operator__eq__(vector2 a, vector2 b)
{
  return (a.x == b.x) && (a.y == b.y);
}

int __operator__ne__(vector2 a, vector2 b)
{
  return (a.x != b.x) || (a.y != b.y);
}

//
// For vector2, define most of the stdosl functions to match vector
//

vector2 abs(vector2 a)
{
  return vector2(abs(a.x), abs(a.y));
}

vector2 ceil(vector2 a)
{
  return vector2(ceil(a.x), ceil(a.y));
}

vector2 floor(vector2 a)
{
  return vector2(floor(a.x), floor(a.y));
}

vector2 sqrt(vector2 a)
{
  return vector2(sqrt(a.x), sqrt(a.y));
}

vector2 exp(vector2 a)
{
  return vector2(exp(a.x), exp(a.y));
}

vector2 log(vector2 a)
{
  return vector2(log(a.x), log(a.y));
}

vector2 log2(vector2 a)
{
  return vector2(log2(a.x), log2(a.y));
}

vector2 mix(vector2 a, vector2 b, float x)
{
  return vector2(mix(a.x, b.x, x), mix(a.y, b.y, x));
}

float dot(vector2 a, vector2 b)
{
  return (a.x * b.x + a.y * b.y);
}

float length(vector2 a)
{
  return hypot(a.x, a.y);
}

vector2 smoothstep(vector2 low, vector2 high, vector2 in)
{
  return vector2(smoothstep(low.x, high.x, in.x), smoothstep(low.y, high.y, in.y));
}

vector2 smoothstep(float low, float high, vector2 in)
{
  return vector2(smoothstep(low, high, in.x), smoothstep(low, high, in.y));
}

vector2 clamp(vector2 in, vector2 low, vector2 high)
{
  return vector2(clamp(in.x, low.x, high.x), clamp(in.y, low.y, high.y));
}

vector2 clamp(vector2 in, float low, float high)
{
  return clamp(in, vector2(low, low), vector2(high, high));
}

vector2 max(vector2 a, vector2 b)
{
  return vector2(max(a.x, b.x), max(a.y, b.y));
}

vector2 max(vector2 a, float b)
{
  return max(a, vector2(b, b));
}

vector2 normalize(vector2 a)
{
  return a / length(a);
}

vector2 min(vector2 a, vector2 b)
{
  return vector2(min(a.x, a.x), min(b.y, b.y));
}

vector2 min(vector2 a, float b)
{
  return min(a, vector2(b, b));
}

vector2 fmod(vector2 a, vector2 b)
{
  return vector2(fmod(a.x, b.x), fmod(a.y, b.y));
}

vector2 fmod(vector2 a, float b)
{
  return fmod(a, vector2(b, b));
}

vector2 pow(vector2 in, vector2 amount)
{
  return vector2(pow(in.x, amount.x), pow(in.y, amount.y));
}

vector2 pow(vector2 in, float amount)
{
  return pow(in, vector2(amount, amount));
}

vector2 sign(vector2 a)
{
  return vector2(sign(a.x), sign(a.y));
}

vector2 sin(vector2 a)
{
  return vector2(sin(a.x), sin(a.y));
}

vector2 cos(vector2 a)
{
  return vector2(cos(a.x), cos(a.y));
}

vector2 tan(vector2 a)
{
  return vector2(tan(a.x), tan(a.y));
}

vector2 asin(vector2 a)
{
  return vector2(asin(a.x), asin(a.y));
}

vector2 acos(vector2 a)
{
  return vector2(acos(a.x), acos(a.y));
}

vector2 atan2(vector2 a, float f)
{
  return vector2(atan2(a.x, f), atan2(a.y, f));
}

vector2 atan2(vector2 a, vector2 b)
{
  return vector2(atan2(a.x, b.x), atan2(a.y, b.y));
}