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

vector4.h « shaders « kernel « cycles « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 58e1b3c2e23e2b5f88395a7e5c93c93178d8d03f (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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
// Open Shading Language : Copyright (c) 2009-2017 Sony Pictures Imageworks Inc., et al.
// https://github.com/imageworks/OpenShadingLanguage/blob/master/LICENSE

#pragma once
#define VECTOR4_H

// vector4 is a 4D vector
struct vector4 {
  float x;
  float y;
  float z;
  float w;
};

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

vector4 __operator__neg__(vector4 a)
{
  return vector4(-a.x, -a.y, -a.z, -a.w);
}

vector4 __operator__add__(vector4 a, vector4 b)
{
  return vector4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
}

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

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

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

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

vector4 __operator__sub__(vector4 a, vector4 b)
{
  return vector4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
}

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

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

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

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

vector4 __operator__mul__(vector4 a, vector4 b)
{
  return vector4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
}

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

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

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

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

vector4 __operator__div__(vector4 a, vector4 b)
{
  return vector4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
}

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

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

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

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

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

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

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

vector4 abs(vector4 in)
{
  return vector4(abs(in.x), abs(in.y), abs(in.z), abs(in.w));
}

vector4 ceil(vector4 in)
{
  return vector4(ceil(in.x), ceil(in.y), ceil(in.z), ceil(in.w));
}

vector4 floor(vector4 in)
{
  return vector4(floor(in.x), floor(in.y), floor(in.z), floor(in.w));
}

vector4 sqrt(vector4 in)
{
  return vector4(sqrt(in.x), sqrt(in.y), sqrt(in.z), sqrt(in.w));
}

vector4 exp(vector4 in)
{
  return vector4(exp(in.x), exp(in.y), exp(in.z), exp(in.w));
}

vector4 log(vector4 in)
{
  return vector4(log(in.x), log(in.y), log(in.z), log(in.w));
}

vector4 log2(vector4 in)
{
  return vector4(log2(in.x), log2(in.y), log2(in.z), log2(in.w));
}

vector4 mix(vector4 value1, vector4 value2, float x)
{
  return vector4(mix(value1.x, value2.x, x),
                 mix(value1.y, value2.y, x),
                 mix(value1.z, value2.z, x),
                 mix(value1.w, value2.w, x));
}

vector vec4ToVec3(vector4 v)
{
  return vector(v.x, v.y, v.z) / v.w;
}

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

float length(vector4 a)
{
  return sqrt(a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w);
}

vector4 smoothstep(vector4 low, vector4 high, vector4 in)
{
  return vector4(smoothstep(low.x, high.x, in.x),
                 smoothstep(low.y, high.y, in.y),
                 smoothstep(low.z, high.z, in.z),
                 smoothstep(low.w, high.w, in.w));
}

vector4 smoothstep(float low, float high, vector4 in)
{
  return vector4(smoothstep(low, high, in.x),
                 smoothstep(low, high, in.y),
                 smoothstep(low, high, in.z),
                 smoothstep(low, high, in.w));
}

vector4 clamp(vector4 in, vector4 low, vector4 high)
{
  return vector4(clamp(in.x, low.x, high.x),
                 clamp(in.y, low.y, high.y),
                 clamp(in.z, low.z, high.z),
                 clamp(in.w, low.w, high.w));
}

vector4 clamp(vector4 in, float low, float high)
{
  return vector4(clamp(in.x, low, high),
                 clamp(in.y, low, high),
                 clamp(in.z, low, high),
                 clamp(in.w, low, high));
}

vector4 max(vector4 a, vector4 b)
{
  return vector4(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z), max(a.w, b.w));
}

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

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

vector4 min(vector4 a, vector4 b)
{
  return vector4(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z), min(a.w, b.w));
}

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

vector4 fmod(vector4 a, vector4 b)
{
  return vector4(fmod(a.x, b.x), fmod(a.y, b.y), fmod(a.z, b.z), fmod(a.w, b.w));
}

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

vector4 pow(vector4 in, vector4 amount)
{
  return vector4(
      pow(in.x, amount.x), pow(in.y, amount.y), pow(in.z, amount.z), pow(in.w, amount.w));
}

vector4 pow(vector4 in, float amount)
{
  return vector4(pow(in.x, amount), pow(in.y, amount), pow(in.z, amount), pow(in.w, amount));
}

vector4 sign(vector4 a)
{
  return vector4(sign(a.x), sign(a.y), sign(a.z), sign(a.w));
}

vector4 sin(vector4 a)
{
  return vector4(sin(a.x), sin(a.y), sin(a.z), sin(a.w));
}

vector4 cos(vector4 a)
{
  return vector4(cos(a.x), cos(a.y), cos(a.z), cos(a.w));
}

vector4 tan(vector4 a)
{
  return vector4(tan(a.x), tan(a.y), tan(a.z), tan(a.w));
}

vector4 asin(vector4 a)
{
  return vector4(asin(a.x), asin(a.y), asin(a.z), asin(a.w));
}

vector4 acos(vector4 a)
{
  return vector4(acos(a.x), acos(a.y), acos(a.z), acos(a.w));
}

vector4 atan2(vector4 a, float f)
{
  return vector4(atan2(a.x, f), atan2(a.y, f), atan2(a.z, f), atan2(a.w, f));
}

vector4 atan2(vector4 a, vector4 b)
{
  return vector4(atan2(a.x, b.x), atan2(a.y, b.y), atan2(a.z, b.z), atan2(a.w, b.w));
}

vector4 transform(matrix M, vector4 p)
{
  return vector4(M[0][0] * p.x + M[0][1] * p.y + M[0][2] * p.z + M[0][2] * p.w,
                 M[1][0] * p.x + M[1][1] * p.y + M[1][2] * p.z + M[1][2] * p.w,
                 M[2][0] * p.x + M[2][1] * p.y + M[2][2] * p.z + M[2][2] * p.w,
                 M[3][0] * p.x + M[3][1] * p.y + M[3][2] * p.z + M[3][2] * p.w);
}

vector4 transform(string fromspace, string tospace, vector4 p)
{
  return transform(matrix(fromspace, tospace), p);
}