typegpu 0.12.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/data/vectorOps.js CHANGED
@@ -1,227 +1,28 @@
1
1
  import { mat2x2f, mat3x3f, mat4x4f } from "./matrix.js";
2
- import { bitcastF32toU32Impl, bitcastU32toF32Impl, bitcastU32toI32Impl, clamp, divInteger, smoothstepScalar, } from "./numberOps.js";
3
- import * as vectorConstructors from "./vector.js";
4
- const vec2b = vectorConstructors.vec2b;
5
- const vec2f = vectorConstructors.vec2f;
6
- const vec2h = vectorConstructors.vec2h;
7
- const vec2i = vectorConstructors.vec2i;
8
- const vec2u = vectorConstructors.vec2u;
9
- const vec3b = vectorConstructors.vec3b;
10
- const vec3f = vectorConstructors.vec3f;
11
- const vec3h = vectorConstructors.vec3h;
12
- const vec3i = vectorConstructors.vec3i;
13
- const vec3u = vectorConstructors.vec3u;
14
- const vec4b = vectorConstructors.vec4b;
15
- const vec4f = vectorConstructors.vec4f;
16
- const vec4h = vectorConstructors.vec4h;
17
- const vec4i = vectorConstructors.vec4i;
18
- const vec4u = vectorConstructors.vec4u;
2
+ import { bitcastF32toU32Impl, bitcastU32toF32Impl, bitcastU32toI32Impl } from "./numberOps.js";
3
+ import { vec2f, vec2i, vec2u, vec3f, vec3h, vec3i, vec3u, vec4f, vec4i, vec4u } from "./vector.js";
19
4
  const lengthVec2 = (v) => Math.sqrt(v.x ** 2 + v.y ** 2);
20
5
  const lengthVec3 = (v) => Math.sqrt(v.x ** 2 + v.y ** 2 + v.z ** 2);
21
6
  const lengthVec4 = (v) => Math.sqrt(v.x ** 2 + v.y ** 2 + v.z ** 2 + v.w ** 2);
22
7
  const dotVec2 = (lhs, rhs) => lhs.x * rhs.x + lhs.y * rhs.y;
23
8
  const dotVec3 = (lhs, rhs) => lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z;
24
9
  const dotVec4 = (lhs, rhs) => lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z + lhs.w * rhs.w;
25
- const unary2f = (op) => (a) => vec2f(op(a.x), op(a.y));
26
- const unary2h = (op) => (a) => vec2h(op(a.x), op(a.y));
27
- const unary2i = (op) => (a) => vec2i(op(a.x), op(a.y));
28
- const unary2u = (op) => (a) => vec2u(op(a.x), op(a.y));
29
- const unary3f = (op) => (a) => vec3f(op(a.x), op(a.y), op(a.z));
30
- const unary3h = (op) => (a) => vec3h(op(a.x), op(a.y), op(a.z));
31
- const unary3i = (op) => (a) => vec3i(op(a.x), op(a.y), op(a.z));
32
- const unary3u = (op) => (a) => vec3u(op(a.x), op(a.y), op(a.z));
33
- const unary4f = (op) => (a) => vec4f(op(a.x), op(a.y), op(a.z), op(a.w));
34
- const unary4h = (op) => (a) => vec4h(op(a.x), op(a.y), op(a.z), op(a.w));
35
- const unary4i = (op) => (a) => vec4i(op(a.x), op(a.y), op(a.z), op(a.w));
36
- const unary4u = (op) => (a) => vec4u(op(a.x), op(a.y), op(a.z), op(a.w));
37
- const unary2x2f = (op) => (a) => {
38
- const a_ = a.columns;
39
- return mat2x2f(unary2f(op)(a_[0]), unary2f(op)(a_[1]));
40
- };
41
- const unary3x3f = (op) => (a) => {
42
- const a_ = a.columns;
43
- return mat3x3f(unary3f(op)(a_[0]), unary3f(op)(a_[1]), unary3f(op)(a_[2]));
44
- };
45
- const unary4x4f = (op) => (a) => {
46
- const a_ = a.columns;
47
- return mat4x4f(unary4f(op)(a_[0]), unary4f(op)(a_[1]), unary4f(op)(a_[2]), unary4f(op)(a_[3]));
48
- };
49
- const binaryComponentWise2f = (op) => (a, b) => vec2f(op(a.x, b.x), op(a.y, b.y));
50
- const binaryComponentWise2h = (op) => (a, b) => vec2h(op(a.x, b.x), op(a.y, b.y));
51
- const binaryComponentWise2i = (op) => (a, b) => vec2i(op(a.x, b.x), op(a.y, b.y));
52
10
  const binaryComponentWise2u = (op) => (a, b) => vec2u(op(a.x, b.x), op(a.y, b.y));
53
- const binaryComponentWise3f = (op) => (a, b) => vec3f(op(a.x, b.x), op(a.y, b.y), op(a.z, b.z));
54
- const binaryComponentWise3h = (op) => (a, b) => vec3h(op(a.x, b.x), op(a.y, b.y), op(a.z, b.z));
55
- const binaryComponentWise3i = (op) => (a, b) => vec3i(op(a.x, b.x), op(a.y, b.y), op(a.z, b.z));
56
11
  const binaryComponentWise3u = (op) => (a, b) => vec3u(op(a.x, b.x), op(a.y, b.y), op(a.z, b.z));
57
- const binaryComponentWise4f = (op) => (a, b) => vec4f(op(a.x, b.x), op(a.y, b.y), op(a.z, b.z), op(a.w, b.w));
58
- const binaryComponentWise4h = (op) => (a, b) => vec4h(op(a.x, b.x), op(a.y, b.y), op(a.z, b.z), op(a.w, b.w));
59
- const binaryComponentWise4i = (op) => (a, b) => vec4i(op(a.x, b.x), op(a.y, b.y), op(a.z, b.z), op(a.w, b.w));
60
12
  const binaryComponentWise4u = (op) => (a, b) => vec4u(op(a.x, b.x), op(a.y, b.y), op(a.z, b.z), op(a.w, b.w));
61
13
  const binaryComponentWise2i2u = (op) => (a, b) => vec2i(op(a.x, b.x), op(a.y, b.y));
62
14
  const binaryComponentWise3i3u = (op) => (a, b) => vec3i(op(a.x, b.x), op(a.y, b.y), op(a.z, b.z));
63
15
  const binaryComponentWise4i4u = (op) => (a, b) => vec4i(op(a.x, b.x), op(a.y, b.y), op(a.z, b.z), op(a.w, b.w));
64
- const binaryComponentWise2x2f = (op) => (a, b) => {
65
- const a_ = a.columns;
66
- const b_ = b.columns;
67
- return mat2x2f(binaryComponentWise2f(op)(a_[0], b_[0]), binaryComponentWise2f(op)(a_[1], b_[1]));
68
- };
69
- const binaryComponentWise3x3f = (op) => (a, b) => {
70
- const a_ = a.columns;
71
- const b_ = b.columns;
72
- return mat3x3f(binaryComponentWise3f(op)(a_[0], b_[0]), binaryComponentWise3f(op)(a_[1], b_[1]), binaryComponentWise3f(op)(a_[2], b_[2]));
73
- };
74
- const binaryComponentWise4x4f = (op) => (a, b) => {
75
- const a_ = a.columns;
76
- const b_ = b.columns;
77
- return mat4x4f(binaryComponentWise4f(op)(a_[0], b_[0]), binaryComponentWise4f(op)(a_[1], b_[1]), binaryComponentWise4f(op)(a_[2], b_[2]), binaryComponentWise4f(op)(a_[3], b_[3]));
78
- };
79
- const ternaryComponentWise2f = (op) => (a, b, c) => vec2f(op(a.x, b.x, c.x), op(a.y, b.y, c.y));
80
- const ternaryComponentWise2h = (op) => (a, b, c) => vec2h(op(a.x, b.x, c.x), op(a.y, b.y, c.y));
81
- const ternaryComponentWise3f = (op) => (a, b, c) => vec3f(op(a.x, b.x, c.x), op(a.y, b.y, c.y), op(a.z, b.z, c.z));
82
- const ternaryComponentWise3h = (op) => (a, b, c) => vec3h(op(a.x, b.x, c.x), op(a.y, b.y, c.y), op(a.z, b.z, c.z));
83
- const ternaryComponentWise4f = (op) => (a, b, c) => vec4f(op(a.x, b.x, c.x), op(a.y, b.y, c.y), op(a.z, b.z, c.z), op(a.w, b.w, c.w));
84
- const ternaryComponentWise4h = (op) => (a, b, c) => vec4h(op(a.x, b.x, c.x), op(a.y, b.y, c.y), op(a.z, b.z, c.z), op(a.w, b.w, c.w));
16
+ /**
17
+ * Functions that cannot be simply generalized via `generalizeFn`
18
+ * have their overloads listed explicitly here.
19
+ */
85
20
  export const VectorOps = {
86
- eq: {
87
- vec2f: (e1, e2) => vec2b(e1.x === e2.x, e1.y === e2.y),
88
- vec2h: (e1, e2) => vec2b(e1.x === e2.x, e1.y === e2.y),
89
- vec2i: (e1, e2) => vec2b(e1.x === e2.x, e1.y === e2.y),
90
- vec2u: (e1, e2) => vec2b(e1.x === e2.x, e1.y === e2.y),
91
- 'vec2<bool>': (e1, e2) => vec2b(e1.x === e2.x, e1.y === e2.y),
92
- vec3f: (e1, e2) => vec3b(e1.x === e2.x, e1.y === e2.y, e1.z === e2.z),
93
- vec3h: (e1, e2) => vec3b(e1.x === e2.x, e1.y === e2.y, e1.z === e2.z),
94
- vec3i: (e1, e2) => vec3b(e1.x === e2.x, e1.y === e2.y, e1.z === e2.z),
95
- vec3u: (e1, e2) => vec3b(e1.x === e2.x, e1.y === e2.y, e1.z === e2.z),
96
- 'vec3<bool>': (e1, e2) => vec3b(e1.x === e2.x, e1.y === e2.y, e1.z === e2.z),
97
- vec4f: (e1, e2) => vec4b(e1.x === e2.x, e1.y === e2.y, e1.z === e2.z, e1.w === e2.w),
98
- vec4h: (e1, e2) => vec4b(e1.x === e2.x, e1.y === e2.y, e1.z === e2.z, e1.w === e2.w),
99
- vec4i: (e1, e2) => vec4b(e1.x === e2.x, e1.y === e2.y, e1.z === e2.z, e1.w === e2.w),
100
- vec4u: (e1, e2) => vec4b(e1.x === e2.x, e1.y === e2.y, e1.z === e2.z, e1.w === e2.w),
101
- 'vec4<bool>': (e1, e2) => vec4b(e1.x === e2.x, e1.y === e2.y, e1.z === e2.z, e1.w === e2.w),
102
- },
103
- lt: {
104
- vec2f: (e1, e2) => vec2b(e1.x < e2.x, e1.y < e2.y),
105
- vec2h: (e1, e2) => vec2b(e1.x < e2.x, e1.y < e2.y),
106
- vec2i: (e1, e2) => vec2b(e1.x < e2.x, e1.y < e2.y),
107
- vec2u: (e1, e2) => vec2b(e1.x < e2.x, e1.y < e2.y),
108
- vec3f: (e1, e2) => vec3b(e1.x < e2.x, e1.y < e2.y, e1.z < e2.z),
109
- vec3h: (e1, e2) => vec3b(e1.x < e2.x, e1.y < e2.y, e1.z < e2.z),
110
- vec3i: (e1, e2) => vec3b(e1.x < e2.x, e1.y < e2.y, e1.z < e2.z),
111
- vec3u: (e1, e2) => vec3b(e1.x < e2.x, e1.y < e2.y, e1.z < e2.z),
112
- vec4f: (e1, e2) => vec4b(e1.x < e2.x, e1.y < e2.y, e1.z < e2.z, e1.w < e2.w),
113
- vec4h: (e1, e2) => vec4b(e1.x < e2.x, e1.y < e2.y, e1.z < e2.z, e1.w < e2.w),
114
- vec4i: (e1, e2) => vec4b(e1.x < e2.x, e1.y < e2.y, e1.z < e2.z, e1.w < e2.w),
115
- vec4u: (e1, e2) => vec4b(e1.x < e2.x, e1.y < e2.y, e1.z < e2.z, e1.w < e2.w),
116
- },
117
- or: {
118
- 'vec2<bool>': (e1, e2) => vec2b(e1.x || e2.x, e1.y || e2.y),
119
- 'vec3<bool>': (e1, e2) => vec3b(e1.x || e2.x, e1.y || e2.y, e1.z || e2.z),
120
- 'vec4<bool>': (e1, e2) => vec4b(e1.x || e2.x, e1.y || e2.y, e1.z || e2.z, e1.w || e2.w),
121
- },
122
21
  all: {
123
22
  'vec2<bool>': (e) => e.x && e.y,
124
23
  'vec3<bool>': (e) => e.x && e.y && e.z,
125
24
  'vec4<bool>': (e) => e.x && e.y && e.z && e.w,
126
25
  },
127
- abs: {
128
- vec2f: unary2f(Math.abs),
129
- vec2h: unary2h(Math.abs),
130
- vec2i: unary2i(Math.abs),
131
- vec2u: unary2u(Math.abs),
132
- vec3f: unary3f(Math.abs),
133
- vec3h: unary3h(Math.abs),
134
- vec3i: unary3i(Math.abs),
135
- vec3u: unary3u(Math.abs),
136
- vec4f: unary4f(Math.abs),
137
- vec4h: unary4h(Math.abs),
138
- vec4i: unary4i(Math.abs),
139
- vec4u: unary4u(Math.abs),
140
- },
141
- atan2: {
142
- vec2f: binaryComponentWise2f(Math.atan2),
143
- vec2h: binaryComponentWise2h(Math.atan2),
144
- vec3f: binaryComponentWise3f(Math.atan2),
145
- vec3h: binaryComponentWise3h(Math.atan2),
146
- vec4f: binaryComponentWise4f(Math.atan2),
147
- vec4h: binaryComponentWise4h(Math.atan2),
148
- },
149
- acos: {
150
- vec2f: unary2f(Math.acos),
151
- vec2h: unary2h(Math.acos),
152
- vec2i: unary2i(Math.acos),
153
- vec2u: unary2u(Math.acos),
154
- vec3f: unary3f(Math.acos),
155
- vec3h: unary3h(Math.acos),
156
- vec3i: unary3i(Math.acos),
157
- vec3u: unary3u(Math.acos),
158
- vec4f: unary4f(Math.acos),
159
- vec4h: unary4h(Math.acos),
160
- vec4i: unary4i(Math.acos),
161
- vec4u: unary4u(Math.acos),
162
- },
163
- acosh: {
164
- vec2f: unary2f(Math.acosh),
165
- vec2h: unary2h(Math.acosh),
166
- vec3f: unary3f(Math.acosh),
167
- vec3h: unary3h(Math.acosh),
168
- vec4f: unary4f(Math.acosh),
169
- vec4h: unary4h(Math.acosh),
170
- },
171
- asin: {
172
- vec2f: unary2f(Math.asin),
173
- vec2h: unary2h(Math.asin),
174
- vec3f: unary3f(Math.asin),
175
- vec3h: unary3h(Math.asin),
176
- vec4f: unary4f(Math.asin),
177
- vec4h: unary4h(Math.asin),
178
- },
179
- asinh: {
180
- vec2f: unary2f(Math.asinh),
181
- vec2h: unary2h(Math.asinh),
182
- vec3f: unary3f(Math.asinh),
183
- vec3h: unary3h(Math.asinh),
184
- vec4f: unary4f(Math.asinh),
185
- vec4h: unary4h(Math.asinh),
186
- },
187
- atan: {
188
- vec2f: unary2f(Math.atan),
189
- vec2h: unary2h(Math.atan),
190
- vec3f: unary3f(Math.atan),
191
- vec3h: unary3h(Math.atan),
192
- vec4f: unary4f(Math.atan),
193
- vec4h: unary4h(Math.atan),
194
- },
195
- atanh: {
196
- vec2f: unary2f(Math.atanh),
197
- vec2h: unary2h(Math.atanh),
198
- vec3f: unary3f(Math.atanh),
199
- vec3h: unary3h(Math.atanh),
200
- vec4f: unary4f(Math.atanh),
201
- vec4h: unary4h(Math.atanh),
202
- },
203
- ceil: {
204
- vec2f: unary2f(Math.ceil),
205
- vec2h: unary2h(Math.ceil),
206
- vec3f: unary3f(Math.ceil),
207
- vec3h: unary3h(Math.ceil),
208
- vec4f: unary4f(Math.ceil),
209
- vec4h: unary4h(Math.ceil),
210
- },
211
- clamp: {
212
- vec2f: (v, low, high) => vec2f(clamp(v.x, low.x, high.x), clamp(v.y, low.y, high.y)),
213
- vec2h: (v, low, high) => vec2h(clamp(v.x, low.x, high.x), clamp(v.y, low.y, high.y)),
214
- vec2i: (v, low, high) => vec2i(clamp(v.x, low.x, high.x), clamp(v.y, low.y, high.y)),
215
- vec2u: (v, low, high) => vec2u(clamp(v.x, low.x, high.x), clamp(v.y, low.y, high.y)),
216
- vec3f: (v, low, high) => vec3f(clamp(v.x, low.x, high.x), clamp(v.y, low.y, high.y), clamp(v.z, low.z, high.z)),
217
- vec3h: (v, low, high) => vec3h(clamp(v.x, low.x, high.x), clamp(v.y, low.y, high.y), clamp(v.z, low.z, high.z)),
218
- vec3i: (v, low, high) => vec3i(clamp(v.x, low.x, high.x), clamp(v.y, low.y, high.y), clamp(v.z, low.z, high.z)),
219
- vec3u: (v, low, high) => vec3u(clamp(v.x, low.x, high.x), clamp(v.y, low.y, high.y), clamp(v.z, low.z, high.z)),
220
- vec4f: (v, low, high) => vec4f(clamp(v.x, low.x, high.x), clamp(v.y, low.y, high.y), clamp(v.z, low.z, high.z), clamp(v.w, low.w, high.w)),
221
- vec4h: (v, low, high) => vec4h(clamp(v.x, low.x, high.x), clamp(v.y, low.y, high.y), clamp(v.z, low.z, high.z), clamp(v.w, low.w, high.w)),
222
- vec4i: (v, low, high) => vec4i(clamp(v.x, low.x, high.x), clamp(v.y, low.y, high.y), clamp(v.z, low.z, high.z), clamp(v.w, low.w, high.w)),
223
- vec4u: (v, low, high) => vec4u(clamp(v.x, low.x, high.x), clamp(v.y, low.y, high.y), clamp(v.z, low.z, high.z), clamp(v.w, low.w, high.w)),
224
- },
225
26
  length: {
226
27
  vec2f: lengthVec2,
227
28
  vec2h: lengthVec2,
@@ -230,78 +31,7 @@ export const VectorOps = {
230
31
  vec4f: lengthVec4,
231
32
  vec4h: lengthVec4,
232
33
  },
233
- add: {
234
- vec2f: binaryComponentWise2f((a, b) => a + b),
235
- vec2h: binaryComponentWise2h((a, b) => a + b),
236
- vec2i: binaryComponentWise2i((a, b) => a + b),
237
- vec2u: binaryComponentWise2u((a, b) => a + b),
238
- vec3f: binaryComponentWise3f((a, b) => a + b),
239
- vec3h: binaryComponentWise3h((a, b) => a + b),
240
- vec3i: binaryComponentWise3i((a, b) => a + b),
241
- vec3u: binaryComponentWise3u((a, b) => a + b),
242
- vec4f: binaryComponentWise4f((a, b) => a + b),
243
- vec4h: binaryComponentWise4h((a, b) => a + b),
244
- vec4i: binaryComponentWise4i((a, b) => a + b),
245
- vec4u: binaryComponentWise4u((a, b) => a + b),
246
- mat2x2f: binaryComponentWise2x2f((a, b) => a + b),
247
- mat3x3f: binaryComponentWise3x3f((a, b) => a + b),
248
- mat4x4f: binaryComponentWise4x4f((a, b) => a + b),
249
- },
250
- smoothstep: {
251
- vec2f: ternaryComponentWise2f(smoothstepScalar),
252
- vec2h: ternaryComponentWise2h(smoothstepScalar),
253
- vec3f: ternaryComponentWise3f(smoothstepScalar),
254
- vec3h: ternaryComponentWise3h(smoothstepScalar),
255
- vec4f: ternaryComponentWise4f(smoothstepScalar),
256
- vec4h: ternaryComponentWise4h(smoothstepScalar),
257
- },
258
- addMixed: {
259
- vec2f: (a, b) => unary2f((e) => e + b)(a),
260
- vec2h: (a, b) => unary2h((e) => e + b)(a),
261
- vec2i: (a, b) => unary2i((e) => e + b)(a),
262
- vec2u: (a, b) => unary2u((e) => e + b)(a),
263
- vec3f: (a, b) => unary3f((e) => e + b)(a),
264
- vec3h: (a, b) => unary3h((e) => e + b)(a),
265
- vec3i: (a, b) => unary3i((e) => e + b)(a),
266
- vec3u: (a, b) => unary3u((e) => e + b)(a),
267
- vec4f: (a, b) => unary4f((e) => e + b)(a),
268
- vec4h: (a, b) => unary4h((e) => e + b)(a),
269
- vec4i: (a, b) => unary4i((e) => e + b)(a),
270
- vec4u: (a, b) => unary4u((e) => e + b)(a),
271
- mat2x2f: (a, b) => unary2x2f((e) => e + b)(a),
272
- mat3x3f: (a, b) => unary3x3f((e) => e + b)(a),
273
- mat4x4f: (a, b) => unary4x4f((e) => e + b)(a),
274
- },
275
- mulSxV: {
276
- vec2f: (s, v) => unary2f((e) => s * e)(v),
277
- vec2h: (s, v) => unary2h((e) => s * e)(v),
278
- vec2i: (s, v) => unary2i((e) => s * e)(v),
279
- vec2u: (s, v) => unary2u((e) => s * e)(v),
280
- vec3f: (s, v) => unary3f((e) => s * e)(v),
281
- vec3h: (s, v) => unary3h((e) => s * e)(v),
282
- vec3i: (s, v) => unary3i((e) => s * e)(v),
283
- vec3u: (s, v) => unary3u((e) => s * e)(v),
284
- vec4f: (s, v) => unary4f((e) => s * e)(v),
285
- vec4h: (s, v) => unary4h((e) => s * e)(v),
286
- vec4i: (s, v) => unary4i((e) => s * e)(v),
287
- vec4u: (s, v) => unary4u((e) => s * e)(v),
288
- mat2x2f: (s, m) => unary2x2f((e) => s * e)(m),
289
- mat3x3f: (s, m) => unary3x3f((e) => s * e)(m),
290
- mat4x4f: (s, m) => unary4x4f((e) => s * e)(m),
291
- },
292
- mulVxV: {
293
- vec2f: binaryComponentWise2f((a, b) => a * b),
294
- vec2h: binaryComponentWise2h((a, b) => a * b),
295
- vec2i: binaryComponentWise2i((a, b) => a * b),
296
- vec2u: binaryComponentWise2u((a, b) => a * b),
297
- vec3f: binaryComponentWise3f((a, b) => a * b),
298
- vec3h: binaryComponentWise3h((a, b) => a * b),
299
- vec3i: binaryComponentWise3i((a, b) => a * b),
300
- vec3u: binaryComponentWise3u((a, b) => a * b),
301
- vec4f: binaryComponentWise4f((a, b) => a * b),
302
- vec4h: binaryComponentWise4h((a, b) => a * b),
303
- vec4i: binaryComponentWise4i((a, b) => a * b),
304
- vec4u: binaryComponentWise4u((a, b) => a * b),
34
+ mulMxM: {
305
35
  mat2x2f: (a, b) => {
306
36
  const a_ = a.columns;
307
37
  const b_ = b.columns;
@@ -346,20 +76,6 @@ export const VectorOps = {
346
76
  return vec4f(v.x * m_[0].x + v.y * m_[0].y + v.z * m_[0].z + v.w * m_[0].w, v.x * m_[1].x + v.y * m_[1].y + v.z * m_[1].z + v.w * m_[1].w, v.x * m_[2].x + v.y * m_[2].y + v.z * m_[2].z + v.w * m_[2].w, v.x * m_[3].x + v.y * m_[3].y + v.z * m_[3].z + v.w * m_[3].w);
347
77
  },
348
78
  },
349
- div: {
350
- vec2f: binaryComponentWise2f((a, b) => a / b),
351
- vec2h: binaryComponentWise2h((a, b) => a / b),
352
- vec2i: binaryComponentWise2i(divInteger),
353
- vec2u: binaryComponentWise2u(divInteger),
354
- vec3f: binaryComponentWise3f((a, b) => a / b),
355
- vec3h: binaryComponentWise3h((a, b) => a / b),
356
- vec3i: binaryComponentWise3i(divInteger),
357
- vec3u: binaryComponentWise3u(divInteger),
358
- vec4f: binaryComponentWise4f((a, b) => a / b),
359
- vec4h: binaryComponentWise4h((a, b) => a / b),
360
- vec4i: binaryComponentWise4i(divInteger),
361
- vec4u: binaryComponentWise4u(divInteger),
362
- },
363
79
  dot: {
364
80
  vec2f: dotVec2,
365
81
  vec2h: dotVec2,
@@ -374,56 +90,6 @@ export const VectorOps = {
374
90
  vec4i: dotVec4,
375
91
  vec4u: dotVec4,
376
92
  },
377
- normalize: {
378
- vec2f: (v) => {
379
- const len = lengthVec2(v);
380
- return vec2f(v.x / len, v.y / len);
381
- },
382
- vec2h: (v) => {
383
- const len = lengthVec2(v);
384
- return vec2h(v.x / len, v.y / len);
385
- },
386
- vec2i: (v) => {
387
- const len = lengthVec2(v);
388
- return vec2i(v.x / len, v.y / len);
389
- },
390
- vec2u: (v) => {
391
- const len = lengthVec2(v);
392
- return vec2u(v.x / len, v.y / len);
393
- },
394
- vec3f: (v) => {
395
- const len = lengthVec3(v);
396
- return vec3f(v.x / len, v.y / len, v.z / len);
397
- },
398
- vec3h: (v) => {
399
- const len = lengthVec3(v);
400
- return vec3h(v.x / len, v.y / len, v.z / len);
401
- },
402
- vec3i: (v) => {
403
- const len = lengthVec3(v);
404
- return vec3i(v.x / len, v.y / len, v.z / len);
405
- },
406
- vec3u: (v) => {
407
- const len = lengthVec3(v);
408
- return vec3u(v.x / len, v.y / len, v.z / len);
409
- },
410
- vec4f: (v) => {
411
- const len = lengthVec4(v);
412
- return vec4f(v.x / len, v.y / len, v.z / len, v.w / len);
413
- },
414
- vec4h: (v) => {
415
- const len = lengthVec4(v);
416
- return vec4h(v.x / len, v.y / len, v.z / len, v.w / len);
417
- },
418
- vec4i: (v) => {
419
- const len = lengthVec4(v);
420
- return vec4i(v.x / len, v.y / len, v.z / len, v.w / len);
421
- },
422
- vec4u: (v) => {
423
- const len = lengthVec4(v);
424
- return vec4u(v.x / len, v.y / len, v.z / len, v.w / len);
425
- },
426
- },
427
93
  cross: {
428
94
  vec3f: (a, b) => {
429
95
  return vec3f(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
@@ -432,235 +98,6 @@ export const VectorOps = {
432
98
  return vec3h(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
433
99
  },
434
100
  },
435
- mod: {
436
- vec2f: binaryComponentWise2f((a, b) => a % b),
437
- vec2h: binaryComponentWise2h((a, b) => a % b),
438
- vec2i: binaryComponentWise2i((a, b) => a % b),
439
- vec2u: binaryComponentWise2u((a, b) => a % b),
440
- vec3f: binaryComponentWise3f((a, b) => a % b),
441
- vec3h: binaryComponentWise3h((a, b) => a % b),
442
- vec3i: binaryComponentWise3i((a, b) => a % b),
443
- vec3u: binaryComponentWise3u((a, b) => a % b),
444
- vec4f: binaryComponentWise4f((a, b) => a % b),
445
- vec4h: binaryComponentWise4h((a, b) => a % b),
446
- vec4i: binaryComponentWise4i((a, b) => a % b),
447
- vec4u: binaryComponentWise4u((a, b) => a % b),
448
- },
449
- floor: {
450
- vec2f: unary2f(Math.floor),
451
- vec2h: unary2h(Math.floor),
452
- vec3f: unary3f(Math.floor),
453
- vec3h: unary3h(Math.floor),
454
- vec4f: unary4f(Math.floor),
455
- vec4h: unary4h(Math.floor),
456
- },
457
- max: {
458
- vec2f: binaryComponentWise2f(Math.max),
459
- vec2h: binaryComponentWise2h(Math.max),
460
- vec2i: binaryComponentWise2i(Math.max),
461
- vec2u: binaryComponentWise2u(Math.max),
462
- vec3f: binaryComponentWise3f(Math.max),
463
- vec3h: binaryComponentWise3h(Math.max),
464
- vec3i: binaryComponentWise3i(Math.max),
465
- vec3u: binaryComponentWise3u(Math.max),
466
- vec4f: binaryComponentWise4f(Math.max),
467
- vec4h: binaryComponentWise4h(Math.max),
468
- vec4i: binaryComponentWise4i(Math.max),
469
- vec4u: binaryComponentWise4u(Math.max),
470
- },
471
- min: {
472
- vec2f: binaryComponentWise2f(Math.min),
473
- vec2h: binaryComponentWise2h(Math.min),
474
- vec2i: binaryComponentWise2i(Math.min),
475
- vec2u: binaryComponentWise2u(Math.min),
476
- vec3f: binaryComponentWise3f(Math.min),
477
- vec3h: binaryComponentWise3h(Math.min),
478
- vec3i: binaryComponentWise3i(Math.min),
479
- vec3u: binaryComponentWise3u(Math.min),
480
- vec4f: binaryComponentWise4f(Math.min),
481
- vec4h: binaryComponentWise4h(Math.min),
482
- vec4i: binaryComponentWise4i(Math.min),
483
- vec4u: binaryComponentWise4u(Math.min),
484
- },
485
- pow: {
486
- vec2f: (base, exponent) => vec2f(base.x ** exponent.x, base.y ** exponent.y),
487
- vec2h: (base, exponent) => vec2h(base.x ** exponent.x, base.y ** exponent.y),
488
- vec3f: (base, exponent) => vec3f(base.x ** exponent.x, base.y ** exponent.y, base.z ** exponent.z),
489
- vec3h: (base, exponent) => vec3h(base.x ** exponent.x, base.y ** exponent.y, base.z ** exponent.z),
490
- vec4f: (base, exponent) => vec4f(base.x ** exponent.x, base.y ** exponent.y, base.z ** exponent.z, base.w ** exponent.w),
491
- vec4h: (base, exponent) => vec4h(base.x ** exponent.x, base.y ** exponent.y, base.z ** exponent.z, base.w ** exponent.w),
492
- },
493
- sign: {
494
- vec2f: unary2f(Math.sign),
495
- vec2h: unary2h(Math.sign),
496
- vec2i: unary2i(Math.sign),
497
- vec3f: unary3f(Math.sign),
498
- vec3h: unary3h(Math.sign),
499
- vec3i: unary3i(Math.sign),
500
- vec4f: unary4f(Math.sign),
501
- vec4h: unary4h(Math.sign),
502
- vec4i: unary4i(Math.sign),
503
- },
504
- sqrt: {
505
- vec2f: unary2f(Math.sqrt),
506
- vec2h: unary2h(Math.sqrt),
507
- vec3f: unary3f(Math.sqrt),
508
- vec3h: unary3h(Math.sqrt),
509
- vec4f: unary4f(Math.sqrt),
510
- vec4h: unary4h(Math.sqrt),
511
- },
512
- mix: {
513
- vec2f: (e1, e2, e3) => {
514
- if (typeof e3 === 'number') {
515
- return vec2f(e1.x * (1 - e3) + e2.x * e3, e1.y * (1 - e3) + e2.y * e3);
516
- }
517
- return vec2f(e1.x * (1 - e3.x) + e2.x * e3.x, e1.y * (1 - e3.y) + e2.y * e3.y);
518
- },
519
- vec2h: (e1, e2, e3) => {
520
- if (typeof e3 === 'number') {
521
- return vec2h(e1.x * (1 - e3) + e2.x * e3, e1.y * (1 - e3) + e2.y * e3);
522
- }
523
- return vec2h(e1.x * (1 - e3.x) + e2.x * e3.x, e1.y * (1 - e3.y) + e2.y * e3.y);
524
- },
525
- vec3f: (e1, e2, e3) => {
526
- if (typeof e3 === 'number') {
527
- return vec3f(e1.x * (1 - e3) + e2.x * e3, e1.y * (1 - e3) + e2.y * e3, e1.z * (1 - e3) + e2.z * e3);
528
- }
529
- return vec3f(e1.x * (1 - e3.x) + e2.x * e3.x, e1.y * (1 - e3.y) + e2.y * e3.y, e1.z * (1 - e3.z) + e2.z * e3.z);
530
- },
531
- vec3h: (e1, e2, e3) => {
532
- if (typeof e3 === 'number') {
533
- return vec3h(e1.x * (1 - e3) + e2.x * e3, e1.y * (1 - e3) + e2.y * e3, e1.z * (1 - e3) + e2.z * e3);
534
- }
535
- return vec3h(e1.x * (1 - e3.x) + e2.x * e3.x, e1.y * (1 - e3.y) + e2.y * e3.y, e1.z * (1 - e3.z) + e2.z * e3.z);
536
- },
537
- vec4f: (e1, e2, e3) => {
538
- if (typeof e3 === 'number') {
539
- return vec4f(e1.x * (1 - e3) + e2.x * e3, e1.y * (1 - e3) + e2.y * e3, e1.z * (1 - e3) + e2.z * e3, e1.w * (1 - e3) + e2.w * e3);
540
- }
541
- return vec4f(e1.x * (1 - e3.x) + e2.x * e3.x, e1.y * (1 - e3.y) + e2.y * e3.y, e1.z * (1 - e3.z) + e2.z * e3.z, e1.w * (1 - e3.w) + e2.w * e3.w);
542
- },
543
- vec4h: (e1, e2, e3) => {
544
- if (typeof e3 === 'number') {
545
- return vec4h(e1.x * (1 - e3) + e2.x * e3, e1.y * (1 - e3) + e2.y * e3, e1.z * (1 - e3) + e2.z * e3, e1.w * (1 - e3) + e2.w * e3);
546
- }
547
- return vec4h(e1.x * (1 - e3.x) + e2.x * e3.x, e1.y * (1 - e3.y) + e2.y * e3.y, e1.z * (1 - e3.z) + e2.z * e3.z, e1.w * (1 - e3.w) + e2.w * e3.w);
548
- },
549
- },
550
- sin: {
551
- vec2f: unary2f(Math.sin),
552
- vec2h: unary2h(Math.sin),
553
- vec3f: unary3f(Math.sin),
554
- vec3h: unary3h(Math.sin),
555
- vec4f: unary4f(Math.sin),
556
- vec4h: unary4h(Math.sin),
557
- },
558
- cos: {
559
- vec2f: unary2f(Math.cos),
560
- vec2h: unary2h(Math.cos),
561
- vec3f: unary3f(Math.cos),
562
- vec3h: unary3h(Math.cos),
563
- vec4f: unary4f(Math.cos),
564
- vec4h: unary4h(Math.cos),
565
- },
566
- cosh: {
567
- vec2f: unary2f(Math.cosh),
568
- vec2h: unary2h(Math.cosh),
569
- vec3f: unary3f(Math.cosh),
570
- vec3h: unary3h(Math.cosh),
571
- vec4f: unary4f(Math.cosh),
572
- vec4h: unary4h(Math.cosh),
573
- },
574
- exp: {
575
- vec2f: unary2f(Math.exp),
576
- vec2h: unary2h(Math.exp),
577
- vec3f: unary3f(Math.exp),
578
- vec3h: unary3h(Math.exp),
579
- vec4f: unary4f(Math.exp),
580
- vec4h: unary4h(Math.exp),
581
- },
582
- exp2: {
583
- vec2f: unary2f((val) => 2 ** val),
584
- vec2h: unary2h((val) => 2 ** val),
585
- vec3f: unary3f((val) => 2 ** val),
586
- vec3h: unary3h((val) => 2 ** val),
587
- vec4f: unary4f((val) => 2 ** val),
588
- vec4h: unary4h((val) => 2 ** val),
589
- },
590
- log: {
591
- vec2f: unary2f(Math.log),
592
- vec2h: unary2h(Math.log),
593
- vec3f: unary3f(Math.log),
594
- vec3h: unary3h(Math.log),
595
- vec4f: unary4f(Math.log),
596
- vec4h: unary4h(Math.log),
597
- },
598
- log2: {
599
- vec2f: unary2f(Math.log2),
600
- vec2h: unary2h(Math.log2),
601
- vec3f: unary3f(Math.log2),
602
- vec3h: unary3h(Math.log2),
603
- vec4f: unary4f(Math.log2),
604
- vec4h: unary4h(Math.log2),
605
- },
606
- fract: {
607
- vec2f: unary2f((value) => value - Math.floor(value)),
608
- vec2h: unary2h((value) => value - Math.floor(value)),
609
- vec3f: unary3f((value) => value - Math.floor(value)),
610
- vec3h: unary3h((value) => value - Math.floor(value)),
611
- vec4f: unary4f((value) => value - Math.floor(value)),
612
- vec4h: unary4h((value) => value - Math.floor(value)),
613
- },
614
- isCloseToZero: {
615
- vec2f: (v, n) => Math.abs(v.x) <= n && Math.abs(v.y) <= n,
616
- vec2h: (v, n) => Math.abs(v.x) <= n && Math.abs(v.y) <= n,
617
- vec3f: (v, n) => Math.abs(v.x) <= n && Math.abs(v.y) <= n && Math.abs(v.z) <= n,
618
- vec3h: (v, n) => Math.abs(v.x) <= n && Math.abs(v.y) <= n && Math.abs(v.z) <= n,
619
- vec4f: (v, n) => Math.abs(v.x) <= n && Math.abs(v.y) <= n && Math.abs(v.z) <= n && Math.abs(v.w) <= n,
620
- vec4h: (v, n) => Math.abs(v.x) <= n && Math.abs(v.y) <= n && Math.abs(v.z) <= n && Math.abs(v.w) <= n,
621
- },
622
- neg: {
623
- vec2f: unary2f((value) => -value),
624
- vec2h: unary2h((value) => -value),
625
- vec2i: unary2i((value) => -value),
626
- vec2u: unary2u((value) => -value),
627
- 'vec2<bool>': (e) => vec2b(!e.x, !e.y),
628
- vec3f: unary3f((value) => -value),
629
- vec3h: unary3h((value) => -value),
630
- vec3i: unary3i((value) => -value),
631
- vec3u: unary3u((value) => -value),
632
- 'vec3<bool>': (e) => vec3b(!e.x, !e.y, !e.z),
633
- vec4f: unary4f((value) => -value),
634
- vec4h: unary4h((value) => -value),
635
- vec4i: unary4i((value) => -value),
636
- vec4u: unary4u((value) => -value),
637
- 'vec4<bool>': (e) => vec4b(!e.x, !e.y, !e.z, !e.w),
638
- },
639
- select: {
640
- vec2f: (f, t, c) => vec2f(c.x ? t.x : f.x, c.y ? t.y : f.y),
641
- vec2h: (f, t, c) => vec2h(c.x ? t.x : f.x, c.y ? t.y : f.y),
642
- vec2i: (f, t, c) => vec2i(c.x ? t.x : f.x, c.y ? t.y : f.y),
643
- vec2u: (f, t, c) => vec2u(c.x ? t.x : f.x, c.y ? t.y : f.y),
644
- 'vec2<bool>': (f, t, c) => vec2b(c.x ? t.x : f.x, c.y ? t.y : f.y),
645
- vec3f: (f, t, c) => vec3f(c.x ? t.x : f.x, c.y ? t.y : f.y, c.z ? t.z : f.z),
646
- vec3h: (f, t, c) => vec3h(c.x ? t.x : f.x, c.y ? t.y : f.y, c.z ? t.z : f.z),
647
- vec3i: (f, t, c) => vec3i(c.x ? t.x : f.x, c.y ? t.y : f.y, c.z ? t.z : f.z),
648
- vec3u: (f, t, c) => vec3u(c.x ? t.x : f.x, c.y ? t.y : f.y, c.z ? t.z : f.z),
649
- 'vec3<bool>': (f, t, c) => vec3b(c.x ? t.x : f.x, c.y ? t.y : f.y, c.z ? t.z : f.z),
650
- vec4f: (f, t, c) => vec4f(c.x ? t.x : f.x, c.y ? t.y : f.y, c.z ? t.z : f.z, c.w ? t.w : f.w),
651
- vec4h: (f, t, c) => vec4h(c.x ? t.x : f.x, c.y ? t.y : f.y, c.z ? t.z : f.z, c.w ? t.w : f.w),
652
- vec4i: (f, t, c) => vec4i(c.x ? t.x : f.x, c.y ? t.y : f.y, c.z ? t.z : f.z, c.w ? t.w : f.w),
653
- vec4u: (f, t, c) => vec4u(c.x ? t.x : f.x, c.y ? t.y : f.y, c.z ? t.z : f.z, c.w ? t.w : f.w),
654
- 'vec4<bool>': (f, t, c) => vec4b(c.x ? t.x : f.x, c.y ? t.y : f.y, c.z ? t.z : f.z, c.w ? t.w : f.w),
655
- },
656
- tanh: {
657
- vec2f: unary2f(Math.tanh),
658
- vec2h: unary2h(Math.tanh),
659
- vec3f: unary3f(Math.tanh),
660
- vec3h: unary3h(Math.tanh),
661
- vec4f: unary4f(Math.tanh),
662
- vec4h: unary4h(Math.tanh),
663
- },
664
101
  bitShiftLeft: {
665
102
  vec2i: binaryComponentWise2i2u((a, b) => a << b),
666
103
  vec2u: binaryComponentWise2u((a, b) => a << b),
@@ -35,7 +35,7 @@ export type { TgpuComputePipeline } from './core/pipeline/computePipeline.ts';
35
35
  export type { TgpuCommandEncoder } from './core/commandEncoder/commandEncoder.ts';
36
36
  export type { TgpuRenderBundleEncoder, TgpuRenderCommands, TgpuRenderPass, TgpuRenderPassDescriptor, } from './core/commandEncoder/renderPass.ts';
37
37
  export type { TgpuComputePass, TgpuComputePassDescriptor, } from './core/commandEncoder/computePass.ts';
38
- export type { IndexFlag, TgpuBuffer, Uniform, UniformFlag, UsageLiteral, ValidUsagesFor, Vertex, VertexFlag, TgpuStorageBuffer, TgpuUniformBuffer, TgpuVertexBuffer, TgpuIndexBuffer, BufferWriteOptions, BufferInitCallback, BufferInitialData, } from './core/buffer/buffer.ts';
38
+ export type { IndirectFlag, IndexFlag, TgpuBuffer, Uniform, UniformFlag, UsageLiteral, ValidUsagesFor, Vertex, VertexFlag, TgpuStorageBuffer, TgpuUniformBuffer, TgpuVertexBuffer, TgpuIndexBuffer, BufferWriteOptions, BufferInitCallback, BufferInitialData, } from './core/buffer/buffer.ts';
39
39
  export type { TgpuBufferMutable, TgpuBufferReadonly, TgpuBufferUniform, } from './core/buffer/bufferUsage.ts';
40
40
  export type { TgpuBufferBinding, TgpuMutable, TgpuReadonly, TgpuUniform, } from './core/buffer/bufferBinding.ts';
41
41
  export type { Eventual, TgpuAccessor, TgpuLazy, TgpuMutableAccessor, TgpuSlot, } from './core/slot/slotTypes.ts';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typegpu",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.",
5
5
  "keywords": [
6
6
  "compute",
package/shared/meta.js CHANGED
@@ -1,4 +1,4 @@
1
- const version = "0.12.0";
1
+ const version = "0.12.1";
2
2
  import { DEV, TEST } from "./env.js";
3
3
  import { $getNameForward, $soul, isMarkedInternal } from "./symbols.js";
4
4
  import { normalizeMetadata } from "./normalizeMetadata.js";
package/shared/symbols.js CHANGED
@@ -1,4 +1,4 @@
1
- const version = "0.12.0";
1
+ const version = "0.12.1";
2
2
  export const $internal = Symbol(`typegpu:${version}:$internal`);
3
3
  /** A plain record of all definitional state of a resource, surviving transfer between runtimes */
4
4
  export const $soul = Symbol(`typegpu:${version}:$soul`);