glre 0.35.0 → 0.37.0
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/dist/index.cjs +37 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +256 -301
- package/dist/index.js +37 -29
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +37 -29
- package/dist/native.cjs.map +1 -1
- package/dist/native.d.ts +18 -9
- package/dist/native.js +37 -29
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +37 -29
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +37 -29
- package/dist/react.js.map +1 -1
- package/dist/solid.cjs +37 -29
- package/dist/solid.cjs.map +1 -1
- package/dist/solid.d.ts +1 -1
- package/dist/solid.js +37 -29
- package/dist/solid.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +5 -4
- package/src/node/core.ts +121 -0
- package/src/node/index.ts +80 -159
- package/src/node/node.ts +32 -21
- package/src/node/scope.ts +7 -13
- package/src/node/types.ts +168 -139
- package/src/node/{const.ts → utils/const.ts} +111 -119
- package/src/node/{code.ts → utils/index.ts} +29 -12
- package/src/node/{infer.ts → utils/infer.ts} +12 -8
- package/src/node/{parse.ts → utils/parse.ts} +60 -16
- package/src/node/{utils.ts → utils/utils.ts} +30 -39
- package/src/types.ts +60 -50
- package/src/utils/helpers.ts +16 -0
- package/src/utils/pipeline.ts +41 -12
- package/src/utils/program.ts +95 -13
- package/src/webgl.ts +95 -38
- package/src/webgpu.ts +87 -53
package/src/node/types.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { CONSTANTS, CONVERSIONS, FUNCTIONS, OPERATOR_KEYS } from './const'
|
|
1
|
+
import { CONSTANTS, CONVERSIONS, FUNCTIONS, OPERATOR_KEYS } from './utils/const'
|
|
2
|
+
import type { GL } from '../types'
|
|
4
3
|
|
|
5
4
|
export type Constants = (typeof CONSTANTS)[number] | 'void'
|
|
6
|
-
|
|
7
5
|
export type Conversions = (typeof CONVERSIONS)[number]
|
|
8
|
-
|
|
9
6
|
export type Functions = (typeof FUNCTIONS)[number]
|
|
10
|
-
|
|
11
7
|
export type Operators = (typeof OPERATOR_KEYS)[number]
|
|
12
8
|
|
|
13
9
|
export interface FnLayout {
|
|
@@ -25,6 +21,7 @@ export interface FnLayout {
|
|
|
25
21
|
export type NodeTypes =
|
|
26
22
|
// headers
|
|
27
23
|
| 'attribute'
|
|
24
|
+
| 'storage'
|
|
28
25
|
| 'uniform'
|
|
29
26
|
| 'constant'
|
|
30
27
|
// variables
|
|
@@ -38,6 +35,9 @@ export type NodeTypes =
|
|
|
38
35
|
// struct
|
|
39
36
|
| 'struct'
|
|
40
37
|
| 'member'
|
|
38
|
+
| 'element'
|
|
39
|
+
| 'gather'
|
|
40
|
+
| 'scatter'
|
|
41
41
|
// scopes
|
|
42
42
|
| 'scope'
|
|
43
43
|
| 'assign'
|
|
@@ -55,7 +55,6 @@ export interface NodeProps<T extends Record<string, NodeProxy> = {}> {
|
|
|
55
55
|
children?: any[]
|
|
56
56
|
inferFrom?: any[]
|
|
57
57
|
layout?: FnLayout
|
|
58
|
-
parent?: NodeProxy
|
|
59
58
|
// for struct
|
|
60
59
|
fields?: T
|
|
61
60
|
initialValues?: T
|
|
@@ -63,9 +62,9 @@ export interface NodeProps<T extends Record<string, NodeProxy> = {}> {
|
|
|
63
62
|
|
|
64
63
|
export interface NodeContext {
|
|
65
64
|
gl?: Partial<GL>
|
|
66
|
-
|
|
65
|
+
label?: 'vert' | 'frag' | 'compute'
|
|
67
66
|
isWebGL?: boolean
|
|
68
|
-
|
|
67
|
+
units?: any // @TODO FIX
|
|
69
68
|
infers?: WeakMap<NodeProxy, Constants>
|
|
70
69
|
onMount?: (name: string) => void
|
|
71
70
|
code?: {
|
|
@@ -74,6 +73,7 @@ export interface NodeContext {
|
|
|
74
73
|
vertInputs: Map<string, string>
|
|
75
74
|
vertOutputs: Map<string, string>
|
|
76
75
|
vertVaryings: Map<string, string>
|
|
76
|
+
computeInputs: Map<string, string>
|
|
77
77
|
dependencies: Map<string, Set<string>>
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -81,6 +81,20 @@ export interface NodeContext {
|
|
|
81
81
|
/**
|
|
82
82
|
* infer
|
|
83
83
|
*/
|
|
84
|
+
type _StringLength<S extends string> = S extends `${infer _}${infer Rest}`
|
|
85
|
+
? Rest extends ''
|
|
86
|
+
? 1
|
|
87
|
+
: Rest extends `${infer _}${infer Rest2}`
|
|
88
|
+
? Rest2 extends ''
|
|
89
|
+
? 2
|
|
90
|
+
: Rest2 extends `${infer _}${infer Rest3}`
|
|
91
|
+
? Rest3 extends ''
|
|
92
|
+
? 3
|
|
93
|
+
: 4
|
|
94
|
+
: never
|
|
95
|
+
: never
|
|
96
|
+
: 0
|
|
97
|
+
|
|
84
98
|
// Unified logic with infer.ts inferOperator function
|
|
85
99
|
// prettier-ignore
|
|
86
100
|
type InferOperator<L extends Constants, R extends Constants> =
|
|
@@ -97,19 +111,13 @@ type InferOperator<L extends Constants, R extends Constants> =
|
|
|
97
111
|
L extends 'vec3' ? R extends 'mat3' ? L /* default */ : L :
|
|
98
112
|
L extends 'vec2' ? R extends 'mat2' ? L /* default */ : L : L
|
|
99
113
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
? Rest3 extends ''
|
|
108
|
-
? 3
|
|
109
|
-
: 4
|
|
110
|
-
: never
|
|
111
|
-
: never
|
|
112
|
-
: 0
|
|
114
|
+
// Unified logic with infer.ts inferArrayElement function
|
|
115
|
+
// prettier-ignore
|
|
116
|
+
type InferArrayElement<T extends Constants> =
|
|
117
|
+
T extends 'mat4' ? 'vec4' :
|
|
118
|
+
T extends 'mat3' ? 'vec3' :
|
|
119
|
+
T extends 'mat2' ? 'vec2' :
|
|
120
|
+
'float'
|
|
113
121
|
|
|
114
122
|
type InferSwizzleType<S extends string> = _StringLength<S> extends 4
|
|
115
123
|
? 'vec4'
|
|
@@ -142,6 +150,72 @@ type NodeProxyMethods =
|
|
|
142
150
|
| 'assign'
|
|
143
151
|
| 'toVar'
|
|
144
152
|
| 'toString'
|
|
153
|
+
| 'element'
|
|
154
|
+
|
|
155
|
+
type ReadNodeProxy = {
|
|
156
|
+
[K in string as K extends NodeProxyMethods ? never : K]: any
|
|
157
|
+
} & {
|
|
158
|
+
[K in Swizzles]: NodeProxy<InferSwizzleType<K>>
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Internal NodeProxy implementation (renamed from original)
|
|
162
|
+
type NodeProxyImpl<T extends Constants = string> = BaseNodeProxy<T> & ReadNodeProxy
|
|
163
|
+
|
|
164
|
+
export type Bool = NodeProxyImpl<'bool'>
|
|
165
|
+
export type UInt = NodeProxyImpl<'uint'>
|
|
166
|
+
export type Int = NodeProxyImpl<'int'>
|
|
167
|
+
export type Float = NodeProxyImpl<'float'>
|
|
168
|
+
export type BVec2 = NodeProxyImpl<'bvec2'>
|
|
169
|
+
export type IVec2 = NodeProxyImpl<'ivec2'>
|
|
170
|
+
export type UVec2 = NodeProxyImpl<'uvec2'>
|
|
171
|
+
export type Vec2 = NodeProxyImpl<'vec2'>
|
|
172
|
+
export type BVec3 = NodeProxyImpl<'bvec3'>
|
|
173
|
+
export type IVec3 = NodeProxyImpl<'ivec3'>
|
|
174
|
+
export type UVec3 = NodeProxyImpl<'uvec3'>
|
|
175
|
+
export type Vec3 = NodeProxyImpl<'vec3'>
|
|
176
|
+
export type BVec4 = NodeProxyImpl<'bvec4'>
|
|
177
|
+
export type IVec4 = NodeProxyImpl<'ivec4'>
|
|
178
|
+
export type UVec4 = NodeProxyImpl<'uvec4'>
|
|
179
|
+
export type Vec4 = NodeProxyImpl<'vec4'>
|
|
180
|
+
export type Color = NodeProxyImpl<'color'>
|
|
181
|
+
export type Mat2 = NodeProxyImpl<'mat2'>
|
|
182
|
+
export type Mat3 = NodeProxyImpl<'mat3'>
|
|
183
|
+
export type Mat4 = NodeProxyImpl<'mat4'>
|
|
184
|
+
export type Texture = NodeProxyImpl<'texture'>
|
|
185
|
+
export type Sampler2D = NodeProxyImpl<'sampler2D'>
|
|
186
|
+
export type Struct = NodeProxyImpl<'struct'>
|
|
187
|
+
|
|
188
|
+
export interface ConstantsToType {
|
|
189
|
+
bool: Bool
|
|
190
|
+
uint: UInt
|
|
191
|
+
int: Int
|
|
192
|
+
float: Float
|
|
193
|
+
bvec2: BVec2
|
|
194
|
+
ivec2: IVec2
|
|
195
|
+
uvec2: UVec2
|
|
196
|
+
vec2: Vec2
|
|
197
|
+
bvec3: BVec3
|
|
198
|
+
ivec3: IVec3
|
|
199
|
+
uvec3: UVec3
|
|
200
|
+
vec3: Vec3
|
|
201
|
+
bvec4: BVec4
|
|
202
|
+
ivec4: IVec4
|
|
203
|
+
uvec4: UVec4
|
|
204
|
+
vec4: Vec4
|
|
205
|
+
color: Color
|
|
206
|
+
mat2: Mat2
|
|
207
|
+
mat3: Mat3
|
|
208
|
+
mat4: Mat4
|
|
209
|
+
texture: Texture
|
|
210
|
+
sampler2D: Sampler2D
|
|
211
|
+
struct: Struct
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export type NodeProxy<T extends Constants = string> = T extends keyof ConstantsToType
|
|
215
|
+
? ConstantsToType[T]
|
|
216
|
+
: NodeProxyImpl<T>
|
|
217
|
+
|
|
218
|
+
export type X<T extends Constants = string> = number | string | boolean | undefined | NodeProxy<T> | X[]
|
|
145
219
|
|
|
146
220
|
export interface BaseNodeProxy<T extends Constants> {
|
|
147
221
|
// System properties
|
|
@@ -153,6 +227,9 @@ export interface BaseNodeProxy<T extends Constants> {
|
|
|
153
227
|
isProxy: true
|
|
154
228
|
listeners: Set<(value: any) => void>
|
|
155
229
|
|
|
230
|
+
// Element access for array/matrix types
|
|
231
|
+
element<Index extends X>(index: Index): NodeProxy<InferArrayElement<T>>
|
|
232
|
+
|
|
156
233
|
// Operators methods
|
|
157
234
|
add<U extends Constants>(x: X<U>): NodeProxy<InferOperator<T, U>>
|
|
158
235
|
sub<U extends Constants>(x: X<U>): NodeProxy<InferOperator<T, U>>
|
|
@@ -199,131 +276,83 @@ export interface BaseNodeProxy<T extends Constants> {
|
|
|
199
276
|
toMat3(): Mat3
|
|
200
277
|
toMat4(): Mat4
|
|
201
278
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
acos(): NodeProxy<T>
|
|
215
|
-
atan(): NodeProxy<T>
|
|
216
|
-
exp(): NodeProxy<T>
|
|
217
|
-
exp2(): NodeProxy<T>
|
|
218
|
-
log(): NodeProxy<T>
|
|
219
|
-
log2(): NodeProxy<T>
|
|
220
|
-
sqrt(): NodeProxy<T>
|
|
221
|
-
inverseSqrt(): NodeProxy<T>
|
|
222
|
-
normalize(): NodeProxy<T>
|
|
223
|
-
oneMinus(): NodeProxy<T>
|
|
224
|
-
saturate(): NodeProxy<T>
|
|
225
|
-
negate(): NodeProxy<T>
|
|
226
|
-
reciprocal(): NodeProxy<T>
|
|
227
|
-
dFdx(): NodeProxy<T>
|
|
228
|
-
dFdy(): NodeProxy<T>
|
|
229
|
-
fwidth(): NodeProxy<T>
|
|
230
|
-
|
|
231
|
-
// Scalar return functions
|
|
279
|
+
/**
|
|
280
|
+
* 3.1. unified logic with:
|
|
281
|
+
* 1.1. index.ts functions and
|
|
282
|
+
* 2.1. const.ts FUNCTION_RETURN_TYPES
|
|
283
|
+
*/
|
|
284
|
+
// 0. Always return bool
|
|
285
|
+
all(): Bool
|
|
286
|
+
any(): Bool
|
|
287
|
+
// 2. Always return float
|
|
288
|
+
determinant(): Float
|
|
289
|
+
distance<U extends Constants>(y: X<U>): Float
|
|
290
|
+
dot<U extends Constants>(y: X<U>): Float
|
|
232
291
|
length(): Float
|
|
233
292
|
lengthSq(): Float
|
|
234
|
-
determinant(): Float
|
|
235
293
|
luminance(): Float
|
|
236
|
-
|
|
237
|
-
// Bool return functions
|
|
238
|
-
all(): Bool
|
|
239
|
-
any(): Bool
|
|
240
|
-
|
|
241
|
-
// Specific return type functions
|
|
294
|
+
// 3. Always return vec3
|
|
242
295
|
cross<U extends Constants>(y: X<U>): Vec3
|
|
243
|
-
|
|
244
|
-
|
|
296
|
+
// 4. Always return vec4
|
|
297
|
+
cubeTexture(...args: X[]): Vec4
|
|
298
|
+
texture(...args: X[]): Vec4
|
|
299
|
+
texelFetch(...args: X[]): Vec4
|
|
300
|
+
textureLod(...args: X[]): Vec4
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* 3.1. unified with:
|
|
304
|
+
* 1.1. index.ts functions and
|
|
305
|
+
* 2.1. const.ts FUNCTIONS
|
|
306
|
+
*/
|
|
307
|
+
// 0. Component-wise functions
|
|
308
|
+
abs(): NodeProxy
|
|
309
|
+
acos(): NodeProxy
|
|
310
|
+
acosh(): NodeProxy
|
|
311
|
+
asin(): NodeProxy
|
|
312
|
+
asinh(): NodeProxy
|
|
313
|
+
atan(): NodeProxy
|
|
314
|
+
atanh(): NodeProxy
|
|
315
|
+
ceil(): NodeProxy
|
|
316
|
+
cos(): NodeProxy
|
|
317
|
+
cosh(): NodeProxy
|
|
318
|
+
degrees(): NodeProxy
|
|
319
|
+
dFdx(): NodeProxy
|
|
320
|
+
dFdy(): NodeProxy
|
|
321
|
+
exp(): NodeProxy
|
|
322
|
+
exp2(): NodeProxy
|
|
323
|
+
floor(): NodeProxy
|
|
324
|
+
fract(): NodeProxy
|
|
325
|
+
fwidth(): NodeProxy
|
|
326
|
+
inverseSqrt(): NodeProxy
|
|
327
|
+
log(): NodeProxy
|
|
328
|
+
log2(): NodeProxy
|
|
329
|
+
negate(): NodeProxy
|
|
330
|
+
normalize(): NodeProxy
|
|
331
|
+
oneMinus(): NodeProxy
|
|
332
|
+
radians(): NodeProxy
|
|
333
|
+
reciprocal(): NodeProxy
|
|
334
|
+
round(): NodeProxy
|
|
335
|
+
saturate(): NodeProxy
|
|
336
|
+
sign(): NodeProxy
|
|
337
|
+
sin(): NodeProxy
|
|
338
|
+
sinh(): NodeProxy
|
|
339
|
+
sqrt(): NodeProxy
|
|
340
|
+
tan(): NodeProxy
|
|
341
|
+
tanh(): NodeProxy
|
|
342
|
+
trunc(): NodeProxy
|
|
343
|
+
|
|
344
|
+
// 1. Functions where first argument determines return type
|
|
245
345
|
atan2<U extends Constants>(x: X<U>): NodeProxy<T>
|
|
346
|
+
clamp<U extends Constants, V>(mix: X<U>, max: V): NodeProxy<InferOperator<T, U>>
|
|
347
|
+
max<U extends Constants>(y: X<U>): NodeProxy<InferOperator<T, U>>
|
|
348
|
+
min<U extends Constants>(y: X<U>): NodeProxy<InferOperator<T, U>>
|
|
349
|
+
mix<U extends Constants, V>(y: X<U>, a: V): NodeProxy<InferOperator<T, U>>
|
|
246
350
|
pow<U extends Constants>(y: X<U>): NodeProxy<T>
|
|
247
|
-
distance<U extends Constants>(y: X<U>): Float
|
|
248
|
-
dot<U extends Constants>(y: X<U>): Float
|
|
249
351
|
reflect<U extends Constants>(N: X<U>): NodeProxy<T>
|
|
250
352
|
refract<U extends Constants>(N: X<U>, eta: any): NodeProxy<T>
|
|
251
353
|
|
|
252
|
-
//
|
|
253
|
-
min<U extends Constants>(y: X<U>): NodeProxy<InferOperator<T, U>>
|
|
254
|
-
max<U extends Constants>(y: X<U>): NodeProxy<InferOperator<T, U>>
|
|
255
|
-
mix<U extends Constants, V>(y: X<U>, a: V): NodeProxy<InferOperator<T, U>>
|
|
256
|
-
clamp<U extends Constants, V>(mix: X<U>, max: V): NodeProxy<InferOperator<T, U>>
|
|
257
|
-
step<U extends Constants>(edge: X<U>): NodeProxy<InferOperator<T, U>>
|
|
354
|
+
// 2. Functions where not first argument determines return type
|
|
258
355
|
smoothstep<U extends Constants, V>(edge0: X<U>, edge1: V): NodeProxy<InferOperator<T, U>>
|
|
259
|
-
|
|
260
|
-
//
|
|
261
|
-
pow2(): NodeProxy<T>
|
|
262
|
-
pow3(): NodeProxy<T>
|
|
263
|
-
pow4(): NodeProxy<T>
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
type ReadNodeProxy = {
|
|
267
|
-
[K in string as K extends NodeProxyMethods ? never : K]: any
|
|
268
|
-
} & {
|
|
269
|
-
[K in Swizzles]: NodeProxy<InferSwizzleType<K>>
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// Internal NodeProxy implementation (renamed from original)
|
|
273
|
-
type NodeProxyImpl<T extends Constants = string> = BaseNodeProxy<T> & ReadNodeProxy
|
|
274
|
-
|
|
275
|
-
export type Bool = NodeProxyImpl<'bool'>
|
|
276
|
-
export type UInt = NodeProxyImpl<'uint'>
|
|
277
|
-
export type Int = NodeProxyImpl<'int'>
|
|
278
|
-
export type Float = NodeProxyImpl<'float'>
|
|
279
|
-
export type BVec2 = NodeProxyImpl<'bvec2'>
|
|
280
|
-
export type IVec2 = NodeProxyImpl<'ivec2'>
|
|
281
|
-
export type UVec2 = NodeProxyImpl<'uvec2'>
|
|
282
|
-
export type Vec2 = NodeProxyImpl<'vec2'>
|
|
283
|
-
export type BVec3 = NodeProxyImpl<'bvec3'>
|
|
284
|
-
export type IVec3 = NodeProxyImpl<'ivec3'>
|
|
285
|
-
export type UVec3 = NodeProxyImpl<'uvec3'>
|
|
286
|
-
export type Vec3 = NodeProxyImpl<'vec3'>
|
|
287
|
-
export type BVec4 = NodeProxyImpl<'bvec4'>
|
|
288
|
-
export type IVec4 = NodeProxyImpl<'ivec4'>
|
|
289
|
-
export type UVec4 = NodeProxyImpl<'uvec4'>
|
|
290
|
-
export type Vec4 = NodeProxyImpl<'vec4'>
|
|
291
|
-
export type Color = NodeProxyImpl<'color'>
|
|
292
|
-
export type Mat2 = NodeProxyImpl<'mat2'>
|
|
293
|
-
export type Mat3 = NodeProxyImpl<'mat3'>
|
|
294
|
-
export type Mat4 = NodeProxyImpl<'mat4'>
|
|
295
|
-
export type Texture = NodeProxyImpl<'texture'>
|
|
296
|
-
export type Sampler2D = NodeProxyImpl<'sampler2D'>
|
|
297
|
-
export type Struct = NodeProxyImpl<'struct'>
|
|
298
|
-
|
|
299
|
-
export interface ConstantsToType {
|
|
300
|
-
bool: Bool
|
|
301
|
-
uint: UInt
|
|
302
|
-
int: Int
|
|
303
|
-
float: Float
|
|
304
|
-
bvec2: BVec2
|
|
305
|
-
ivec2: IVec2
|
|
306
|
-
uvec2: UVec2
|
|
307
|
-
vec2: Vec2
|
|
308
|
-
bvec3: BVec3
|
|
309
|
-
ivec3: IVec3
|
|
310
|
-
uvec3: UVec3
|
|
311
|
-
vec3: Vec3
|
|
312
|
-
bvec4: BVec4
|
|
313
|
-
ivec4: IVec4
|
|
314
|
-
uvec4: UVec4
|
|
315
|
-
vec4: Vec4
|
|
316
|
-
color: Color
|
|
317
|
-
mat2: Mat2
|
|
318
|
-
mat3: Mat3
|
|
319
|
-
mat4: Mat4
|
|
320
|
-
texture: Texture
|
|
321
|
-
sampler2D: Sampler2D
|
|
322
|
-
struct: Struct
|
|
356
|
+
step<U extends Constants>(edge: X<U>): NodeProxy<InferOperator<T, U>>
|
|
357
|
+
// @NOTE: mod is operator
|
|
323
358
|
}
|
|
324
|
-
|
|
325
|
-
export type NodeProxy<T extends Constants = string> = T extends keyof ConstantsToType
|
|
326
|
-
? ConstantsToType[T]
|
|
327
|
-
: NodeProxyImpl<T>
|
|
328
|
-
|
|
329
|
-
export type X<T extends Constants = string> = number | string | boolean | undefined | NodeProxy<T> | X[]
|
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
export const SWIZZLES = ['x', 'y', 'z', 'w', 'r', 'g', 'b', 'a', 's', 't', 'p', 'q'] as const
|
|
2
2
|
|
|
3
|
+
// Unified order with TYPE_MAPPING array
|
|
4
|
+
export const CONVERSIONS = [
|
|
5
|
+
'toBool',
|
|
6
|
+
'toUint',
|
|
7
|
+
'toInt',
|
|
8
|
+
'toFloat',
|
|
9
|
+
'toBvec2',
|
|
10
|
+
'toIvec2',
|
|
11
|
+
'toUvec2',
|
|
12
|
+
'toVec2',
|
|
13
|
+
'toBvec3',
|
|
14
|
+
'toIvec3',
|
|
15
|
+
'toUvec3',
|
|
16
|
+
'toVec3',
|
|
17
|
+
'toBvec4',
|
|
18
|
+
'toIvec4',
|
|
19
|
+
'toUvec4',
|
|
20
|
+
'toVec4',
|
|
21
|
+
'toColor',
|
|
22
|
+
'toMat2',
|
|
23
|
+
'toMat3',
|
|
24
|
+
'toMat4',
|
|
25
|
+
] as const
|
|
26
|
+
|
|
27
|
+
// Unified order with CONVERSIONS array
|
|
3
28
|
export const TYPE_MAPPING = {
|
|
4
29
|
bool: 'bool',
|
|
5
30
|
uint: 'u32',
|
|
@@ -28,29 +53,6 @@ export const TYPE_MAPPING = {
|
|
|
28
53
|
|
|
29
54
|
export const CONSTANTS = Object.keys(TYPE_MAPPING) as unknown as keyof typeof TYPE_MAPPING
|
|
30
55
|
|
|
31
|
-
export const CONVERSIONS = [
|
|
32
|
-
'toBool',
|
|
33
|
-
'toUint',
|
|
34
|
-
'toInt',
|
|
35
|
-
'toFloat',
|
|
36
|
-
'toBvec2',
|
|
37
|
-
'toIvec2',
|
|
38
|
-
'toUvec2',
|
|
39
|
-
'toVec2',
|
|
40
|
-
'toBvec3',
|
|
41
|
-
'toIvec3',
|
|
42
|
-
'toUvec3',
|
|
43
|
-
'toVec3',
|
|
44
|
-
'toBvec4',
|
|
45
|
-
'toIvec4',
|
|
46
|
-
'toUvec4',
|
|
47
|
-
'toVec4',
|
|
48
|
-
'toColor',
|
|
49
|
-
'toMat2',
|
|
50
|
-
'toMat3',
|
|
51
|
-
'toMat4',
|
|
52
|
-
] as const
|
|
53
|
-
|
|
54
56
|
export const OPERATORS = {
|
|
55
57
|
add: '+',
|
|
56
58
|
sub: '-',
|
|
@@ -74,84 +76,6 @@ export const OPERATORS = {
|
|
|
74
76
|
|
|
75
77
|
export const OPERATOR_KEYS = Object.keys(OPERATORS) as (keyof typeof OPERATORS)[]
|
|
76
78
|
|
|
77
|
-
// All shader functions (type inference now handled by inferFrom)
|
|
78
|
-
export const FUNCTIONS = [
|
|
79
|
-
// Float return functions
|
|
80
|
-
'dot',
|
|
81
|
-
'distance',
|
|
82
|
-
'length',
|
|
83
|
-
'lengthSq',
|
|
84
|
-
'determinant',
|
|
85
|
-
'luminance',
|
|
86
|
-
// Bool return functions
|
|
87
|
-
'all',
|
|
88
|
-
'any',
|
|
89
|
-
// Component-wise functions (preserve input type)
|
|
90
|
-
'abs',
|
|
91
|
-
'sign',
|
|
92
|
-
'floor',
|
|
93
|
-
'ceil',
|
|
94
|
-
'round',
|
|
95
|
-
'fract',
|
|
96
|
-
'trunc',
|
|
97
|
-
'sin',
|
|
98
|
-
'cos',
|
|
99
|
-
'tan',
|
|
100
|
-
'asin',
|
|
101
|
-
'acos',
|
|
102
|
-
'atan',
|
|
103
|
-
'sinh',
|
|
104
|
-
'cosh',
|
|
105
|
-
'tanh',
|
|
106
|
-
'asinh',
|
|
107
|
-
'acosh',
|
|
108
|
-
'atanh',
|
|
109
|
-
'exp',
|
|
110
|
-
'exp2',
|
|
111
|
-
'log',
|
|
112
|
-
'log2',
|
|
113
|
-
'sqrt',
|
|
114
|
-
'inverseSqrt',
|
|
115
|
-
'normalize',
|
|
116
|
-
'oneMinus',
|
|
117
|
-
'saturate',
|
|
118
|
-
'negate',
|
|
119
|
-
'reciprocal',
|
|
120
|
-
'dFdx',
|
|
121
|
-
'dFdy',
|
|
122
|
-
'fwidth',
|
|
123
|
-
'degrees',
|
|
124
|
-
'radians',
|
|
125
|
-
// Vector functions
|
|
126
|
-
'cross',
|
|
127
|
-
'reflect',
|
|
128
|
-
'refract',
|
|
129
|
-
// Multi-argument functions
|
|
130
|
-
'min',
|
|
131
|
-
'max',
|
|
132
|
-
'mix',
|
|
133
|
-
'clamp',
|
|
134
|
-
'step',
|
|
135
|
-
'smoothstep',
|
|
136
|
-
'pow',
|
|
137
|
-
'atan2',
|
|
138
|
-
// Texture functions
|
|
139
|
-
'texture',
|
|
140
|
-
'textureLod',
|
|
141
|
-
'textureSize',
|
|
142
|
-
'cubeTexture',
|
|
143
|
-
// Utility functions
|
|
144
|
-
'faceforward',
|
|
145
|
-
'bitcast',
|
|
146
|
-
'cbrt',
|
|
147
|
-
'difference',
|
|
148
|
-
'equals',
|
|
149
|
-
'pow2',
|
|
150
|
-
'pow3',
|
|
151
|
-
'pow4',
|
|
152
|
-
'transformDirection',
|
|
153
|
-
] as const
|
|
154
|
-
|
|
155
79
|
export const COMPONENT_COUNT_TO_TYPE = {
|
|
156
80
|
1: 'float',
|
|
157
81
|
2: 'vec2',
|
|
@@ -161,24 +85,6 @@ export const COMPONENT_COUNT_TO_TYPE = {
|
|
|
161
85
|
16: 'mat4',
|
|
162
86
|
} as const
|
|
163
87
|
|
|
164
|
-
// Function return type mapping for method chaining
|
|
165
|
-
export const FUNCTION_RETURN_TYPES = {
|
|
166
|
-
// Always return vec4
|
|
167
|
-
texture: 'vec4',
|
|
168
|
-
cubeTexture: 'vec4',
|
|
169
|
-
textureSize: 'vec4',
|
|
170
|
-
// Always return float
|
|
171
|
-
length: 'float',
|
|
172
|
-
lengthSq: 'float',
|
|
173
|
-
distance: 'float',
|
|
174
|
-
dot: 'float',
|
|
175
|
-
// Always return bool
|
|
176
|
-
all: 'bool',
|
|
177
|
-
any: 'bool',
|
|
178
|
-
// Always return vec3
|
|
179
|
-
cross: 'vec3',
|
|
180
|
-
} as const
|
|
181
|
-
|
|
182
88
|
export const BUILTIN_TYPES = {
|
|
183
89
|
// WGSL builtin variables
|
|
184
90
|
position: 'vec4',
|
|
@@ -189,6 +95,7 @@ export const BUILTIN_TYPES = {
|
|
|
189
95
|
sample_index: 'uint',
|
|
190
96
|
sample_mask: 'uint',
|
|
191
97
|
point_coord: 'vec2',
|
|
98
|
+
global_invocation_id: 'uvec3',
|
|
192
99
|
|
|
193
100
|
// TSL compatible variables
|
|
194
101
|
positionLocal: 'vec3',
|
|
@@ -238,3 +145,88 @@ export const WGSL_TO_GLSL_BUILTIN = {
|
|
|
238
145
|
point_coord: 'gl_PointCoord',
|
|
239
146
|
uv: 'gl_FragCoord.xy',
|
|
240
147
|
} as const
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 2.1. unified with:
|
|
151
|
+
* 1.1. index.ts functions and
|
|
152
|
+
* 3.1. types.ts BaseNodeProxy
|
|
153
|
+
*/
|
|
154
|
+
// Function return type mapping for method chaining
|
|
155
|
+
export const FUNCTION_RETURN_TYPES = {
|
|
156
|
+
// 0. Always return bool
|
|
157
|
+
all: 'bool',
|
|
158
|
+
any: 'bool',
|
|
159
|
+
// 2. Always return float
|
|
160
|
+
determinant: 'float',
|
|
161
|
+
distance: 'float',
|
|
162
|
+
dot: 'float',
|
|
163
|
+
length: 'float',
|
|
164
|
+
lengthSq: 'float',
|
|
165
|
+
luminance: 'float',
|
|
166
|
+
// 3. Always return vec3
|
|
167
|
+
cross: 'vec3',
|
|
168
|
+
// 4. Always return vec4
|
|
169
|
+
cubeTexture: 'vec4',
|
|
170
|
+
texture: 'vec4',
|
|
171
|
+
texelFetch: 'vec4',
|
|
172
|
+
textureLod: 'vec4',
|
|
173
|
+
} as const
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 2.2. unified with:
|
|
177
|
+
* 1.2. index.ts functions and
|
|
178
|
+
* 3.2. types.ts BaseNodeProxy
|
|
179
|
+
*/
|
|
180
|
+
// All shader functions (type inference now handled by inferFrom)
|
|
181
|
+
export const FUNCTIONS = [
|
|
182
|
+
...(Object.keys(FUNCTION_RETURN_TYPES) as (keyof typeof FUNCTION_RETURN_TYPES)[]),
|
|
183
|
+
// 0. Component-wise functions
|
|
184
|
+
'abs',
|
|
185
|
+
'acos',
|
|
186
|
+
'acosh',
|
|
187
|
+
'asin',
|
|
188
|
+
'asinh',
|
|
189
|
+
'atan',
|
|
190
|
+
'atanh',
|
|
191
|
+
'ceil',
|
|
192
|
+
'cos',
|
|
193
|
+
'cosh',
|
|
194
|
+
'dFdx',
|
|
195
|
+
'dFdy',
|
|
196
|
+
'degrees',
|
|
197
|
+
'exp',
|
|
198
|
+
'exp2',
|
|
199
|
+
'floor',
|
|
200
|
+
'fract',
|
|
201
|
+
'fwidth',
|
|
202
|
+
'inverseSqrt',
|
|
203
|
+
'log',
|
|
204
|
+
'log2',
|
|
205
|
+
'negate',
|
|
206
|
+
'normalize',
|
|
207
|
+
'oneMinus',
|
|
208
|
+
'radians',
|
|
209
|
+
'reciprocal',
|
|
210
|
+
'round',
|
|
211
|
+
'saturate',
|
|
212
|
+
'sign',
|
|
213
|
+
'sin',
|
|
214
|
+
'sinh',
|
|
215
|
+
'sqrt',
|
|
216
|
+
'tan',
|
|
217
|
+
'tanh',
|
|
218
|
+
'trunc',
|
|
219
|
+
// 1. Functions where first argument determines return type
|
|
220
|
+
'atan2',
|
|
221
|
+
'clamp',
|
|
222
|
+
'max',
|
|
223
|
+
'min',
|
|
224
|
+
'mix',
|
|
225
|
+
'pow',
|
|
226
|
+
'reflect',
|
|
227
|
+
'refract',
|
|
228
|
+
// 2. Functions where not first argument determines return type
|
|
229
|
+
'smoothstep',
|
|
230
|
+
'step',
|
|
231
|
+
// @NOTE: mod is operator
|
|
232
|
+
] as const
|